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

Update tests / pending test against ADP-1738 #3267

Merged
merged 2 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -3458,6 +3458,95 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
(`shouldBe` tokens')
]

describe "TRANS_NEW_CREATE_MINT_SCRIPTS - I can mint and burn with different policy scripts" $ do
let scenarios =
[ ( "all", [json|{ "all": [ "cosigner#0" ] }|] )
, ( "any", [json|{ "any": [ "cosigner#0" ] }|] )
, ( "some", [json|{ "some": {"at_least": 1, "from": [ "cosigner#0" ]} }|] )
, ( "all, active_until 57297561", [json|{ "all": [ "cosigner#0", { "active_until": 57297561 } ] }|] )
, ( "any, active_until 57297561", [json|{ "any": [ "cosigner#0", { "active_until": 57297561 } ] }|] )
, ( "some, active_until 57297561", [json|{ "some": {"at_least": 1, "from": [ "cosigner#0", { "active_until": 57297561 } ]} }|] )
, ( "all, active_from 10", [json|{ "all": [ "cosigner#0", { "active_from": 10 } ] }|] )
, ( "any, active_from 10", [json|{ "any": [ "cosigner#0", { "active_from": 10 } ] }|] )
, ( "some, active_from 10", [json|{ "some": {"at_least": 1, "from": [ "cosigner#0", { "active_from": 10 } ]} }|] )
, ( "all, active_from 10, active_until 57297561", [json|{ "all": [ "cosigner#0", { "active_from": 10 }, { "active_until": 57297561 } ] }|] )
, ( "any, active_from 10, active_until 57297561", [json|{ "any": [ "cosigner#0", { "active_from": 10 }, { "active_until": 57297561 } ] }|] )
, ( "some, active_from 10, active_until 57297561", [json|{ "some": {"at_least": 1, "from": [ "cosigner#0", { "active_from": 10 }, { "active_until": 57297561 } ]} }|] )
]
forM_ scenarios $ \(title, policyScriptTemplate) -> it title $ \ctx -> runResourceT $ do
liftIO $ pendingWith "ADP-1738"
w <- fixtureWallet ctx

-- Mint it!
let payloadMint = Json [json|{
"mint_burn": [
{ "policy_script_template": #{policyScriptTemplate}
, "asset_name": "1111"
, "operation": { "mint": { "quantity": 50000 } }
}
]
}|]

rTx <- request @(ApiConstructTransaction n) ctx
(Link.createUnsignedTransaction @'Shelley w) Default payloadMint
verify rTx [ expectResponseCode HTTP.status202 ]
let apiTx = getFromResponse #transaction rTx
signedTx <- signTx ctx w apiTx [ expectResponseCode HTTP.status202 ]
submittedTx <- submitTxWithWid ctx w signedTx
verify submittedTx [ expectResponseCode HTTP.status202 ]

let initialBalance = w ^. #balance . #available . #getQuantity
let expectedFee = getFromResponse (#fee . #getQuantity) rTx

eventually "Assets are minted!" $ do
rW <- request @ApiWallet ctx
(Link.getWallet @'Shelley w) Default Empty
verify rW
[ expectSuccess
, expectField
(#balance . #available . #getQuantity)
(`shouldBe` initialBalance - fromIntegral expectedFee)
, expectField (#assets . #available . #getApiT)
(`shouldNotBe` TokenMap.empty)
, expectField (#assets . #total . #getApiT)
(`shouldNotBe` TokenMap.empty)
]

-- Burn it!
let payloadBurn = Json [json|{
"mint_burn": [
{ "policy_script_template": #{policyScriptTemplate}
, "asset_name": "1111"
, "operation": { "burn": { "quantity": 50000 } }
}
]
}|]

rTx2 <- request @(ApiConstructTransaction n) ctx
(Link.createUnsignedTransaction @'Shelley w) Default payloadBurn
verify rTx2 [ expectResponseCode HTTP.status202 ]
let apiTx2 = getFromResponse #transaction rTx2
signedTx2 <- signTx ctx w apiTx2 [ expectResponseCode HTTP.status202 ]
submittedTx2 <- submitTxWithWid ctx w signedTx2
verify submittedTx2 [ expectResponseCode HTTP.status202 ]

let newBalance = initialBalance - fromIntegral expectedFee
let expectedFeeBurn = getFromResponse (#fee . #getQuantity) rTx2

eventually "Assets are burned!" $ do
rW <- request @ApiWallet ctx
(Link.getWallet @'Shelley w) Default Empty
verify rW
[ expectSuccess
, expectField
(#balance . #available . #getQuantity)
(`shouldBe` newBalance - fromIntegral expectedFeeBurn)
, expectField (#assets . #available . #getApiT)
(`shouldBe` TokenMap.empty)
, expectField (#assets . #total . #getApiT)
(`shouldBe` TokenMap.empty)
]

it "TRANS_NEW_CREATE_11 - Get policy id - incorrect template \
\" $ \ctx -> runResourceT $ do
wa <- fixtureWallet ctx
Expand Down
29 changes: 9 additions & 20 deletions test/e2e/spec/e2e_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -621,32 +621,18 @@ def fingerprint

describe "Minting and Burning" do
def mint(asset_name, quantity, policy_script, address = nil)
mint = {
'operation' => {
'mint' =>
{
'amount' => { 'quantity' => quantity,
'unit' => 'assets'
}
}
},
'policy_script_template' => policy_script
}
mint = { 'operation' => { 'mint' => { 'quantity' => quantity } },
'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

def burn(asset_name, quantity, policy_script)
burn = {
'operation' => {
'burn' => { 'quantity' => quantity,
'unit' => 'assets'
}

},
'policy_script_template' => policy_script
}
burn = { 'operation' => { 'burn' => { 'quantity' => quantity } },
'policy_script_template' => policy_script
}
burn['asset_name'] = asset_name unless asset_name == nil
burn
end
Expand All @@ -670,6 +656,7 @@ def get_policy_id_from_decode(tx_decoded_mint_or_burn)
# Tx2: Burns 3 x 500 of each and verifies 500 of each remain on wallet
# Tx3: Burns remaining 3 x 500 and verifies they're no longer on balance
it "Can mint and then burn" do
pending "ADP-1738"
src_before = get_shelley_balances(@wid)
address = SHELLEY.addresses.list(@wid).first['id']
policy_script1 = 'cosigner#0'
Expand Down Expand Up @@ -772,6 +759,7 @@ def get_policy_id_from_decode(tx_decoded_mint_or_burn)
# Tx1: Mints 3 x 1 assets with metadata
# Tx2: Burns 3 x 1 assets and also assign metadata to tx
it "Can mint and burn with metadata" do
pending "ADP-1738"
src_before = get_shelley_balances(@wid)
address = SHELLEY.addresses.list(@wid).first['id']
policy_script1 = 'cosigner#0'
Expand Down Expand Up @@ -855,6 +843,7 @@ def get_policy_id_from_decode(tx_decoded_mint_or_burn)
# Tx2: Mints 500 more of A1 and burns 500 of A2 => A1 = 1000, A2 = 0
# Tx3: Burns remaining 1000 of A1 => A1 = 0, A2 = 0
it "Can mint and burn in the same tx" do
pending "ADP-1738"
src_before = get_shelley_balances(@wid)
address = SHELLEY.addresses.list(@wid).first['id']
policy_script1 = { "some" => {"at_least" => 1, "from" => [ "cosigner#0" ]} }
Expand Down