Skip to content

Commit

Permalink
Merge pull request #12 from piotr-iohk/redeem_rewards
Browse files Browse the repository at this point in the history
Redeem rewards
  • Loading branch information
piotr-iohk authored Jul 31, 2020
2 parents a151722 + 6706221 commit 924ca8f
Show file tree
Hide file tree
Showing 12 changed files with 606 additions and 90 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Set up cardano-wallet
run: NODE_CONFIG_PATH=`pwd`/spec/shelley-testnet docker-compose -f docker-compose-shelley.yml up --detach
run: NODE_CONFIG_PATH=`pwd`/spec/testnet docker-compose -f docker-compose-shelley.yml up --detach
- name: Set up Ruby
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
# change this to (see https://github.com/ruby/setup-ruby#versioning):
Expand All @@ -24,11 +24,11 @@ jobs:
run: bundle install
- name: Wait until node is synced
run: bundle exec rake wait_until_node_synced
- name: Run all tests
run: bundle exec rspec
- name: Run all tests (temporarily without nightly)
run: bundle exec rspec . -t ~nightly
env:
CI: true
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
NETWORK: testnet
WALLET: dev-master-shelley
NODE: master
NODE: 1.18.0
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Set up cardano-wallet
run: NODE_CONFIG_PATH=`pwd`/spec/shelley-testnet docker-compose -f docker-compose-shelley.yml up --detach
run: NODE_CONFIG_PATH=`pwd`/spec/testnet docker-compose -f docker-compose-shelley.yml up --detach
- name: Set up Ruby
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
# change this to (see https://github.com/ruby/setup-ruby#versioning):
Expand All @@ -38,4 +38,4 @@ jobs:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
NETWORK: testnet
WALLET: dev-master-shelley
NODE: master
NODE: 1.18.0
4 changes: 2 additions & 2 deletions docker-compose-shelley.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
- node-db:/data
- node-ipc:/ipc
- ${NODE_CONFIG_PATH}:/config
command: run --socket-path /ipc/node.socket --config /config/shelley_testnet-config.json --topology /config/shelley_testnet-topology.json --database-path /data
command: run --socket-path /ipc/node.socket --config /config/${NETWORK}-config.json --topology /config/${NETWORK}-topology.json --database-path /data
restart: on-failure

cardano-wallet:
Expand All @@ -18,7 +18,7 @@ services:
- ${NODE_CONFIG_PATH}:/config
ports:
- 8090:8090
command: serve --testnet /config/shelley_testnet-genesis.json --node-socket /ipc/node.socket --database /wallet-db --listen-address 0.0.0.0
command: serve --testnet /config/${NETWORK}-byron-genesis.json --node-socket /ipc/node.socket --database /wallet-db --listen-address 0.0.0.0
restart: on-failure

volumes:
Expand Down
41 changes: 29 additions & 12 deletions lib/cardano_wallet/shelley.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,26 @@ def list(wid, q = {})
# @param wid [String] source wallet id
# @param passphrase [String] source wallet's passphrase
# @param payments [Hash] addres, amount pair
# @param q [Hash] query param (currently only withdrawRewards = true | false)
# @param withdrawal [Strin or Array] 'self' or mnemonic sentence
#
# @example
# create(wid, passphrase, {addr1: 1000000}, q)
def create(wid, passphrase, payments, q = {})
# create(wid, passphrase, {addr1: 1000000}, 'self')
def create(wid, passphrase, payments, withdrawal = nil)
payments_formatted = Utils.format_payments(payments)
q.empty? ? query = '' : query = Utils.to_query(q)
self.class.post("/wallets/#{wid}/transactions#{query}",
:body => { :payments => payments_formatted,
:passphrase => passphrase
}.to_json,

if withdrawal
payload = { :payments => payments_formatted,
:passphrase => passphrase,
:withdrawal => withdrawal,
}
else
payload = { :payments => payments_formatted,
:passphrase => passphrase
}
end

self.class.post("/wallets/#{wid}/transactions",
:body => payload.to_json,
:headers => { 'Content-Type' => 'application/json' } )
end

Expand All @@ -214,11 +223,19 @@ def create(wid, passphrase, payments, q = {})
#
# @example
# payment_fees(wid, {addr1: 1000000})
def payment_fees(wid, payments, q = {})
def payment_fees(wid, payments, withdrawal = nil)
payments_formatted = Utils.format_payments(payments)
q.empty? ? query = '' : query = Utils.to_query(q)
self.class.post("/wallets/#{wid}/payment-fees#{query}",
:body => { :payments => payments_formatted }.to_json,

if withdrawal
payload = { :payments => payments_formatted,
:withdrawal => withdrawal
}
else
payload = { :payments => payments_formatted }
end

self.class.post("/wallets/#{wid}/payment-fees",
:body => payload.to_json,
:headers => { 'Content-Type' => 'application/json' } )
end

Expand Down
2 changes: 1 addition & 1 deletion lib/cardano_wallet/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module CardanoWallet
VERSION = "0.1.7"
VERSION = "0.1.8"
end
60 changes: 0 additions & 60 deletions spec/shelley-testnet/shelley_testnet-genesis.json

This file was deleted.

10 changes: 5 additions & 5 deletions spec/shelley_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@
end
end

it "I can send transaction using 'withdrawRewards' flag and funds are received", :nightly => true do
it "I can send transaction using 'withdrawal' flag and funds are received", :nightly => true do
amt = 1000000
wid = create_fixture_shelley_wallet
wait_for_shelley_wallet_to_sync(wid)
target_id = create_shelley_wallet
wait_for_shelley_wallet_to_sync(target_id)
address = SHELLEY.addresses.list(target_id)[0]['id']

tx_sent = SHELLEY.transactions.create(wid, PASS, {address => amt}, {withdrawRewards: true})
tx_sent = SHELLEY.transactions.create(wid, PASS, {address => amt}, 'self')
expect(tx_sent.code).to eq 202

eventually "Funds are on target wallet: #{target_id}" do
Expand All @@ -243,8 +243,8 @@
address = SHELLEY.addresses.list(target_id)[0]['id']
txs = SHELLEY.transactions

tx_sent = txs.create(id, PASS, {address => 1000000}, {withdrawRewards: true})
expect(tx_sent).to include "not_enough_money"
tx_sent = txs.create(id, PASS, {address => 1000000}, 'self')
expect(tx_sent).to include "withdrawal_not_worth"
expect(tx_sent.code).to eq 403
end

Expand All @@ -259,7 +259,7 @@
expect(fees).to include "not_enough_money"
expect(fees.code).to eq 403

fees = txs.payment_fees(id, {address => 1000000}, {withdrawRewards: true})
fees = txs.payment_fees(id, {address => 1000000}, 'self')
expect(fees).to include "not_enough_money"
expect(fees.code).to eq 403
end
Expand Down
Loading

0 comments on commit 924ca8f

Please sign in to comment.