Add new script context test scenario covering minting & values.
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
use aiken/list
|
||||
use aiken/option
|
||||
use aiken/transaction.{ScriptContext, Spend, TransactionId}
|
||||
use aiken/transaction.{NoDatum, ScriptContext, Spend, TransactionId}
|
||||
use aiken/transaction/credential.{VerificationKeyCredential}
|
||||
use aiken/transaction/value
|
||||
|
||||
fn spend(_datum: Void, _redeemer: Void, ctx: ScriptContext) {
|
||||
[
|
||||
assert_id(ctx.transaction),
|
||||
assert_purpose(ctx.purpose),
|
||||
assert_outputs(ctx.transaction),
|
||||
assert_fee(ctx.transaction),
|
||||
@@ -13,6 +14,12 @@ fn spend(_datum: Void, _redeemer: Void, ctx: ScriptContext) {
|
||||
|> list.and
|
||||
}
|
||||
|
||||
fn assert_id(transaction) {
|
||||
transaction.id != TransactionId(
|
||||
#"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
)
|
||||
}
|
||||
|
||||
fn assert_purpose(purpose) {
|
||||
when purpose is {
|
||||
Spend(ref) ->
|
||||
@@ -36,6 +43,8 @@ fn assert_outputs(transaction) {
|
||||
#"11111111111111111111111111111111111111111111111111111111",
|
||||
),
|
||||
option.is_none(output.address.stake_credential),
|
||||
output.datum == NoDatum,
|
||||
output.reference_script == None,
|
||||
]
|
||||
|> list.and
|
||||
_ -> error("unexpected number of outputs")
|
||||
|
||||
38
examples/acceptance_tests/script_context/validators/mint.ak
Normal file
38
examples/acceptance_tests/script_context/validators/mint.ak
Normal file
@@ -0,0 +1,38 @@
|
||||
use aiken/dict
|
||||
use aiken/list
|
||||
use aiken/transaction.{Mint, ScriptContext}
|
||||
use aiken/transaction/value
|
||||
|
||||
fn mint(redeemer: Data, ctx: ScriptContext) {
|
||||
[
|
||||
assert_purpose(ctx),
|
||||
assert_mint(ctx.purpose, ctx.transaction),
|
||||
assert_redeemers(ctx, redeemer),
|
||||
]
|
||||
|> list.and
|
||||
}
|
||||
|
||||
fn assert_purpose(ctx) {
|
||||
expect [my_policy_id] =
|
||||
ctx.transaction.mint
|
||||
|> value.without_lovelace
|
||||
|> value.policies
|
||||
expect Mint(policy_id) = ctx.purpose
|
||||
|
||||
my_policy_id == policy_id
|
||||
}
|
||||
|
||||
fn assert_mint(purpose, transaction) {
|
||||
expect Mint(policy_id) = purpose
|
||||
let tokens = value.tokens(transaction.mint, policy_id)
|
||||
|
||||
when dict.get(tokens, #"666f6f") is {
|
||||
None -> error("token not found")
|
||||
Some(quantity) -> quantity == 1337
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_redeemers(ctx, my_redeemer) {
|
||||
expect Some(redeemer) = dict.get(ctx.transaction.redeemers, ctx.purpose)
|
||||
my_redeemer == redeemer && dict.size(ctx.transaction.redeemers) == 1
|
||||
}
|
||||
Reference in New Issue
Block a user