Skip to content

Commit

Permalink
Checks for Machine-readable utxo_too_small error in e2e tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Stachyra authored and jonathanknowles committed Oct 29, 2022
1 parent 626efce commit f67247d
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 48 deletions.
122 changes: 74 additions & 48 deletions test/e2e/spec/e2e_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,7 @@

# Fund payment address to be used as collateral utxo
collateral_amt = 10000000
payment = [{ :address => payment_address,
:amount => { :quantity => collateral_amt,
:unit => 'lovelace' }
}]
tx = construct_sign_submit(@wid, payment)
tx = construct_sign_submit(@wid, payment_payload(collateral_amt, payment_address))
wait_for_tx_in_ledger(@wid, tx.last['id'])
collateral_utxo = CARDANO_CLI.get_utxos(payment_address).last
# Try to spend from alwaysfails.plutus address
Expand Down Expand Up @@ -132,11 +128,7 @@
expect(target_after['available']).to eq (target_before['available'] + collateral_ret_amt)

# Make sure you can spend collateral return output from the wallet
payment = [{ :address => payment_address,
:amount => { :quantity => 6500000,
:unit => 'lovelace' }
}]
tx = construct_sign_submit(@target_id, payment)
tx = construct_sign_submit(@target_id, payment_address(6500000, payment_address))
wait_for_tx_in_ledger(@target_id, tx.last['id'])

end
Expand Down Expand Up @@ -400,17 +392,24 @@ def fingerprint
end

describe "E2E Construct -> Sign -> Submit" do
it "I can get min_utxo_value when contructing tx" do
amt = 1
tx_constructed = SHELLEY.transactions.construct(@wid, payment_payload(amt))
expect(tx_constructed.code).to eq 403
expect(tx_constructed['code']).to eq 'utxo_too_small'
required_minimum = tx_constructed['info']['tx_output_lovelace_required_minimum']['quantity']

tx_constructed = SHELLEY.transactions.construct(@wid, payment_payload(required_minimum))
expect(tx_constructed).to be_correct_and_respond 202
end

it "Single output transaction" do
amt = MIN_UTXO_VALUE_PURE_ADA
address = SHELLEY.addresses.list(@target_id)[0]['id']
target_before = get_shelley_balances(@target_id)
src_before = get_shelley_balances(@wid)

payment = [{ :address => address,
:amount => { :quantity => amt,
:unit => 'lovelace' }
}]
tx_constructed = SHELLEY.transactions.construct(@wid, payment)
tx_constructed = SHELLEY.transactions.construct(@wid, payment_payload(amt, address))
expect(tx_constructed).to be_correct_and_respond 202
expected_fee = tx_constructed['fee']['quantity']
tx_decoded = SHELLEY.transactions.decode(@wid, tx_constructed["transaction"])
Expand Down Expand Up @@ -1794,17 +1793,24 @@ def fingerprint

describe "E2E Shared" do
describe "E2E Construct -> Sign -> Submit", :shared do
it "I can get min_utxo_value when contructing tx" do
amt = 1
tx_constructed = SHARED.transactions.construct(@wid_sha, payment_payload(amt))
expect(tx_constructed.code).to eq 403
expect(tx_constructed['code']).to eq 'utxo_too_small'
required_minimum = tx_constructed['info']['tx_output_lovelace_required_minimum']['quantity']

tx_constructed = SHARED.transactions.construct(@wid_sha, payment_payload(required_minimum))
expect(tx_constructed).to be_correct_and_respond 202
end

it "Single output transaction" do
amt = MIN_UTXO_VALUE_PURE_ADA
address = SHELLEY.addresses.list(@target_id)[1]['id']
target_before = get_shelley_balances(@target_id)
src_before = get_shared_balances(@wid_sha)

payment = [{ :address => address,
:amount => { :quantity => amt,
:unit => 'lovelace' }
}]
tx_constructed = SHARED.transactions.construct(@wid_sha, payment)
tx_constructed = SHARED.transactions.construct(@wid_sha, payment_payload(amt, address))
expect(tx_constructed).to be_correct_and_respond 202
expected_fee = tx_constructed['fee']['quantity']

Expand Down Expand Up @@ -2048,13 +2054,9 @@ def fingerprint
target_before = get_shelley_balances(@target_id)
src_before = get_shared_balances(@wid_sha)

payment = [{ :address => address,
:amount => { :quantity => amt,
:unit => 'lovelace' }
}]
validity_interval = {"invalid_before" => {"quantity" => 500, "unit" => "slot"},
"invalid_hereafter" => {"quantity" => 5000000000, "unit" => "slot"}}
tx_constructed = SHARED.transactions.construct(@wid_sha, payment,
tx_constructed = SHARED.transactions.construct(@wid_sha, payment_payload(amt, address),
withdrawal = nil,
metadata = nil,
delegations = nil,
Expand Down Expand Up @@ -2438,14 +2440,18 @@ def fingerprint
end

describe "Shelley Transactions" do
it "I can send transaction and funds are received" do
amt = MIN_UTXO_VALUE_PURE_ADA

it "I can send transaction and funds are received (min_utxo_value)" do
address = SHELLEY.addresses.list(@target_id)[0]['id']
available_before = SHELLEY.wallets.get(@target_id)['balance']['available']['quantity']
total_before = SHELLEY.wallets.get(@target_id)['balance']['total']['quantity']

tx_sent = SHELLEY.transactions.create(@wid, PASS, [{ address => amt }])
# get required minimum ada
tx = SHELLEY.transactions.create(@wid, PASS, payment_payload(1, address))
expect(tx.code).to eq 403
expect(tx['code']).to eq 'utxo_too_small'
amt = tx['info']['tx_output_lovelace_required_minimum']['quantity']

tx_sent = SHELLEY.transactions.create(@wid, PASS, payment_payload(amt, address))

expect(tx_sent).to be_correct_and_respond 202
expect(tx_sent.to_s).to include "pending"
Expand All @@ -2458,7 +2464,6 @@ def fingerprint
(available == amt + available_before) && (total == amt + total_before)
end


# examine the tx in history
# on src wallet
tx = SHELLEY.transactions.get(@wid, tx_sent['id'])
Expand Down Expand Up @@ -2594,20 +2599,22 @@ def fingerprint

end

it "I can estimate fee" do
it "I can estimate fee (min_utxo_value)" do
metadata = METADATA

address = SHELLEY.addresses.list(@target_id)[0]['id']
amt = [{ address => MIN_UTXO_VALUE_PURE_ADA }]

txs = SHELLEY.transactions
fees = txs.payment_fees(@wid, amt)
# get required minimum ada
fees = txs.payment_fees(@wid, payment_payload(1))
expect(fees.code).to eq 403
expect(fees['code']).to eq 'utxo_too_small'
amt = fees['info']['tx_output_lovelace_required_minimum']['quantity']

fees = txs.payment_fees(@wid, payment_payload(amt))
expect(fees).to be_correct_and_respond 202

fees = txs.payment_fees(@wid, amt, 'self')
fees = txs.payment_fees(@wid, payment_payload(amt), 'self')
expect(fees).to be_correct_and_respond 202

fees = txs.payment_fees(@wid, amt, 'self', metadata)
fees = txs.payment_fees(@wid, payment_payload(amt), 'self', metadata)
expect(fees).to be_correct_and_respond 202
end
end
Expand Down Expand Up @@ -2820,13 +2827,30 @@ def fingerprint

describe "E2E Byron" do

def test_byron_fees(source_wid)
txs = BYRON.transactions
# get required minimum ada
fees = txs.payment_fees(source_wid, payment_payload(1))
expect(fees.code).to eq 403
expect(fees['code']).to eq 'utxo_too_small'
amt = fees['info']['tx_output_lovelace_required_minimum']['quantity']

fees = txs.payment_fees(source_wid, payment_payload(amt))
expect(fees).to be_correct_and_respond 202
end

def test_byron_tx(source_wid, target_wid)
amt = MIN_UTXO_VALUE_PURE_ADA
address = SHELLEY.addresses.list(target_wid)[0]['id']
target_before = get_shelley_balances(target_wid)
src_before = get_byron_balances(source_wid)

tx_sent = BYRON.transactions.create(source_wid, PASS, [{ address => amt }])
# get required minimum ada
tx = BYRON.transactions.create(source_wid, PASS, payment_payload(1, address))
expect(tx.code).to eq 403
expect(tx['code']).to eq 'utxo_too_small'
amt = tx['info']['tx_output_lovelace_required_minimum']['quantity']

tx_sent = BYRON.transactions.create(source_wid, PASS, payment_payload(amt, address))

expect(tx_sent).to be_correct_and_respond 202
expect(tx_sent.to_s).to include "pending"
Expand Down Expand Up @@ -2892,12 +2916,19 @@ def test_byron_assets_tx(source_id, target_id)
end

describe "Byron Transactions" do
it "I can estimate fees (min_utxo_value), random" do
test_byron_fees(@wid_rnd)
end

it "I can send transaction and funds are received, random -> shelley" do
it "I can estimate fees (min_utxo_value), icarus" do
test_byron_fees(@wid_ic)
end

it "I can send transaction and funds are received (min_utxo_value), random -> shelley" do
test_byron_tx(@wid_rnd, @target_id)
end

it "I can send transaction and funds are received, icarus -> shelley" do
it "I can send transaction and funds are received (min_utxo_value), icarus -> shelley" do
test_byron_tx(@wid_ic, @target_id)
end
end
Expand Down Expand Up @@ -2927,7 +2958,6 @@ def test_byron_assets_tx(source_id, target_id)
end

describe "Native Assets" do

it "I can list assets -> random" do
assets = BYRON.assets.get @wid_rnd
expect(assets).to be_correct_and_respond 200
Expand Down Expand Up @@ -2988,11 +3018,7 @@ def test_byron_assets_tx(source_id, target_id)
target_before = get_shelley_balances(@target_id)
src_before = get_shelley_balances(@wid)

payment = [{ :address => address,
:amount => { :quantity => amt,
:unit => 'lovelace' }
}]
tx_constructed = SHELLEY.transactions.construct(@wid, payment)
tx_constructed = SHELLEY.transactions.construct(@wid, payment_payload(amt, address))
expect(tx_constructed).to be_correct_and_respond 202
expected_fee = tx_constructed['fee']['quantity']
tx_decoded = SHELLEY.transactions.decode(@wid, tx_constructed["transaction"])
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
TXID = "1acf9c0f504746cbd102b49ffaf16dcafd14c0a2f1bbb23af265fbe0a04951cc"
SPID = "feea59bc6664572e631e9adfee77142cb51264156debf2e52970cc00"
SPID_BECH32 = "pool1v7g9ays8h668d74xjvln9xuh9adzh6xz0v0hvcd3xukpck5z56d"
DEV_NULL_ADDR = "addr_test1qp760qtlwv6cyvvkpz3a6s0y72aea4xd4da85rm5qe2u6awgscyn6cz7plwgtanjanvpg9xt4lc3wlrqhcw5cmxk334q0wca8l"

# exemplary metadata
METADATA = { "0" => { "string" => "cardano" },
Expand Down Expand Up @@ -99,6 +100,13 @@
# 1 ADA, however should be enough for sending pure Ada output to shelley address
MIN_UTXO_VALUE_PURE_ADA = 1000000

def payment_payload(amt, addr = DEV_NULL_ADDR)
[{ :address => addr,
:amount => { :quantity => amt,
:unit => 'lovelace' }
}]
end

def create_incomplete_shared_wallet(m, acc_ix, acc_xpub)
script_template = { 'cosigners' =>
{ 'cosigner#0' => acc_xpub },
Expand Down

0 comments on commit f67247d

Please sign in to comment.