Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust e2e tests for minting/burning edge cases #3236

Merged
merged 2 commits into from
Apr 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 28 additions & 31 deletions test/e2e/spec/e2e_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -621,19 +620,19 @@ 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' =>
{
'receiving_address' => address,
'amount' => { 'quantity' => quantity,
'unit' => 'assets'
}
}
},
'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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -741,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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -1192,18 +1188,26 @@ 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'])
assets = assets_balance(target_after_minting['assets_total'], { assets_to_check: assets_to_check })
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,
Expand Down Expand Up @@ -1254,7 +1258,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
Expand All @@ -1265,15 +1269,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
Expand All @@ -1293,7 +1296,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
Expand All @@ -1315,7 +1317,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|
Expand All @@ -1324,9 +1326,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
Expand Down Expand Up @@ -1396,10 +1395,9 @@ 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

end

describe "E2E Shared" do
Expand Down Expand Up @@ -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"]
Expand Down