stellar-base 0.21.0 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -2
  3. data/{LICENSE.txt → LICENSE} +0 -0
  4. data/README.md +3 -4
  5. data/generated/stellar-base-generated.rb +25 -1
  6. data/generated/stellar/allow_trust_op.rb +3 -2
  7. data/generated/stellar/authenticated_message.rb +4 -4
  8. data/generated/stellar/authenticated_message/v0.rb +4 -4
  9. data/generated/stellar/change_trust_result_code.rb +1 -1
  10. data/generated/stellar/crypto_key_type.rb +8 -4
  11. data/generated/stellar/curve25519_public.rb +1 -1
  12. data/generated/stellar/curve25519_secret.rb +1 -1
  13. data/generated/stellar/envelope_type.rb +9 -5
  14. data/generated/stellar/fee_bump_transaction.rb +39 -0
  15. data/generated/stellar/fee_bump_transaction/ext.rb +24 -0
  16. data/generated/stellar/fee_bump_transaction/inner_tx.rb +25 -0
  17. data/generated/stellar/fee_bump_transaction_envelope.rb +22 -0
  18. data/generated/stellar/hmac_sha256_key.rb +1 -1
  19. data/generated/stellar/hmac_sha256_mac.rb +1 -1
  20. data/generated/stellar/inner_transaction_result.rb +56 -0
  21. data/generated/stellar/inner_transaction_result/ext.rb +24 -0
  22. data/generated/stellar/inner_transaction_result/result.rb +52 -0
  23. data/generated/stellar/inner_transaction_result_pair.rb +20 -0
  24. data/generated/stellar/ledger_close_meta.rb +23 -0
  25. data/generated/stellar/ledger_close_meta_v0.rb +35 -0
  26. data/generated/stellar/manage_buy_offer_result_code.rb +5 -4
  27. data/generated/stellar/manage_sell_offer_result_code.rb +12 -8
  28. data/generated/stellar/message_type.rb +6 -1
  29. data/generated/stellar/muxed_account.rb +35 -0
  30. data/generated/stellar/muxed_account/med25519.rb +22 -0
  31. data/generated/stellar/operation.rb +3 -3
  32. data/generated/stellar/operation/body.rb +2 -2
  33. data/generated/stellar/operation_result.rb +1 -1
  34. data/generated/stellar/operation_result/tr.rb +1 -1
  35. data/generated/stellar/operation_result_code.rb +3 -3
  36. data/generated/stellar/path_payment_strict_receive_op.rb +4 -4
  37. data/generated/stellar/path_payment_strict_receive_result_code.rb +21 -12
  38. data/generated/stellar/path_payment_strict_send_op.rb +6 -6
  39. data/generated/stellar/path_payment_strict_send_result_code.rb +20 -12
  40. data/generated/stellar/payment_op.rb +4 -4
  41. data/generated/stellar/peer_stats.rb +48 -0
  42. data/generated/stellar/signed_survey_request_message.rb +20 -0
  43. data/generated/stellar/signed_survey_response_message.rb +20 -0
  44. data/generated/stellar/stellar_message.rb +22 -12
  45. data/generated/stellar/survey_message_command_type.rb +20 -0
  46. data/generated/stellar/survey_request_message.rb +26 -0
  47. data/generated/stellar/survey_response_body.rb +23 -0
  48. data/generated/stellar/survey_response_message.rb +26 -0
  49. data/generated/stellar/topology_response_body.rb +25 -0
  50. data/generated/stellar/transaction.rb +2 -2
  51. data/generated/stellar/transaction_envelope.rb +17 -8
  52. data/generated/stellar/transaction_meta.rb +4 -0
  53. data/generated/stellar/transaction_meta_v2.rb +24 -0
  54. data/generated/stellar/transaction_result.rb +3 -0
  55. data/generated/stellar/transaction_result/result.rb +9 -3
  56. data/generated/stellar/transaction_result_code.rb +21 -14
  57. data/generated/stellar/transaction_result_meta.rb +22 -0
  58. data/generated/stellar/transaction_signature_payload.rb +3 -1
  59. data/generated/stellar/transaction_signature_payload/tagged_transaction.rb +7 -3
  60. data/generated/stellar/transaction_v0.rb +39 -0
  61. data/generated/stellar/transaction_v0/ext.rb +24 -0
  62. data/generated/stellar/transaction_v0_envelope.rb +22 -0
  63. data/generated/stellar/transaction_v1_envelope.rb +22 -0
  64. data/generated/stellar/trust_line_flags.rb +6 -2
  65. data/generated/stellar/upgrade_entry_meta.rb +20 -0
  66. data/lib/stellar-base.rb +27 -24
  67. data/lib/stellar/account_flags.rb +2 -4
  68. data/lib/stellar/asset.rb +6 -6
  69. data/lib/stellar/base.rb +1 -1
  70. data/lib/stellar/{base/compat.rb → compat.rb} +6 -7
  71. data/lib/stellar/concerns/transaction.rb +49 -0
  72. data/lib/stellar/convert.rb +2 -2
  73. data/lib/stellar/factories.rb +1 -3
  74. data/lib/stellar/fee_bump_transaction.rb +21 -0
  75. data/lib/stellar/key_pair.rb +9 -6
  76. data/lib/stellar/networks.rb +5 -7
  77. data/lib/stellar/operation.rb +426 -392
  78. data/lib/stellar/path_payment_strict_receive_result.rb +1 -2
  79. data/lib/stellar/price.rb +2 -4
  80. data/lib/stellar/signer_key.rb +4 -8
  81. data/lib/stellar/thresholds.rb +5 -7
  82. data/lib/stellar/transaction.rb +154 -187
  83. data/lib/stellar/transaction_builder.rb +149 -0
  84. data/lib/stellar/transaction_envelope.rb +40 -8
  85. data/lib/stellar/transaction_v0.rb +39 -0
  86. data/lib/stellar/util/continued_fraction.rb +19 -19
  87. data/lib/stellar/util/strkey.rb +39 -14
  88. data/lib/stellar/{base/version.rb → version.rb} +1 -1
  89. metadata +50 -204
  90. data/.gitignore +0 -17
  91. data/.travis.yml +0 -16
  92. data/.yardopts +0 -8
  93. data/CONTRIBUTING.md +0 -48
  94. data/Gemfile +0 -15
  95. data/Guardfile +0 -5
  96. data/Rakefile +0 -4
  97. data/examples/allow_trust.rb +0 -51
  98. data/examples/create_account.rb +0 -26
  99. data/examples/low_level_transaction_post.rb +0 -46
  100. data/examples/mid_level_transaction_post.rb +0 -33
  101. data/examples/non_native_payment.rb +0 -60
  102. data/examples/offer.rb +0 -75
  103. data/examples/transaction_merge.rb +0 -23
  104. data/ruby-stellar-base.gemspec +0 -34
  105. data/spec/lib/stellar/account_flags_spec.rb +0 -19
  106. data/spec/lib/stellar/asset_spec.rb +0 -45
  107. data/spec/lib/stellar/convert_spec.rb +0 -61
  108. data/spec/lib/stellar/key_pair_spec.rb +0 -251
  109. data/spec/lib/stellar/networks_spec.rb +0 -77
  110. data/spec/lib/stellar/operation_spec.rb +0 -133
  111. data/spec/lib/stellar/path_payment_strict_receive_result_spec.rb +0 -95
  112. data/spec/lib/stellar/price_spec.rb +0 -34
  113. data/spec/lib/stellar/signer_key_spec.rb +0 -26
  114. data/spec/lib/stellar/thresholds_spec.rb +0 -62
  115. data/spec/lib/stellar/transaction_envelope_spec.rb +0 -93
  116. data/spec/lib/stellar/transaction_spec.rb +0 -132
  117. data/spec/lib/stellar/util/strkey_spec.rb +0 -54
  118. data/spec/spec_helper.rb +0 -16
  119. data/spec/support/matchers/be_strkey.rb +0 -9
  120. data/spec/support/matchers/eq_bytes.rb +0 -5
  121. data/spec/support/matchers/have_length.rb +0 -5
  122. data/tasks/rspec.rake +0 -6
  123. data/tasks/travis.rake +0 -1
  124. data/tasks/xdr.rake +0 -45
  125. data/xdr/Stellar-SCP.x +0 -86
  126. data/xdr/Stellar-ledger-entries.x +0 -295
  127. data/xdr/Stellar-ledger.x +0 -318
  128. data/xdr/Stellar-overlay.x +0 -146
  129. data/xdr/Stellar-transaction.x +0 -901
  130. data/xdr/Stellar-types.x +0 -81
@@ -1,133 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Stellar::Operation, ".payment" do
4
-
5
-
6
- it "correctly translates the provided amount to the native representation" do
7
- op = Stellar::Operation.payment(destination: Stellar::KeyPair.random, amount: [:native, 20])
8
- expect(op.body.value.amount).to eql(20_0000000)
9
- op = Stellar::Operation.payment(destination: Stellar::KeyPair.random, amount: [:native, "20"])
10
- expect(op.body.value.amount).to eql(20_0000000)
11
- end
12
-
13
- end
14
-
15
- def pk_to_address(pk)
16
- Stellar::Convert.pk_to_address(pk)
17
- end
18
-
19
- describe "path payment operations" do
20
- let(:destination){ Stellar::KeyPair.random }
21
- let(:send_asset_issuer){ Stellar::KeyPair.master }
22
- let(:send_asset){ Stellar::Asset.alphanum4("USD", send_asset_issuer) }
23
- let(:dest_asset_issuer){ Stellar::KeyPair.master }
24
- let(:dest_asset){ Stellar::Asset.alphanum4("EUR", dest_asset_issuer) }
25
- let(:amount){ [:alphanum4, dest_asset.code, dest_asset_issuer, 9.2] }
26
- let(:with){ [:alphanum4, send_asset.code, send_asset_issuer, 10] }
27
-
28
- describe Stellar::Operation, ".path_payment" do
29
- it "works" do
30
- destination = Stellar::KeyPair.random
31
- amount = [:alphanum4, "USD", Stellar::KeyPair.master, 10]
32
- with = [:alphanum4, "EUR", Stellar::KeyPair.master, 9.2]
33
-
34
- op = Stellar::Operation.path_payment(
35
- destination: destination,
36
- amount: amount,
37
- with: with
38
- )
39
-
40
- expect(op.body.arm).to eql(:path_payment_strict_receive_op)
41
- end
42
- end
43
-
44
- describe Stellar::Operation, ".path_payment_strict_receive" do
45
- it "works" do
46
- op = Stellar::Operation.path_payment_strict_receive(
47
- destination: destination,
48
- amount: amount,
49
- with: with
50
- )
51
-
52
- expect(op.body.arm).to eql(:path_payment_strict_receive_op)
53
- expect(op.body.value.destination).to eql(destination.public_key)
54
- expect(op.body.value.send_asset).to eql(send_asset)
55
- expect(op.body.value.dest_asset).to eql(dest_asset)
56
- expect(op.body.value.send_max).to eq(100000000)
57
- expect(op.body.value.dest_amount).to eq(92000000)
58
- end
59
- end
60
-
61
- describe Stellar::Operation, ".path_payment_strict_send" do
62
- it "works" do
63
- op = Stellar::Operation.path_payment_strict_send(
64
- destination: destination,
65
- amount: amount,
66
- with: with
67
- )
68
-
69
- expect(op.body.arm).to eql(:path_payment_strict_send_op)
70
- expect(op.body.value.destination).to eql(destination.public_key)
71
- expect(op.body.value.send_asset).to eql(send_asset)
72
- expect(op.body.value.dest_asset).to eql(dest_asset)
73
- expect(op.body.value.send_amount).to eq(100000000)
74
- expect(op.body.value.dest_min).to eq(92000000)
75
- end
76
- end
77
- end
78
-
79
- describe Stellar::Operation, ".manage_data" do
80
-
81
- it "works" do
82
- op = Stellar::Operation.manage_data(name: "my name", value: "hello")
83
- expect(op.body.manage_data_op!.data_name).to eql("my name")
84
- expect(op.body.manage_data_op!.data_value).to eql("hello")
85
- expect{ op.to_xdr }.to_not raise_error
86
-
87
- op = Stellar::Operation.manage_data(name: "my name")
88
- expect(op.body.manage_data_op!.data_name).to eql("my name")
89
- expect(op.body.manage_data_op!.data_value).to be_nil
90
- expect{ op.to_xdr }.to_not raise_error
91
- end
92
-
93
- end
94
-
95
- describe Stellar::Operation, ".change_trust" do
96
-
97
- let(:issuer) { Stellar::KeyPair.from_address("GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7") }
98
- let(:asset) { Stellar::Asset.alphanum4("USD", issuer) }
99
-
100
- it "creates a ChangeTrustOp" do
101
- op = Stellar::Operation.change_trust(line: [:alphanum4, "USD", issuer])
102
- expect(op.body.value).to be_an_instance_of(Stellar::ChangeTrustOp)
103
- expect(op.body.value.line).to eq(Stellar::Asset.alphanum4("USD", issuer))
104
- expect(op.body.value.limit).to eq(9223372036854775807)
105
- end
106
-
107
- it "creates a ChangeTrustOp with an asset" do
108
- asset = Stellar::Asset.alphanum4("USD", issuer)
109
- op = Stellar::Operation.change_trust(line: asset, limit: 1234.75)
110
- expect(op.body.value).to be_an_instance_of(Stellar::ChangeTrustOp)
111
- expect(op.body.value.line).to eq(Stellar::Asset.alphanum4("USD", issuer))
112
- expect(op.body.value.limit).to eq(12347500000)
113
- end
114
-
115
- it "only allow sound `line` arguments" do
116
- expect {
117
- Stellar::Operation.change_trust(line: [:harmful_call, "USD", issuer])
118
- }.to raise_error(ArgumentError, "must be one of #{Stellar::Asset::TYPES}")
119
- end
120
-
121
- it "creates a ChangeTrustOp with limit" do
122
- op = Stellar::Operation.change_trust(line: [:alphanum4, "USD", issuer], limit: 1234.75)
123
- expect(op.body.value).to be_an_instance_of(Stellar::ChangeTrustOp)
124
- expect(op.body.value.line).to eq(Stellar::Asset.alphanum4("USD", issuer))
125
- expect(op.body.value.limit).to eq(12347500000)
126
- end
127
-
128
- it "throws ArgumentError for incorrect limit argument" do
129
- expect {
130
- Stellar::Operation.change_trust(line: [:alphanum4, "USD", issuer], limit: true)
131
- }.to raise_error(ArgumentError)
132
- end
133
- end
@@ -1,95 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Stellar::PathPaymentStrictReceiveResult, "#send_amount" do
4
-
5
-
6
- context "when the result is not successful" do
7
- subject{ Stellar::PathPaymentStrictReceiveResult.new(:path_payment_strict_receive_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::PathPaymentStrictReceiveResult::Success.new(last: simple_success) }
17
-
18
- subject{ Stellar::PathPaymentStrictReceiveResult.new(:path_payment_strict_receive_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::PathPaymentStrictReceiveResult::Success.new({
34
- offers: offers,
35
- last: simple_success,
36
- })
37
- end
38
-
39
- subject{ Stellar::PathPaymentStrictReceiveResult.new(:path_payment_strict_receive_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::PathPaymentStrictReceiveResult::Success.new({
57
- offers: offers,
58
- last: simple_success,
59
- })
60
- end
61
-
62
- subject{ Stellar::PathPaymentStrictReceiveResult.new(:path_payment_strict_receive_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::PathPaymentStrictReceiveResult::Success.new({
83
- offers: offers,
84
- last: simple_success,
85
- })
86
- end
87
-
88
- subject{ Stellar::PathPaymentStrictReceiveResult.new(:path_payment_strict_receive_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
@@ -1,34 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Stellar::Price, "#from_f" do
4
- subject{ Stellar::Price }
5
- let(:seed){ 225571644875421139403973254661022579608 } #generated using Random.new
6
- let(:random){ Random.new(seed) }
7
- let(:iterations){ ENV["SMOKE_ITERATIONS"].present? ? ENV["SMOKE_ITERATIONS"].to_i : 2000}
8
-
9
- it "withstands a random smoke test" do
10
- iterations.times do |i|
11
- expected = random.rand
12
- actual_p = subject.from_f(expected)
13
- actual = actual_p.to_f
14
-
15
- expect(actual).to be_within(0.000000001).of(actual)
16
- expect(actual_p.n).to be <= Stellar::Price::MAX_PRECISION
17
- expect(actual_p.d).to be <= Stellar::Price::MAX_PRECISION
18
- end
19
- end
20
-
21
- it "works with bigdecimal" do
22
- whole = random.rand(1_000_000)
23
- fractional = random.rand(10_000_000) # seven significant digits available for fractional
24
-
25
- expected = BigDecimal("#{whole}.#{fractional}")
26
- actual_p = subject.from_f(expected)
27
- actual = BigDecimal(actual_p.n) / BigDecimal(actual_p.d)
28
-
29
- expect(actual).to be_within(BigDecimal("0.000000001")).of(actual)
30
- expect(actual_p.n).to be <= Stellar::Price::MAX_PRECISION
31
- expect(actual_p.d).to be <= Stellar::Price::MAX_PRECISION
32
- end
33
-
34
- end
@@ -1,26 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Stellar::SignerKey, ".hash_x" do
4
-
5
- subject{ Stellar::SignerKey }
6
-
7
- let(:hash_preimage){ "a" * 32 }
8
- let(:hash){ Digest::SHA256.digest(hash_preimage) }
9
-
10
- it "raises an argument error when not provided a 32-byte string" do
11
- expect{subject.hash_x("hello world")}.to raise_error(ArgumentError)
12
- expect{subject.hash_x("")}.to raise_error(ArgumentError)
13
- expect{subject.hash_x("a" * 31)}.to raise_error(ArgumentError)
14
- expect{subject.hash_x("a" * 33)}.to raise_error(ArgumentError)
15
- expect{subject.hash_x([0] * 32)}.to raise_error(ArgumentError)
16
-
17
- end
18
-
19
- it "creates a HashX signer key" do
20
- sk = subject.hash_x(hash_preimage)
21
- expect(sk.switch).to eq(Stellar::SignerKeyType.signer_key_type_hash_x)
22
- expect(sk.value).to be_an_instance_of(String)
23
- expect(sk.value).to eq(hash)
24
- end
25
-
26
- end
@@ -1,62 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Stellar::Thresholds, ".parse" do
4
- subject{ Stellar::Thresholds }
5
- let(:raw) { "\x01\x02\x03\x04" }
6
- let(:result) { subject.parse raw }
7
-
8
- it "sets master_weight as the 1st byte" do
9
- expect(result[:master_weight]).to eq(1)
10
- end
11
-
12
- it "sets low as the 2nd byte" do
13
- expect(result[:low]).to eq(2)
14
- end
15
-
16
- it "sets medium as the 3rd byte" do
17
- expect(result[:medium]).to eq(3)
18
- end
19
-
20
- it "sets high as the 4th byte" do
21
- expect(result[:high]).to eq(4)
22
- end
23
- end
24
-
25
- describe Stellar::Thresholds, ".make" do
26
- subject{ Stellar::Thresholds }
27
- let(:good){{master_weight: 1, low: 2, medium: 3, high: 4}}
28
-
29
- it "works" do
30
- expect(subject.make(good)).to eq("\x01\x02\x03\x04")
31
- end
32
-
33
- it "errors unless all components are provided" do
34
- expect{ subject.make(good.except(:master_weight)) }.to raise_error(ArgumentError)
35
- expect{ subject.make(good.except(:low)) }.to raise_error(ArgumentError)
36
- expect{ subject.make(good.except(:medium)) }.to raise_error(ArgumentError)
37
- expect{ subject.make(good.except(:high)) }.to raise_error(ArgumentError)
38
- end
39
-
40
- it "errors unless all components are numbers" do
41
- expect{ subject.make(good.merge(master_weight: "hello")) }.to raise_error(ArgumentError)
42
- expect{ subject.make(good.merge(low: "hello")) }.to raise_error(ArgumentError)
43
- expect{ subject.make(good.merge(medium: "hello")) }.to raise_error(ArgumentError)
44
- expect{ subject.make(good.merge(high: "hello")) }.to raise_error(ArgumentError)
45
- end
46
-
47
- it "errors unless all components are in (0..255)" do
48
- expect{ subject.make(good.merge(master_weight: -1)) }.to raise_error(ArgumentError)
49
- expect{ subject.make(good.merge(master_weight: 256)) }.to raise_error(ArgumentError)
50
- expect{ subject.make(good.merge(low: -1)) }.to raise_error(ArgumentError)
51
- expect{ subject.make(good.merge(low: 256)) }.to raise_error(ArgumentError)
52
- expect{ subject.make(good.merge(medium: -1)) }.to raise_error(ArgumentError)
53
- expect{ subject.make(good.merge(medium: 256)) }.to raise_error(ArgumentError)
54
- expect{ subject.make(good.merge(high: -1)) }.to raise_error(ArgumentError)
55
- expect{ subject.make(good.merge(high: 256)) }.to raise_error(ArgumentError)
56
- end
57
-
58
- it "ignores additional keys" do
59
- expect{ subject.make(good.merge(foo: "a string")) }.not_to raise_error
60
- end
61
-
62
- end
@@ -1,93 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Stellar::TransactionEnvelope do
4
- let(:sender) { Stellar::KeyPair.random }
5
- let(:receiver){ Stellar::KeyPair.random }
6
- let(:transaction) do
7
- Stellar::Transaction.payment({
8
- account: sender,
9
- destination: receiver,
10
- sequence: 1,
11
- amount: [:native, 20000000]
12
- })
13
- end
14
-
15
- let(:envelope){ transaction.to_envelope(*signers) }
16
-
17
- describe "#signed_correctly?" do
18
- subject{ envelope.signed_correctly?(*verifiers) }
19
-
20
- context "when unsigned" do
21
- let(:signers) { [] }
22
- let(:verifiers){ [sender] }
23
-
24
- it{ should be_falsey }
25
- end
26
-
27
- context "when signed by a single account" do
28
- let(:signers) { [sender] }
29
- let(:verifiers){ signers }
30
-
31
- context "and signed correctly" do
32
- it{ should be_truthy }
33
- end
34
-
35
- context "and the signature is corrupted" do
36
- before(:each){ envelope.signatures.first.signature = "\xFF" * 32}
37
- it{ should be_falsey }
38
- end
39
-
40
- context "and the signature is from a different message" do
41
- before(:each){ envelope.signatures = [sender.sign_decorated("hello")]}
42
- it{ should be_falsey }
43
- end
44
-
45
- context "and the key for the signing account is not provided" do
46
- let(:verifiers){ [] }
47
- it{ should be_falsey }
48
- end
49
-
50
- context "and the key for the signing account is wrong" do
51
- let(:verifiers){ [receiver] }
52
- it{ should be_falsey }
53
- end
54
- end
55
-
56
- context "when signed by a multiple accounts" do
57
- let(:alternate_signer){ Stellar::KeyPair.random }
58
- let(:signers) { [sender, alternate_signer] }
59
- let(:verifiers){ signers }
60
-
61
- context "and all public keys are provided" do
62
- it{ should be_truthy }
63
- end
64
-
65
- context "and all public keys are provided, with additional unused keys provided" do
66
- let(:verifiers){ signers + [Stellar::KeyPair.random] }
67
- it{ should be_truthy }
68
- end
69
-
70
- context "and not all public keys for the signers are provided" do
71
- let(:verifiers){ [alternate_signer] }
72
- it{ should be_falsey }
73
- end
74
-
75
- context "and one of the signatures is corrupted" do
76
- before(:each){ envelope.signatures.last.signature = "\xFF" * 32}
77
- it{ should be_falsey }
78
- end
79
-
80
- context "and the signature is from a different message" do
81
- before(:each){ envelope.signatures = signers.map{|s| s.sign_decorated("hello")}}
82
- it{ should be_falsey }
83
- end
84
- end
85
-
86
- end
87
-
88
- describe "#hash" do
89
- let(:signers) { [sender] }
90
- subject{ envelope.hash }
91
- it{ should eq(Digest::SHA256.digest envelope.to_xdr)}
92
- end
93
- end