Fix script context translations for withdrawals and validity intervals.
This commit is contained in:
@@ -16,7 +16,7 @@ const void_hash =
|
||||
#"923918e403bf43c34b4ef6b48eb2ee04babed17320d8d1b9ff9ad086e86f44ec"
|
||||
|
||||
validator {
|
||||
fn mint_1(_tmp2: Void, ctx: ScriptContext) {
|
||||
fn mint_1(_tmp2: Data, ctx: ScriptContext) {
|
||||
let our_policy_id = assert_script_info(ctx.info)
|
||||
let other_policy_id = assert_redeemers(ctx.transaction.redeemers)
|
||||
assert_outputs(ctx.transaction.outputs, our_policy_id, other_policy_id)
|
||||
|
||||
@@ -22,7 +22,7 @@ const only9s =
|
||||
#"9999999999999999999999999999999999999999999999999999999999999999"
|
||||
|
||||
validator {
|
||||
fn script(_tmp0: Void, ctx: ScriptContext) {
|
||||
fn script(_tmp0: Data, ctx: ScriptContext) {
|
||||
assert_redeemer(ctx.redeemer)
|
||||
|
||||
let votes = ctx.transaction.votes
|
||||
@@ -35,18 +35,14 @@ validator {
|
||||
|
||||
expect
|
||||
Some(
|
||||
Pair(
|
||||
ConstitutionalCommitteeMember(VerificationKey(only0s)),
|
||||
[
|
||||
Pair(
|
||||
GovernanceActionId {
|
||||
transaction: only9s,
|
||||
proposal_procedure: 152,
|
||||
},
|
||||
No,
|
||||
),
|
||||
],
|
||||
),
|
||||
Pair(ConstitutionalCommitteeMember(VerificationKey(only0s)),
|
||||
[
|
||||
Pair(GovernanceActionId {
|
||||
transaction: only9s,
|
||||
proposal_procedure: 152,
|
||||
},
|
||||
No),
|
||||
]),
|
||||
) == list.at(votes, 1)
|
||||
|
||||
expect Some(Pair(DelegateRepresentative(Script(..)), [_, ..])) =
|
||||
@@ -54,23 +50,15 @@ validator {
|
||||
|
||||
expect
|
||||
Some(
|
||||
Pair(
|
||||
DelegateRepresentative(VerificationKey(only0s)),
|
||||
[
|
||||
Pair(
|
||||
GovernanceActionId { transaction: only7s, proposal_procedure: 2 },
|
||||
Abstain,
|
||||
),
|
||||
Pair(
|
||||
GovernanceActionId { transaction: only8s, proposal_procedure: 1 },
|
||||
Abstain,
|
||||
),
|
||||
Pair(
|
||||
GovernanceActionId { transaction: only9s, proposal_procedure: 0 },
|
||||
Abstain,
|
||||
),
|
||||
],
|
||||
),
|
||||
Pair(DelegateRepresentative(VerificationKey(only0s)),
|
||||
[
|
||||
Pair(GovernanceActionId { transaction: only7s, proposal_procedure: 2 },
|
||||
Abstain),
|
||||
Pair(GovernanceActionId { transaction: only8s, proposal_procedure: 1 },
|
||||
Abstain),
|
||||
Pair(GovernanceActionId { transaction: only9s, proposal_procedure: 0 },
|
||||
Abstain),
|
||||
]),
|
||||
) == list.at(votes, 3)
|
||||
|
||||
expect Some(Pair(StakePool(pool_id), [_, ..])) = list.at(votes, 4)
|
||||
@@ -83,8 +71,10 @@ validator {
|
||||
fn assert_redeemer(data: Data) {
|
||||
let is_valid =
|
||||
if data is Foo(42): Foo {
|
||||
trace data
|
||||
True
|
||||
} else if data is Void {
|
||||
trace data
|
||||
True
|
||||
} else {
|
||||
False
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
use aiken/collection/list
|
||||
use aiken/interval
|
||||
use cardano/credential.{Address, Inline, Pointer, Script, VerificationKey}
|
||||
use cardano/transaction.{ScriptContext, Withdrawing}
|
||||
|
||||
const only0s = #"00000000000000000000000000000000000000000000000000000000"
|
||||
|
||||
const only1s = #"11111111111111111111111111111111111111111111111111111111"
|
||||
|
||||
validator {
|
||||
fn spend(_tmp0: Void, _tmp1: Void, _ctx: Data) {
|
||||
True
|
||||
}
|
||||
|
||||
fn withdraw(_tmp0: Void, ctx: ScriptContext) {
|
||||
expect Withdrawing(Script(my_script_hash)) = ctx.info
|
||||
|
||||
expect
|
||||
interval.entirely_before(1596059092000) == ctx.transaction.validity_range
|
||||
|
||||
let addresses = list.map(ctx.transaction.outputs, fn(out) { out.address })
|
||||
|
||||
expect
|
||||
Some(
|
||||
Address {
|
||||
payment_credential: VerificationKey(only0s),
|
||||
stake_credential: Some(Inline(Script(only1s))),
|
||||
},
|
||||
) == list.at(addresses, 0)
|
||||
|
||||
expect
|
||||
Some(
|
||||
Address {
|
||||
payment_credential: VerificationKey(only0s),
|
||||
stake_credential: Some(Pointer(2498243, 27, 3)),
|
||||
},
|
||||
) == list.at(addresses, 1)
|
||||
|
||||
expect
|
||||
Some(
|
||||
Address {
|
||||
payment_credential: Script(only1s),
|
||||
stake_credential: Some(Pointer(2498243, 27, 3)),
|
||||
},
|
||||
) == list.at(addresses, 2)
|
||||
|
||||
expect
|
||||
[Pair(Script(my_script_hash), 0), Pair(VerificationKey(only0s), 14)] == ctx.transaction.withdrawals
|
||||
|
||||
True
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user