Skip to content

Commit

Permalink
Adjust e2e tests for minting/burning
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Stachyra committed Apr 15, 2022
1 parent fec6ec6 commit 14c905f
Showing 1 changed file with 24 additions and 27 deletions.
51 changes: 24 additions & 27 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,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' =>
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 @@ -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,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'])
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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|
Expand All @@ -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
Expand Down Expand Up @@ -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

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

0 comments on commit 14c905f

Please sign in to comment.