From 14c905f7107ef46e68de096b25d19d54f9682a50 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 15 Apr 2022 11:57:25 +0200 Subject: [PATCH 1/2] Adjust e2e tests for minting/burning --- test/e2e/spec/e2e_spec.rb | 51 ++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/test/e2e/spec/e2e_spec.rb b/test/e2e/spec/e2e_spec.rb index 91b03aca373..50dc39dd772 100644 --- a/test/e2e/spec/e2e_spec.rb +++ b/test/e2e/spec/e2e_spec.rb @@ -423,10 +423,9 @@ def fingerprint target_after, target_before, amt) - # Target wallet only lists my associated assets + # Target wallet lists my associated assets assets = SHELLEY.assets.get(@target_id) expect(assets).to be_correct_and_respond 200 - expect(assets.size).to eq 2 expect(assets.to_s).to include ASSETS[0]["policy_id"] expect(assets.to_s).to include ASSETS[0]["asset_name"] expect(assets.to_s).to include ASSETS[0]["metadata"]["name"] @@ -621,7 +620,7 @@ def fingerprint end describe "Minting and Burning" do - def mint(asset_name, quantity, policy_script, address) + def mint(asset_name, quantity, policy_script, address = nil) mint = { 'operation' => { 'mint' => @@ -679,8 +678,8 @@ def get_policy_id_from_decode(tx_decoded_mint_or_burn) # Minting: mint = [mint(asset_name('Token1'), 1000, policy_script1, address), - mint(asset_name('Token2'), 1000, policy_script2, address), - mint('', 1000, policy_script3, address) + mint(asset_name('Token2'), 1000, policy_script2), + mint('', 1000, policy_script3) ] create_policy_key_if_not_exists(@wid) tx_constructed, tx_signed, tx_submitted = construct_sign_submit(@wid, @@ -783,8 +782,8 @@ def get_policy_id_from_decode(tx_decoded_mint_or_burn) # Minting: mint = [mint(asset_name('TokenMetadata1'), assets_quantity, policy_script1, address), - mint(asset_name('TokenMetadata2'), assets_quantity, policy_script2, address), - mint(asset_name('TokenMetadata3'), assets_quantity, policy_script3, address) + mint(asset_name('TokenMetadata2'), assets_quantity, policy_script2), + mint(asset_name('TokenMetadata3'), assets_quantity, policy_script3) ] create_policy_key_if_not_exists(@wid) tx_constructed, tx_signed, tx_submitted = construct_sign_submit(@wid, @@ -863,7 +862,7 @@ def get_policy_id_from_decode(tx_decoded_mint_or_burn) # Minting: mint = [mint(asset_name('Asset1'), 500, policy_script1, address), - mint(asset_name('Asset2'), 500, policy_script2, address)] + mint(asset_name('Asset2'), 500, policy_script2)] create_policy_key_if_not_exists(@wid) tx_constructed, tx_signed, tx_submitted = construct_sign_submit(@wid, @@ -892,7 +891,7 @@ def get_policy_id_from_decode(tx_decoded_mint_or_burn) expect(assets).to eq(assets_to_check.map{|z| {z => 500}}.to_set) # Minting and burning: - mint_burn = [mint(asset_name('Asset1'), 500, policy_script1, address), + mint_burn = [mint(asset_name('Asset1'), 500, policy_script1), burn(asset_name('Asset2'), 500, policy_script2)] # p JSON.parse(mint_burn.to_json) @@ -1030,7 +1029,6 @@ def get_policy_id_from_decode(tx_decoded_mint_or_burn) { assets_to_check: assets_burned_to_check }) expect(assets_minted).to eq(assets_minted_to_check.map{|z| {z => 1}}.to_set) - p assets_burned_to_check # Burn all the rest: burn = [burn(assets_name, 1, policy_script)] @@ -1162,8 +1160,6 @@ def get_policy_id_from_decode(tx_decoded_mint_or_burn) # Tx4: Burns them it "Mint to foreign wallet / Cannot burn if I don't have keys" do - skip "TODO MINT: It doesn't mint to foreign wallet!" - src_before = get_shelley_balances(@wid) target_before = get_shelley_balances(@target_id) address = SHELLEY.addresses.list(@target_id).first['id'] @@ -1192,9 +1188,16 @@ def get_policy_id_from_decode(tx_decoded_mint_or_burn) src_after_minting = get_shelley_balances(@wid) target_after_minting = get_shelley_balances(@target_id) - # verify ADA balance is correct (fee is deducted) - expect(src_after_minting['available']).to eq (src_before['available'] - expected_fee) - expect(src_after_minting['total']).to eq (src_before['total'] - expected_fee) + # verify ADA balance is correct on src wallet: + # we are minting and sending to external address + # therefore the cost is fee + mintUTxOValue of ADA that is required + # for transfering the assets over the network + # in this the total `cost` is pure ADA minUTxOValue + 11 'utxo words' + fee + min_utxo_value = NETWORK.parameters['minimum_utxo_value']['quantity'].to_i + lovelace_per_utxo_word = 34482 + min_utxo_value_tokens = min_utxo_value + 11 * lovelace_per_utxo_word + expect(src_after_minting['available']).to eq (src_before['available'] - expected_fee - min_utxo_value_tokens) + expect(src_after_minting['total']).to eq (src_before['total'] - expected_fee - min_utxo_value_tokens) # verify assets have been minted and on target wallet's balance assets_to_check = get_assets_from_decode(tx_decoded['mint']) @@ -1254,7 +1257,7 @@ def get_policy_id_from_decode(tx_decoded_mint_or_burn) # make sure it was burned src_after_burning = get_shelley_balances(@wid) assets_to_check = get_assets_from_decode(tx_decoded['burn']) - assets = assets_balance(src_after_sending['assets_total'], { assets_to_check: assets_to_check }) + assets = assets_balance(src_after_burning['assets_total'], { assets_to_check: assets_to_check }) expect(assets).to eq({}.to_set) end @@ -1265,15 +1268,14 @@ def get_policy_id_from_decode(tx_decoded_mint_or_burn) matrix = [ [-9223372036854775808, 400, "bad_request"], [-1, 400, "bad_request"], - [0, 403, "bad_request"], - [9223372036854775808, 403, "bad_request"] + [0, 403, "mint_or_burn_asset_quantity_out_of_bounds"], + [9223372036854775808, 403, "mint_or_burn_asset_quantity_out_of_bounds"] ] matrix.each do |m| quantity = m[0] code = m[1] message = m[2] it "Cannot mint #{quantity} assets" do - skip "TODO MINT: Mint burn quantities edge cases" policy_script = 'cosigner#0' assets_name = asset_name('AmazingNFTIdontHave') assets_quantity = quantity @@ -1293,7 +1295,6 @@ def get_policy_id_from_decode(tx_decoded_mint_or_burn) end it "Cannot burn #{quantity} assets" do - skip "TODO MINT: Mint burn quantities edge cases" policy_script = 'cosigner#0' assets_name = asset_name('AmazingNFTIdontHave') assets_quantity = quantity @@ -1315,7 +1316,7 @@ def get_policy_id_from_decode(tx_decoded_mint_or_burn) # Make sure minting above boundary asset_name values returns proper error describe "Mint/Burn asset_name" do matrix = [ - ['too long', '1' * 66, 400, "bad_request"], + ['too long', '1' * 66, 403, "asset_name_too_long"], ['invalid hex', '1', 400, "bad_request"] ] matrix.each do |m| @@ -1324,9 +1325,6 @@ def get_policy_id_from_decode(tx_decoded_mint_or_burn) code = m[2] message = m[3] it "Cannot mint if my asset name is #{test}" do - - skip "TODO MINT: asset name too long throws 'Something went wrong' on construct" - address = SHELLEY.addresses.list(@wid).first['id'] policy_script = 'cosigner#0' assets_quantity = 1500 @@ -1396,7 +1394,7 @@ def get_policy_id_from_decode(tx_decoded_mint_or_burn) mint) expect(tx_constructed).to be_correct_and_respond 403 - expect(tx_constructed['code']).to eq 'transaction_is_too_big' + expect(tx_constructed['code']).to eq 'output_token_bundle_size_exceeds_limit' end end @@ -1936,10 +1934,9 @@ def test_byron_assets_tx(source_id, target_id) target_after, target_before, amt) - # Target wallet only lists my associated assets + # Target wallet lists my associated assets assets = SHELLEY.assets.get(target_id) expect(assets).to be_correct_and_respond 200 - expect(assets.size).to eq 2 expect(assets.to_s).to include ASSETS[0]["policy_id"] expect(assets.to_s).to include ASSETS[0]["asset_name"] expect(assets.to_s).to include ASSETS[0]["metadata"]["name"] From 9d92609d4251e9451743311f8e76ba11ecbcbd18 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 15 Apr 2022 16:33:55 +0200 Subject: [PATCH 2/2] Receiving address can be also empty --- test/e2e/spec/e2e_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/e2e/spec/e2e_spec.rb b/test/e2e/spec/e2e_spec.rb index 50dc39dd772..f69e50f4a2a 100644 --- a/test/e2e/spec/e2e_spec.rb +++ b/test/e2e/spec/e2e_spec.rb @@ -625,7 +625,6 @@ def mint(asset_name, quantity, policy_script, address = nil) 'operation' => { 'mint' => { - 'receiving_address' => address, 'amount' => { 'quantity' => quantity, 'unit' => 'assets' } @@ -633,6 +632,7 @@ def mint(asset_name, quantity, policy_script, address = nil) }, 'policy_script_template' => policy_script } + mint['operation']['mint']['receiving_address'] = address unless address == nil mint['asset_name'] = asset_name unless asset_name == nil mint end @@ -740,7 +740,7 @@ def get_policy_id_from_decode(tx_decoded_mint_or_burn) # Burn all the rest: burn = [burn(asset_name('Token1'), 500, policy_script1), burn(asset_name('Token2'), 500, policy_script2), - burn('', 500, policy_script3) + burn(nil, 500, policy_script3) ] tx_constructed, tx_signed, tx_submitted = construct_sign_submit(@wid, payments = nil, @@ -1205,8 +1205,9 @@ def get_policy_id_from_decode(tx_decoded_mint_or_burn) expect(assets).to eq(assets_to_check.map{|z| {z => assets_quantity}}.to_set) # Try to burn on target wallet and fail: + create_policy_key_if_not_exists(@target_id) burn = [burn(assets_name, assets_quantity, policy_script)] - tx_constructed = SHELLEY.transactions.construct(@wid, + tx_constructed = SHELLEY.transactions.construct(@target_id, payments = nil, withdrawal = nil, metadata = nil, @@ -1397,7 +1398,6 @@ def get_policy_id_from_decode(tx_decoded_mint_or_burn) expect(tx_constructed['code']).to eq 'output_token_bundle_size_exceeds_limit' end end - end describe "E2E Shared" do