stellar-sdk 0.7.0 → 0.23.0

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