Move script context e2e tests under a nested 'v2' directory.
And rework scripts to run them in anticipation of new v3 contexts.
This commit is contained in:
1
examples/acceptance_tests/script_context/v2/.gitignore
vendored
Normal file
1
examples/acceptance_tests/script_context/v2/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
ctx/**/*.cbor
|
||||
56
examples/acceptance_tests/script_context/v2/README.md
Normal file
56
examples/acceptance_tests/script_context/v2/README.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# V2 Script Context Tests
|
||||
|
||||
This project contains a few handcrafted Plutus V2 validators and transactions
|
||||
whose sole purpose is to test the interpretation of the `ScriptContext` from
|
||||
within an Aiken's validators.
|
||||
|
||||
So validators are meant to work hand-in-hand with an associated context.
|
||||
Because we can't have fully static context (since they contain the validator
|
||||
and its hash), we define _templates_.
|
||||
|
||||
Everything is a bit clunky, but steps have been captured in a `test.sh` script
|
||||
for convenience.
|
||||
|
||||
## How to use
|
||||
|
||||
```
|
||||
./test.sh [VALIDATOR_TITLE]
|
||||
```
|
||||
|
||||
## Test Coverage
|
||||
|
||||
- [ ] Purpose
|
||||
- [x] spend
|
||||
- [x] mint
|
||||
- [x] withdraw
|
||||
- [ ] publish
|
||||
|
||||
- [ ] Transaction
|
||||
- [ ] inputs
|
||||
- [ ] reference inputs
|
||||
- [ ] outputs
|
||||
- [ ] address
|
||||
- [x] verification key
|
||||
- [x] script
|
||||
- [ ] pointer
|
||||
- [x] value
|
||||
- [x] datum
|
||||
- [x] none
|
||||
- [x] hash
|
||||
- [x] inline
|
||||
- [x] script
|
||||
- [x] none
|
||||
- [x] 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
|
||||
- [x] datums
|
||||
16
examples/acceptance_tests/script_context/v2/aiken.lock
Normal file
16
examples/acceptance_tests/script_context/v2/aiken.lock
Normal file
@@ -0,0 +1,16 @@
|
||||
# This file was generated by Aiken
|
||||
# You typically do not need to edit this file
|
||||
|
||||
[[requirements]]
|
||||
name = "aiken-lang/stdlib"
|
||||
version = "main"
|
||||
source = "github"
|
||||
|
||||
[[packages]]
|
||||
name = "aiken-lang/stdlib"
|
||||
version = "main"
|
||||
requirements = []
|
||||
source = "github"
|
||||
|
||||
[etags]
|
||||
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1723298787, nanos_since_epoch = 494542000 }, "5e58899446492a704d0927a43299139856bef746e697b55895ba34206fa28452"]
|
||||
10
examples/acceptance_tests/script_context/v2/aiken.toml
Normal file
10
examples/acceptance_tests/script_context/v2/aiken.toml
Normal file
@@ -0,0 +1,10 @@
|
||||
name = "script_context/v2"
|
||||
version = "0.0.0"
|
||||
plutus = "v2"
|
||||
license = "Apache-2.0"
|
||||
description = "Aiken contracts for project 'script_context/v2'"
|
||||
|
||||
[[dependencies]]
|
||||
name = "aiken-lang/stdlib"
|
||||
version = "main"
|
||||
source = "github"
|
||||
@@ -0,0 +1 @@
|
||||
81825820000000000000000000000000000000000000000000000000000000000000000000
|
||||
@@ -0,0 +1 @@
|
||||
81A300581D70{{ VALIDATOR_HASH }}011A3B9ACA00028201D81843D87980
|
||||
@@ -0,0 +1 @@
|
||||
84A70081825820000000000000000000000000000000000000000000000000000000000000000000018182581D60111111111111111111111111111111111111111111111111111111111A3B9ACA0002182A0B5820FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0D818258200000000000000000000000000000000000000000000000000000000000000000001082581D60000000000000000000000000000000000000000000000000000000001A3B9ACA001101A20581840000D87980821A000F42401A05F5E1000681{{ VALIDATOR }}F5F6
|
||||
@@ -0,0 +1,34 @@
|
||||
[
|
||||
{ 0:
|
||||
[ [h'0000000000000000000000000000000000000000000000000000000000000000', 0]
|
||||
]
|
||||
|
||||
, 1:
|
||||
[ [h'6011111111111111111111111111111111111111111111111111111111', 1000000000]
|
||||
]
|
||||
|
||||
, 2: 42
|
||||
|
||||
, 11: h'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'
|
||||
|
||||
, 13:
|
||||
[ [h'0000000000000000000000000000000000000000000000000000000000000000', 0]
|
||||
]
|
||||
|
||||
, 16:
|
||||
[ h'6000000000000000000000000000000000000000000000000000000000', 1000000000
|
||||
]
|
||||
|
||||
, 17: 1
|
||||
},
|
||||
|
||||
{ 5: [[0, 0, 121([]), [1000000, 100000000]]]
|
||||
|
||||
, 6: [h'{{ VALIDATOR }}']
|
||||
|
||||
},
|
||||
|
||||
true,
|
||||
|
||||
null
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
81825820000000000000000000000000000000000000000000000000000000000000000000
|
||||
@@ -0,0 +1 @@
|
||||
81A300581D70{{ VALIDATOR_HASH }}011A000F4240028201D81843D87980
|
||||
@@ -0,0 +1 @@
|
||||
84A300818258200000000000000000000000000000000000000000000000000000000000000000000182A400581D6000000000000000000000000000000000000000000000000000000000011A000F42400282005820FCAA61FB85676101D9E3398A484674E71C45C3FD41B492682F3B0054F4CF327303D81858418202583D583B0100003232323232323222253330064A22930B180080091129998030010A4C26600A6002600E0046660060066010004002AE695CDAAB9F5742AE89A3005839100000000000000000000000000000000000000000000000000000000066666666666666666666666666666666666666666666666666666666011A000F4240028201D81846D8799F182AFF0201A30482D8799FFFD8799F182AFF0581840000D87980821A000F42401A05F5E1000681{{ VALIDATOR }}F5F6
|
||||
@@ -0,0 +1,33 @@
|
||||
[
|
||||
{ 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: [h'{{ VALIDATOR }}']
|
||||
|
||||
},
|
||||
|
||||
true,
|
||||
|
||||
null
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
81825820000000000000000000000000000000000000000000000000000000000000000000
|
||||
@@ -0,0 +1 @@
|
||||
81A200581D60FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF011A000F4240
|
||||
@@ -0,0 +1 @@
|
||||
84A400818258200000000000000000000000000000000000000000000000000000000000000000000180020109A1581C{{ VALIDATOR_HASH }}A143666F6F190539A20581840100D87980821A000F42401A05F5E1000681{{ VALIDATOR }}F5F6
|
||||
@@ -0,0 +1,25 @@
|
||||
[
|
||||
{ 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
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
81825820000000000000000000000000000000000000000000000000000000000000000000
|
||||
@@ -0,0 +1 @@
|
||||
81A300581D70{{ VALIDATOR_HASH }}011A3B9ACA00028201D81843D87980
|
||||
@@ -0,0 +1 @@
|
||||
84A80081825820000000000000000000000000000000000000000000000000000000000000000000018182581D60111111111111111111111111111111111111111111111111111111111A3B9ACA0002182A05A2581DE022222222222222222222222222222222222222222222222222222222182A581DF0AFDDC16C18E7D8DE379FB9AAD39B3D1B5AFD27603E5EBAC818432A720E0B5820FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0D818258200000000000000000000000000000000000000000000000000000000000000000001082581D60000000000000000000000000000000000000000000000000000000001A3B9ACA001101A20582840000D87980821A000F42401A05F5E100840301D87980821A000F42401A05F5E1000682{{ VALIDATOR }}583D583B010000323232323232322253330054A22930B180080091129998030010A4C26600A6002600E0046660060066010004002AE695CDAAB9F5742AE881F5F6
|
||||
@@ -0,0 +1,42 @@
|
||||
[
|
||||
{ 0:
|
||||
[ [h'0000000000000000000000000000000000000000000000000000000000000000', 0]
|
||||
]
|
||||
|
||||
, 1:
|
||||
[ [h'6011111111111111111111111111111111111111111111111111111111', 1000000000]
|
||||
]
|
||||
|
||||
, 2: 42
|
||||
|
||||
, 5:
|
||||
{ h'e022222222222222222222222222222222222222222222222222222222': 42
|
||||
, h'f0afddc16c18e7d8de379fb9aad39b3d1b5afd27603e5ebac818432a72': 14
|
||||
}
|
||||
|
||||
, 11: h'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'
|
||||
|
||||
, 13:
|
||||
[ [h'0000000000000000000000000000000000000000000000000000000000000000', 0]
|
||||
]
|
||||
|
||||
, 16:
|
||||
[ h'6000000000000000000000000000000000000000000000000000000000', 1000000000
|
||||
]
|
||||
|
||||
, 17: 1
|
||||
},
|
||||
|
||||
{ 5:
|
||||
[ [0, 0, 121([]), [1000000, 100000000]]
|
||||
, [3, 1, 121([]), [1000000, 100000000]]
|
||||
]
|
||||
|
||||
, 6: [ {{ VALIDATOR }}, h'583b010000323232323232322253330054a22930b180080091129998030010a4c26600a6002600e0046660060066010004002ae695cdaab9f5742ae881' ]
|
||||
|
||||
},
|
||||
|
||||
true,
|
||||
|
||||
null
|
||||
]
|
||||
94
examples/acceptance_tests/script_context/v2/plutus.json
Normal file
94
examples/acceptance_tests/script_context/v2/plutus.json
Normal file
@@ -0,0 +1,94 @@
|
||||
{
|
||||
"preamble": {
|
||||
"title": "script_context/v2",
|
||||
"description": "Aiken contracts for project 'script_context/v2'",
|
||||
"version": "0.0.0",
|
||||
"plutusVersion": "v2",
|
||||
"compiler": {
|
||||
"name": "Aiken",
|
||||
"version": "v1.0.31-alpha+4645fd3"
|
||||
},
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"validators": [
|
||||
{
|
||||
"title": "basic.spend",
|
||||
"datum": {
|
||||
"title": "_datum",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Void"
|
||||
}
|
||||
},
|
||||
"redeemer": {
|
||||
"title": "_redeemer",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Void"
|
||||
}
|
||||
},
|
||||
"compiledCode": "590340010000323232323232323223232232253330073253330083330083375e601a601c601c601c601c601c601c601c601c601c601c601c60146ea8c004c028dd5001260126d8799f58200000000000000000000000000000000000000000000000000000000000000000ff004a09444c94ccc024c94ccc028cdc3a400460166ea80044c94ccc02ccdd7980218069baa0014c0126d8799f58200000000000000000000000000000000000000000000000000000000000000000ff0013009375a6006601a6ea8004528180798061baa001163001300b375400626464a6660166464a6660200022c2a6660206026002264a66601c66ebcc018c040dd50009ba6300448202a35ae41c54ccc038cdd7980398081baa30073010375400298122d8799f581c11111111111111111111111111111111111111111111111111111111ff001533300e533300e300c300f3754600c60206ea8c01cc040dd50008a5014a22a66601c66ebcc00cc040dd5000a60103d879800013375e600a60206ea800530103d87a800014a029405280a5030120011637586002601c6ea8c014c038dd50031180898091809000899baf3002300d37546008601a6ea8014dd31800a40a8294094ccc02cc02400452f5bded8c0264646600200297adef6c6022533301100113301233760981014000374c00697adef6c60132323232533301233720910100002133016337609801014000374c00e00a2a66602466e3d22100002133016337609801014000374c00e00626602c66ec0dd48011ba600133006006003375660260066eb8c044008c054008c04c004c8cc0040052f5bded8c044a66602000226602266ec13001014000375000697adef6c60132323232533301133720910100002133015337609801014000375000e00a2a66602266e3d22100002133015337609801014000375000e00626602a66ec0dd48011ba800133006006003375a60240066eb8c040008c050008c0480048c03cc040c040c0400045281180718078008a502300d00114984d9594cccccc03000454ccc014c00cc018dd50008a99980418039baa00114985858585858594cccccc02800854ccc00cc004c010dd50010a99980318029baa0021498585858585858dc3a4000ae6955ceaab9e5573eae815d0aba25749",
|
||||
"hash": "b4722fea910f2527073750f2d145f259ef3d8fec59b726abfd36a0b1"
|
||||
},
|
||||
{
|
||||
"title": "deploy.spend",
|
||||
"datum": {
|
||||
"title": "datum",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Data"
|
||||
}
|
||||
},
|
||||
"redeemer": {
|
||||
"title": "_redeemer",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Data"
|
||||
}
|
||||
},
|
||||
"compiledCode": "5902620100003232323232323232222533300453330043375e00698103d879800013253330053323223253330093370e900018051baa0011323232533300c3375e980106d8799f182aff0000213370e600c00a90020a50533300b3370e900018061baa001132533300f0011613253330103013002149858c94cccccc0500045858584dd68008b180880098069baa001165333333011001100116161616300e300b37540022c64646600200200644a66601c002298103d87a8000132323232533300f3372200e0042a66601e66e3c01c0084cdd2a40006602600297ae014c0103d87a80001330060060033010003375c601c004602400460200026e50dd9a6106d8799f182aff00300100122533300a0011480004cdc02400466004004601a0026eacc028c02cc02cc02cc02cc02cc02cc02cc02cc02cc02cc01cdd5180098039baa00213232533300a00116132533300b00116132533300932533300a3375e600a60186ea800530126d87a9f5820fcaa61fb85676101d9e3398a484674e71c45c3fd41b492682f3b0054f4cf3273ff0013375e601e60206020602060186ea800530122d8799f581ce37db487fbd58c45d059bcbf5cd6b1604d3bec16cf888f1395a4ebc4ff0014a0601c0062a66601266ebcc038c03cc02cdd5180298059baa0014c012ad8799fd8799fd8799f581c66666666666666666666666666666666666666666666666666666666ffffff00153330093370e900218051baa3004300b37540022944585280a50300d001300d0013758600260106ea8c008c020dd500191805980618060008a502300a00114a029309b2b2b9a5573aaae7955cfaba05742ae895d201",
|
||||
"hash": "afe28fb3a5ca0c66aa19eb0ea419c60e20ea6e3c82875f74db76d32e"
|
||||
},
|
||||
{
|
||||
"title": "mint.mint",
|
||||
"redeemer": {
|
||||
"title": "redeemer",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Data"
|
||||
}
|
||||
},
|
||||
"compiledCode": "5903070100003232323232323222533300332323232325332330093232533300e00116132533300f3012002132533300d3005300e3754002266e3c008dd7180918079baa001163008300e37540142c6eb8c040004cc004004cc010c00cdd5980298061baa3007300c375401091010022533300e00114bd70099807980618080009980100118088008a999191980599912999806980298071baa002132533300e3005300f37540022c266e1cdd6980998081baa001483c850c8cc004004c94ccc03cc018c040dd50008a5eb7bdb1804dd5980a18089baa00132323300100130093756601660246ea8010894ccc0500045300103d87a800013232323253330153372200e0042a66602a66e3c01c0084c02ccc064dd3000a5eb80530103d87a80001330060060033756602c0066eb8c050008c060008c058004dd7180998081baa00322533301200114c103d87a800013232323253330133372291103666f6f00002153330133371e910103666f6f000021300933017375000297ae014c0103d87a8000133006006003375a60280066eb8c048008c058008c05000458c01cc034dd5004980418069baa009132323232533300f3007301037540022a66601e66ebc038c044c8cdd8180a800980a980b0009bac3014301137540022600c60046eacc010c044dd5180618089baa00d14a02c64660020026eacc010c044dd5180618089baa00d22533301300114c103d87a80001323253330123375e6026004601c60286ea80404c020cc058dd39980b18098011980b180a00125eb812f5c0266008008002602e004602a002600200244a66602200229000099b8048008cc008008c0500048c044c048c048c048c048c048c048c048c048c048004dd2a40006e1d200214a06e1d200014a046600400291010022323300100100322533300d00114bd6f7b630099191919299980719b910070021533300e3371e00e0042006200a26602466ec0dd48011ba6001330060060033756601e0066eb8c034008c044008c03c0048c02cc030c030c030c0300048c028c02c0048c024004526136565734aae7555cf2ab9f5740ae855d101",
|
||||
"hash": "cae7d307b37aaa4d2500641c8c6e823ea313aa43fb6dbc9ed72b7228"
|
||||
},
|
||||
{
|
||||
"title": "withdrawals.spend",
|
||||
"datum": {
|
||||
"title": "_datum",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Void"
|
||||
}
|
||||
},
|
||||
"redeemer": {
|
||||
"title": "_redeemer",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Void"
|
||||
}
|
||||
},
|
||||
"compiledCode": "590249010000323232323232323223223225333006323232533300932533300a3370e900118059baa0011613370e6eb4c030c8cdd81808000980818088009bac300f300c3754002902a198009bab3002300b3754600660166ea80108cdd79805800a6126d8799fd8799f581c22222222222222222222222222222222222222222222222222222222ffff001533300932533300a3370e900118059baa0011613370e6eb4c030c8cdd81808000980818088009bac300f300c3754002900e198009bab3002300b3754600660166ea80108cdd79805800a60126d8799fd87a9f581cafddc16c18e7d8de379fb9aad39b3d1b5afd27603e5ebac818432a72ffff0013375e6e9cc8cc004004dd5980198061baa3004300c375400a44a66601c002297ae013300f300c3010001330020023011001374e6601a98126d8799fd8799f581c22222222222222222222222222222222222222222222222222222222ffff003300d4c126d8799fd87a9f581cafddc16c18e7d8de379fb9aad39b3d1b5afd27603e5ebac818432a72ffff004bd700a5014a044646600200200644a66601e002298103d87a800013232533300e300500213374a9000198091ba733012300f0023301230100024bd7025eb804cc010010004c04c008c0440048c034c038c038c038c038c038c0380048c03000452613656533333300b001153330043370e900018029baa00115333007300637540022930b0b0b0b0b0b29999998048008a99980119b8748000c00cdd50008a99980298021baa00114985858585858595cd2ab9d5573caae7d5d02ba15744ae901",
|
||||
"hash": "45d4f36c2dcf9831e37995edb428bed6928a55b39b401c1dd5ab7886"
|
||||
}
|
||||
],
|
||||
"definitions": {
|
||||
"Data": {
|
||||
"title": "Data",
|
||||
"description": "Any Plutus data."
|
||||
},
|
||||
"Void": {
|
||||
"title": "Unit",
|
||||
"description": "The nullary constructor.",
|
||||
"anyOf": [
|
||||
{
|
||||
"dataType": "constructor",
|
||||
"index": 0,
|
||||
"fields": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
42
examples/acceptance_tests/script_context/v2/test.sh
Executable file
42
examples/acceptance_tests/script_context/v2/test.sh
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
TITLE=$1
|
||||
if [ -z $TITLE ]; then
|
||||
echo -e "\033[31mMissing argument: \033[1mVALIDATOR_TITLE\033[0m"
|
||||
echo ""
|
||||
echo -e "\033[1mUsage: \033[0m"
|
||||
echo " test.sh {ACCEPTANCE_TEST}"
|
||||
echo ""
|
||||
echo -e "\033[1mExample: \033[0m"
|
||||
echo " test.sh basic"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v jq &> /dev/null
|
||||
then
|
||||
echo "\033[1mjq\033[0m missing from system but required."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v cbor-diag &> /dev/null
|
||||
then
|
||||
echo "\033[1mcbor-diag\033[0m missing from system but required."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cargo run -r --quiet -- build 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
BLUEPRINT=$(jq ".validators[] | select(.title|contains(\"$TITLE\"))" plutus.json)
|
||||
|
||||
VALIDATOR_HASH=$(echo $BLUEPRINT | jq .hash | sed s/\"//g)
|
||||
VALIDATOR=$(echo $BLUEPRINT | jq .compiledCode | sed s/\"//g)
|
||||
VALIDATOR=$(cbor-diag --to hex --from diag <<< "h'$VALIDATOR'")
|
||||
|
||||
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 }}/$VALIDATOR/" ctx/$TITLE/tx.cbor.template | sed "s/{{ VALIDATOR_HASH }}/$VALIDATOR_HASH/" > ctx/$TITLE/tx.cbor
|
||||
|
||||
cargo run -r --quiet -- tx simulate 1>$TITLE.log 2>&1 ctx/$TITLE/tx.cbor ctx/$TITLE/inputs.cbor ctx/$TITLE/outputs.cbor
|
||||
@@ -0,0 +1,51 @@
|
||||
use aiken/option
|
||||
use aiken/transaction.{NoDatum,
|
||||
ScriptContext, Spend, Transaction, TransactionId}
|
||||
use aiken/transaction/credential.{VerificationKeyCredential}
|
||||
use aiken/transaction/value
|
||||
|
||||
validator {
|
||||
fn spend(_datum: Void, _redeemer: Void, ctx: ScriptContext) {
|
||||
and {
|
||||
assert_id(ctx.transaction),
|
||||
assert_purpose(ctx.purpose),
|
||||
assert_outputs(ctx.transaction),
|
||||
assert_fee(ctx.transaction),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_id(transaction: Transaction) {
|
||||
transaction.id != TransactionId(
|
||||
#"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
)
|
||||
}
|
||||
|
||||
fn assert_purpose(purpose) {
|
||||
when purpose is {
|
||||
Spend(ref) ->
|
||||
ref.transaction_id == TransactionId(
|
||||
#"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
) && ref.output_index == 0
|
||||
_ -> fail @"script purpose isn't 'Spend'"
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_fee(transaction: Transaction) {
|
||||
transaction.fee == value.from_lovelace(42)
|
||||
}
|
||||
|
||||
fn assert_outputs(transaction: Transaction) {
|
||||
when transaction.outputs is {
|
||||
[output] -> and {
|
||||
output.value == value.from_lovelace(1000000000),
|
||||
output.address.payment_credential == VerificationKeyCredential(
|
||||
#"11111111111111111111111111111111111111111111111111111111",
|
||||
),
|
||||
option.is_none(output.address.stake_credential),
|
||||
output.datum == NoDatum,
|
||||
output.reference_script == None,
|
||||
}
|
||||
_ -> fail @"unexpected number of outputs"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
use aiken/builtin
|
||||
use aiken/dict.{Dict}
|
||||
use aiken/hash.{blake2b_256}
|
||||
use aiken/transaction.{DatumHash, InlineDatum, Output, ScriptContext}
|
||||
use aiken/transaction/credential.{Inline, VerificationKeyCredential}
|
||||
|
||||
validator {
|
||||
fn spend(datum: Data, _redeemer: Data, ctx: ScriptContext) {
|
||||
and {
|
||||
assert_datum(datum),
|
||||
assert_datums(ctx.transaction.datums),
|
||||
assert_outputs(ctx.transaction.outputs),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_datum(datum) {
|
||||
let my_datum: Data = Void
|
||||
datum == my_datum
|
||||
}
|
||||
|
||||
type MyDatum {
|
||||
MyDatum(Int)
|
||||
}
|
||||
|
||||
fn assert_datums(datums: Dict<ByteArray, Data>) {
|
||||
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)
|
||||
_ -> fail @"expected transaction to have (at least) 2 outputs"
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_first_output(output: Output) {
|
||||
and {
|
||||
output.datum == DatumHash(
|
||||
#"fcaa61fb85676101d9e3398a484674e71c45c3fd41b492682f3b0054f4cf3273",
|
||||
),
|
||||
output.reference_script == Some(
|
||||
#"e37db487fbd58c45d059bcbf5cd6b1604d3bec16cf888f1395a4ebc4",
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_second_output(output: Output) {
|
||||
and {
|
||||
output.address.stake_credential == Some(
|
||||
Inline(
|
||||
VerificationKeyCredential(
|
||||
#"66666666666666666666666666666666666666666666666666666666",
|
||||
),
|
||||
),
|
||||
),
|
||||
when output.datum is {
|
||||
InlineDatum(_) -> True
|
||||
_ -> fail @"expected inline datum"
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
use aiken/dict
|
||||
use aiken/list
|
||||
use aiken/transaction.{Mint, ScriptContext, Transaction}
|
||||
use aiken/transaction/value
|
||||
|
||||
validator {
|
||||
fn mint(redeemer: Data, ctx: ScriptContext) {
|
||||
and {
|
||||
assert_purpose(ctx),
|
||||
assert_mint(ctx.purpose, ctx.transaction),
|
||||
assert_redeemers(ctx, redeemer),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_purpose(ctx: ScriptContext) {
|
||||
expect [my_policy_id] =
|
||||
ctx.transaction.mint
|
||||
|> value.from_minted_value
|
||||
|> value.without_lovelace
|
||||
|> value.policies
|
||||
|
||||
expect Mint(policy_id) = ctx.purpose
|
||||
|
||||
my_policy_id == policy_id
|
||||
}
|
||||
|
||||
fn assert_mint(purpose, transaction: Transaction) {
|
||||
expect Mint(policy_id) = purpose
|
||||
let tokens =
|
||||
value.tokens(transaction.mint |> value.from_minted_value, policy_id)
|
||||
|
||||
when dict.get(tokens, #"666f6f") is {
|
||||
None -> fail @"token not found"
|
||||
Some(quantity) -> quantity == 1337
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_redeemers(ctx: ScriptContext, my_redeemer) {
|
||||
expect Some(Pair(_, redeemer)) =
|
||||
list.find(ctx.transaction.redeemers, fn(kv) { kv.1st == ctx.purpose })
|
||||
my_redeemer == redeemer && list.length(ctx.transaction.redeemers) == 1
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
use aiken/list
|
||||
use aiken/transaction.{ScriptContext}
|
||||
use aiken/transaction/credential.{
|
||||
Inline, ScriptCredential, VerificationKeyCredential,
|
||||
}
|
||||
|
||||
validator {
|
||||
fn spend(_datum: Void, _redeemer: Void, ctx: ScriptContext) {
|
||||
let alice =
|
||||
Inline(
|
||||
VerificationKeyCredential(
|
||||
#"22222222222222222222222222222222222222222222222222222222",
|
||||
),
|
||||
)
|
||||
|
||||
let bob =
|
||||
Inline(
|
||||
ScriptCredential(
|
||||
#"afddc16c18e7d8de379fb9aad39b3d1b5afd27603e5ebac818432a72",
|
||||
),
|
||||
)
|
||||
|
||||
and {
|
||||
when
|
||||
list.find(ctx.transaction.withdrawals, fn(kv) { kv.1st == alice })
|
||||
is {
|
||||
None -> fail @"alice's withdrawal not found"
|
||||
Some(value) -> value.2nd == 42
|
||||
},
|
||||
when list.find(ctx.transaction.withdrawals, fn(kv) { kv.1st == bob }) is {
|
||||
None -> fail @"bob's withdrawal not found"
|
||||
Some(value) -> value.2nd == 14
|
||||
},
|
||||
list.map(ctx.transaction.withdrawals, fn(kv) { kv.1st }) == [alice, bob],
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user