stellar-base 0.19.0 → 0.23.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/{LICENSE.txt → LICENSE} +0 -0
  3. data/README.md +2 -3
  4. data/generated/stellar-base-generated.rb +45 -8
  5. data/generated/stellar/allow_trust_op.rb +5 -4
  6. data/generated/stellar/allow_trust_op/asset.rb +4 -4
  7. data/generated/stellar/asset.rb +2 -2
  8. data/generated/stellar/asset/alpha_num12.rb +2 -2
  9. data/generated/stellar/asset/alpha_num4.rb +2 -2
  10. data/generated/stellar/authenticated_message.rb +4 -4
  11. data/generated/stellar/authenticated_message/v0.rb +4 -4
  12. data/generated/stellar/bucket_entry.rb +6 -0
  13. data/generated/stellar/bucket_entry_type.rb +8 -2
  14. data/generated/stellar/bucket_metadata.rb +32 -0
  15. data/generated/stellar/bucket_metadata/ext.rb +24 -0
  16. data/generated/stellar/claim_offer_atom.rb +2 -2
  17. data/generated/stellar/{create_passive_offer_op.rb → create_passive_sell_offer_op.rb} +2 -2
  18. data/generated/stellar/crypto_key_type.rb +8 -4
  19. data/generated/stellar/curve25519_public.rb +1 -1
  20. data/generated/stellar/curve25519_secret.rb +1 -1
  21. data/generated/stellar/envelope_type.rb +10 -4
  22. data/generated/stellar/fee_bump_transaction.rb +39 -0
  23. data/generated/stellar/fee_bump_transaction/ext.rb +24 -0
  24. data/generated/stellar/fee_bump_transaction/inner_tx.rb +25 -0
  25. data/generated/stellar/fee_bump_transaction_envelope.rb +22 -0
  26. data/generated/stellar/hmac_sha256_key.rb +1 -1
  27. data/generated/stellar/hmac_sha256_mac.rb +1 -1
  28. data/generated/stellar/inner_transaction_result.rb +56 -0
  29. data/generated/stellar/inner_transaction_result/ext.rb +24 -0
  30. data/generated/stellar/inner_transaction_result/result.rb +52 -0
  31. data/generated/stellar/inner_transaction_result_pair.rb +20 -0
  32. data/generated/stellar/ledger_close_meta.rb +23 -0
  33. data/generated/stellar/ledger_close_meta_v0.rb +35 -0
  34. data/generated/stellar/ledger_close_value_signature.rb +20 -0
  35. data/generated/stellar/ledger_key.rb +1 -1
  36. data/generated/stellar/ledger_key/offer.rb +2 -2
  37. data/generated/stellar/manage_buy_offer_op.rb +29 -0
  38. data/generated/stellar/{manage_offer_result.rb → manage_buy_offer_result.rb} +5 -5
  39. data/generated/stellar/manage_buy_offer_result_code.rb +51 -0
  40. data/generated/stellar/{manage_offer_op.rb → manage_sell_offer_op.rb} +4 -4
  41. data/generated/stellar/manage_sell_offer_result.rb +26 -0
  42. data/generated/stellar/manage_sell_offer_result_code.rb +54 -0
  43. data/generated/stellar/message_type.rb +6 -1
  44. data/generated/stellar/muxed_account.rb +35 -0
  45. data/generated/stellar/muxed_account/med25519.rb +22 -0
  46. data/generated/stellar/offer_entry.rb +2 -2
  47. data/generated/stellar/operation.rb +13 -9
  48. data/generated/stellar/operation/body.rb +37 -29
  49. data/generated/stellar/operation_result.rb +10 -6
  50. data/generated/stellar/operation_result/tr.rb +38 -30
  51. data/generated/stellar/operation_result_code.rb +11 -7
  52. data/generated/stellar/operation_type.rb +20 -16
  53. data/generated/stellar/{path_payment_op.rb → path_payment_strict_receive_op.rb} +6 -6
  54. data/generated/stellar/path_payment_strict_receive_result.rb +38 -0
  55. data/generated/stellar/path_payment_strict_receive_result/success.rb +22 -0
  56. data/generated/stellar/path_payment_strict_receive_result_code.rb +56 -0
  57. data/generated/stellar/path_payment_strict_send_op.rb +32 -0
  58. data/generated/stellar/{path_payment_result.rb → path_payment_strict_send_result.rb} +7 -7
  59. data/generated/stellar/{path_payment_result → path_payment_strict_send_result}/success.rb +1 -1
  60. data/generated/stellar/path_payment_strict_send_result_code.rb +55 -0
  61. data/generated/stellar/payment_op.rb +4 -4
  62. data/generated/stellar/peer_stats.rb +48 -0
  63. data/generated/stellar/signed_survey_request_message.rb +20 -0
  64. data/generated/stellar/signed_survey_response_message.rb +20 -0
  65. data/generated/stellar/signer.rb +1 -1
  66. data/generated/stellar/stellar_message.rb +22 -12
  67. data/generated/stellar/stellar_value.rb +7 -5
  68. data/generated/stellar/stellar_value/ext.rb +8 -4
  69. data/generated/stellar/stellar_value_type.rb +22 -0
  70. data/generated/stellar/survey_message_command_type.rb +20 -0
  71. data/generated/stellar/survey_request_message.rb +26 -0
  72. data/generated/stellar/survey_response_body.rb +23 -0
  73. data/generated/stellar/survey_response_message.rb +26 -0
  74. data/generated/stellar/time_bounds.rb +4 -4
  75. data/generated/stellar/topology_response_body.rb +25 -0
  76. data/generated/stellar/transaction.rb +4 -4
  77. data/generated/stellar/transaction_envelope.rb +17 -8
  78. data/generated/stellar/transaction_meta.rb +4 -0
  79. data/generated/stellar/transaction_meta_v1.rb +1 -1
  80. data/generated/stellar/transaction_meta_v2.rb +24 -0
  81. data/generated/stellar/transaction_result.rb +3 -0
  82. data/generated/stellar/transaction_result/result.rb +9 -3
  83. data/generated/stellar/transaction_result_code.rb +21 -14
  84. data/generated/stellar/transaction_result_meta.rb +22 -0
  85. data/generated/stellar/transaction_signature_payload.rb +3 -1
  86. data/generated/stellar/transaction_signature_payload/tagged_transaction.rb +7 -3
  87. data/generated/stellar/transaction_v0.rb +39 -0
  88. data/generated/stellar/transaction_v0/ext.rb +24 -0
  89. data/generated/stellar/transaction_v0_envelope.rb +22 -0
  90. data/generated/stellar/transaction_v1_envelope.rb +22 -0
  91. data/generated/stellar/trust_line_flags.rb +6 -2
  92. data/generated/stellar/upgrade_entry_meta.rb +20 -0
  93. data/lib/stellar-base.rb +28 -23
  94. data/lib/stellar/account_flags.rb +2 -4
  95. data/lib/stellar/asset.rb +6 -6
  96. data/lib/stellar/base.rb +1 -1
  97. data/lib/stellar/compat.rb +21 -0
  98. data/lib/stellar/concerns/transaction.rb +49 -0
  99. data/lib/stellar/convert.rb +2 -2
  100. data/lib/stellar/factories.rb +1 -3
  101. data/lib/stellar/fee_bump_transaction.rb +21 -0
  102. data/lib/stellar/key_pair.rb +9 -6
  103. data/lib/stellar/networks.rb +5 -7
  104. data/lib/stellar/operation.rb +428 -317
  105. data/lib/stellar/{path_payment_result.rb → path_payment_strict_receive_result.rb} +2 -3
  106. data/lib/stellar/price.rb +2 -4
  107. data/lib/stellar/signer_key.rb +4 -8
  108. data/lib/stellar/thresholds.rb +5 -7
  109. data/lib/stellar/transaction.rb +154 -169
  110. data/lib/stellar/transaction_builder.rb +149 -0
  111. data/lib/stellar/transaction_envelope.rb +40 -8
  112. data/lib/stellar/transaction_v0.rb +39 -0
  113. data/lib/stellar/util/continued_fraction.rb +19 -19
  114. data/lib/stellar/util/strkey.rb +39 -14
  115. data/lib/stellar/{base/version.rb → version.rb} +1 -1
  116. metadata +68 -210
  117. data/.gitignore +0 -17
  118. data/.travis.yml +0 -13
  119. data/.yardopts +0 -8
  120. data/CHANGELOG.md +0 -120
  121. data/CONTRIBUTING.md +0 -48
  122. data/Gemfile +0 -15
  123. data/Guardfile +0 -5
  124. data/Rakefile +0 -4
  125. data/examples/create_account.rb +0 -26
  126. data/examples/low_level_transaction_post.rb +0 -46
  127. data/examples/mid_level_transaction_post.rb +0 -33
  128. data/examples/non_native_payment.rb +0 -60
  129. data/examples/offer.rb +0 -75
  130. data/examples/transaction_merge.rb +0 -23
  131. data/generated/stellar/manage_offer_result_code.rb +0 -50
  132. data/generated/stellar/path_payment_result_code.rb +0 -47
  133. data/ruby-stellar-base.gemspec +0 -34
  134. data/spec/lib/stellar/account_flags_spec.rb +0 -19
  135. data/spec/lib/stellar/asset_spec.rb +0 -45
  136. data/spec/lib/stellar/convert_spec.rb +0 -61
  137. data/spec/lib/stellar/key_pair_spec.rb +0 -251
  138. data/spec/lib/stellar/networks_spec.rb +0 -77
  139. data/spec/lib/stellar/operation_spec.rb +0 -71
  140. data/spec/lib/stellar/path_payment_result_spec.rb +0 -95
  141. data/spec/lib/stellar/price_spec.rb +0 -34
  142. data/spec/lib/stellar/signer_key_spec.rb +0 -26
  143. data/spec/lib/stellar/thresholds_spec.rb +0 -62
  144. data/spec/lib/stellar/transaction_envelope_spec.rb +0 -93
  145. data/spec/lib/stellar/transaction_spec.rb +0 -100
  146. data/spec/lib/stellar/util/strkey_spec.rb +0 -54
  147. data/spec/spec_helper.rb +0 -16
  148. data/spec/support/matchers/be_strkey.rb +0 -9
  149. data/spec/support/matchers/eq_bytes.rb +0 -5
  150. data/spec/support/matchers/have_length.rb +0 -5
  151. data/tasks/rspec.rake +0 -6
  152. data/tasks/travis.rake +0 -1
  153. data/tasks/xdr.rake +0 -50
  154. data/xdr/Stellar-SCP.x +0 -86
  155. data/xdr/Stellar-ledger-entries.x +0 -288
  156. data/xdr/Stellar-ledger.x +0 -283
  157. data/xdr/Stellar-overlay.x +0 -146
  158. data/xdr/Stellar-transaction.x +0 -777
  159. data/xdr/Stellar-types.x +0 -81
@@ -1,77 +0,0 @@
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::TESTNET)
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
@@ -1,71 +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
-
16
- describe Stellar::Operation, ".manage_data" do
17
-
18
- it "works" do
19
- op = Stellar::Operation.manage_data(name: "my name", value: "hello")
20
- expect(op.body.manage_data_op!.data_name).to eql("my name")
21
- expect(op.body.manage_data_op!.data_value).to eql("hello")
22
- expect{ op.to_xdr }.to_not raise_error
23
-
24
- op = Stellar::Operation.manage_data(name: "my name")
25
- expect(op.body.manage_data_op!.data_name).to eql("my name")
26
- expect(op.body.manage_data_op!.data_value).to be_nil
27
- expect{ op.to_xdr }.to_not raise_error
28
- end
29
-
30
- end
31
-
32
- describe Stellar::Operation, ".change_trust" do
33
-
34
- let(:issuer) { Stellar::KeyPair.from_address("GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7") }
35
- let(:asset) { Stellar::Asset.alphanum4("USD", issuer) }
36
-
37
- it "creates a ChangeTrustOp" do
38
- op = Stellar::Operation.change_trust(line: [:alphanum4, "USD", issuer])
39
- expect(op.body.value).to be_an_instance_of(Stellar::ChangeTrustOp)
40
- expect(op.body.value.line).to eq(Stellar::Asset.alphanum4("USD", issuer))
41
- expect(op.body.value.limit).to eq(9223372036854775807)
42
- end
43
-
44
- it "creates a ChangeTrustOp with an asset" do
45
- asset = Stellar::Asset.alphanum4("USD", issuer)
46
- op = Stellar::Operation.change_trust(line: asset, limit: 1234.75)
47
- expect(op.body.value).to be_an_instance_of(Stellar::ChangeTrustOp)
48
- expect(op.body.value.line).to eq(Stellar::Asset.alphanum4("USD", issuer))
49
- expect(op.body.value.limit).to eq(12347500000)
50
- end
51
-
52
- it "only allow sound `line` arguments" do
53
- expect {
54
- Stellar::Operation.change_trust(line: [:harmful_call, "USD", issuer])
55
- }.to raise_error(ArgumentError, "must be one of #{Stellar::Asset::TYPES}")
56
- end
57
-
58
- it "creates a ChangeTrustOp with limit" do
59
- op = Stellar::Operation.change_trust(line: [:alphanum4, "USD", issuer], limit: 1234.75)
60
- expect(op.body.value).to be_an_instance_of(Stellar::ChangeTrustOp)
61
- expect(op.body.value.line).to eq(Stellar::Asset.alphanum4("USD", issuer))
62
- expect(op.body.value.limit).to eq(12347500000)
63
- end
64
-
65
- it "throws ArgumentError for incorrect limit argument" do
66
- expect {
67
- Stellar::Operation.change_trust(line: [:alphanum4, "USD", issuer], limit: true)
68
- }.to raise_error(ArgumentError)
69
- end
70
-
71
- end
@@ -1,95 +0,0 @@
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
@@ -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.new("#{whole}.#{fractional}")
26
- actual_p = subject.from_f(expected)
27
- actual = BigDecimal.new(actual_p.n) / BigDecimal.new(actual_p.d)
28
-
29
- expect(actual).to be_within(BigDecimal.new("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