Skip to content

Commit

Permalink
Merge #3236
Browse files Browse the repository at this point in the history
3236: Adjust e2e tests for minting/burning edge cases r=piotr-iohk a=piotr-iohk

<!--
Detail in a few bullet points the work accomplished in this PR.

Before you submit, don't forget to:

* Make sure the GitHub PR fields are correct:
   ✓ Set a good Title for your PR.
   ✓ Assign yourself to the PR.
   ✓ Assign one or more reviewer(s).
   ✓ Link to a Jira issue, and/or other GitHub issues or PRs.
   ✓ In the PR description delete any empty sections
     and all text commented in <!--, so that this text does not appear
     in merge commit messages.

* Don't waste reviewers' time:
   ✓ If it's a draft, select the Create Draft PR option.
   ✓ Self-review your changes to make sure nothing unexpected slipped through.

* Try to make your intent clear:
   ✓ Write a good Description that explains what this PR is meant to do.
   ✓ Jira will detect and link to this PR once created, but you can also
     link this PR in the description of the corresponding Jira ticket.
   ✓ Highlight what Testing you have done.
   ✓ Acknowledge any changes required to the Documentation.
-->


- [x] Adjust e2e tests for minting/burning edge cases

### Comments

Adjust tests after #3226.

### Issue Number

adp-1542

Co-authored-by: Piotr Stachyra <piotr.stachyra@iohk.io>
  • Loading branch information
iohk-bors[bot] and Piotr Stachyra authored Apr 15, 2022
2 parents 72d6eb7 + 9d92609 commit 2e7c771
Showing 1 changed file with 28 additions and 31 deletions.
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

0 comments on commit 2e7c771

Please sign in to comment.