stellar-sdk 0.2.0 → 0.3.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.
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ module Stellar
4
+ RSpec.describe Account do
5
+
6
+ describe "#lookup" do
7
+ it "should peforms federation lookup", vcr: {record: :once, match_requests_on: [:method]} do
8
+ account_id = described_class.lookup('john@email.com*stellarfed.org')
9
+ expect(account_id).to eq 'GDSRO6H2YM6MC6ZO7KORPJXSTUMBMT3E7MZ66CFVNMUAULFG6G2OP32I'
10
+ end
11
+
12
+ it "should handle 404 request when performing federation lookup", vcr: {record: :once, match_requests_on: [:method]} do
13
+ expect { described_class.lookup('jane@email.com*stellarfed.org') }.to raise_error(AccountNotFound)
14
+ end
15
+
16
+ it "should handle domains that are not federation servers", vcr: {record: :once, match_requests_on: [:method]} do
17
+ expect { described_class.lookup('john*stellar.org') }.to raise_error(InvalidStellarDomain)
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ module Stellar
4
+ RSpec.describe Amount do
5
+
6
+ describe "#to_payment" do
7
+ context "when asset is the native type" do
8
+ it "returns an array of values" do
9
+ amount = described_class.new(100)
10
+ payment = amount.to_payment
11
+ expect(payment[0]).to eq :native
12
+ expect(payment[1]).to eq 100
13
+ end
14
+ end
15
+
16
+ context "when asset is alphanum4" do
17
+ let(:issuer_account) { Stellar::Account.random }
18
+
19
+ it "returns an array of values" do
20
+ asset = Stellar::Asset.alphanum4("BTC", issuer_account.keypair)
21
+ amount = described_class.new(100, asset)
22
+
23
+ payment = amount.to_payment
24
+ expect(payment[0]).to eq :alphanum4
25
+ expect(payment[1]).to include "BTC"
26
+ expect(payment[2].public_key.value).
27
+ to eq issuer_account.keypair.public_key.value
28
+ expect(payment[3]).to eq 100
29
+ end
30
+ end
31
+
32
+ context "when asset is alphanum12" do
33
+ let(:issuer_account) { Stellar::Account.random }
34
+
35
+ it "returns an array of values" do
36
+ asset = Stellar::Asset.alphanum12("LONGNAME", issuer_account.keypair)
37
+ amount = described_class.new(100, asset)
38
+
39
+ payment = amount.to_payment
40
+ expect(payment[0]).to eq :alphanum12
41
+ expect(payment[1]).to include "LONGNAME"
42
+ expect(payment[2].public_key.value).
43
+ to eq issuer_account.keypair.public_key.value
44
+ expect(payment[3]).to eq 100
45
+ end
46
+ end
47
+ end
48
+
49
+ describe "#inspect" do
50
+ context "when asset is not explicitly supplied" do
51
+ it "uses the native asset type" do
52
+ amount = described_class.new(200)
53
+ expect(amount.inspect).to eq "#<Stellar::Amount native(200)>"
54
+ end
55
+ end
56
+
57
+ context "when asset is supplied" do
58
+ let(:issuer_account) { Stellar::Account.random }
59
+
60
+ it "uses the supplied asset type" do
61
+ asset = Stellar::Asset.alphanum4("BTC", issuer_account.keypair)
62
+ address = issuer_account.address
63
+ amount = described_class.new(1_000000, asset)
64
+ expect(amount.inspect).to eq "#<Stellar::Amount #{asset}(1000000)>"
65
+ end
66
+ end
67
+ end
68
+
69
+ end
70
+ end
@@ -1,7 +1,118 @@
1
1
  require "spec_helper"
2
2
 
3
- describe Stellar::Client, ".localhost" do
4
- subject{ Stellar::Client.localhost }
3
+ describe Stellar::Client do
5
4
 
6
- it{ should be_a(Stellar::Client) }
7
- end
5
+ subject(:client) { Stellar::Client.default_testnet }
6
+
7
+ describe "#create_account" do
8
+ let(:source) { Stellar::Account.from_seed(CONFIG[:source_seed]) }
9
+ let(:destination) { Stellar::Account.random }
10
+
11
+ it "creates the account", vcr: {record: :once, match_requests_on: [:method]} do
12
+ client.create_account(
13
+ funder: source,
14
+ account: destination,
15
+ starting_balance: 100,
16
+ )
17
+
18
+ destination_info = client.account_info(destination)
19
+ balances = destination_info.balances
20
+ expect(balances).to_not be_empty
21
+ native_asset_balance_info = balances.find do |b|
22
+ b["asset_type"] == "native"
23
+ end
24
+ expect(native_asset_balance_info["balance"].to_f).to eq 100.0
25
+ end
26
+ end
27
+
28
+ describe "#send_payment" do
29
+ let(:source) { Stellar::Account.from_seed(CONFIG[:source_seed]) }
30
+
31
+ context "native asset" do
32
+ let(:destination) { Stellar::Account.random }
33
+
34
+ it "sends a native payment to the account", vcr: {record: :once, match_requests_on: [:method]} do
35
+ client.create_account(
36
+ funder: source,
37
+ account: destination,
38
+ starting_balance: 100,
39
+ )
40
+
41
+ amount = Stellar::Amount.new(150)
42
+
43
+ client.send_payment(
44
+ from: source,
45
+ to: destination,
46
+ amount: amount,
47
+ )
48
+
49
+ destination_info = client.account_info(destination)
50
+ balances = destination_info.balances
51
+ expect(balances).to_not be_empty
52
+ native_asset_balance_info = balances.find do |b|
53
+ b["asset_type"] == "native"
54
+ end
55
+ expect(native_asset_balance_info["balance"].to_f).to eq 250.0
56
+ end
57
+ end
58
+
59
+ context "alphanum4 asset" do
60
+ let(:destination) { Stellar::Account.from_seed(CONFIG[:destination_seed]) }
61
+
62
+ it "sends a alphanum4 asset to the destination", vcr: {record: :once, match_requests_on: [:method]} do
63
+ destination_info = client.account_info(destination)
64
+ old_balances = destination_info.balances
65
+ old_btc_balance = old_balances.find do |b|
66
+ b["asset_code"] == "BTC"
67
+ end["balance"].to_f
68
+
69
+ asset = Stellar::Asset.alphanum4("BTC", source.keypair)
70
+ amount = Stellar::Amount.new(150, asset)
71
+
72
+ client.send_payment(
73
+ from: source,
74
+ to: destination,
75
+ amount: amount,
76
+ )
77
+
78
+ destination_info = client.account_info(destination)
79
+ new_balances = destination_info.balances
80
+ new_btc_balance = new_balances.find do |b|
81
+ b["asset_code"] == "BTC"
82
+ end["balance"].to_f
83
+
84
+ expect(new_btc_balance - old_btc_balance).to eq 150.0
85
+ end
86
+ end
87
+
88
+ context "alphanum12 asset" do
89
+ let(:destination) { Stellar::Account.from_seed(CONFIG[:destination_seed]) }
90
+
91
+ it "sends a alphanum12 asset to the destination", vcr: {record: :once, match_requests_on: [:method]} do
92
+ destination_info = client.account_info(destination)
93
+ old_balances = destination_info.balances
94
+ old_btc_balance = old_balances.find do |b|
95
+ b["asset_code"] == "LONGNAME"
96
+ end["balance"].to_f
97
+
98
+ asset = Stellar::Asset.alphanum12("LONGNAME", source.keypair)
99
+ amount = Stellar::Amount.new(150, asset)
100
+
101
+ client.send_payment(
102
+ from: source,
103
+ to: destination,
104
+ amount: amount,
105
+ )
106
+
107
+ destination_info = client.account_info(destination)
108
+ new_balances = destination_info.balances
109
+ new_btc_balance = new_balances.find do |b|
110
+ b["asset_code"] == "LONGNAME"
111
+ end["balance"].to_f
112
+
113
+ expect(new_btc_balance - old_btc_balance).to eq 150.0
114
+ end
115
+ end
116
+ end
117
+
118
+ end
@@ -6,8 +6,9 @@ SimpleCov.start
6
6
 
7
7
  require 'pry'
8
8
  require 'stellar-sdk'
9
+ require "pathname"
9
10
 
10
- SPEC_ROOT = File.dirname(__FILE__)
11
+ SPEC_ROOT = Pathname.new(File.dirname(__FILE__))
11
12
 
12
13
  Dir["#{SPEC_ROOT}/support/**/*.rb"].each { |f| require f }
13
14
 
@@ -0,0 +1,3 @@
1
+ require "yaml"
2
+
3
+ CONFIG = YAML.load_file(SPEC_ROOT.join("config.yml")).with_indifferent_access
@@ -0,0 +1,10 @@
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
@@ -1,9 +1 @@
1
- file "lib/libsodium.so" => :build_libsodium do
2
- cp $LIBSODIUM_PATH, "lib/libsodium.so"
3
- end
4
-
5
- task "ci:sodium" => "lib/libsodium.so"
6
-
7
- task :travis => %w(ci:sodium spec)
8
-
9
- CLEAN.add "lib/libsodium.*"
1
+ task :travis => %w(spec)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stellar-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.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: 2016-11-08 00:00:00.000000000 Z
11
+ date: 2018-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stellar-base
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.11.0
19
+ version: 0.13.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.11.0
26
+ version: 0.13.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: hyperclient
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -68,18 +68,32 @@ dependencies:
68
68
  version: '0.7'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 4.2.7
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 4.2.7
83
+ - !ruby/object:Gem::Dependency
84
+ name: toml-rb
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '4'
89
+ version: 1.1.1
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '4'
96
+ version: 1.1.1
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: bundler
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +178,34 @@ dependencies:
164
178
  - - ">="
165
179
  - !ruby/object:Gem::Version
166
180
  version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: vcr
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '3.0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '3.0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: webmock
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: '2.3'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: '2.3'
167
209
  description:
168
210
  email:
169
211
  - scott@stellar.org
@@ -172,8 +214,10 @@ extensions: []
172
214
  extra_rdoc_files: []
173
215
  files:
174
216
  - ".gitignore"
217
+ - ".ruby-version"
175
218
  - ".travis.yml"
176
219
  - ".yardopts"
220
+ - CHANGELOG.md
177
221
  - CONTRIBUTING.md
178
222
  - Gemfile
179
223
  - Guardfile
@@ -194,11 +238,23 @@ files:
194
238
  - lib/stellar/transaction_page.rb
195
239
  - lib/stellar/version.rb
196
240
  - ruby-stellar-sdk.gemspec
241
+ - spec/config.yml.sample
242
+ - spec/fixtures/vcr_cassettes/Stellar_Account/_lookup/should_handle_404_request_when_performing_federation_lookup.yml
243
+ - spec/fixtures/vcr_cassettes/Stellar_Account/_lookup/should_handle_domains_that_are_not_federation_servers.yml
244
+ - spec/fixtures/vcr_cassettes/Stellar_Account/_lookup/should_peforms_federation_lookup.yml
245
+ - spec/fixtures/vcr_cassettes/Stellar_Client/_create_account/creates_the_account.yml
246
+ - spec/fixtures/vcr_cassettes/Stellar_Client/_send_payment/alphanum12_asset/sends_a_alphanum12_asset_to_the_destination.yml
247
+ - spec/fixtures/vcr_cassettes/Stellar_Client/_send_payment/alphanum4_asset/sends_a_alphanum4_asset_to_the_destination.yml
248
+ - spec/fixtures/vcr_cassettes/Stellar_Client/_send_payment/native_asset/sends_a_native_payment_to_the_account.yml
249
+ - spec/lib/stellar/account_spec.rb
250
+ - spec/lib/stellar/amount_spec.rb
197
251
  - spec/lib/stellar/client_spec.rb
198
252
  - spec/spec_helper.rb
253
+ - spec/support/config.rb
199
254
  - spec/support/matchers/be_base58_check.rb
200
255
  - spec/support/matchers/eq_bytes.rb
201
256
  - spec/support/matchers/have_length.rb
257
+ - spec/support/vcr.rb
202
258
  - tasks/rspec.rake
203
259
  - tasks/travis.rake
204
260
  homepage: http://github.com/stellar/ruby-stellar-sdk
@@ -221,14 +277,26 @@ required_rubygems_version: !ruby/object:Gem::Requirement
221
277
  version: '0'
222
278
  requirements: []
223
279
  rubyforge_project:
224
- rubygems_version: 2.2.2
280
+ rubygems_version: 2.5.1
225
281
  signing_key:
226
282
  specification_version: 4
227
283
  summary: Stellar client library
228
284
  test_files:
285
+ - spec/config.yml.sample
286
+ - spec/fixtures/vcr_cassettes/Stellar_Account/_lookup/should_handle_404_request_when_performing_federation_lookup.yml
287
+ - spec/fixtures/vcr_cassettes/Stellar_Account/_lookup/should_handle_domains_that_are_not_federation_servers.yml
288
+ - spec/fixtures/vcr_cassettes/Stellar_Account/_lookup/should_peforms_federation_lookup.yml
289
+ - spec/fixtures/vcr_cassettes/Stellar_Client/_create_account/creates_the_account.yml
290
+ - spec/fixtures/vcr_cassettes/Stellar_Client/_send_payment/alphanum12_asset/sends_a_alphanum12_asset_to_the_destination.yml
291
+ - spec/fixtures/vcr_cassettes/Stellar_Client/_send_payment/alphanum4_asset/sends_a_alphanum4_asset_to_the_destination.yml
292
+ - spec/fixtures/vcr_cassettes/Stellar_Client/_send_payment/native_asset/sends_a_native_payment_to_the_account.yml
293
+ - spec/lib/stellar/account_spec.rb
294
+ - spec/lib/stellar/amount_spec.rb
229
295
  - spec/lib/stellar/client_spec.rb
230
296
  - spec/spec_helper.rb
297
+ - spec/support/config.rb
231
298
  - spec/support/matchers/be_base58_check.rb
232
299
  - spec/support/matchers/eq_bytes.rb
233
300
  - spec/support/matchers/have_length.rb
301
+ - spec/support/vcr.rb
234
302
  has_rdoc: