stellar-sdk 0.6.0 → 0.23.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +15 -0
  3. data/{LICENSE.txt → LICENSE} +0 -0
  4. data/README.md +12 -12
  5. data/lib/stellar-sdk.rb +3 -4
  6. data/lib/stellar/account.rb +16 -18
  7. data/lib/stellar/amount.rb +9 -13
  8. data/lib/stellar/client.rb +204 -93
  9. data/lib/stellar/horizon/problem.rb +14 -16
  10. data/lib/stellar/sep10.rb +347 -0
  11. data/lib/stellar/transaction_page.rb +4 -6
  12. data/lib/stellar/version.rb +1 -1
  13. metadata +21 -217
  14. data/.gitignore +0 -16
  15. data/.travis.yml +0 -17
  16. data/.yardopts +0 -7
  17. data/CONTRIBUTING.md +0 -48
  18. data/Gemfile +0 -14
  19. data/Guardfile +0 -5
  20. data/Rakefile +0 -3
  21. data/examples/01_get_funded.rb +0 -37
  22. data/examples/02_payment.rb +0 -15
  23. data/examples/03_transaction_history.rb +0 -21
  24. data/examples/04_setting_trust.rb +0 -1
  25. data/examples/05_fiat_payment.rb +0 -13
  26. data/examples/06_fund_testnet_friendbot.rb +0 -15
  27. data/ruby-stellar-sdk.gemspec +0 -36
  28. data/spec/config.yml.sample +0 -12
  29. data/spec/fixtures/vcr_cassettes/Stellar_Account/_lookup/should_handle_404_request_when_performing_federation_lookup.yml +0 -133
  30. data/spec/fixtures/vcr_cassettes/Stellar_Account/_lookup/should_handle_domains_that_are_not_federation_servers.yml +0 -44
  31. data/spec/fixtures/vcr_cassettes/Stellar_Account/_lookup/should_peforms_federation_lookup.yml +0 -85
  32. data/spec/fixtures/vcr_cassettes/Stellar_Client/_account_info/returns_the_current_details_for_the_account.yml +0 -190
  33. data/spec/fixtures/vcr_cassettes/Stellar_Client/_account_merge/merges_source_account_into_destination.yml +0 -714
  34. data/spec/fixtures/vcr_cassettes/Stellar_Client/_change_trust/given_an_asset_described_as_an_array/creates_updates_or_deletes_a_trustline.yml +0 -1156
  35. data/spec/fixtures/vcr_cassettes/Stellar_Client/_create_account/creates_the_account.yml +0 -323
  36. data/spec/fixtures/vcr_cassettes/Stellar_Client/_send_payment/alphanum12_asset/sends_a_alphanum12_asset_to_the_destination.yml +0 -747
  37. data/spec/fixtures/vcr_cassettes/Stellar_Client/_send_payment/alphanum4_asset/sends_a_alphanum4_asset_to_the_destination.yml +0 -747
  38. data/spec/fixtures/vcr_cassettes/Stellar_Client/_send_payment/memo/accepts_the_memo_attribute.yml +0 -716
  39. data/spec/fixtures/vcr_cassettes/Stellar_Client/_send_payment/native_asset/sends_a_native_payment_to_the_account.yml +0 -562
  40. data/spec/fixtures/vcr_cassettes/Stellar_Client/_send_payment/using_a_payment_channel/sends_a_payment_account_through_a_channel_account.yml +0 -694
  41. data/spec/fixtures/vcr_cassettes/Stellar_Client/_send_payment/using_a_payment_channel/sends_a_payment_when_the_channel_is_the_same_as_from_.yml +0 -586
  42. data/spec/fixtures/vcr_cassettes/Stellar_Client/_transactions/account_transactions/accepts_a_cursor_to_return_less_data.yml +0 -94
  43. data/spec/fixtures/vcr_cassettes/Stellar_Client/_transactions/account_transactions/returns_a_list_of_transaction_for_an_account.yml +0 -94
  44. data/spec/fixtures/vcr_cassettes/Stellar_Client/_transactions/all_transactions/accepts_a_cursor_to_return_less_data.yml +0 -94
  45. data/spec/fixtures/vcr_cassettes/Stellar_Client/_transactions/all_transactions/returns_a_list_of_transactions.yml +0 -94
  46. data/spec/lib/stellar/account_spec.rb +0 -59
  47. data/spec/lib/stellar/amount_spec.rb +0 -70
  48. data/spec/lib/stellar/client_spec.rb +0 -392
  49. data/spec/spec_helper.rb +0 -14
  50. data/spec/support/config.rb +0 -3
  51. data/spec/support/vcr.rb +0 -10
  52. data/tasks/rspec.rake +0 -6
  53. data/tasks/travis.rake +0 -1
@@ -1,392 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Stellar::Client do
4
-
5
- subject(:client) { Stellar::Client.default_testnet }
6
-
7
- describe "#default_testnet" do
8
- it 'instantiates a client pointing to horizon testnet' do
9
- client = described_class.default_testnet
10
- expect(client.horizon._url).to eq(described_class::HORIZON_TESTNET_URL)
11
- end
12
- end
13
-
14
- describe "#default" do
15
- it 'instantiates a client pointing to horizon mainnet' do
16
- client = described_class.default
17
- expect(client.horizon._url).to eq(described_class::HORIZON_MAINNET_URL)
18
- end
19
- end
20
-
21
- describe "#localhost" do
22
- it 'instantiates a client pointing to localhost horizon' do
23
- client = described_class.localhost
24
- expect(client.horizon._url).to eq(described_class::HORIZON_LOCALHOST_URL)
25
- end
26
- end
27
-
28
- describe "#initialize" do
29
- let(:custom_horizon_url) { 'https://horizon.domain.com' }
30
- it 'instantiates a client accepting custom options' do
31
- client = described_class.new(horizon: custom_horizon_url)
32
- expect(client.horizon._url).to eq(custom_horizon_url)
33
- end
34
- end
35
-
36
- describe "#create_account" do
37
- let(:source) { Stellar::Account.from_seed(CONFIG[:source_seed]) }
38
- let(:destination) { Stellar::Account.random }
39
-
40
- it "creates the account", vcr: {record: :once, match_requests_on: [:method]} do
41
- client.create_account(
42
- funder: source,
43
- account: destination,
44
- starting_balance: 100,
45
- )
46
-
47
- destination_info = client.account_info(destination)
48
- balances = destination_info.balances
49
- expect(balances).to_not be_empty
50
- native_asset_balance_info = balances.find do |b|
51
- b["asset_type"] == "native"
52
- end
53
- expect(native_asset_balance_info["balance"].to_f).to eq 100.0
54
- end
55
- end
56
-
57
- describe "#account_info" do
58
- let(:account) { Stellar::Account.from_seed(CONFIG[:source_seed]) }
59
- let(:client) { Stellar::Client.default_testnet }
60
-
61
- it "returns the current details for the account", vcr: { record: :once, match_requests_on: [:method]} do
62
- response = client.account_info(account)
63
-
64
- expect(response.id).to eq CONFIG[:source_address]
65
- expect(response.paging_token).to be_empty
66
- expect(response.sequence).to eq "346973227974715"
67
- expect(response.subentry_count).to eq 0
68
- expect(response.thresholds).to include("low_threshold" => 0, "med_threshold" => 0, "high_threshold" => 0)
69
- expect(response.flags).to include("auth_required" => false, "auth_revocable" => false)
70
- expect(response.balances).to include("balance" => "3494.9997500", "asset_type" => "native")
71
- expect(response.signers).to include(
72
- "public_key" => CONFIG[:source_address],
73
- "weight" => 1,
74
- "type" => "ed25519_public_key",
75
- "key" => CONFIG[:source_address]
76
- )
77
- expect(response.data).to be_empty
78
- end
79
- end
80
-
81
- describe "#account_merge" do
82
- let(:funder) { Stellar::Account.from_seed(CONFIG[:source_seed]) }
83
- let(:client) { Stellar::Client.default_testnet }
84
- let(:source) { Stellar::Account.random }
85
- let(:destination) { Stellar::Account.random }
86
-
87
- it "merges source account into destination", vcr: { record: :once, match_requests_on: [:method]} do
88
- [source, destination].each do |account|
89
- account = client.create_account(
90
- funder: funder,
91
- account: account,
92
- starting_balance: 100,
93
- )
94
- end
95
-
96
- client.account_merge(
97
- account: source,
98
- destination: destination
99
- )
100
-
101
- destination_info = client.account_info(destination)
102
- native_asset_balance_info = destination_info.balances.find do |b|
103
- b["asset_type"] == "native"
104
- end
105
- # balance of merged account is the balance of both accounts minus transaction fee for merge
106
- expect(native_asset_balance_info["balance"].to_f).to eq 199.99999
107
- end
108
- end
109
-
110
- describe "#send_payment" do
111
- let(:source) { Stellar::Account.from_seed(CONFIG[:source_seed]) }
112
-
113
- context "native asset" do
114
- let(:destination) { Stellar::Account.random }
115
-
116
- it "sends a native payment to the account", vcr: {record: :once, match_requests_on: [:method]} do
117
- client.create_account(
118
- funder: source,
119
- account: destination,
120
- starting_balance: 100,
121
- )
122
-
123
- amount = Stellar::Amount.new(150)
124
-
125
- client.send_payment(
126
- from: source,
127
- to: destination,
128
- amount: amount,
129
- )
130
-
131
- destination_info = client.account_info(destination)
132
- balances = destination_info.balances
133
- expect(balances).to_not be_empty
134
- native_asset_balance_info = balances.find do |b|
135
- b["asset_type"] == "native"
136
- end
137
- expect(native_asset_balance_info["balance"].to_f).to eq 250.0
138
- end
139
- end
140
-
141
- context "alphanum4 asset" do
142
- let(:issuer) { Stellar::Account.from_seed(CONFIG[:source_seed]) }
143
- let(:destination) { Stellar::Account.random }
144
-
145
- it("sends a alphanum4 asset to the destination", {
146
- vcr: {record: :once, match_requests_on: [:method]},
147
- }) do
148
- client.create_account(
149
- funder: issuer,
150
- account: destination,
151
- starting_balance: 2,
152
- )
153
-
154
- client.change_trust(
155
- asset: [:alphanum4, "BTC", issuer.keypair],
156
- source: destination,
157
- )
158
-
159
- asset = Stellar::Asset.alphanum4("BTC", source.keypair)
160
- amount = Stellar::Amount.new(150, asset)
161
- client.send_payment(
162
- from: source,
163
- to: destination,
164
- amount: amount,
165
- )
166
-
167
- destination_info = client.account_info(destination)
168
- btc_balance = destination_info.balances.find do |b|
169
- b["asset_code"] == "BTC"
170
- end["balance"].to_f
171
-
172
- expect(btc_balance).to eq 150.0
173
- end
174
- end
175
-
176
- context "alphanum12 asset" do
177
- let(:issuer) { Stellar::Account.from_seed(CONFIG[:source_seed]) }
178
- let(:destination) { Stellar::Account.random }
179
-
180
- it("sends a alphanum12 asset to the destination", {
181
- vcr: {record: :once, match_requests_on: [:method]},
182
- }) do
183
- client.create_account(
184
- funder: issuer,
185
- account: destination,
186
- starting_balance: 2,
187
- )
188
-
189
- client.change_trust(
190
- asset: [:alphanum12, "LONGNAME", issuer.keypair],
191
- source: destination,
192
- )
193
-
194
- asset = Stellar::Asset.alphanum12("LONGNAME", source.keypair)
195
- amount = Stellar::Amount.new(150, asset)
196
-
197
- client.send_payment(
198
- from: source,
199
- to: destination,
200
- amount: amount,
201
- )
202
-
203
- destination_info = client.account_info(destination)
204
- btc_balance = destination_info.balances.find do |b|
205
- b["asset_code"] == "LONGNAME"
206
- end["balance"].to_f
207
-
208
- expect(btc_balance).to eq 150.0
209
- end
210
- end
211
-
212
- context "memo" do
213
- let(:destination) { Stellar::Account.random }
214
-
215
- it("accepts the memo attribute", {
216
- vcr: {record: :once, match_requests_on: [:method]}
217
- }) do
218
- client.create_account(
219
- funder: source,
220
- account: destination,
221
- starting_balance: 100,
222
- )
223
-
224
- amount = Stellar::Amount.new(150)
225
-
226
- client.send_payment(
227
- from: source,
228
- to: destination,
229
- amount: amount,
230
- memo: "DESUKA",
231
- )
232
-
233
- last_tx = client.account_info(destination).
234
- transactions(order: "desc")._get._embedded.records.first
235
- expect(last_tx.memo).to eq "DESUKA"
236
- end
237
- end
238
-
239
- context "using a payment channel" do
240
- let(:transaction_source) { Stellar::Account.from_seed(CONFIG[:channel_seed]) }
241
- let(:destination) { Stellar::Account.random }
242
-
243
- it("sends a payment account through a channel account", {
244
- vcr: {record: :once, match_requests_on: [:method]},
245
- }) do
246
- client.create_account(
247
- funder: source,
248
- account: destination,
249
- starting_balance: 1,
250
- )
251
-
252
- tx = client.send_payment(
253
- from: source,
254
- to: destination,
255
- amount: Stellar::Amount.new(0.55),
256
- transaction_source: transaction_source,
257
- )
258
-
259
- tx_hash = tx._attributes["hash"]
260
-
261
- tx = client.horizon.transaction(hash: tx_hash)
262
- expect(tx.source_account).to eq transaction_source.address
263
-
264
- operation = tx.operations.records.first
265
- expect(operation.from).to eq source.address
266
-
267
- destination_info = client.account_info(destination)
268
- balances = destination_info.balances
269
- expect(balances).to_not be_empty
270
- native_asset_balance_info = balances.find do |b|
271
- b["asset_type"] == "native"
272
- end
273
- expect(native_asset_balance_info["balance"].to_f).to eq 1.55
274
- end
275
-
276
- it("sends a payment when the channel is the same as `from`", {
277
- vcr: {record: :once, match_requests_on: [:method]},
278
- }) do
279
- client.create_account(
280
- funder: source,
281
- account: destination,
282
- starting_balance: 1,
283
- )
284
-
285
- tx = client.send_payment(
286
- from: source,
287
- to: destination,
288
- amount: Stellar::Amount.new(0.55),
289
- transaction_source: source,
290
- )
291
-
292
- tx_hash = tx._attributes["hash"]
293
-
294
- tx = client.horizon.transaction(hash: tx_hash)
295
- expect(tx.source_account).to eq source.address
296
-
297
- operation = tx.operations.records.first
298
- expect(operation.from).to eq source.address
299
- end
300
- end
301
- end
302
-
303
- describe "#transactions" do
304
- let(:cursor) { '348403452088320' }
305
-
306
- context "account transactions" do
307
- let(:account) { Stellar::Account.from_seed(CONFIG[:source_seed]) }
308
-
309
- it "returns a list of transaction for an account", vcr: {record: :once, match_requests_on: [:method]} do
310
- response = client.transactions(account: account)
311
- expect(response).to be_a(Stellar::TransactionPage)
312
- end
313
-
314
- it "accepts a cursor to return less data", vcr: {record: :once, match_requests_on: [:method]} do
315
- response = client.transactions(account: account,
316
- cursor: cursor)
317
- expect(response).to be_a(Stellar::TransactionPage)
318
- end
319
- end
320
-
321
- context "all transactions" do
322
- it "returns a list of transactions", vcr: {record: :once, match_requests_on: [:method]} do
323
- response = client.transactions
324
- expect(response).to be_a(Stellar::TransactionPage)
325
- end
326
-
327
- it "accepts a cursor to return less data", vcr: {record: :once, match_requests_on: [:method]} do
328
- response = client.transactions(cursor: cursor)
329
- expect(response).to be_a(Stellar::TransactionPage)
330
- end
331
- end
332
- end
333
-
334
- describe "#change_trust" do
335
- context "given an asset described as an array" do
336
- let(:issuer) { Stellar::Account.from_seed(CONFIG[:source_seed]) }
337
- let(:truster) { Stellar::Account.random }
338
-
339
- it("creates, updates, or deletes a trustline", {
340
- vcr: {record: :once, match_requests_on: [:method]},
341
- }) do
342
- client.create_account(
343
- funder: issuer,
344
- account: truster,
345
- starting_balance: 2,
346
- )
347
-
348
- # Create trustline
349
- client.change_trust(
350
- asset: [:alphanum4, "BTC", issuer.keypair],
351
- source: truster,
352
- )
353
-
354
- truster_info = client.account_info(truster)
355
- btc_balance = truster_info.balances.find do |b|
356
- b["asset_code"] == "BTC" && b["asset_issuer"] == issuer.address
357
- end
358
-
359
- expect(btc_balance).to_not be_nil
360
-
361
- # Update trustline
362
- client.change_trust(
363
- asset: [:alphanum4, "BTC", issuer.keypair],
364
- source: truster,
365
- limit: 100,
366
- )
367
-
368
- truster_info = client.account_info(truster)
369
- btc_balance = truster_info.balances.find do |b|
370
- b["asset_code"] == "BTC" && b["asset_issuer"] == issuer.address
371
- end
372
-
373
- expect(btc_balance["limit"].to_f).to eq 100
374
-
375
- # Delete trustline
376
- client.change_trust(
377
- asset: [:alphanum4, "BTC", issuer.keypair],
378
- source: truster,
379
- limit: 0,
380
- )
381
-
382
- truster_info = client.account_info(truster)
383
- btc_balance = truster_info.balances.find do |b|
384
- b["asset_code"] == "BTC" && b["asset_issuer"] == issuer.address
385
- end
386
-
387
- expect(btc_balance).to be_nil
388
- end
389
- end
390
- end
391
-
392
- end
@@ -1,14 +0,0 @@
1
- require 'simplecov'
2
- SimpleCov.start
3
-
4
- require 'pry'
5
- require 'stellar-sdk'
6
- require "pathname"
7
-
8
- SPEC_ROOT = Pathname.new(File.dirname(__FILE__))
9
-
10
- Dir["#{SPEC_ROOT}/support/**/*.rb"].each { |f| require f }
11
-
12
- RSpec.configure do |config|
13
-
14
- end
@@ -1,3 +0,0 @@
1
- require "yaml"
2
-
3
- CONFIG = YAML.load_file(SPEC_ROOT.join("config.yml")).with_indifferent_access
@@ -1,10 +0,0 @@
1
- require "vcr"
2
-
3
- VCR.configure do |config|
4
- config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
5
- config.hook_into :webmock
6
- config.configure_rspec_metadata!
7
- %i[source_address channel_address].each do |var|
8
- config.filter_sensitive_data("[#{var}]") { CONFIG[var] }
9
- end
10
- end
@@ -1,6 +0,0 @@
1
- begin
2
- require 'rspec/core/rake_task'
3
- RSpec::Core::RakeTask.new(:spec)
4
- task :default => :spec
5
- rescue LoadError
6
- end
@@ -1 +0,0 @@
1
- task :travis => %w(spec)