stellar-sdk 0.4.0 → 0.5.0

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.
@@ -4,6 +4,35 @@ describe Stellar::Client do
4
4
 
5
5
  subject(:client) { Stellar::Client.default_testnet }
6
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
+
7
36
  describe "#create_account" do
8
37
  let(:source) { Stellar::Account.from_seed(CONFIG[:source_seed]) }
9
38
  let(:destination) { Stellar::Account.random }
@@ -32,7 +61,7 @@ describe Stellar::Client do
32
61
  it "returns the current details for the account", vcr: { record: :once, match_requests_on: [:method]} do
33
62
  response = client.account_info(account)
34
63
 
35
- expect(response.id).to eq "GCQSESW66AX4ZRZB7QWCIXSPX2BD7KLOYSS33IUGDCLO4XCPURZEEC6R"
64
+ expect(response.id).to eq CONFIG[:source_address]
36
65
  expect(response.paging_token).to be_empty
37
66
  expect(response.sequence).to eq "346973227974715"
38
67
  expect(response.subentry_count).to eq 0
@@ -40,15 +69,44 @@ describe Stellar::Client do
40
69
  expect(response.flags).to include("auth_required" => false, "auth_revocable" => false)
41
70
  expect(response.balances).to include("balance" => "3494.9997500", "asset_type" => "native")
42
71
  expect(response.signers).to include(
43
- "public_key" => "GCQSESW66AX4ZRZB7QWCIXSPX2BD7KLOYSS33IUGDCLO4XCPURZEEC6R",
72
+ "public_key" => CONFIG[:source_address],
44
73
  "weight" => 1,
45
74
  "type" => "ed25519_public_key",
46
- "key"=>"GCQSESW66AX4ZRZB7QWCIXSPX2BD7KLOYSS33IUGDCLO4XCPURZEEC6R"
75
+ "key" => CONFIG[:source_address]
47
76
  )
48
77
  expect(response.data).to be_empty
49
78
  end
50
79
  end
51
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
+
52
110
  describe "#send_payment" do
53
111
  let(:source) { Stellar::Account.from_seed(CONFIG[:source_seed]) }
54
112
 
@@ -81,18 +139,25 @@ describe Stellar::Client do
81
139
  end
82
140
 
83
141
  context "alphanum4 asset" do
84
- let(:destination) { Stellar::Account.from_seed(CONFIG[:destination_seed]) }
142
+ let(:issuer) { Stellar::Account.from_seed(CONFIG[:source_seed]) }
143
+ let(:destination) { Stellar::Account.random }
85
144
 
86
- it "sends a alphanum4 asset to the destination", vcr: {record: :once, match_requests_on: [:method]} do
87
- destination_info = client.account_info(destination)
88
- old_balances = destination_info.balances
89
- old_btc_balance = old_balances.find do |b|
90
- b["asset_code"] == "BTC"
91
- end["balance"].to_f
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
+ )
92
158
 
93
159
  asset = Stellar::Asset.alphanum4("BTC", source.keypair)
94
160
  amount = Stellar::Amount.new(150, asset)
95
-
96
161
  client.send_payment(
97
162
  from: source,
98
163
  to: destination,
@@ -100,24 +165,31 @@ describe Stellar::Client do
100
165
  )
101
166
 
102
167
  destination_info = client.account_info(destination)
103
- new_balances = destination_info.balances
104
- new_btc_balance = new_balances.find do |b|
168
+ btc_balance = destination_info.balances.find do |b|
105
169
  b["asset_code"] == "BTC"
106
170
  end["balance"].to_f
107
171
 
108
- expect(new_btc_balance - old_btc_balance).to eq 150.0
172
+ expect(btc_balance).to eq 150.0
109
173
  end
110
174
  end
111
175
 
112
176
  context "alphanum12 asset" do
113
- let(:destination) { Stellar::Account.from_seed(CONFIG[:destination_seed]) }
177
+ let(:issuer) { Stellar::Account.from_seed(CONFIG[:source_seed]) }
178
+ let(:destination) { Stellar::Account.random }
114
179
 
115
- it "sends a alphanum12 asset to the destination", vcr: {record: :once, match_requests_on: [:method]} do
116
- destination_info = client.account_info(destination)
117
- old_balances = destination_info.balances
118
- old_btc_balance = old_balances.find do |b|
119
- b["asset_code"] == "LONGNAME"
120
- end["balance"].to_f
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
+ )
121
193
 
122
194
  asset = Stellar::Asset.alphanum12("LONGNAME", source.keypair)
123
195
  amount = Stellar::Amount.new(150, asset)
@@ -129,12 +201,11 @@ describe Stellar::Client do
129
201
  )
130
202
 
131
203
  destination_info = client.account_info(destination)
132
- new_balances = destination_info.balances
133
- new_btc_balance = new_balances.find do |b|
204
+ btc_balance = destination_info.balances.find do |b|
134
205
  b["asset_code"] == "LONGNAME"
135
206
  end["balance"].to_f
136
207
 
137
- expect(new_btc_balance - old_btc_balance).to eq 150.0
208
+ expect(btc_balance).to eq 150.0
138
209
  end
139
210
  end
140
211
  end
@@ -170,4 +241,62 @@ describe Stellar::Client do
170
241
  end
171
242
  end
172
243
 
244
+ describe "#change_trust" do
245
+ context "given an asset described as an array" do
246
+ let(:issuer) { Stellar::Account.from_seed(CONFIG[:source_seed]) }
247
+ let(:truster) { Stellar::Account.random }
248
+
249
+ it("creates, updates, or deletes a trustline", {
250
+ vcr: {record: :once, match_requests_on: [:method]},
251
+ }) do
252
+ client.create_account(
253
+ funder: issuer,
254
+ account: truster,
255
+ starting_balance: 2,
256
+ )
257
+
258
+ # Create trustline
259
+ client.change_trust(
260
+ asset: [:alphanum4, "BTC", issuer.keypair],
261
+ source: truster,
262
+ )
263
+
264
+ truster_info = client.account_info(truster)
265
+ btc_balance = truster_info.balances.find do |b|
266
+ b["asset_code"] == "BTC" && b["asset_issuer"] == issuer.address
267
+ end
268
+
269
+ expect(btc_balance).to_not be_nil
270
+
271
+ # Update trustline
272
+ client.change_trust(
273
+ asset: [:alphanum4, "BTC", issuer.keypair],
274
+ source: truster,
275
+ limit: 100,
276
+ )
277
+
278
+ truster_info = client.account_info(truster)
279
+ btc_balance = truster_info.balances.find do |b|
280
+ b["asset_code"] == "BTC" && b["asset_issuer"] == issuer.address
281
+ end
282
+
283
+ expect(btc_balance["limit"].to_f).to eq 100
284
+
285
+ # Delete trustline
286
+ client.change_trust(
287
+ asset: [:alphanum4, "BTC", issuer.keypair],
288
+ source: truster,
289
+ limit: 0,
290
+ )
291
+
292
+ truster_info = client.account_info(truster)
293
+ btc_balance = truster_info.balances.find do |b|
294
+ b["asset_code"] == "BTC" && b["asset_issuer"] == issuer.address
295
+ end
296
+
297
+ expect(btc_balance).to be_nil
298
+ end
299
+ end
300
+ end
301
+
173
302
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stellar-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Fleckenstein
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-05 00:00:00.000000000 Z
11
+ date: 2018-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stellar-base
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0.13'
19
+ version: 0.16.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0.13'
26
+ version: 0.16.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: hyperclient
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -64,28 +64,28 @@ dependencies:
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '0.7'
67
+ version: '0.16'
68
68
  type: :runtime
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '0.7'
74
+ version: '0.16'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: activesupport
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - ">="
80
80
  - !ruby/object:Gem::Version
81
- version: 4.2.7
81
+ version: 5.2.0
82
82
  type: :runtime
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - ">="
87
87
  - !ruby/object:Gem::Version
88
- version: 4.2.7
88
+ version: 5.2.0
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: toml-rb
91
91
  requirement: !ruby/object:Gem::Requirement
@@ -254,6 +254,8 @@ files:
254
254
  - spec/fixtures/vcr_cassettes/Stellar_Account/_lookup/should_handle_domains_that_are_not_federation_servers.yml
255
255
  - spec/fixtures/vcr_cassettes/Stellar_Account/_lookup/should_peforms_federation_lookup.yml
256
256
  - spec/fixtures/vcr_cassettes/Stellar_Client/_account_info/returns_the_current_details_for_the_account.yml
257
+ - spec/fixtures/vcr_cassettes/Stellar_Client/_account_merge/merges_source_account_into_destination.yml
258
+ - spec/fixtures/vcr_cassettes/Stellar_Client/_change_trust/given_an_asset_described_as_an_array/creates_updates_or_deletes_a_trustline.yml
257
259
  - spec/fixtures/vcr_cassettes/Stellar_Client/_create_account/creates_the_account.yml
258
260
  - spec/fixtures/vcr_cassettes/Stellar_Client/_send_payment/alphanum12_asset/sends_a_alphanum12_asset_to_the_destination.yml
259
261
  - spec/fixtures/vcr_cassettes/Stellar_Client/_send_payment/alphanum4_asset/sends_a_alphanum4_asset_to_the_destination.yml
@@ -300,6 +302,8 @@ test_files:
300
302
  - spec/fixtures/vcr_cassettes/Stellar_Account/_lookup/should_handle_domains_that_are_not_federation_servers.yml
301
303
  - spec/fixtures/vcr_cassettes/Stellar_Account/_lookup/should_peforms_federation_lookup.yml
302
304
  - spec/fixtures/vcr_cassettes/Stellar_Client/_account_info/returns_the_current_details_for_the_account.yml
305
+ - spec/fixtures/vcr_cassettes/Stellar_Client/_account_merge/merges_source_account_into_destination.yml
306
+ - spec/fixtures/vcr_cassettes/Stellar_Client/_change_trust/given_an_asset_described_as_an_array/creates_updates_or_deletes_a_trustline.yml
303
307
  - spec/fixtures/vcr_cassettes/Stellar_Client/_create_account/creates_the_account.yml
304
308
  - spec/fixtures/vcr_cassettes/Stellar_Client/_send_payment/alphanum12_asset/sends_a_alphanum12_asset_to_the_destination.yml
305
309
  - spec/fixtures/vcr_cassettes/Stellar_Client/_send_payment/alphanum4_asset/sends_a_alphanum4_asset_to_the_destination.yml