Support multi-validator in script context accept test.
This commit is contained in:
@@ -21,7 +21,7 @@ for convenience.
|
||||
|
||||
- Purpose
|
||||
- [x] spend
|
||||
- [ ] mint
|
||||
- [x] mint
|
||||
- [ ] withdraw
|
||||
- [ ] publish
|
||||
- [ ] voting
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
[
|
||||
{ 0: h'6000000000000000000000000000000000000000000000000000000000'
|
||||
, 1: 1000000
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,65 @@
|
||||
[
|
||||
{ 0:
|
||||
[ [h'0000000000000000000000000000000000000000000000000000000000000000', 0]
|
||||
]
|
||||
|
||||
, 1:
|
||||
[ { 0: h'6000000000000000000000000000000000000000000000000000000000'
|
||||
, 1: 1000000
|
||||
, 2: [1, 24(h'4463666F6F')]
|
||||
}
|
||||
, { 0: h'6000000000000000000000000000000000000000000000000000000000'
|
||||
, 1:
|
||||
[ 1000000
|
||||
, { h'{{ mint.mint_1.hash }}': { h'74756e61': 100000000000000 }
|
||||
, h'{{ mint.mint_2.hash }}': { h'61696b656e': 42 }
|
||||
}
|
||||
]
|
||||
}
|
||||
, { 0: h'6000000000000000000000000000000000000000000000000000000000'
|
||||
, 1:
|
||||
[ 1000000
|
||||
, { h'{{ mint.mint_2.hash }}': { h'63617264616e6f': 1 }
|
||||
}
|
||||
]
|
||||
, 3: 24(h'82034463666F6F')
|
||||
}
|
||||
]
|
||||
|
||||
, 2: 42
|
||||
|
||||
, 9:
|
||||
{ h'{{ mint.mint_1.hash }}':
|
||||
{ h'74756e61': 100000000000000
|
||||
}
|
||||
, h'{{ mint.mint_2.hash }}':
|
||||
{ h'63617264616e6f': 1
|
||||
, h'61696b656e': -14
|
||||
}
|
||||
}
|
||||
|
||||
, 11: h'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'
|
||||
|
||||
, 13:
|
||||
[ [h'0000000000000000000000000000000000000000000000000000000000000000', 0]
|
||||
]
|
||||
|
||||
, 16:
|
||||
[ h'6000000000000000000000000000000000000000000000000000000000', 1000000000
|
||||
]
|
||||
|
||||
, 17: 1
|
||||
},
|
||||
|
||||
{ 5:
|
||||
[ [1, 0, 121([]), [1000000, 100000000]]
|
||||
, [1, 1, 42, [1000000, 100000000]]
|
||||
]
|
||||
|
||||
|
||||
},
|
||||
|
||||
true,
|
||||
|
||||
null
|
||||
]
|
||||
@@ -0,0 +1,6 @@
|
||||
[
|
||||
{ 0: h'70{{ simple_spend.spend.hash }}'
|
||||
, 1: 1000000000
|
||||
, 2: [1, 24(h'd87980')]
|
||||
}
|
||||
]
|
||||
@@ -4,8 +4,7 @@
|
||||
]
|
||||
|
||||
, 1:
|
||||
[ [h'6011111111111111111111111111111111111111111111111111111111', 1000000000]
|
||||
]
|
||||
[]
|
||||
|
||||
, 2: 42
|
||||
|
||||
@@ -24,7 +23,7 @@
|
||||
|
||||
{ 5: [[0, 0, 121([]), [1000000, 100000000]]]
|
||||
|
||||
, 7: [h'{{ VALIDATOR }}']
|
||||
, 7: [h'{{ simple_spend.spend.cbor }}']
|
||||
|
||||
},
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
81a300581d70{{ VALIDATOR_HASH }}011a3b9aca00028201d818{{ DATUM }}
|
||||
File diff suppressed because one or more lines are too long
@@ -16,13 +16,13 @@ AIKEN=${2:-"cargo run -r --quiet --"}
|
||||
|
||||
if ! command -v jq &> /dev/null
|
||||
then
|
||||
echo "\033[1mjq\033[0m missing from system but required."
|
||||
echo -e "\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."
|
||||
echo -e "\033[1mcbor-diag\033[0m missing from system but required."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -31,21 +31,43 @@ if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
BLUEPRINT=$(jq ".validators[] | select(.title|contains(\"$TITLE\"))" plutus.json)
|
||||
declare -a VALIDATORS=($(jq -c ".validators | map(select(.title|contains(\"$TITLE\"))) | .[]" plutus.json))
|
||||
|
||||
VALIDATOR_HASH=$(echo $BLUEPRINT | jq -r .hash)
|
||||
VALIDATOR=$(echo $BLUEPRINT | jq -r .compiledCode)
|
||||
if [ -z $VALIDATORS ]; then
|
||||
echo -e "\033[31mvalidator \033[1m$TITLE\033[0m\033[31m not found!\033[0m"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DATUM=$(cbor-diag --to hex --from diag <<< "h'$(cat ctx/$TITLE/datum.cbor)'")
|
||||
TRANSACTION=$(cat ctx/$TITLE/tx.template)
|
||||
RESOLVED_INPUTS=$(cat ctx/$TITLE/resolved_inputs.template)
|
||||
|
||||
sed "s/{{ VALIDATOR_HASH }}/$VALIDATOR_HASH/" ctx/$TITLE/resolved_inputs.template \
|
||||
| sed "s/{{ DATUM }}/$DATUM/" \
|
||||
> ctx/$TITLE/resolved_inputs.cbor
|
||||
for ITEM in ${VALIDATORS[@]}; do
|
||||
VALIDATOR_NAME=$(echo $ITEM | jq -r .title)
|
||||
VALIDATOR_HASH=$(echo $ITEM | jq -r .hash)
|
||||
VALIDATOR=$(echo $ITEM | jq -r .compiledCode)
|
||||
|
||||
sed "s/{{ VALIDATOR }}/$VALIDATOR/" ctx/$TITLE/tx.template \
|
||||
| sed "s/{{ VALIDATOR_HASH }}/$VALIDATOR_HASH/" \
|
||||
| cbor-diag --to hex --from diag \
|
||||
> ctx/$TITLE/tx.cbor
|
||||
RESOLVED_INPUTS=$(echo $RESOLVED_INPUTS \
|
||||
| sed "s/{{ $VALIDATOR_NAME.cbor }}/$VALIDATOR/g" \
|
||||
| sed "s/{{ $VALIDATOR_NAME.hash }}/$VALIDATOR_HASH/g")
|
||||
|
||||
TRANSACTION=$(echo $TRANSACTION \
|
||||
| sed "s/{{ $VALIDATOR_NAME.cbor }}/$VALIDATOR/g" \
|
||||
| sed "s/{{ $VALIDATOR_NAME.hash }}/$VALIDATOR_HASH/g")
|
||||
done
|
||||
|
||||
echo $RESOLVED_INPUTS | cbor-diag --to hex --from diag > ctx/$TITLE/resolved_inputs.cbor
|
||||
echo $TRANSACTION | cbor-diag --to hex --from diag > ctx/$TITLE/tx.cbor
|
||||
|
||||
# echo "TRANSACTION"
|
||||
# cat ctx/$TITLE/tx.cbor
|
||||
|
||||
# ogmios inspect transaction $(cat ctx/$TITLE/tx.cbor) | jq
|
||||
|
||||
# echo -e "\n\nINPUTS"
|
||||
# cat ctx/inputs.cbor
|
||||
#
|
||||
# echo -e "\n\nRESOLVED_INPUTS"
|
||||
# cat ctx/$TITLE/resolved_inputs.cbor
|
||||
|
||||
$AIKEN tx simulate \
|
||||
ctx/$TITLE/tx.cbor \
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
use aiken/dict
|
||||
use aiken/transaction.{
|
||||
InlineDatum, Input, Output, OutputReference, ScriptContext, Spend, Spending,
|
||||
}
|
||||
use aiken/transaction/credential.{Address, ScriptCredential}
|
||||
use aiken/transaction/value
|
||||
|
||||
validator {
|
||||
fn mint_1(_tmp2: Void, ctx: ScriptContext) {
|
||||
True
|
||||
}
|
||||
}
|
||||
|
||||
validator {
|
||||
fn mint_2(_tmp2: Void, ctx: ScriptContext) {
|
||||
True
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
use aiken/dict
|
||||
use aiken/transaction.{
|
||||
InlineDatum, Input, Output, OutputReference, ScriptContext, ScriptInfo,
|
||||
ScriptPurpose, Spend, Spending,
|
||||
}
|
||||
use aiken/transaction/credential.{Address, ScriptCredential}
|
||||
use aiken/transaction/value
|
||||
|
||||
validator {
|
||||
fn spend(_tmp1: Void, _tmp2: Void, ctx: ScriptContext) {
|
||||
assert_transaction_id(ctx.transaction.id)
|
||||
|
||||
assert_script_info(ctx.info)
|
||||
|
||||
assert_inputs(ctx.transaction.inputs)
|
||||
|
||||
expect [] = ctx.transaction.outputs
|
||||
|
||||
expect [] = ctx.transaction.reference_inputs
|
||||
|
||||
expect [] = ctx.transaction.extra_signatories
|
||||
|
||||
expect 42 == ctx.transaction.fee
|
||||
|
||||
assert_redeemers(ctx.transaction.redeemers)
|
||||
|
||||
expect [] == dict.to_pairs(ctx.transaction.datums)
|
||||
|
||||
True
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_transaction_id(id: ByteArray) {
|
||||
expect
|
||||
#"c6fbd346681a8f8337f6b3e51e6ec973f1509367eabc3a44c849af58a1d8471b" == id
|
||||
Void
|
||||
}
|
||||
|
||||
fn assert_script_info(info: ScriptInfo) {
|
||||
expect
|
||||
Spending(
|
||||
OutputReference {
|
||||
transaction_id: #"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
output_index: 0,
|
||||
},
|
||||
Some(void()),
|
||||
) == info
|
||||
Void
|
||||
}
|
||||
|
||||
fn assert_inputs(inputs: List<Input>) {
|
||||
expect [
|
||||
Input {
|
||||
output_reference: OutputReference { transaction_id, output_index: 0 },
|
||||
output: Output {
|
||||
address,
|
||||
value: resolved_input_value,
|
||||
datum: InlineDatum(_),
|
||||
reference_script: None,
|
||||
},
|
||||
},
|
||||
] = inputs
|
||||
|
||||
expect
|
||||
transaction_id == #"0000000000000000000000000000000000000000000000000000000000000000"
|
||||
|
||||
expect resolved_input_value == value.from_lovelace(1000000000)
|
||||
|
||||
expect Address {
|
||||
payment_credential: ScriptCredential(_),
|
||||
stake_credential: None,
|
||||
} = address
|
||||
|
||||
Void
|
||||
}
|
||||
|
||||
fn assert_redeemers(redeemers: Pairs<ScriptPurpose, Data>) {
|
||||
expect
|
||||
[
|
||||
Pair(Spend(
|
||||
OutputReference {
|
||||
transaction_id: #"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
output_index: 0,
|
||||
},
|
||||
),
|
||||
void()),
|
||||
] == redeemers
|
||||
Void
|
||||
}
|
||||
|
||||
fn void() -> Data {
|
||||
let void: Data = Void
|
||||
void
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
use aiken/dict
|
||||
use aiken/transaction.{
|
||||
InlineDatum, Input, Output, OutputReference, ScriptContext, Spend, Spending,
|
||||
}
|
||||
use aiken/transaction/credential.{Address, ScriptCredential}
|
||||
use aiken/transaction/value
|
||||
|
||||
validator {
|
||||
fn spend(_tmp1: Void, _tmp2: Void, ctx: ScriptContext) {
|
||||
let void: Data = Void
|
||||
|
||||
expect
|
||||
#"78ec148ea647cf9969446891af31939c5d57b275a2455706782c6183ef0b62f1" == ctx.transaction.id
|
||||
|
||||
expect
|
||||
Spending(
|
||||
OutputReference {
|
||||
transaction_id: #"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
output_index: 0,
|
||||
},
|
||||
Some(void),
|
||||
) == ctx.info
|
||||
|
||||
trace @"inputs": ctx.transaction.inputs
|
||||
|
||||
expect [
|
||||
Input {
|
||||
output_reference: OutputReference { transaction_id, output_index: 0 },
|
||||
output: Output {
|
||||
address,
|
||||
value: resolved_input_value,
|
||||
datum: InlineDatum(_),
|
||||
reference_script: None,
|
||||
},
|
||||
},
|
||||
] = ctx.transaction.inputs
|
||||
|
||||
expect
|
||||
transaction_id == #"0000000000000000000000000000000000000000000000000000000000000000"
|
||||
|
||||
expect resolved_input_value == value.from_lovelace(1000000000)
|
||||
|
||||
expect Address {
|
||||
payment_credential: ScriptCredential(_),
|
||||
stake_credential: None,
|
||||
} = address
|
||||
|
||||
expect [] = ctx.transaction.reference_inputs
|
||||
|
||||
expect [] = ctx.transaction.extra_signatories
|
||||
|
||||
expect 42 == ctx.transaction.fee
|
||||
|
||||
expect
|
||||
[
|
||||
Pair(Spend(
|
||||
OutputReference {
|
||||
transaction_id: #"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
output_index: 0,
|
||||
},
|
||||
),
|
||||
void),
|
||||
] == ctx.transaction.redeemers
|
||||
|
||||
expect [] == dict.to_pairs(ctx.transaction.datums)
|
||||
|
||||
True
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user