Skip to content

Commit

Permalink
Add Friendbot support
Browse files Browse the repository at this point in the history
  • Loading branch information
ramontayag committed Apr 8, 2019
1 parent f18c679 commit 24253ce
Show file tree
Hide file tree
Showing 4 changed files with 273 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- Friendbot support

## [0.6.0] - 2018-11-27
### Added
Expand Down
5 changes: 4 additions & 1 deletion lib/stellar/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Client
HORIZON_LOCALHOST_URL = 'http://127.0.0.1:8000'
HORIZON_MAINNET_URL = 'https://horizon.stellar.org'
HORIZON_TESTNET_URL = 'https://horizon-testnet.stellar.org'
FRIENDBOT_URL = 'https://friendbot.stellar.org'.freeze

def self.default(options={})
new options.merge(
Expand Down Expand Up @@ -76,7 +77,9 @@ def account_merge(options={})
end

def friendbot(account)
raise NotImplementedError
uri = URI.parse(FRIENDBOT_URL)
uri.query = "addr=#{account.address}"
Faraday.post(uri.to_s)
end

Contract ({
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions spec/lib/stellar/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,27 @@
end
end

describe "#friendbot" do
let(:client) { Stellar::Client.default_testnet }
let(:account) { Stellar::Account.random }

it("requests for XLM from a friendbot", {
vcr: {record: :once, match_requests_on: [:method]}
}) do
response = client.friendbot(account)

expect(response).to be_success

destination_info = client.account_info(account)
balances = destination_info.balances
expect(balances).to_not be_empty
native_asset_balance_info = balances.find do |b|
b["asset_type"] == "native"
end
expect(native_asset_balance_info["balance"].to_f).to be > 0
end
end

describe "#create_account" do
let(:source) { Stellar::Account.from_seed(CONFIG[:source_seed]) }
let(:destination) { Stellar::Account.random }
Expand Down

0 comments on commit 24253ce

Please sign in to comment.