open-core 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.travis.yml +15 -0
- data/.yardopts +8 -0
- data/CONTRIBUTING.md +48 -0
- data/Gemfile +15 -0
- data/Guardfile +5 -0
- data/LICENSE.txt +202 -0
- data/README.md +83 -0
- data/Rakefile +4 -0
- data/examples/create_account.rb +26 -0
- data/examples/low_level_transaction_post.rb +46 -0
- data/examples/mid_level_transaction_post.rb +33 -0
- data/examples/non_native_payment.rb +60 -0
- data/examples/offer.rb +75 -0
- data/examples/transaction_merge.rb +23 -0
- data/generated/stellar-base-generated.rb +134 -0
- data/generated/stellar/account_entry.rb +53 -0
- data/generated/stellar/account_entry/ext.rb +24 -0
- data/generated/stellar/account_flags.rb +27 -0
- data/generated/stellar/account_merge_result.rb +26 -0
- data/generated/stellar/account_merge_result_code.rb +30 -0
- data/generated/stellar/allow_trust_op.rb +38 -0
- data/generated/stellar/allow_trust_op/asset.rb +33 -0
- data/generated/stellar/allow_trust_result.rb +25 -0
- data/generated/stellar/allow_trust_result_code.rb +31 -0
- data/generated/stellar/asset.rb +47 -0
- data/generated/stellar/asset/alpha_num12.rb +22 -0
- data/generated/stellar/asset/alpha_num4.rb +22 -0
- data/generated/stellar/asset_type.rb +24 -0
- data/generated/stellar/bucket_entry.rb +28 -0
- data/generated/stellar/bucket_entry_type.rb +22 -0
- data/generated/stellar/change_trust_op.rb +22 -0
- data/generated/stellar/change_trust_result.rb +25 -0
- data/generated/stellar/change_trust_result_code.rb +30 -0
- data/generated/stellar/claim_offer_atom.rb +33 -0
- data/generated/stellar/create_account_op.rb +20 -0
- data/generated/stellar/create_account_result.rb +25 -0
- data/generated/stellar/create_account_result_code.rb +32 -0
- data/generated/stellar/create_passive_offer_op.rb +24 -0
- data/generated/stellar/crypto_key_type.rb +20 -0
- data/generated/stellar/decorated_signature.rb +20 -0
- data/generated/stellar/dont_have.rb +20 -0
- data/generated/stellar/envelope_type.rb +22 -0
- data/generated/stellar/error.rb +20 -0
- data/generated/stellar/hello.rb +26 -0
- data/generated/stellar/inflation_payout.rb +20 -0
- data/generated/stellar/inflation_result.rb +26 -0
- data/generated/stellar/inflation_result_code.rb +24 -0
- data/generated/stellar/ledger_entry.rb +44 -0
- data/generated/stellar/ledger_entry/data.rb +33 -0
- data/generated/stellar/ledger_entry/ext.rb +24 -0
- data/generated/stellar/ledger_entry_change.rb +31 -0
- data/generated/stellar/ledger_entry_change_type.rb +24 -0
- data/generated/stellar/ledger_entry_type.rb +24 -0
- data/generated/stellar/ledger_header.rb +65 -0
- data/generated/stellar/ledger_header/ext.rb +24 -0
- data/generated/stellar/ledger_header_history_entry.rb +33 -0
- data/generated/stellar/ledger_header_history_entry/ext.rb +24 -0
- data/generated/stellar/ledger_key.rb +50 -0
- data/generated/stellar/ledger_key/account.rb +20 -0
- data/generated/stellar/ledger_key/offer.rb +22 -0
- data/generated/stellar/ledger_key/trust_line.rb +22 -0
- data/generated/stellar/ledger_upgrade.rb +27 -0
- data/generated/stellar/ledger_upgrade_type.rb +22 -0
- data/generated/stellar/manage_offer_effect.rb +24 -0
- data/generated/stellar/manage_offer_op.rb +28 -0
- data/generated/stellar/manage_offer_result.rb +26 -0
- data/generated/stellar/manage_offer_result_code.rb +48 -0
- data/generated/stellar/manage_offer_success_result.rb +34 -0
- data/generated/stellar/manage_offer_success_result/offer.rb +30 -0
- data/generated/stellar/memo.rb +38 -0
- data/generated/stellar/memo_type.rb +28 -0
- data/generated/stellar/message_type.rb +45 -0
- data/generated/stellar/offer_entry.rb +49 -0
- data/generated/stellar/offer_entry/ext.rb +24 -0
- data/generated/stellar/offer_entry_flags.rb +21 -0
- data/generated/stellar/operation.rb +51 -0
- data/generated/stellar/operation/body.rb +60 -0
- data/generated/stellar/operation_meta.rb +18 -0
- data/generated/stellar/operation_result.rb +53 -0
- data/generated/stellar/operation_result/tr.rb +61 -0
- data/generated/stellar/operation_result_code.rb +25 -0
- data/generated/stellar/operation_type.rb +38 -0
- data/generated/stellar/path_payment_op.rb +32 -0
- data/generated/stellar/path_payment_result.rb +34 -0
- data/generated/stellar/path_payment_result/success.rb +22 -0
- data/generated/stellar/path_payment_result_code.rb +45 -0
- data/generated/stellar/payment_op.rb +22 -0
- data/generated/stellar/payment_result.rb +25 -0
- data/generated/stellar/payment_result_code.rb +39 -0
- data/generated/stellar/peer_address.rb +22 -0
- data/generated/stellar/price.rb +20 -0
- data/generated/stellar/public_key.rb +23 -0
- data/generated/stellar/scp_ballot.rb +20 -0
- data/generated/stellar/scp_envelope.rb +20 -0
- data/generated/stellar/scp_nomination.rb +22 -0
- data/generated/stellar/scp_quorum_set.rb +22 -0
- data/generated/stellar/scp_statement.rb +59 -0
- data/generated/stellar/scp_statement/pledges.rb +64 -0
- data/generated/stellar/scp_statement/pledges/confirm.rb +28 -0
- data/generated/stellar/scp_statement/pledges/externalize.rb +28 -0
- data/generated/stellar/scp_statement/pledges/prepare.rb +32 -0
- data/generated/stellar/scp_statement_type.rb +26 -0
- data/generated/stellar/set_options_op.rb +41 -0
- data/generated/stellar/set_options_result.rb +25 -0
- data/generated/stellar/set_options_result_code.rb +38 -0
- data/generated/stellar/signer.rb +20 -0
- data/generated/stellar/simple_payment_result.rb +22 -0
- data/generated/stellar/stellar_message.rb +66 -0
- data/generated/stellar/stellar_value.rb +40 -0
- data/generated/stellar/stellar_value/ext.rb +24 -0
- data/generated/stellar/threshold_indexes.rb +26 -0
- data/generated/stellar/time_bounds.rb +20 -0
- data/generated/stellar/transaction.rb +50 -0
- data/generated/stellar/transaction/ext.rb +24 -0
- data/generated/stellar/transaction_envelope.rb +20 -0
- data/generated/stellar/transaction_history_entry.rb +33 -0
- data/generated/stellar/transaction_history_entry/ext.rb +24 -0
- data/generated/stellar/transaction_history_result_entry.rb +33 -0
- data/generated/stellar/transaction_history_result_entry/ext.rb +24 -0
- data/generated/stellar/transaction_meta.rb +31 -0
- data/generated/stellar/transaction_meta/v0.rb +22 -0
- data/generated/stellar/transaction_result.rb +43 -0
- data/generated/stellar/transaction_result/ext.rb +24 -0
- data/generated/stellar/transaction_result/result.rb +30 -0
- data/generated/stellar/transaction_result_code.rb +45 -0
- data/generated/stellar/transaction_result_pair.rb +20 -0
- data/generated/stellar/transaction_result_set.rb +18 -0
- data/generated/stellar/transaction_set.rb +20 -0
- data/generated/stellar/trust_line_entry.rb +41 -0
- data/generated/stellar/trust_line_entry/ext.rb +24 -0
- data/generated/stellar/trust_line_flags.rb +21 -0
- data/lib/stellar-base.rb +32 -0
- data/lib/stellar/account_flags.rb +28 -0
- data/lib/stellar/asset.rb +69 -0
- data/lib/stellar/base.rb +1 -0
- data/lib/stellar/base/version.rb +5 -0
- data/lib/stellar/convert.rb +32 -0
- data/lib/stellar/key_pair.rb +112 -0
- data/lib/stellar/networks.rb +45 -0
- data/lib/stellar/operation.rb +304 -0
- data/lib/stellar/path_payment_result.rb +17 -0
- data/lib/stellar/price.rb +32 -0
- data/lib/stellar/thresholds.rb +39 -0
- data/lib/stellar/transaction.rb +170 -0
- data/lib/stellar/transaction_envelope.rb +32 -0
- data/lib/stellar/util/continued_fraction.rb +96 -0
- data/lib/stellar/util/strkey.rb +43 -0
- data/open-core.gemspec +37 -0
- data/spec/lib/stellar/account_flags_spec.rb +19 -0
- data/spec/lib/stellar/asset_spec.rb +45 -0
- data/spec/lib/stellar/convert_spec.rb +61 -0
- data/spec/lib/stellar/key_pair_spec.rb +238 -0
- data/spec/lib/stellar/networks_spec.rb +77 -0
- data/spec/lib/stellar/path_payment_result_spec.rb +95 -0
- data/spec/lib/stellar/price_spec.rb +34 -0
- data/spec/lib/stellar/thresholds_spec.rb +62 -0
- data/spec/lib/stellar/transaction_envelope_spec.rb +93 -0
- data/spec/lib/stellar/transaction_spec.rb +54 -0
- data/spec/lib/stellar/util/strkey_spec.rb +46 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/matchers/be_strkey.rb +9 -0
- data/spec/support/matchers/eq_bytes.rb +5 -0
- data/spec/support/matchers/have_length.rb +5 -0
- data/tasks/rspec.rake +6 -0
- data/tasks/travis.rake +1 -0
- data/tasks/xdr.rake +50 -0
- data/xdr/Stellar-SCP.x +87 -0
- data/xdr/Stellar-ledger-entries.x +222 -0
- data/xdr/Stellar-ledger.x +231 -0
- data/xdr/Stellar-overlay.x +87 -0
- data/xdr/Stellar-transaction.x +670 -0
- data/xdr/Stellar-types.x +34 -0
- metadata +444 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Stellar::AccountFlags do
|
|
4
|
+
subject{ Stellar::AccountFlags }
|
|
5
|
+
let(:raw) { 3 }
|
|
6
|
+
let(:result) { subject.parse_mask raw }
|
|
7
|
+
|
|
8
|
+
it "parses correctly" do
|
|
9
|
+
expect(subject.parse_mask(1)).to eq([Stellar::AccountFlags.auth_required_flag])
|
|
10
|
+
expect(subject.parse_mask(2)).to eq([Stellar::AccountFlags.auth_revocable_flag])
|
|
11
|
+
expect(subject.parse_mask(3)).to eq([Stellar::AccountFlags.auth_required_flag, Stellar::AccountFlags.auth_revocable_flag])
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "makes correctly" do
|
|
15
|
+
expect(subject.make_mask([Stellar::AccountFlags.auth_required_flag])).to eq(1)
|
|
16
|
+
expect(subject.make_mask([Stellar::AccountFlags.auth_revocable_flag])).to eq(2)
|
|
17
|
+
expect(subject.make_mask([Stellar::AccountFlags.auth_required_flag, Stellar::AccountFlags.auth_revocable_flag])).to eq(3)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Stellar::Asset, ".native" do
|
|
4
|
+
it "returns a asset instance whose type is 'AssetType.asset_type_native'" do
|
|
5
|
+
expect(Stellar::Asset.native.type).to eq(Stellar::AssetType.asset_type_native)
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe Stellar::Asset, ".alphanum4" do
|
|
10
|
+
it "returns a asset instance whose type is 'AssetType.asset_type_credit_alphanum4'" do
|
|
11
|
+
result = Stellar::Asset.alphanum4("USD", Stellar::KeyPair.master)
|
|
12
|
+
expect(result.type).to eq(Stellar::AssetType.asset_type_credit_alphanum4)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "pads the code to 4 bytes, padding on the right and with null bytes" do
|
|
16
|
+
result = Stellar::Asset.alphanum4("USD", Stellar::KeyPair.master)
|
|
17
|
+
expect(result.code).to eq("USD\x00")
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe Stellar::Asset, ".alphanum12" do
|
|
22
|
+
it "returns a asset instance whose type is 'AssetType.asset_type_credit_alphanum12'" do
|
|
23
|
+
result = Stellar::Asset.alphanum12("USD", Stellar::KeyPair.master)
|
|
24
|
+
expect(result.type).to eq(Stellar::AssetType.asset_type_credit_alphanum12)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "pads the code to 12 bytes, padding on the right and with null bytes" do
|
|
28
|
+
result = Stellar::Asset.alphanum12("USD", Stellar::KeyPair.master)
|
|
29
|
+
expect(result.code).to eq("USD\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe Stellar::Asset, "#code" do
|
|
34
|
+
it "returns the asset_code for either alphanum4 or alphanum12 assets" do
|
|
35
|
+
a4 = Stellar::Asset.alphanum4("USD", Stellar::KeyPair.master)
|
|
36
|
+
a12 = Stellar::Asset.alphanum12("USD", Stellar::KeyPair.master)
|
|
37
|
+
|
|
38
|
+
expect(a4.code.strip).to eq("USD")
|
|
39
|
+
expect(a12.code.strip).to eq("USD")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "raises an error when called on a native asset" do
|
|
43
|
+
expect{ Stellar::Asset.native.code }.to raise_error(RuntimeError)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Stellar::Convert do
|
|
4
|
+
subject{ Stellar::Convert }
|
|
5
|
+
let(:raw) { "\x01\x02\x03\x04" }
|
|
6
|
+
let(:hex) { "01020304" }
|
|
7
|
+
let(:base64){ "AQIDBA==" }
|
|
8
|
+
|
|
9
|
+
describe "hex encoding" do
|
|
10
|
+
it "decodes" do
|
|
11
|
+
expect(subject.from_hex(hex)).to eq(raw)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "encodes" do
|
|
15
|
+
expect(subject.to_hex(raw)).to eq(hex)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "round trips" do
|
|
19
|
+
raw1 = subject.from_hex(hex)
|
|
20
|
+
hex1 = subject.to_hex(raw1)
|
|
21
|
+
expect(hex1).to eq(hex)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
hex2 = subject.to_hex(raw)
|
|
25
|
+
raw2 = subject.from_hex(hex2)
|
|
26
|
+
expect(raw2).to eq(raw)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe "base64 encoding" do
|
|
31
|
+
it "decodes" do
|
|
32
|
+
expect(subject.from_base64(base64)).to eq(raw)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "encodes" do
|
|
36
|
+
expect(subject.to_base64(raw)).to eq(base64)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "round trips" do
|
|
40
|
+
raw1 = subject.from_base64(base64)
|
|
41
|
+
base641 = subject.to_base64(raw1)
|
|
42
|
+
expect(base641).to eq(base64)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
base642 = subject.to_base64(raw)
|
|
46
|
+
raw2 = subject.from_base64(base642)
|
|
47
|
+
expect(raw2).to eq(raw)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
describe "#pk_to_address" do
|
|
53
|
+
let(:pk_raw){ "\x00" * 32 }
|
|
54
|
+
let(:pk_account_id){ Stellar::AccountID.new(:key_type_ed25519, pk_raw)}
|
|
55
|
+
|
|
56
|
+
it "converts a Stellar::AccountID into an address using StrKey.check_encode(:account_id)" do
|
|
57
|
+
address = Stellar::Util::StrKey.check_encode(:account_id, pk_raw)
|
|
58
|
+
expect(subject.pk_to_address(pk_account_id)).to eql(address)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require "spec_helper"
|
|
3
|
+
|
|
4
|
+
describe Stellar::KeyPair do
|
|
5
|
+
|
|
6
|
+
describe ".from_seed" do
|
|
7
|
+
subject{ Stellar::KeyPair.from_seed(seed) }
|
|
8
|
+
|
|
9
|
+
context "when provided a strkey encoded seed" do
|
|
10
|
+
let(:seed){ "SBDA4J4PYZJEXWDTHFZBIGFVF2745BTKDKADWDQF72QXP55BP6XOV3B6" }
|
|
11
|
+
it { should be_a(Stellar::KeyPair) }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context "provided value is not strkey encoded" do
|
|
15
|
+
let(:seed){ "allmylifemyhearthasbeensearching" }
|
|
16
|
+
it { expect{ subject }.to raise_error(ArgumentError) }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
context "provided value is not strkey encoded as a seed" do
|
|
20
|
+
let(:raw_seed){ "allmylifemyhearthasbeensearching" }
|
|
21
|
+
let(:seed){ Stellar::Util::StrKey.check_encode(:account_id, raw_seed) }
|
|
22
|
+
it { expect{ subject }.to raise_error(ArgumentError) }
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe ".from_raw_seed" do
|
|
27
|
+
subject{ Stellar::KeyPair.from_raw_seed(raw_seed) }
|
|
28
|
+
|
|
29
|
+
context "when the provided value is a 32-byte string" do
|
|
30
|
+
let(:raw_seed){ "allmylifemyhearthasbeensearching" }
|
|
31
|
+
it { should be_a(Stellar::KeyPair) }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context "when the provided value is < 32-byte string" do
|
|
35
|
+
let(:raw_seed){ "\xFF" * 31 }
|
|
36
|
+
it { expect{ subject }.to raise_error(ArgumentError) }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
context "when the provided value is > 32-byte string" do
|
|
40
|
+
let(:raw_seed){ "\xFF" * 33 }
|
|
41
|
+
it { expect{ subject }.to raise_error(ArgumentError) }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context "when the provided value is a 32 character, but > 32 byte string (i.e. multi-byte characters)" do
|
|
45
|
+
let(:raw_seed){ "ü" + ("\x00" * 31) }
|
|
46
|
+
it { expect{ subject }.to raise_error(ArgumentError) }
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe ".from_public_key" do
|
|
51
|
+
subject{ Stellar::KeyPair.from_public_key(key) }
|
|
52
|
+
|
|
53
|
+
context "when the provided value is a 32-byte string" do
|
|
54
|
+
let(:key){ "\xFF" * 32 }
|
|
55
|
+
it { should be_a(Stellar::KeyPair) }
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
context "when the provided value is < 32-byte string" do
|
|
59
|
+
let(:key){ "\xFF" * 31 }
|
|
60
|
+
it { expect{ subject }.to raise_error(ArgumentError) }
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
context "when the provided value is > 32-byte string" do
|
|
64
|
+
let(:key){ "\xFF" * 33 }
|
|
65
|
+
it { expect{ subject }.to raise_error(ArgumentError) }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
context "when the provided value is a 32 character, but > 32 byte string (i.e. multi-byte characters)" do
|
|
69
|
+
let(:key){ "ü" + ("\x00" * 31) }
|
|
70
|
+
it { expect{ subject }.to raise_error(ArgumentError) }
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
describe ".from_address" do
|
|
75
|
+
subject{ Stellar::KeyPair.from_address(address) }
|
|
76
|
+
|
|
77
|
+
context "when provided a strkey encoded account_id" do
|
|
78
|
+
let(:address){ "GBRAINV4XDXEINVTNN53GOIGTN4B3BK65N6Q2ZBOMXHGHT347OQVNYZQ" }
|
|
79
|
+
it { should be_a(Stellar::KeyPair) }
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
context "provided value is not strkey encoded" do
|
|
83
|
+
let(:address){ "some address" }
|
|
84
|
+
it { expect{ subject }.to raise_error(ArgumentError) }
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
context "provided value is not strkey encoded as an account_id" do
|
|
88
|
+
let(:public_key){ "\xFF" * 32 }
|
|
89
|
+
let(:address){ Stellar::Util::StrKey.check_encode(:seed, public_key) }
|
|
90
|
+
it { expect{ subject }.to raise_error(ArgumentError) }
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
describe ".random" do
|
|
96
|
+
subject{ Stellar::KeyPair.random }
|
|
97
|
+
|
|
98
|
+
it "returns a new KeyPair every time" do
|
|
99
|
+
other = Stellar::KeyPair.random
|
|
100
|
+
expect(subject.raw_seed == other.raw_seed).to eq(false)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
describe ".master" do
|
|
105
|
+
subject{ Stellar::KeyPair.master }
|
|
106
|
+
|
|
107
|
+
it "returns a keypair whose raw_seed is the current_network_id" do
|
|
108
|
+
expect(subject.raw_seed).to eql(Stellar.current_network_id)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
describe "#raw_public_key" do
|
|
113
|
+
let(:key_pair){ Stellar::KeyPair.random }
|
|
114
|
+
subject{ key_pair.raw_public_key }
|
|
115
|
+
|
|
116
|
+
it { should be_a(String) }
|
|
117
|
+
it { should have_length(32) }
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
describe "#public_key" do
|
|
121
|
+
let(:key_pair){ Stellar::KeyPair.random }
|
|
122
|
+
subject{ key_pair.public_key }
|
|
123
|
+
|
|
124
|
+
it { should be_a(Stellar::PublicKey) }
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
describe "#account_id" do
|
|
128
|
+
let(:key_pair){ Stellar::KeyPair.random }
|
|
129
|
+
subject{ key_pair.account_id }
|
|
130
|
+
|
|
131
|
+
it { should be_a(Stellar::AccountID) }
|
|
132
|
+
|
|
133
|
+
it "contains the public key" do
|
|
134
|
+
expect(subject.ed25519!).to eql(key_pair.raw_public_key)
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
describe "#raw_seed" do
|
|
139
|
+
let(:key_pair){ Stellar::KeyPair.random }
|
|
140
|
+
subject{ key_pair.raw_seed }
|
|
141
|
+
|
|
142
|
+
it { should be_a(String) }
|
|
143
|
+
it { should have_length(32) }
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
describe "#signature_hint" do
|
|
147
|
+
let(:key_pair){ Stellar::KeyPair.random }
|
|
148
|
+
subject{ key_pair.signature_hint }
|
|
149
|
+
|
|
150
|
+
it { should be_a(String) }
|
|
151
|
+
it { should have_length(4) }
|
|
152
|
+
|
|
153
|
+
it "is the last 4 bytes of the encoded account_id" do
|
|
154
|
+
expected = key_pair.account_id.to_xdr[-4..-1]
|
|
155
|
+
expect(subject).to eql(expected)
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
describe "#address" do
|
|
160
|
+
let(:key_pair){ Stellar::KeyPair.random }
|
|
161
|
+
subject{ key_pair.address }
|
|
162
|
+
it{ should be_strkey(:account_id)}
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
describe "#seed" do
|
|
166
|
+
let(:key_pair){ Stellar::KeyPair.random }
|
|
167
|
+
subject{ key_pair.seed }
|
|
168
|
+
it{ should be_strkey(:seed)}
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
describe "#sign" do
|
|
172
|
+
let(:message) { "hello" }
|
|
173
|
+
subject{ key_pair.sign(message) }
|
|
174
|
+
|
|
175
|
+
context "when the key_pair has no private key" do
|
|
176
|
+
let(:key_pair){ Stellar::KeyPair.from_public_key("\x00" * 32)}
|
|
177
|
+
|
|
178
|
+
it{ expect{ subject }.to raise_error("no private key") }
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
context "when the key_pair has both public/private keys" do
|
|
182
|
+
let(:key_pair){ Stellar::KeyPair.from_raw_seed("\x00" * 32)}
|
|
183
|
+
|
|
184
|
+
it { should have_length(64) }
|
|
185
|
+
|
|
186
|
+
it "should be a ed25519 signature" do
|
|
187
|
+
verification = key_pair.rbnacl_verify_key.verify(subject, message)
|
|
188
|
+
expect(verification).to be_truthy
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
context "when the message is nil" do
|
|
192
|
+
let(:message){ nil }
|
|
193
|
+
it { expect{subject}.to raise_error(TypeError) }
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
describe "#verify" do
|
|
199
|
+
let(:key_pair) { Stellar::KeyPair.random }
|
|
200
|
+
let(:message) { "hello" }
|
|
201
|
+
subject { key_pair.verify(signature, message) }
|
|
202
|
+
|
|
203
|
+
context "when the signature is correct" do
|
|
204
|
+
let(:signature) { key_pair.sign(message) }
|
|
205
|
+
it{ should be_truthy }
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
context "when the signature is incorrect" do
|
|
209
|
+
let(:signature) { key_pair.sign("some other message") }
|
|
210
|
+
it{ should be_falsey }
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
context "when the signature is invalid" do
|
|
214
|
+
let(:signature) { "food" }
|
|
215
|
+
it{ should be_falsey }
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
context "when the signature is from a different key" do
|
|
219
|
+
let(:signature) { Stellar::KeyPair.random.sign(message) }
|
|
220
|
+
it{ should be_falsey }
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
describe "#sign?" do
|
|
226
|
+
subject{ key_pair.sign? }
|
|
227
|
+
|
|
228
|
+
context "when the key_pair has no private key" do
|
|
229
|
+
let(:key_pair){ Stellar::KeyPair.from_public_key("\x00" * 32)}
|
|
230
|
+
it{ should eq(false) }
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
context "when the key_pair has both public/private keys" do
|
|
234
|
+
let(:key_pair){ Stellar::KeyPair.from_raw_seed("\x00" * 32)}
|
|
235
|
+
it{ should eq(true) }
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Stellar, ".default_network=" do
|
|
4
|
+
|
|
5
|
+
before(:each){ Stellar.default_network = "foo" }
|
|
6
|
+
after(:each){ Stellar.default_network = nil }
|
|
7
|
+
|
|
8
|
+
it "sets the value returned by current_network " do
|
|
9
|
+
expect(Stellar.current_network).to eql("foo")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe Stellar, ".current_network" do
|
|
15
|
+
|
|
16
|
+
after(:each){ Stellar.default_network = nil }
|
|
17
|
+
|
|
18
|
+
it "returns the public network absent any other configuration" do
|
|
19
|
+
expect(Stellar.current_network).to eql(Stellar::Networks::PUBLIC)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "returns the default network if configured and not within a call to on_network" do
|
|
23
|
+
Stellar.default_network = "foo"
|
|
24
|
+
expect(Stellar.current_network).to eql("foo")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "returns the network as specified by on_network, even when a default is set" do
|
|
28
|
+
Stellar.default_network = "foo"
|
|
29
|
+
|
|
30
|
+
Stellar.on_network "bar" do
|
|
31
|
+
expect(Stellar.current_network).to eql("bar")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
expect(Stellar.current_network).to eql("foo")
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe Stellar, ".current_network_id" do
|
|
39
|
+
it "returns the sha256 of the current_network" do
|
|
40
|
+
expect(Stellar.current_network_id).to eql(Digest::SHA256.digest(Stellar.current_network))
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe Stellar, ".on_network" do
|
|
45
|
+
|
|
46
|
+
after(:each){ Thread.current["stellar_network_passphrase"] = nil }
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
it "sets the current_network and a thread local" do
|
|
50
|
+
Stellar.on_network "bar" do
|
|
51
|
+
expect(Stellar.current_network).to eql("bar")
|
|
52
|
+
expect(Thread.current["stellar_network_passphrase"]).to eql("bar")
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
it "nests" do
|
|
58
|
+
Stellar.on_network "foo" do
|
|
59
|
+
expect(Stellar.current_network).to eql("foo")
|
|
60
|
+
Stellar.on_network "bar" do
|
|
61
|
+
expect(Stellar.current_network).to eql("bar")
|
|
62
|
+
end
|
|
63
|
+
expect(Stellar.current_network).to eql("foo")
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
it "resets the network value when an error is raised" do
|
|
69
|
+
begin
|
|
70
|
+
Stellar.on_network "foo" do
|
|
71
|
+
raise "kablow"
|
|
72
|
+
end
|
|
73
|
+
rescue
|
|
74
|
+
expect(Stellar.current_network).to_not eql("foo")
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Stellar::PathPaymentResult, "#send_amount" do
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
context "when the result is not successful" do
|
|
7
|
+
subject{ Stellar::PathPaymentResult.new(:path_payment_malformed) }
|
|
8
|
+
|
|
9
|
+
it "raises an exception if the result is not successful" do
|
|
10
|
+
expect{ subject.send_amount }.to raise_error(XDR::ArmNotSetError)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context "when the result has no claimed offers" do
|
|
15
|
+
let(:simple_success){ Stellar::SimplePaymentResult.new(amount: 100) }
|
|
16
|
+
let(:path_success){ Stellar::PathPaymentResult::Success.new(last: simple_success) }
|
|
17
|
+
|
|
18
|
+
subject{ Stellar::PathPaymentResult.new(:path_payment_success, path_success) }
|
|
19
|
+
|
|
20
|
+
it "returns the amount from the 'last' component" do
|
|
21
|
+
expect(subject.send_amount).to eql(100)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
context "with simple 1-hop result" do
|
|
27
|
+
let(:simple_success){ Stellar::SimplePaymentResult.new(amount: 100) }
|
|
28
|
+
let(:offers) do
|
|
29
|
+
[Stellar::ClaimOfferAtom.new(asset_bought: Stellar::Asset.native, amount_bought: 200)]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
let(:path_success) do
|
|
33
|
+
Stellar::PathPaymentResult::Success.new({
|
|
34
|
+
offers: offers,
|
|
35
|
+
last: simple_success,
|
|
36
|
+
})
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
subject{ Stellar::PathPaymentResult.new(:path_payment_success, path_success) }
|
|
40
|
+
|
|
41
|
+
it "returns the amount from the ClaimOfferAtom" do
|
|
42
|
+
expect(subject.send_amount).to eql(200)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context "with 1-hop result that claimed multiple offers" do
|
|
47
|
+
let(:simple_success){ Stellar::SimplePaymentResult.new(amount: 100) }
|
|
48
|
+
let(:offers) do
|
|
49
|
+
[
|
|
50
|
+
Stellar::ClaimOfferAtom.new(asset_bought: Stellar::Asset.native, amount_bought: 200),
|
|
51
|
+
Stellar::ClaimOfferAtom.new(asset_bought: Stellar::Asset.native, amount_bought: 200),
|
|
52
|
+
]
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
let(:path_success) do
|
|
56
|
+
Stellar::PathPaymentResult::Success.new({
|
|
57
|
+
offers: offers,
|
|
58
|
+
last: simple_success,
|
|
59
|
+
})
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
subject{ Stellar::PathPaymentResult.new(:path_payment_success, path_success) }
|
|
63
|
+
|
|
64
|
+
it "returns the summed amount from the ClaimOfferAtoms" do
|
|
65
|
+
expect(subject.send_amount).to eql(400)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
context "with multi-hop result that claimed multiple offers" do
|
|
71
|
+
let(:simple_success){ Stellar::SimplePaymentResult.new(amount: 100) }
|
|
72
|
+
let(:otherAsset){ Stellar::Asset.alphanum4("USD", Stellar::KeyPair.random) }
|
|
73
|
+
let(:offers) do
|
|
74
|
+
[
|
|
75
|
+
Stellar::ClaimOfferAtom.new(asset_bought: Stellar::Asset.native, amount_bought: 200),
|
|
76
|
+
Stellar::ClaimOfferAtom.new(asset_bought: Stellar::Asset.native, amount_bought: 200),
|
|
77
|
+
Stellar::ClaimOfferAtom.new(asset_bought: otherAsset, amount_bought: 200),
|
|
78
|
+
]
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
let(:path_success) do
|
|
82
|
+
Stellar::PathPaymentResult::Success.new({
|
|
83
|
+
offers: offers,
|
|
84
|
+
last: simple_success,
|
|
85
|
+
})
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
subject{ Stellar::PathPaymentResult.new(:path_payment_success, path_success) }
|
|
89
|
+
|
|
90
|
+
it "returns the summed amount from the ClaimOfferAtoms" do
|
|
91
|
+
expect(subject.send_amount).to eql(400)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
end
|