auction-ruby-base 0.1.1

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.
Files changed (226) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.travis.yml +15 -0
  4. data/.yardopts +8 -0
  5. data/CHANGELOG.md +58 -0
  6. data/CONTRIBUTING.md +48 -0
  7. data/Gemfile +15 -0
  8. data/Guardfile +5 -0
  9. data/LICENSE.txt +202 -0
  10. data/README.md +83 -0
  11. data/Rakefile +4 -0
  12. data/auction-ruby-base.gemspec +35 -0
  13. data/examples/create_account.rb +26 -0
  14. data/examples/low_level_transaction_post.rb +46 -0
  15. data/examples/mid_level_transaction_post.rb +33 -0
  16. data/examples/non_native_payment.rb +60 -0
  17. data/examples/offer.rb +75 -0
  18. data/examples/transaction_merge.rb +23 -0
  19. data/generated/stellar-base-generated.rb +174 -0
  20. data/generated/stellar/account_entry.rb +55 -0
  21. data/generated/stellar/account_entry/ext.rb +24 -0
  22. data/generated/stellar/account_flags.rb +31 -0
  23. data/generated/stellar/account_merge_result.rb +26 -0
  24. data/generated/stellar/account_merge_result_code.rb +30 -0
  25. data/generated/stellar/affirm_fail_op.rb +22 -0
  26. data/generated/stellar/affirm_fail_result.rb +25 -0
  27. data/generated/stellar/affirm_fail_result_code.rb +22 -0
  28. data/generated/stellar/affirm_pass_op.rb +24 -0
  29. data/generated/stellar/affirm_pass_result.rb +25 -0
  30. data/generated/stellar/affirm_pass_result_code.rb +22 -0
  31. data/generated/stellar/allow_trust_op.rb +38 -0
  32. data/generated/stellar/allow_trust_op/asset.rb +33 -0
  33. data/generated/stellar/allow_trust_result.rb +25 -0
  34. data/generated/stellar/allow_trust_result_code.rb +31 -0
  35. data/generated/stellar/asset.rb +47 -0
  36. data/generated/stellar/asset/alpha_num12.rb +22 -0
  37. data/generated/stellar/asset/alpha_num4.rb +22 -0
  38. data/generated/stellar/asset_type.rb +24 -0
  39. data/generated/stellar/auth.rb +20 -0
  40. data/generated/stellar/auth_cert.rb +22 -0
  41. data/generated/stellar/authenticated_message.rb +32 -0
  42. data/generated/stellar/authenticated_message/v0.rb +24 -0
  43. data/generated/stellar/bucket_entry.rb +28 -0
  44. data/generated/stellar/bucket_entry_type.rb +22 -0
  45. data/generated/stellar/change_trust_op.rb +22 -0
  46. data/generated/stellar/change_trust_result.rb +25 -0
  47. data/generated/stellar/change_trust_result_code.rb +31 -0
  48. data/generated/stellar/claim_offer_atom.rb +33 -0
  49. data/generated/stellar/create_account_op.rb +20 -0
  50. data/generated/stellar/create_account_result.rb +25 -0
  51. data/generated/stellar/create_account_result_code.rb +32 -0
  52. data/generated/stellar/create_bid_op.rb +20 -0
  53. data/generated/stellar/create_bid_result.rb +25 -0
  54. data/generated/stellar/create_bid_result_code.rb +22 -0
  55. data/generated/stellar/create_lot_op.rb +46 -0
  56. data/generated/stellar/create_lot_result.rb +25 -0
  57. data/generated/stellar/create_lot_result_code.rb +22 -0
  58. data/generated/stellar/create_passive_offer_op.rb +24 -0
  59. data/generated/stellar/crypto_key_type.rb +20 -0
  60. data/generated/stellar/curve25519_public.rb +18 -0
  61. data/generated/stellar/curve25519_secret.rb +18 -0
  62. data/generated/stellar/decorated_signature.rb +20 -0
  63. data/generated/stellar/dont_have.rb +20 -0
  64. data/generated/stellar/envelope_type.rb +24 -0
  65. data/generated/stellar/error.rb +20 -0
  66. data/generated/stellar/error_code.rb +28 -0
  67. data/generated/stellar/hello.rb +34 -0
  68. data/generated/stellar/hmac_sha256_key.rb +18 -0
  69. data/generated/stellar/hmac_sha256_mac.rb +18 -0
  70. data/generated/stellar/inflation_payout.rb +20 -0
  71. data/generated/stellar/inflation_result.rb +26 -0
  72. data/generated/stellar/inflation_result_code.rb +24 -0
  73. data/generated/stellar/ip_addr_type.rb +22 -0
  74. data/generated/stellar/ledger_entry.rb +52 -0
  75. data/generated/stellar/ledger_entry/data.rb +49 -0
  76. data/generated/stellar/ledger_entry/ext.rb +24 -0
  77. data/generated/stellar/ledger_entry_change.rb +35 -0
  78. data/generated/stellar/ledger_entry_change_type.rb +26 -0
  79. data/generated/stellar/ledger_entry_type.rb +32 -0
  80. data/generated/stellar/ledger_header.rb +69 -0
  81. data/generated/stellar/ledger_header/ext.rb +24 -0
  82. data/generated/stellar/ledger_header_history_entry.rb +33 -0
  83. data/generated/stellar/ledger_header_history_entry/ext.rb +24 -0
  84. data/generated/stellar/ledger_key.rb +87 -0
  85. data/generated/stellar/ledger_key/account.rb +20 -0
  86. data/generated/stellar/ledger_key/lot.rb +22 -0
  87. data/generated/stellar/ledger_key/message.rb +22 -0
  88. data/generated/stellar/ledger_key/offer.rb +22 -0
  89. data/generated/stellar/ledger_key/participant.rb +22 -0
  90. data/generated/stellar/ledger_key/proof.rb +22 -0
  91. data/generated/stellar/ledger_key/trust_line.rb +22 -0
  92. data/generated/stellar/ledger_scp_messages.rb +20 -0
  93. data/generated/stellar/ledger_upgrade.rb +31 -0
  94. data/generated/stellar/ledger_upgrade_type.rb +24 -0
  95. data/generated/stellar/lot_branch.rb +21 -0
  96. data/generated/stellar/lot_entry.rb +64 -0
  97. data/generated/stellar/lot_entry/ext.rb +24 -0
  98. data/generated/stellar/lot_type.rb +21 -0
  99. data/generated/stellar/manage_offer_effect.rb +24 -0
  100. data/generated/stellar/manage_offer_op.rb +28 -0
  101. data/generated/stellar/manage_offer_result.rb +26 -0
  102. data/generated/stellar/manage_offer_result_code.rb +50 -0
  103. data/generated/stellar/manage_offer_success_result.rb +34 -0
  104. data/generated/stellar/manage_offer_success_result/offer.rb +30 -0
  105. data/generated/stellar/memo.rb +38 -0
  106. data/generated/stellar/memo_type.rb +28 -0
  107. data/generated/stellar/message_entry.rb +38 -0
  108. data/generated/stellar/message_entry/ext.rb +24 -0
  109. data/generated/stellar/message_type.rb +51 -0
  110. data/generated/stellar/offer_entry.rb +49 -0
  111. data/generated/stellar/offer_entry/ext.rb +24 -0
  112. data/generated/stellar/offer_entry_flags.rb +21 -0
  113. data/generated/stellar/operation.rb +65 -0
  114. data/generated/stellar/operation/body.rb +88 -0
  115. data/generated/stellar/operation_meta.rb +18 -0
  116. data/generated/stellar/operation_result.rb +67 -0
  117. data/generated/stellar/operation_result/tr.rb +89 -0
  118. data/generated/stellar/operation_result_code.rb +25 -0
  119. data/generated/stellar/operation_type.rb +52 -0
  120. data/generated/stellar/participant_entry.rb +39 -0
  121. data/generated/stellar/participant_entry/ext.rb +24 -0
  122. data/generated/stellar/participant_state.rb +25 -0
  123. data/generated/stellar/path_payment_op.rb +32 -0
  124. data/generated/stellar/path_payment_result.rb +38 -0
  125. data/generated/stellar/path_payment_result/success.rb +22 -0
  126. data/generated/stellar/path_payment_result_code.rb +47 -0
  127. data/generated/stellar/payment_op.rb +22 -0
  128. data/generated/stellar/payment_result.rb +25 -0
  129. data/generated/stellar/payment_result_code.rb +41 -0
  130. data/generated/stellar/peer_address.rb +33 -0
  131. data/generated/stellar/peer_address/ip.rb +29 -0
  132. data/generated/stellar/price.rb +20 -0
  133. data/generated/stellar/proof_entry.rb +42 -0
  134. data/generated/stellar/proof_entry/ext.rb +24 -0
  135. data/generated/stellar/provide_proof_op.rb +24 -0
  136. data/generated/stellar/provide_proof_result.rb +25 -0
  137. data/generated/stellar/provide_proof_result_code.rb +22 -0
  138. data/generated/stellar/public_key.rb +23 -0
  139. data/generated/stellar/register_participant_op.rb +22 -0
  140. data/generated/stellar/register_participant_result.rb +25 -0
  141. data/generated/stellar/register_participant_result_code.rb +22 -0
  142. data/generated/stellar/scp_ballot.rb +20 -0
  143. data/generated/stellar/scp_envelope.rb +20 -0
  144. data/generated/stellar/scp_history_entry.rb +23 -0
  145. data/generated/stellar/scp_history_entry_v0.rb +20 -0
  146. data/generated/stellar/scp_nomination.rb +22 -0
  147. data/generated/stellar/scp_quorum_set.rb +22 -0
  148. data/generated/stellar/scp_statement.rb +58 -0
  149. data/generated/stellar/scp_statement/pledges.rb +63 -0
  150. data/generated/stellar/scp_statement/pledges/confirm.rb +30 -0
  151. data/generated/stellar/scp_statement/pledges/externalize.rb +26 -0
  152. data/generated/stellar/scp_statement/pledges/prepare.rb +32 -0
  153. data/generated/stellar/scp_statement_type.rb +26 -0
  154. data/generated/stellar/send_message_op.rb +22 -0
  155. data/generated/stellar/send_message_result.rb +25 -0
  156. data/generated/stellar/send_message_result_code.rb +22 -0
  157. data/generated/stellar/set_options_op.rb +41 -0
  158. data/generated/stellar/set_options_result.rb +25 -0
  159. data/generated/stellar/set_options_result_code.rb +40 -0
  160. data/generated/stellar/signer.rb +20 -0
  161. data/generated/stellar/simple_payment_result.rb +22 -0
  162. data/generated/stellar/stellar_message.rb +74 -0
  163. data/generated/stellar/stellar_value.rb +41 -0
  164. data/generated/stellar/stellar_value/ext.rb +24 -0
  165. data/generated/stellar/threshold_indexes.rb +26 -0
  166. data/generated/stellar/time_bounds.rb +20 -0
  167. data/generated/stellar/transaction.rb +50 -0
  168. data/generated/stellar/transaction/ext.rb +24 -0
  169. data/generated/stellar/transaction_envelope.rb +20 -0
  170. data/generated/stellar/transaction_history_entry.rb +33 -0
  171. data/generated/stellar/transaction_history_entry/ext.rb +24 -0
  172. data/generated/stellar/transaction_history_result_entry.rb +33 -0
  173. data/generated/stellar/transaction_history_result_entry/ext.rb +24 -0
  174. data/generated/stellar/transaction_meta.rb +23 -0
  175. data/generated/stellar/transaction_result.rb +43 -0
  176. data/generated/stellar/transaction_result/ext.rb +24 -0
  177. data/generated/stellar/transaction_result/result.rb +30 -0
  178. data/generated/stellar/transaction_result_code.rb +45 -0
  179. data/generated/stellar/transaction_result_pair.rb +20 -0
  180. data/generated/stellar/transaction_result_set.rb +18 -0
  181. data/generated/stellar/transaction_set.rb +20 -0
  182. data/generated/stellar/trust_line_entry.rb +41 -0
  183. data/generated/stellar/trust_line_entry/ext.rb +24 -0
  184. data/generated/stellar/trust_line_flags.rb +21 -0
  185. data/lib/stellar-base.rb +33 -0
  186. data/lib/stellar/account_flags.rb +28 -0
  187. data/lib/stellar/asset.rb +69 -0
  188. data/lib/stellar/base.rb +1 -0
  189. data/lib/stellar/base/version.rb +5 -0
  190. data/lib/stellar/convert.rb +32 -0
  191. data/lib/stellar/key_pair.rb +112 -0
  192. data/lib/stellar/networks.rb +45 -0
  193. data/lib/stellar/operation.rb +384 -0
  194. data/lib/stellar/path_payment_result.rb +17 -0
  195. data/lib/stellar/price.rb +32 -0
  196. data/lib/stellar/thresholds.rb +39 -0
  197. data/lib/stellar/transaction.rb +205 -0
  198. data/lib/stellar/transaction_envelope.rb +32 -0
  199. data/lib/stellar/util/continued_fraction.rb +96 -0
  200. data/lib/stellar/util/strkey.rb +43 -0
  201. data/spec/lib/stellar/account_flags_spec.rb +19 -0
  202. data/spec/lib/stellar/asset_spec.rb +45 -0
  203. data/spec/lib/stellar/convert_spec.rb +61 -0
  204. data/spec/lib/stellar/key_pair_spec.rb +238 -0
  205. data/spec/lib/stellar/networks_spec.rb +77 -0
  206. data/spec/lib/stellar/operation_spec.rb +13 -0
  207. data/spec/lib/stellar/path_payment_result_spec.rb +95 -0
  208. data/spec/lib/stellar/price_spec.rb +34 -0
  209. data/spec/lib/stellar/thresholds_spec.rb +62 -0
  210. data/spec/lib/stellar/transaction_envelope_spec.rb +93 -0
  211. data/spec/lib/stellar/transaction_spec.rb +83 -0
  212. data/spec/lib/stellar/util/strkey_spec.rb +46 -0
  213. data/spec/spec_helper.rb +16 -0
  214. data/spec/support/matchers/be_strkey.rb +9 -0
  215. data/spec/support/matchers/eq_bytes.rb +5 -0
  216. data/spec/support/matchers/have_length.rb +5 -0
  217. data/tasks/rspec.rake +6 -0
  218. data/tasks/travis.rake +1 -0
  219. data/tasks/xdr.rake +50 -0
  220. data/xdr/Stellar-SCP.x +86 -0
  221. data/xdr/Stellar-ledger-entries.x +351 -0
  222. data/xdr/Stellar-ledger.x +288 -0
  223. data/xdr/Stellar-overlay.x +146 -0
  224. data/xdr/Stellar-transaction.x +936 -0
  225. data/xdr/Stellar-types.x +55 -0
  226. metadata +495 -0
@@ -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::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
@@ -0,0 +1,13 @@
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
@@ -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