stellar-base 0.22.0 → 0.23.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) 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 +10 -1
  5. data/generated/stellar/allow_trust_op.rb +3 -2
  6. data/generated/stellar/authenticated_message.rb +4 -4
  7. data/generated/stellar/authenticated_message/v0.rb +4 -4
  8. data/generated/stellar/change_trust_result_code.rb +1 -1
  9. data/generated/stellar/crypto_key_type.rb +8 -4
  10. data/generated/stellar/curve25519_public.rb +1 -1
  11. data/generated/stellar/curve25519_secret.rb +1 -1
  12. data/generated/stellar/envelope_type.rb +9 -5
  13. data/generated/stellar/fee_bump_transaction.rb +39 -0
  14. data/generated/stellar/fee_bump_transaction/ext.rb +24 -0
  15. data/generated/stellar/fee_bump_transaction/inner_tx.rb +25 -0
  16. data/generated/stellar/fee_bump_transaction_envelope.rb +22 -0
  17. data/generated/stellar/hmac_sha256_key.rb +1 -1
  18. data/generated/stellar/hmac_sha256_mac.rb +1 -1
  19. data/generated/stellar/inner_transaction_result.rb +56 -0
  20. data/generated/stellar/inner_transaction_result/ext.rb +24 -0
  21. data/generated/stellar/inner_transaction_result/result.rb +52 -0
  22. data/generated/stellar/inner_transaction_result_pair.rb +20 -0
  23. data/generated/stellar/ledger_close_meta.rb +1 -1
  24. data/generated/stellar/manage_buy_offer_result_code.rb +5 -4
  25. data/generated/stellar/manage_sell_offer_result_code.rb +12 -8
  26. data/generated/stellar/muxed_account.rb +35 -0
  27. data/generated/stellar/muxed_account/med25519.rb +22 -0
  28. data/generated/stellar/operation.rb +3 -3
  29. data/generated/stellar/operation/body.rb +2 -2
  30. data/generated/stellar/operation_result.rb +1 -1
  31. data/generated/stellar/operation_result/tr.rb +1 -1
  32. data/generated/stellar/operation_result_code.rb +3 -3
  33. data/generated/stellar/path_payment_strict_receive_op.rb +4 -4
  34. data/generated/stellar/path_payment_strict_receive_result_code.rb +21 -12
  35. data/generated/stellar/path_payment_strict_send_op.rb +6 -6
  36. data/generated/stellar/path_payment_strict_send_result_code.rb +20 -12
  37. data/generated/stellar/payment_op.rb +4 -4
  38. data/generated/stellar/survey_response_body.rb +2 -2
  39. data/generated/stellar/transaction.rb +2 -2
  40. data/generated/stellar/transaction_envelope.rb +17 -8
  41. data/generated/stellar/transaction_result.rb +3 -0
  42. data/generated/stellar/transaction_result/result.rb +9 -3
  43. data/generated/stellar/transaction_result_code.rb +21 -14
  44. data/generated/stellar/transaction_signature_payload.rb +3 -1
  45. data/generated/stellar/transaction_signature_payload/tagged_transaction.rb +7 -3
  46. data/generated/stellar/transaction_v0.rb +39 -0
  47. data/generated/stellar/transaction_v0/ext.rb +24 -0
  48. data/generated/stellar/transaction_v0_envelope.rb +22 -0
  49. data/generated/stellar/transaction_v1_envelope.rb +22 -0
  50. data/generated/stellar/trust_line_flags.rb +6 -2
  51. data/lib/stellar-base.rb +27 -25
  52. data/lib/stellar/account_flags.rb +2 -4
  53. data/lib/stellar/asset.rb +6 -6
  54. data/lib/stellar/base.rb +1 -1
  55. data/lib/stellar/{base/compat.rb → compat.rb} +6 -7
  56. data/lib/stellar/concerns/transaction.rb +49 -0
  57. data/lib/stellar/convert.rb +2 -2
  58. data/lib/stellar/factories.rb +1 -3
  59. data/lib/stellar/fee_bump_transaction.rb +21 -0
  60. data/lib/stellar/key_pair.rb +9 -6
  61. data/lib/stellar/networks.rb +5 -7
  62. data/lib/stellar/operation.rb +421 -416
  63. data/lib/stellar/path_payment_strict_receive_result.rb +1 -2
  64. data/lib/stellar/price.rb +2 -4
  65. data/lib/stellar/signer_key.rb +4 -8
  66. data/lib/stellar/thresholds.rb +5 -7
  67. data/lib/stellar/transaction.rb +154 -198
  68. data/lib/stellar/transaction_builder.rb +66 -23
  69. data/lib/stellar/transaction_envelope.rb +40 -8
  70. data/lib/stellar/transaction_v0.rb +39 -0
  71. data/lib/stellar/util/continued_fraction.rb +19 -19
  72. data/lib/stellar/util/strkey.rb +39 -14
  73. data/lib/stellar/{base/version.rb → version.rb} +1 -1
  74. metadata +33 -203
  75. data/.gitignore +0 -17
  76. data/.travis.yml +0 -16
  77. data/.yardopts +0 -8
  78. data/CHANGELOG.md +0 -149
  79. data/CONTRIBUTING.md +0 -48
  80. data/Gemfile +0 -9
  81. data/Guardfile +0 -5
  82. data/Rakefile +0 -4
  83. data/examples/allow_trust.rb +0 -51
  84. data/examples/create_account.rb +0 -26
  85. data/examples/low_level_transaction_post.rb +0 -46
  86. data/examples/mid_level_transaction_post.rb +0 -33
  87. data/examples/non_native_payment.rb +0 -60
  88. data/examples/offer.rb +0 -75
  89. data/examples/transaction_merge.rb +0 -23
  90. data/ruby-stellar-base.gemspec +0 -34
  91. data/spec/lib/stellar/account_flags_spec.rb +0 -19
  92. data/spec/lib/stellar/asset_spec.rb +0 -45
  93. data/spec/lib/stellar/convert_spec.rb +0 -61
  94. data/spec/lib/stellar/key_pair_spec.rb +0 -251
  95. data/spec/lib/stellar/networks_spec.rb +0 -77
  96. data/spec/lib/stellar/operation_spec.rb +0 -131
  97. data/spec/lib/stellar/path_payment_strict_receive_result_spec.rb +0 -95
  98. data/spec/lib/stellar/price_spec.rb +0 -34
  99. data/spec/lib/stellar/signer_key_spec.rb +0 -26
  100. data/spec/lib/stellar/thresholds_spec.rb +0 -62
  101. data/spec/lib/stellar/transaction_builder_spec.rb +0 -263
  102. data/spec/lib/stellar/transaction_envelope_spec.rb +0 -93
  103. data/spec/lib/stellar/transaction_spec.rb +0 -132
  104. data/spec/lib/stellar/util/strkey_spec.rb +0 -54
  105. data/spec/spec_helper.rb +0 -16
  106. data/spec/support/matchers/be_strkey.rb +0 -9
  107. data/spec/support/matchers/eq_bytes.rb +0 -5
  108. data/spec/support/matchers/have_length.rb +0 -5
  109. data/tasks/rspec.rake +0 -6
  110. data/tasks/travis.rake +0 -1
  111. data/tasks/xdr.rake +0 -45
  112. data/xdr/Stellar-SCP.x +0 -86
  113. data/xdr/Stellar-ledger-entries.x +0 -295
  114. data/xdr/Stellar-ledger.x +0 -372
  115. data/xdr/Stellar-overlay.x +0 -229
  116. data/xdr/Stellar-transaction.x +0 -901
  117. 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,131 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Stellar::Operation, ".payment" do
4
- it "correctly translates the provided amount to the native representation" do
5
- op = Stellar::Operation.payment(destination: Stellar::KeyPair.random, amount: [:native, 20])
6
- expect(op.body.value.amount).to eql(20_0000000)
7
- op = Stellar::Operation.payment(destination: Stellar::KeyPair.random, amount: [:native, "20"])
8
- expect(op.body.value.amount).to eql(20_0000000)
9
- end
10
- end
11
-
12
- def pk_to_address(pk)
13
- Stellar::Convert.pk_to_address(pk)
14
- end
15
-
16
- describe "path payment operations" do
17
- let(:destination){ Stellar::KeyPair.random }
18
- let(:send_asset_issuer){ Stellar::KeyPair.master }
19
- let(:send_asset){ Stellar::Asset.alphanum4("USD", send_asset_issuer) }
20
- let(:dest_asset_issuer){ Stellar::KeyPair.master }
21
- let(:dest_asset){ Stellar::Asset.alphanum4("EUR", dest_asset_issuer) }
22
- let(:amount){ [Stellar::Asset.alphanum4(dest_asset.code, dest_asset_issuer), 9.2] }
23
- let(:with){ [Stellar::Asset.alphanum4(send_asset.code, send_asset_issuer), 10] }
24
-
25
- describe Stellar::Operation, ".path_payment" do
26
- it "works" do
27
- destination = Stellar::KeyPair.random
28
- # test both forms of arrays
29
- amount = [Stellar::Asset.alphanum4("USD", Stellar::KeyPair.master), 10]
30
- with = [:alphanum4, "EUR", Stellar::KeyPair.master, 9.2]
31
-
32
- op = Stellar::Operation.path_payment(
33
- destination: destination,
34
- amount: amount,
35
- with: with
36
- )
37
-
38
- expect(op.body.arm).to eql(:path_payment_strict_receive_op)
39
- end
40
- end
41
-
42
- describe Stellar::Operation, ".path_payment_strict_receive" do
43
- it "works" do
44
- op = Stellar::Operation.path_payment_strict_receive(
45
- destination: destination,
46
- amount: amount,
47
- with: with
48
- )
49
-
50
- expect(op.body.arm).to eql(:path_payment_strict_receive_op)
51
- expect(op.body.value.destination).to eql(destination.public_key)
52
- expect(op.body.value.send_asset).to eql(send_asset)
53
- expect(op.body.value.dest_asset).to eql(dest_asset)
54
- expect(op.body.value.send_max).to eq(100000000)
55
- expect(op.body.value.dest_amount).to eq(92000000)
56
- end
57
- end
58
-
59
- describe Stellar::Operation, ".path_payment_strict_send" do
60
- it "works" do
61
- op = Stellar::Operation.path_payment_strict_send(
62
- destination: destination,
63
- amount: amount,
64
- with: with
65
- )
66
-
67
- expect(op.body.arm).to eql(:path_payment_strict_send_op)
68
- expect(op.body.value.destination).to eql(destination.public_key)
69
- expect(op.body.value.send_asset).to eql(send_asset)
70
- expect(op.body.value.dest_asset).to eql(dest_asset)
71
- expect(op.body.value.send_amount).to eq(100000000)
72
- expect(op.body.value.dest_min).to eq(92000000)
73
- end
74
- end
75
- end
76
-
77
- describe Stellar::Operation, ".manage_data" do
78
-
79
- it "works" do
80
- op = Stellar::Operation.manage_data(name: "my name", value: "hello")
81
- expect(op.body.manage_data_op!.data_name).to eql("my name")
82
- expect(op.body.manage_data_op!.data_value).to eql("hello")
83
- expect{ op.to_xdr }.to_not raise_error
84
-
85
- op = Stellar::Operation.manage_data(name: "my name")
86
- expect(op.body.manage_data_op!.data_name).to eql("my name")
87
- expect(op.body.manage_data_op!.data_value).to be_nil
88
- expect{ op.to_xdr }.to_not raise_error
89
- end
90
-
91
- end
92
-
93
- describe Stellar::Operation, ".change_trust" do
94
-
95
- let(:issuer) { Stellar::KeyPair.from_address("GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7") }
96
- let(:asset) { Stellar::Asset.alphanum4("USD", issuer) }
97
-
98
- it "creates a ChangeTrustOp" do
99
- op = Stellar::Operation.change_trust(line: Stellar::Asset.alphanum4("USD", issuer))
100
- expect(op.body.value).to be_an_instance_of(Stellar::ChangeTrustOp)
101
- expect(op.body.value.line).to eq(Stellar::Asset.alphanum4("USD", issuer))
102
- expect(op.body.value.limit).to eq(9223372036854775807)
103
- end
104
-
105
- it "creates a ChangeTrustOp with an asset" do
106
- asset = Stellar::Asset.alphanum4("USD", issuer)
107
- op = Stellar::Operation.change_trust(line: asset, limit: 1234.75)
108
- expect(op.body.value).to be_an_instance_of(Stellar::ChangeTrustOp)
109
- expect(op.body.value.line).to eq(Stellar::Asset.alphanum4("USD", issuer))
110
- expect(op.body.value.limit).to eq(12347500000)
111
- end
112
-
113
- it "only allow sound `line` arguments" do
114
- expect {
115
- Stellar::Operation.change_trust(line: [:harmful_call, "USD", issuer])
116
- }.to raise_error(ArgumentError, "must be one of #{Stellar::Asset::TYPES}")
117
- end
118
-
119
- it "creates a ChangeTrustOp with limit" do
120
- op = Stellar::Operation.change_trust(line: Stellar::Asset.alphanum4("USD", issuer), limit: 1234.75)
121
- expect(op.body.value).to be_an_instance_of(Stellar::ChangeTrustOp)
122
- expect(op.body.value.line).to eq(Stellar::Asset.alphanum4("USD", issuer))
123
- expect(op.body.value.limit).to eq(12347500000)
124
- end
125
-
126
- it "throws ArgumentError for incorrect limit argument" do
127
- expect {
128
- Stellar::Operation.change_trust(line: Stellar::Asset.alphanum4("USD", issuer), limit: true)
129
- }.to raise_error(ArgumentError)
130
- end
131
- 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,263 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Stellar::TransactionBuilder do
4
- let(:key_pair){ Stellar::KeyPair.random }
5
- builder = nil
6
- before(:each) do
7
- builder = Stellar::TransactionBuilder.new(
8
- source_account: key_pair,
9
- sequence_number: 1
10
- )
11
- end
12
-
13
- describe ".initialize" do
14
- it "bad source_account" do
15
- expect {
16
- Stellar::TransactionBuilder.new(
17
- source_account: key_pair.account_id,
18
- sequence_number: 1
19
- )
20
- }.to raise_error(
21
- ArgumentError, "Bad :source_account"
22
- )
23
- end
24
- it "bad sequence_number" do
25
- expect {
26
- Stellar::TransactionBuilder.new(
27
- source_account: key_pair,
28
- sequence_number: -1
29
- )
30
- }.to raise_error(
31
- ArgumentError, "Bad :sequence_number"
32
- )
33
- end
34
- it "bad timeout" do
35
- expect {
36
- Stellar::TransactionBuilder.new(
37
- source_account: key_pair,
38
- sequence_number: 1,
39
- time_bounds: 600
40
- )
41
- }.to raise_error(
42
- ArgumentError, "Bad :time_bounds"
43
- )
44
- end
45
- it "bad base_fee" do
46
- expect {
47
- Stellar::TransactionBuilder.new(
48
- source_account: key_pair,
49
- sequence_number: 1,
50
- base_fee: 0
51
- )
52
- }.to raise_error(
53
- ArgumentError, "Bad :base_fee"
54
- )
55
- end
56
- it "bad memo" do
57
- expect {
58
- Stellar::TransactionBuilder.new(
59
- source_account: key_pair,
60
- sequence_number: 1,
61
- memo: {"data" => "Testing bad memo"}
62
- )
63
- }.to raise_error(
64
- ArgumentError, "Bad :memo"
65
- )
66
- end
67
- it "success" do
68
- builder = Stellar::TransactionBuilder.new(
69
- source_account: key_pair,
70
- sequence_number: 1,
71
- time_bounds: Stellar::TimeBounds.new(min_time: 0, max_time: 600),
72
- base_fee: 200,
73
- memo: "My test memo"
74
- )
75
- expect(builder.memo).to eql(Stellar::Memo.new(:memo_text, "My test memo"))
76
- end
77
- end
78
-
79
- describe ".add_operation" do
80
- it "bad operation" do
81
- expect {
82
- builder.add_operation(
83
- [:bump_sequence, 1]
84
- )
85
- }.to raise_error(
86
- ArgumentError, "Bad operation"
87
- )
88
- end
89
-
90
- it "returns self" do
91
- expect(builder.add_operation(
92
- Stellar::Operation.bump_sequence({"bump_to": 1})
93
- )).to be_an_instance_of(Stellar::TransactionBuilder)
94
- end
95
- end
96
-
97
- describe ".clear_operations" do
98
- it "can clear operations" do
99
- builder = builder.add_operation(
100
- Stellar::Operation.bump_sequence({"bump_to": 1})
101
- ).clear_operations
102
- expect(builder.operations).to eql([])
103
- end
104
-
105
- it "returns self" do
106
- expect(builder.add_operation(
107
- Stellar::Operation.bump_sequence({"bump_to": 1})
108
- ).clear_operations).to be_an_instance_of(Stellar::TransactionBuilder)
109
- end
110
- end
111
-
112
- describe ".set_sequence_number" do
113
- it "allows sequence number to be updated" do
114
- builder.set_sequence_number(5)
115
- expect(builder.sequence_number).to eql(5)
116
- end
117
-
118
- it "returns self" do
119
- expect(builder.set_sequence_number(3)).to be_an_instance_of(Stellar::TransactionBuilder)
120
- end
121
-
122
- it "raises an error for bad sequence number" do
123
- expect {
124
- builder.set_sequence_number(nil)
125
- }.to raise_error(
126
- ArgumentError, "Bad sequence number"
127
- )
128
- end
129
- end
130
-
131
- describe ".set_timeout" do
132
- it "raises an error for non-integers" do
133
- expect {
134
- builder.set_timeout(nil)
135
- }.to raise_error(
136
- ArgumentError, "Timeout must be a non-negative integer"
137
- )
138
- end
139
-
140
- it "raises an error for negative timeouts" do
141
- expect {
142
- builder.set_timeout(-1)
143
- }.to raise_error(
144
- ArgumentError, "Timeout must be a non-negative integer"
145
- )
146
- end
147
-
148
- it "returns self" do
149
- expect(builder.set_timeout(10)).to be_an_instance_of(Stellar::TransactionBuilder)
150
- end
151
- end
152
-
153
- describe ".set_memo" do
154
- it "raises an error for bad memos" do
155
- expect {
156
- builder.set_memo({"data" => "Testing bad memo"})
157
- }.to raise_error(
158
- ArgumentError, "Bad :memo"
159
- )
160
- end
161
-
162
- it "works and returns self" do
163
- expect(builder.set_memo("Hello").memo).to eql(Stellar::Memo.new(:memo_text, "Hello"))
164
- end
165
- end
166
-
167
- describe ".build" do
168
- it "raises error for time_bounds not set" do
169
- expect {
170
- tx = builder.add_operation(
171
- Stellar::Operation.bump_sequence({"bump_to": 1})
172
- ).build()
173
- }.to raise_error(
174
- RuntimeError,
175
- "TransactionBuilder.time_bounds must be set during initialization or by calling set_timeout"
176
- )
177
- end
178
-
179
- it "raises an error for non-integer timebounds" do
180
- builder = Stellar::TransactionBuilder.new(
181
- source_account: key_pair,
182
- sequence_number: 1,
183
- time_bounds: Stellar::TimeBounds.new(min_time: "not", max_time: "integers")
184
- )
185
- expect {
186
- tx = builder.add_operation(
187
- Stellar::Operation.bump_sequence({"bump_to": 1})
188
- ).build()
189
- }.to raise_error(
190
- RuntimeError, "TimeBounds.min_time and max_time must be Integers"
191
- )
192
- end
193
-
194
- it "raises an error for bad TimeBounds range" do
195
- builder = Stellar::TransactionBuilder.new(
196
- source_account: key_pair,
197
- sequence_number: 1,
198
- time_bounds: Stellar::TimeBounds.new(min_time: Time.now.to_i + 10, max_time: Time.now.to_i)
199
- )
200
- expect {
201
- tx = builder.add_operation(
202
- Stellar::Operation.bump_sequence({"bump_to": 1})
203
- ).build()
204
- }.to raise_error(
205
- RuntimeError, "Timebounds.max_time must be greater than min_time"
206
- )
207
- end
208
-
209
- it "allows max_time to be zero" do
210
- tx = builder.add_operation(
211
- Stellar::Operation.bump_sequence({"bump_to": 1})
212
- ).set_timeout(0).build()
213
- expect(builder.time_bounds.max_time).to eql(0)
214
- end
215
-
216
- it "updates sequence number by 1 per build" do
217
- builder.add_operation(
218
- Stellar::Operation.bump_sequence({"bump_to": 1})
219
- ).set_timeout(0).build()
220
- expect(builder.sequence_number).to eql(2)
221
- end
222
-
223
- it "creates transaction successfully" do
224
- bump_op = Stellar::Operation.bump_sequence({"bump_to": 1})
225
- builder.add_operation(
226
- Stellar::Operation.bump_sequence({"bump_to": 1})
227
- ).set_timeout(600).build()
228
- expect(builder.operations).to eql([bump_op])
229
- end
230
-
231
- it "allows for multiple transactions to be created" do
232
- first_max_time = Time.now.to_i + 1000
233
- bump_op = Stellar::Operation.bump_sequence({"bump_to": 1})
234
- builder = Stellar::TransactionBuilder.new(
235
- source_account: key_pair,
236
- sequence_number: 1,
237
- time_bounds: Stellar::TimeBounds.new(min_time: 0, max_time: first_max_time)
238
- )
239
- tx1 = builder.add_operation(
240
- Stellar::Operation.bump_sequence({"bump_to": 1})
241
- ).build()
242
- expect(tx1.seq_num).to eql(1)
243
- expect(tx1.operations).to eql([
244
- Stellar::Operation.bump_sequence({"bump_to": 1})
245
- ])
246
- expect(tx1.time_bounds.max_time).to eql(first_max_time)
247
-
248
- tx2 = builder.clear_operations.add_operation(
249
- Stellar::Operation.bump_sequence({"bump_to": 2})
250
- ).set_timeout(0).build()
251
- expect(tx2.seq_num).to eql(2)
252
- expect(tx2.operations).to eql([
253
- Stellar::Operation.bump_sequence({"bump_to": 2})
254
- ])
255
- expect(tx2.time_bounds.max_time).to eql(0)
256
-
257
- expect(builder.sequence_number).to eql(3)
258
- expect(builder.operations).to eql([
259
- Stellar::Operation.bump_sequence({"bump_to": 2})
260
- ])
261
- end
262
- end
263
- end