Make basic script a template, and add more assertions.

This commit is contained in:
KtorZ 2023-02-14 11:37:10 +01:00
parent 545323128c
commit 251aa756d9
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
11 changed files with 118 additions and 10 deletions

View File

@ -0,0 +1 @@
data/**/*.cbor

View File

@ -1 +0,0 @@
81A300581D70{{ VALIDATOR_HASH }}1ED86D464F20AB66EE47AB662572820052078CC8D75345E06A9E8D4011A3B9ACA00028201D81843D87980

View File

@ -1 +0,0 @@
84A80081825820000000000000000000000000000000000000000000000000000000000000000000018182581D60000000000000000000000000000000000000000000000000000000001A3B9ACA00021A0002DF6705A1581DE0000000000000000000000000000000000000000000000000000000001A0280DE800B5820FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0D818258200000000000000000000000000000000000000000000000000000000000000000001082581D60000000000000000000000000000000000000000000000000000000001A3B9ACA00111A00044F1BA20581840000D87980821A000F42401A05F5E100068158A2{{ VALIDATOR }}8A00100003232323232323232222533300632323370E646460026EB0CC00CC010CC00CC010015200048010C004004894CCC03400452000132337009001198018018009807800A400444646660020029000001911199980619B8700400201023330040043370000690011809000800918049BAA001149858C0040048894CCC01C0085261330053001300800233300300330090020015734AE6D55CF2AB9F5742AE89F5F6

View File

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

View File

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

View File

@ -0,0 +1,32 @@
[
{ 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
]

View File

@ -29,8 +29,8 @@
} }
] ]
}, },
"compiledCode": "58a00100003232323232323232222533300632323370e646460026eb0cc00cc010cc00cc010015200048010c004004894ccc03400452000132337009001198018018009807800a400444646660020029000001911199980619b8700400201023330040043370000690011809000800918049baa001149858c0040048894ccc01c0085261330053001300800233300300330090020015734ae6d55cf2ab9f5742ae89", "compiledCode": "5903dd010000323232323232323232323222253330063232323232300200132323232323301533300f323253330113370e002900109919299980999baf3300c300d0014800130126d8799f58200000000000000000000000000000000000000000000000000000000000000000ff0013370e6eb4cc030c034005200248000528180c80098058010a99809a491c73637269707420707572706f73652069736e277420275370656e6427001630133754002660106012014900126103d87a80004c0103d87980003301533300f32325333016001153301349011c756e6578706563746564206e756d626572206f66206f7574707574730016132533301700113232300b001330193330133375e6e98dd5998061806800a40046e98c0152080a8d6b9074c103d87a80004c0103d8798000330193330133375e66018601a66018601a002900024000980122d8799f581c11111111111111111111111111111111111111111111111111111111ff004c0103d87a80004c0103d879800033019333013323253330153370e0029000099250300f00214a2602e6ea8004cc030c034cc030c034005200048009300103d87a80004c0103d87980004bd70180c8010a9980a2491c756e6578706563746564206e756d626572206f66206f757470757473001630190013758660126014002900219804180480524000980103d87a80004c0103d87980003301533300f323375e6e98dd5998049805000a400c6e98c009205433008300900a4800130103d87a80004c0103d87980004bd7011999111919000999911199804801801000a5eb7bdb180010004ccc888ccc02800c0080052f5bded8c0004002910100488100001300100122225333015003133016337606ea4008dd3000a5eb7bdb1804c8c8c8c94ccc050cdc800300089980d19bb0375200c6e9801401c54ccc050cdc780300089980d19bb0375200c6e9801400c4cc068cdd81ba9001374c004666601001000600c00a6eb8c05800cdd5980b001180c802180b80198008009111299980980189980a19bb037520046ea00052f5bded8c0264646464a66602466e400180044cc060cdd81ba9006375000a00e2a66602466e3c0180044cc060cdd81ba9006375000a00626603066ec0dd48009ba80023333008008003006005375c60280066eb4c050008c05c010c05400cc004004894ccc03c0045288991929998060010998020020008a5030130023370e900118069baa301100122323330010014800000c888cccc030cdc3802001009919980200219b8000348008c0540040048c02cdd50008a4c2c6002002444a666012004293099802980098058011998018019806001000ab9a5736ae7155ceaab9e5573eae815d0aba201",
"hash": "81ed86d464f20ab66ee47ab662572820052078cc8d75345e06a9e8d4" "hash": "0a7d654e443b18df327a2710a65bd9eee74dc7a9e26b1aca91bac9e5"
} }
] ]
} }

View File

@ -1,4 +0,0 @@
#!/usr/bin/env bash
aiken build
VALIDATOR=$(jq ".validators[] | select(.title == \"basic\")" plutus.json)

View 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
aiken build
if [ $? -ne 0 ]; then
exit $?
fi
BLUEPRINT=$(jq ".validators[] | select(.title == \"$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 data/$TITLE/inputs.cbor.template data/$TITLE/inputs.cbor
sed "s/{{ VALIDATOR_HASH }}/$VALIDATOR_HASH/" data/$TITLE/outputs.cbor.template > data/$TITLE/outputs.cbor
sed "s/{{ VALIDATOR }}/$VALIDATOR/" data/$TITLE/tx.cbor.template > data/$TITLE/tx.cbor
aiken tx simulate data/$TITLE/tx.cbor data/$TITLE/inputs.cbor data/$TITLE/outputs.cbor

View File

@ -1,6 +1,43 @@
use aiken/list use aiken/list
use aiken/transaction.{ScriptContext} use aiken/option
use aiken/transaction.{ScriptContext, Spend, TransactionId}
use aiken/transaction/credential.{VerificationKeyCredential}
use aiken/transaction/value
fn spend(_datum: Void, _redeemer: Void, ctx: ScriptContext) { fn spend(_datum: Void, _redeemer: Void, ctx: ScriptContext) {
list.length(ctx.transaction.outputs) == 1 [
assert_purpose(ctx.purpose),
assert_outputs(ctx.transaction),
assert_fee(ctx.transaction),
]
|> list.and
}
fn assert_purpose(purpose) {
when purpose is {
Spend(ref) ->
ref.transaction_id == TransactionId(
#"0000000000000000000000000000000000000000000000000000000000000000",
) && ref.output_index == 0
_ -> error("script purpose isn't 'Spend'")
}
}
fn assert_fee(transaction) {
transaction.fee == value.from_lovelace(42)
}
fn assert_outputs(transaction) {
when transaction.outputs is {
[output] ->
[
output.value == value.from_lovelace(1000000000),
output.address.payment_credential == VerificationKeyCredential(
#"11111111111111111111111111111111111111111111111111111111",
),
option.is_none(output.address.stake_credential),
]
|> list.and
_ -> error("unexpected number of outputs")
}
} }