stellar-sdk 0.5.0 → 0.9.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -2
- data/{LICENSE.txt → LICENSE} +0 -0
- data/README.md +17 -11
- data/lib/stellar-sdk.rb +3 -4
- data/lib/stellar/account.rb +16 -18
- data/lib/stellar/amount.rb +9 -13
- data/lib/stellar/client.rb +217 -91
- data/lib/stellar/horizon/problem.rb +14 -16
- data/lib/stellar/sep10.rb +347 -0
- data/lib/stellar/transaction_page.rb +4 -6
- data/lib/stellar/version.rb +1 -1
- metadata +17 -207
- data/.gitignore +0 -16
- data/.travis.yml +0 -13
- data/.yardopts +0 -7
- data/CONTRIBUTING.md +0 -48
- data/Gemfile +0 -14
- data/Guardfile +0 -5
- data/Rakefile +0 -3
- data/examples/01_get_funded.rb +0 -37
- data/examples/02_payment.rb +0 -15
- data/examples/03_transaction_history.rb +0 -21
- data/examples/04_setting_trust.rb +0 -1
- data/examples/05_fiat_payment.rb +0 -13
- data/examples/06_fund_testnet_friendbot.rb +0 -15
- data/ruby-stellar-sdk.gemspec +0 -36
- data/spec/config.yml.sample +0 -7
- data/spec/fixtures/vcr_cassettes/Stellar_Account/_lookup/should_handle_404_request_when_performing_federation_lookup.yml +0 -133
- data/spec/fixtures/vcr_cassettes/Stellar_Account/_lookup/should_handle_domains_that_are_not_federation_servers.yml +0 -44
- data/spec/fixtures/vcr_cassettes/Stellar_Account/_lookup/should_peforms_federation_lookup.yml +0 -85
- data/spec/fixtures/vcr_cassettes/Stellar_Client/_account_info/returns_the_current_details_for_the_account.yml +0 -190
- data/spec/fixtures/vcr_cassettes/Stellar_Client/_account_merge/merges_source_account_into_destination.yml +0 -714
- 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
- data/spec/fixtures/vcr_cassettes/Stellar_Client/_create_account/creates_the_account.yml +0 -323
- data/spec/fixtures/vcr_cassettes/Stellar_Client/_send_payment/alphanum12_asset/sends_a_alphanum12_asset_to_the_destination.yml +0 -737
- data/spec/fixtures/vcr_cassettes/Stellar_Client/_send_payment/alphanum4_asset/sends_a_alphanum4_asset_to_the_destination.yml +0 -737
- data/spec/fixtures/vcr_cassettes/Stellar_Client/_send_payment/native_asset/sends_a_native_payment_to_the_account.yml +0 -469
- data/spec/fixtures/vcr_cassettes/Stellar_Client/_transactions/account_transactions/accepts_a_cursor_to_return_less_data.yml +0 -94
- data/spec/fixtures/vcr_cassettes/Stellar_Client/_transactions/account_transactions/returns_a_list_of_transaction_for_an_account.yml +0 -94
- data/spec/fixtures/vcr_cassettes/Stellar_Client/_transactions/all_transactions/accepts_a_cursor_to_return_less_data.yml +0 -94
- data/spec/fixtures/vcr_cassettes/Stellar_Client/_transactions/all_transactions/returns_a_list_of_transactions.yml +0 -94
- data/spec/lib/stellar/account_spec.rb +0 -59
- data/spec/lib/stellar/amount_spec.rb +0 -70
- data/spec/lib/stellar/client_spec.rb +0 -302
- data/spec/spec_helper.rb +0 -14
- data/spec/support/config.rb +0 -3
- data/spec/support/vcr.rb +0 -10
- data/tasks/rspec.rake +0 -6
- data/tasks/travis.rake +0 -1
@@ -1,302 +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
|
-
end
|
212
|
-
|
213
|
-
describe "#transactions" do
|
214
|
-
let(:cursor) { '348403452088320' }
|
215
|
-
|
216
|
-
context "account transactions" do
|
217
|
-
let(:account) { Stellar::Account.from_seed(CONFIG[:source_seed]) }
|
218
|
-
|
219
|
-
it "returns a list of transaction for an account", vcr: {record: :once, match_requests_on: [:method]} do
|
220
|
-
response = client.transactions(account: account)
|
221
|
-
expect(response).to be_a(Stellar::TransactionPage)
|
222
|
-
end
|
223
|
-
|
224
|
-
it "accepts a cursor to return less data", vcr: {record: :once, match_requests_on: [:method]} do
|
225
|
-
response = client.transactions(account: account,
|
226
|
-
cursor: cursor)
|
227
|
-
expect(response).to be_a(Stellar::TransactionPage)
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
context "all transactions" do
|
232
|
-
it "returns a list of transactions", vcr: {record: :once, match_requests_on: [:method]} do
|
233
|
-
response = client.transactions
|
234
|
-
expect(response).to be_a(Stellar::TransactionPage)
|
235
|
-
end
|
236
|
-
|
237
|
-
it "accepts a cursor to return less data", vcr: {record: :once, match_requests_on: [:method]} do
|
238
|
-
response = client.transactions(cursor: cursor)
|
239
|
-
expect(response).to be_a(Stellar::TransactionPage)
|
240
|
-
end
|
241
|
-
end
|
242
|
-
end
|
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
|
-
|
302
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -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
|
data/spec/support/config.rb
DELETED
data/spec/support/vcr.rb
DELETED
@@ -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 destination_address].each do |var|
|
8
|
-
config.filter_sensitive_data("[#{var}]") { CONFIG[var] }
|
9
|
-
end
|
10
|
-
end
|
data/tasks/rspec.rake
DELETED
data/tasks/travis.rake
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
task :travis => %w(spec)
|