Add new context test for datums and reference scripts

This commit is contained in:
KtorZ 2023-02-15 17:10:14 +01:00
parent 6772e20d85
commit 47e77aa819
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
7 changed files with 149 additions and 29 deletions

View File

@ -22,7 +22,7 @@ for convenience.
- [ ] Purpose - [ ] Purpose
- [x] Spend - [x] Spend
- [x] Mint - [x] Mint
- [ ] Withdraw - [x] Withdraw
- [ ] Publish - [ ] Publish
- [ ] Transaction - [ ] Transaction
@ -31,15 +31,16 @@ for convenience.
- [ ] outputs - [ ] outputs
- [ ] address - [ ] address
- [x] verification key - [x] verification key
- [ ] script - [x] script
- [ ] pointer
- [x] value - [x] value
- [ ] datum - [x] datum
- [x] None - [x] None
- [ ] Hash - [x] Hash
- [ ] Inline - [x] Inline
- [ ] script - [x] script
- [x] None - [x] None
- [ ] Reference - [x] Reference
- [x] values - [x] values
- [x] Pure Ada - [x] Pure Ada
- [x] Native assets - [x] Native assets
@ -52,4 +53,4 @@ for convenience.
- [ ] validity range - [ ] validity range
- [x] extra signatories - [x] extra signatories
- [x] redeemers - [x] redeemers
- [ ] datums - [x] datums

View File

@ -0,0 +1 @@
81825820000000000000000000000000000000000000000000000000000000000000000000

View File

@ -0,0 +1 @@
81A300581D70{{ VALIDATOR_HASH }}011A000F4240028201D81843D87980

View File

@ -0,0 +1 @@
84A300818258200000000000000000000000000000000000000000000000000000000000000000000182A400581D6000000000000000000000000000000000000000000000000000000000011A000F42400282005820FCAA61FB85676101D9E3398A484674E71C45C3FD41B492682F3B0054F4CF327303D81858418202583D583B0100003232323232323222253330064A22930B180080091129998030010A4C26600A6002600E0046660060066010004002AE695CDAAB9F5742AE89A3005839100000000000000000000000000000000000000000000000000000000066666666666666666666666666666666666666666666666666666666011A000F4240028201D81846D8799F182AFF0201A30482D8799FFFD8799F182AFF0581840000D87980821A000F42401A05F5E1000681{{ VALIDATOR }}F5F6

View File

@ -0,0 +1,30 @@
[
{ 0:
[ [h'0000000000000000000000000000000000000000000000000000000000000000', 0]
]
, 1:
[ { 0: h'6000000000000000000000000000000000000000000000000000000000'
, 1: 1000000
, 2: [ 0, h'fcaa61fb85676101d9e3398a484674e71c45c3fd41b492682f3b0054f4cf3273' ]
, 3: 24(h'8202583D583B0100003232323232323222253330064A22930B180080091129998030010A4C26600A6002600E0046660060066010004002AE695CDAAB9F5742AE89')
}
, { 0: h'100000000000000000000000000000000000000000000000000000000066666666666666666666666666666666666666666666666666666666'
, 1: 1000000
, 2: [ 1, 24(h'D8799F182AFF') ]
}
]
, 2: 1
},
{ 4: [121([]), 121([42])]
, 5: [[0, 0, 121([]), [1000000, 100000000]]]
, 6: []
},
true,
null
]

View File

@ -4,6 +4,34 @@
"version": "0.0.0" "version": "0.0.0"
}, },
"validators": [ "validators": [
{
"title": "withdrawals",
"purpose": "spend",
"datum": {
"title": "Unit",
"description": "The nullary constructor.",
"anyOf": [
{
"dataType": "constructor",
"index": 0,
"fields": []
}
]
},
"redeemer": {
"title": "Unit",
"description": "The nullary constructor.",
"anyOf": [
{
"dataType": "constructor",
"index": 0,
"fields": []
}
]
},
"compiledCode": "5902d80100003232323232323232323232222533300632323232323001003300100122533301000114a226464a66601a0042660080080022940c050008cdc3a4004601c6ea8c048004c8c8c8cc044ccc02cc8c94ccc034cdc3800a40042a6601e9211c616c6963652773207769746864726177616c206e6f7420666f756e640016132323370e002902a1bad30150013007002300f3754002660026eaccc010c014cc010c01401920004803130126d8799fd8799f581c22222222222222222222222222222222222222222222222222222222ffff004c0103d87a80004c0103d87980003301133300b3232533300d3370e00290010a99807a491a626f622773207769746864726177616c206e6f7420666f756e640016132323370e002900e1bad30150013007002300f3754002660026eaccc010c014cc010c01401920004803130126d8799fd87a9f581cafddc16c18e7d8de379fb9aad39b3d1b5afd27603e5ebac818432a72ffff004c0103d87a80004c0103d87980003301133300b3375e6e9cc8c8c8c008004dd599803180399803180380424000900618008009129998090008a5eb804c8c8c8c8cc05c004cc01801800cc04c00cdd69809801180b001180a0009ba7330114c0126d8799fd8799f581c22222222222222222222222222222222222222222222222222222222ffff00330114c126d8799fd87a9f581cafddc16c18e7d8de379fb9aad39b3d1b5afd27603e5ebac818432a72ffff004bd7026103d87a80004c0103d87980004bd70111980180100098008009112999808001099ba5480092f5c0264646464a66601e66ebc0140044cdd2a40006602a6ea00092f5c0266600e00e00600a60220066eb4c044008c05000cc04800888c8ccc0040052000003222333300c3370e008004026466600800866e0000d200230150010012300b37540022930b180080091129998048010a4c26600a600260160046660060066018004002ae695cdab9c5573aaae7955cfaba05742ae89",
"hash": "d728bee57cec0eeab091201017a43001978acda9c0957bae8c9704df"
},
{ {
"title": "mint", "title": "mint",
"purpose": "mint", "purpose": "mint",
@ -43,32 +71,18 @@
"hash": "dfee0efa0f0c05bf6f3b69d626911891396a6c21d50da7653ce91aac" "hash": "dfee0efa0f0c05bf6f3b69d626911891396a6c21d50da7653ce91aac"
}, },
{ {
"title": "withdrawals", "title": "deploy",
"purpose": "spend", "purpose": "spend",
"datum": { "datum": {
"title": "Unit", "title": "Data",
"description": "The nullary constructor.", "description": "Any Plutus data."
"anyOf": [
{
"dataType": "constructor",
"index": 0,
"fields": []
}
]
}, },
"redeemer": { "redeemer": {
"title": "Unit", "title": "Data",
"description": "The nullary constructor.", "description": "Any Plutus data."
"anyOf": [
{
"dataType": "constructor",
"index": 0,
"fields": []
}
]
}, },
"compiledCode": "5902d80100003232323232323232323232222533300632323232323001003300100122533301000114a226464a66601a0042660080080022940c050008cdc3a4004601c6ea8c048004c8c8c8cc044ccc02cc8c94ccc034cdc3800a40042a6601e9211c616c6963652773207769746864726177616c206e6f7420666f756e640016132323370e002902a1bad30150013007002300f3754002660026eaccc010c014cc010c01401920004803130126d8799fd8799f581c22222222222222222222222222222222222222222222222222222222ffff004c0103d87a80004c0103d87980003301133300b3232533300d3370e00290010a99807a491a626f622773207769746864726177616c206e6f7420666f756e640016132323370e002900e1bad30150013007002300f3754002660026eaccc010c014cc010c01401920004803130126d8799fd87a9f581cafddc16c18e7d8de379fb9aad39b3d1b5afd27603e5ebac818432a72ffff004c0103d87a80004c0103d87980003301133300b3375e6e9cc8c8c8c008004dd599803180399803180380424000900618008009129998090008a5eb804c8c8c8c8cc05c004cc01801800cc04c00cdd69809801180b001180a0009ba7330114c0126d8799fd8799f581c22222222222222222222222222222222222222222222222222222222ffff00330114c126d8799fd87a9f581cafddc16c18e7d8de379fb9aad39b3d1b5afd27603e5ebac818432a72ffff004bd7026103d87a80004c0103d87980004bd70111980180100098008009112999808001099ba5480092f5c0264646464a66601e66ebc0140044cdd2a40006602a6ea00092f5c0266600e00e00600a60220066eb4c044008c05000cc04800888c8ccc0040052000003222333300c3370e008004026466600800866e0000d200230150010012300b37540022930b180080091129998048010a4c26600a600260160046660060066018004002ae695cdab9c5573aaae7955cfaba05742ae89", "compiledCode": "5904b001000032323232323232323232322225333006323232323230020013301033300a32323375e0040026601893260103d87980000074c103d87a80004c0103d87980003301033300a32323232323232330123253330123370e002900009919299980c980e0010a4c2a6602c921364c6973742f5475706c652f436f6e73747220636f6e7461696e73206d6f7265206974656d73207468616e2069742065787065637465640016375a603400260180042a660289212b436f6e73747220696e64657820646964206e6f74206d6174636820616e7920747970652076617269616e74001630143754002a66602266ebd30106d8799f182aff0000113370e64600a00200690020a50301700130093253330103370e900018099baa0011001153301249012a4173736572746564206f6e20696e636f727265637420636f6e7374727563746f722076617269616e742e00163322330060020010013237280026ecd30106d8799f182aff0037566600e60106600e6010012900024028600200244a6660260022900009919b8048008cc00c00c004c058004c0040048894ccc0480084cdd2a400497ae013232323253330113371e00a002266e952000330170024bd7009998038038018029bae30130033013002301600330140024c0103d87a80004c0103d87980003301033300a325333010001153300d4901316578706563746564207472616e73616374696f6e20746f206861766520286174206c65617374292032206f75747075747300161325333011001153300e4901316578706563746564207472616e73616374696f6e20746f206861766520286174206c65617374292032206f757470757473001613253330120011323232533301032323009001330173330113375e6601460160029002260126d87a9f5820fcaa61fb85676101d9e3398a484674e71c45c3fd41b492682f3b0054f4cf3273ff004c0103d87a80004c0103d8798000330173330113375e6601460160029003260122d8799f581ce37db487fbd58c45d059bcbf5cd6b1604d3bec16cf888f1395a4ebc4ff004c0103d87a80004c0103d87980004bd700018991918048009980b99980899baf3300a300b3300a300b0014800120024c012ad8799fd8799fd8799f581c66666666666666666666666666666666666666666666666666666666ffffff004c0103d87a80004c0103d879800033017333011323253330133370e0029002099251300d0021533015490115657870656374656420696e6c696e6520646174756d001630153754002660146016002900226103d87a80004c0103d87980004bd700010a50301700430150033014003153300f4901316578706563746564207472616e73616374696f6e20746f206861766520286174206c65617374292032206f757470757473001630140013013001375866006600866006600800a900024008980103d87a80004c0103d87980004bd7018008009129998078008a5113232533300c00213300400400114a0602600466e1d2002300d3754602200244646660020029000001911199980619b870040020132333004004337000069001180a800800918059baa001149858c0040048894ccc0240085261330053001300b002333003003300c0020015734ae6d5ce2ab9d5573caae7d5d02ba15745",
"hash": "d728bee57cec0eeab091201017a43001978acda9c0957bae8c9704df" "hash": "40d205673f92b78edf545e560dcbbaa13e9e6b60bca1bebe70950efd"
} }
] ]
} }

View File

@ -0,0 +1,72 @@
use aiken/builtin
use aiken/dict
use aiken/hash.{blake2b_256}
use aiken/list
use aiken/transaction.{DatumHash, InlineDatum, ScriptContext}
use aiken/transaction/credential.{Inline, VerificationKeyCredential}
fn spend(datum: Data, _redeemer: Data, ctx: ScriptContext) {
[
assert_datum(datum),
assert_datums(ctx.transaction.datums),
assert_outputs(ctx.transaction.outputs),
]
|> list.and
}
fn assert_datum(datum) {
let my_datum: Data = Void
datum == my_datum
}
type MyDatum {
MyDatum(Int)
}
fn assert_datums(datums) {
let my_datum = MyDatum(42)
expect Some(datum) =
dict.get(datums, blake2b_256(builtin.serialise_data(my_datum)))
expect datum: MyDatum = datum
my_datum == datum && dict.size(datums) == 2
}
fn assert_outputs(outputs) {
when outputs is {
[output_1, output_2, ..] ->
assert_first_output(output_1) && assert_second_output(output_2)
_ -> error("expected transaction to have (at least) 2 outputs")
}
}
fn assert_first_output(output) {
[
output.datum == DatumHash(
#"fcaa61fb85676101d9e3398a484674e71c45c3fd41b492682f3b0054f4cf3273",
),
output.reference_script == Some(
#"e37db487fbd58c45d059bcbf5cd6b1604d3bec16cf888f1395a4ebc4",
),
]
|> list.and
}
fn assert_second_output(output) {
[
output.address.stake_credential == Some(
Inline(
VerificationKeyCredential(
#"66666666666666666666666666666666666666666666666666666666",
))
)
,
when output.datum is {
InlineDatum(_) -> True
_ -> error("expected inline datum")
},
]
|> list.and
}