Add new script context test scenario covering minting & values.

This commit is contained in:
KtorZ 2023-02-15 12:49:56 +01:00
parent cf7f206324
commit b300cf38db
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
9 changed files with 124 additions and 4 deletions

View File

@ -16,3 +16,40 @@ for convenience.
``` ```
./test.sh [VALIDATOR_TITLE] ./test.sh [VALIDATOR_TITLE]
``` ```
## Test Coverage
- [ ] Purpose
- [x] Spend
- [x] Mint
- [ ] Withdraw
- [ ] Publish
- [ ] Transaction
- [ ] inputs
- [ ] reference inputs
- [ ] outputs
- [ ] address
- [x] verification key
- [ ] script
- [x] value
- [ ] datum
- [x] None
- [ ] Hash
- [ ] Inline
- [ ] script
- [x] None
- [ ] Reference
- [x] values
- [x] Pure Ada
- [x] Native assets
- [x] fee
- [x] mint
- [ ] certificates
- [x] withdrawals
- [x] verification key
- [x] script
- [ ] validity range
- [x] extra signatories
- [x] redeemers
- [ ] datums

View File

@ -0,0 +1 @@
81825820000000000000000000000000000000000000000000000000000000000000000000

View File

@ -0,0 +1 @@
81A200581D60FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF011A000F4240

View File

@ -0,0 +1 @@
84A400818258200000000000000000000000000000000000000000000000000000000000000000000180020109A1581C{{ VALIDATOR_HASH }}A143666F6F190539A20581840100D87980821A000F42401A05F5E1000681{{ VALIDATOR }}F5F6

View File

@ -0,0 +1,23 @@
[
{ 0:
[ [h'0000000000000000000000000000000000000000000000000000000000000000', 0]
]
, 1:
[]
, 2: 1
, 9:
{ h'{{ VALIDATOR_HASH }}': { h'666f6f': 1337 }
}
},
{ 5: [[1, 0, 121([]), [1000000, 100000000]]]
, 6: [h'{{ VALIDATOR }}']
},
true,
null
]

View File

@ -4,6 +4,16 @@
"version": "0.0.0" "version": "0.0.0"
}, },
"validators": [ "validators": [
{
"title": "mint",
"purpose": "mint",
"redeemer": {
"title": "Data",
"description": "Any Plutus data."
},
"compiledCode": "59049e010000323232323232323232323222533300532323232323001003300100122533300f00114a226464a6660180042660080080022940c04c008cdc3a4004601a6ea8c044004cc034ccc01cc8c8c8c8c8c8c94ccc04cc0580084c8c8cdc78018009bae3016001300932533300f3370e900018091baa0011001153301149012a4173736572746564206f6e20696e636f727265637420636f6e7374727563746f722076617269616e742e00163300830090034800854cc0412401364c6973742f5475706c652f436f6e73747220636f6e7461696e73206d6f7265206974656d73207468616e2069742065787065637465640016375c602800264646464600c00200200264640026644660100040020029110000137566600c600e6600c600e00290002401000e600200244a666020002297ae01323232323301537520026600c00c0066eb8c04400cdd59808801180a0011809000980080091129998078010a5eb7bdb1804c8c8c8c94ccc038cdc7802800880189980a19bb037520026e98008ccc01c01c00c014dd718080019bab3010002301300330110024c103d87a80004c0103d87980003300d333007323232323322323232323253330123370e00290010a9980a2490f746f6b656e206e6f7420666f756e640016132323370e00290790a1bad301a001300d00230143754002664466010004002002910103666f6f0033223233223253330153370e00290010801099190009bab301d00130100033017375400400297adef6c6033223300b002001002001375666012601400690040009bae30150013008533300d3370e900018081baa0021002153300f49012a4173736572746564206f6e20696e636f727265637420636f6e7374727563746f722076617269616e742e001633005300600748008cc014c01801d20003001001222533301100213374a900125eb804c8c8c8c94ccc040cdc7802800899ba548000cc058dd400125eb804ccc01c01c00c014dd718090019bad3012002301500330130023001001222533300f00213374a900125eb804c8c8c8c94ccc038cdc7802800899ba548000cc050dd300125eb804ccc01c01c00c014dd718080019bab3010002301300330110024c103d87a80004c0103d87980003300d3330073232323233223232533300f3375e006002266e1cc8c018004dd5998049805198049805002240009009240042940c054004c020c94ccc038cdc3a400060226ea8004400454cc0412412a4173736572746564206f6e20696e636f727265637420636f6e7374727563746f722076617269616e742e001633223300700200137566600e60106600e60100049000240246600e6010004900100380418008009129998080008a400026466e0120023300300300130130013001001222533300f00213374a900125eb804c8c8c8c94ccc038cdd7802800899ba548000cc0500092f5c0266600e00e00600a6020006602000460260066022004980103d87a80004c0103d87980004bd701119199800800a4000006444666601666e1c0100080488ccc010010cdc0001a40046028002002460146ea8004526163001001222533300900214984cc014c004c02c008ccc00c00cc0300080055cd2b9b5738aae7555cf2ab9f5740ae855d11",
"hash": "c941d5e9386a58d33f19ed088fc631bf0ded090d148268803e3dce7b"
},
{ {
"title": "withdrawals", "title": "withdrawals",
"purpose": "spend", "purpose": "spend",
@ -57,8 +67,8 @@
} }
] ]
}, },
"compiledCode": "59042a010000323232323232323232323222253330063232323232300200132323232323233016333010323253330123370e002900109919299980a19baf3300d300e0014800130126d8799f58200000000000000000000000000000000000000000000000000000000000000000ff0013370e6eb4cc034c038005200248000528180d00098060010a9980a2491c73637269707420707572706f73652069736e277420275370656e6427001630143754002660126014016900126103d87a80004c0103d87980003301633301032325333017001153301449011c756e6578706563746564206e756d626572206f66206f7574707574730016132533301800113232300c0013301a3330143375e6e98dd5998069807000a40046e98c0152080a8d6b9074c103d87a80004c0103d87980003301a3330143375e6601a601c6601a601c002900024000980122d8799f581c11111111111111111111111111111111111111111111111111111111ff004c0103d87a80004c0103d87980003301a333014323253330163370e0029000099250301000214a260306ea8004cc034c038cc034c038005200048009300103d87a80004c0103d87980004bd70180d0010a9980aa491c756e6578706563746564206e756d626572206f66206f7574707574730016301a00137586601460160029002198049805005a4000980103d87a80004c0103d879800033016333010323375e6e98dd5998051805800a400c6e98c009205433009300a00b4800130103d87a80004c0103d87980004bd7011999111919000999991111999805002001801000a5eb7bdb180010004020cccc8888cccc03001000c0080052f5bded8c000400200e9101004881000013001001222225333017004133018337606ea400cdd300125eb7bdb1804c8c8c8c94ccc058cdd79980280380099ba5480012f5c026603866ec0dd48039ba6006008153330163371e00e00226603866ec0dd48039ba600600313301c337606ea4004dd3001199998048048018038030029bae301800337566030004603600a603200844a66601c66e400080044cdd2a400097ae01533300e3371e004002266e9520024bd70099ba5480112f5c0600200244444a66602800826602a66ec0dd48019ba80024bd6f7b630099191919299980999baf330050070013374a900025eb804cc064cdd81ba9007375000c0102a66602666e3c01c0044cc064cdd81ba9007375000c00626603266ec0dd48009ba800233333009009003007006005375c602a0066eb4c054008c060014c058010c004004894ccc03c0045288991929998060010998020020008a5030130023370e900118069baa301100122323330010014800000c888cccc030cdc3802001009919980200219b8000348008c0540040048c02cdd50008a4c2c6002002444a666012004293099802980098058011998018019806001000ab9a5736ae7155ceaab9e5573eae815d0aba201", "compiledCode": "5904cb010000323232323232323232323222253330063232323232300200132323232323233016333010323330113375e660146016002900b26126d8799f58200000000000000000000000000000000000000000000000000000000000000000ff004a0944cc024c02802d20004c0103d87a80004c0103d879800033016333010323253330123370e002900109919299980a19baf3300d300e00148001300126d8799f58200000000000000000000000000000000000000000000000000000000000000000ff0013370e6eb4cc034c038005200248000528180d00098060010a9980a2491c73637269707420707572706f73652069736e277420275370656e6427001630143754002660126014016900126103d87a80004c0103d87980003301633301032325333017001153301449011c756e6578706563746564206e756d626572206f66206f7574707574730016132533301800113232300c0013301a3330143375e6e98dd5998069807000a40046e98c0152080a8d6b9074c103d87a80004c0103d87980003301a3330143375e6601a601c6601a601c002900024000980122d8799f581c11111111111111111111111111111111111111111111111111111111ff004c0103d87a80004c0103d87980003301a333014323253330163370e0029000099250301000214a260306ea8004cc034c038cc034c038005200048009300103d87a80004c0103d87980003301a3330143375e6601a601c002900219ba5480012f5c098103d87a80004c0103d87980003301a3330143375e6601a601c002900319ba5480092f5c098103d87a80004c0103d87980004bd70180d0010a9980aa491c756e6578706563746564206e756d626572206f66206f7574707574730016301a00137586601460160029002198049805005a4000980103d87a80004c0103d879800033016333010323375e6e98dd5998051805800a400c6e98c009205433009300a00b4800130103d87a80004c0103d87980004bd7011999111919000999991111999805002001801000a5eb7bdb180010004020cccc8888cccc03001000c0080052f5bded8c000400200e9101004881000013001001222225333017004133018337606ea400cdd300125eb7bdb1804c8c8c8c94ccc058cdd79980280380099ba5480012f5c026603866ec0dd48039ba6006008153330163371e00e00226603866ec0dd48039ba600600313301c337606ea4004dd3001199998048048018038030029bae301800337566030004603600a603200844a66601c66e400080044cdd2a400097ae01533300e3371e004002266e9520024bd70099ba5480112f5c0600200244444a66602800826602a66ec0dd48019ba80024bd6f7b630099191919299980999baf330050070013374a900025eb804cc064cdd81ba9007375000c0102a66602666e3c01c0044cc064cdd81ba9007375000c00626603266ec0dd48009ba800233333009009003007006005375c602a0066eb4c054008c060014c058010c004004894ccc03c0045288991929998060010998020020008a5030130023370e900118069baa301100122323330010014800000c888cccc030cdc3802001009919980200219b8000348008c0540040048c02cdd50008a4c2c6002002444a666012004293099802980098058011998018019806001000ab9a5736ae7155ceaab9e5573eae815d0aba201",
"hash": "1afe9a73274c140722127c27511395d861b5ed8e0bee1e7e9171c47a" "hash": "dfee0efa0f0c05bf6f3b69d626911891396a6c21d50da7653ce91aac"
} }
] ]
} }

View File

@ -37,6 +37,6 @@ VALIDATOR=$(cbor-diag --to hex --from diag <<< "h'$VALIDATOR'")
cp ctx/$TITLE/inputs.cbor.template ctx/$TITLE/inputs.cbor cp ctx/$TITLE/inputs.cbor.template ctx/$TITLE/inputs.cbor
sed "s/{{ VALIDATOR_HASH }}/$VALIDATOR_HASH/" ctx/$TITLE/outputs.cbor.template > ctx/$TITLE/outputs.cbor sed "s/{{ VALIDATOR_HASH }}/$VALIDATOR_HASH/" ctx/$TITLE/outputs.cbor.template > ctx/$TITLE/outputs.cbor
sed "s/{{ VALIDATOR }}/$VALIDATOR/" ctx/$TITLE/tx.cbor.template > ctx/$TITLE/tx.cbor sed "s/{{ VALIDATOR }}/$VALIDATOR/" ctx/$TITLE/tx.cbor.template | sed "s/{{ VALIDATOR_HASH }}/$VALIDATOR_HASH/" > ctx/$TITLE/tx.cbor
cargo run --quiet -- tx simulate ctx/$TITLE/tx.cbor ctx/$TITLE/inputs.cbor ctx/$TITLE/outputs.cbor cargo run --quiet -- tx simulate ctx/$TITLE/tx.cbor ctx/$TITLE/inputs.cbor ctx/$TITLE/outputs.cbor

View File

@ -1,11 +1,12 @@
use aiken/list use aiken/list
use aiken/option use aiken/option
use aiken/transaction.{ScriptContext, Spend, TransactionId} use aiken/transaction.{NoDatum, ScriptContext, Spend, TransactionId}
use aiken/transaction/credential.{VerificationKeyCredential} use aiken/transaction/credential.{VerificationKeyCredential}
use aiken/transaction/value use aiken/transaction/value
fn spend(_datum: Void, _redeemer: Void, ctx: ScriptContext) { fn spend(_datum: Void, _redeemer: Void, ctx: ScriptContext) {
[ [
assert_id(ctx.transaction),
assert_purpose(ctx.purpose), assert_purpose(ctx.purpose),
assert_outputs(ctx.transaction), assert_outputs(ctx.transaction),
assert_fee(ctx.transaction), assert_fee(ctx.transaction),
@ -13,6 +14,12 @@ fn spend(_datum: Void, _redeemer: Void, ctx: ScriptContext) {
|> list.and |> list.and
} }
fn assert_id(transaction) {
transaction.id != TransactionId(
#"0000000000000000000000000000000000000000000000000000000000000000",
)
}
fn assert_purpose(purpose) { fn assert_purpose(purpose) {
when purpose is { when purpose is {
Spend(ref) -> Spend(ref) ->
@ -36,6 +43,8 @@ fn assert_outputs(transaction) {
#"11111111111111111111111111111111111111111111111111111111", #"11111111111111111111111111111111111111111111111111111111",
), ),
option.is_none(output.address.stake_credential), option.is_none(output.address.stake_credential),
output.datum == NoDatum,
output.reference_script == None,
] ]
|> list.and |> list.and
_ -> error("unexpected number of outputs") _ -> error("unexpected number of outputs")

View 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
}