Update remaining script context e2e tests.

This commit is contained in:
KtorZ 2024-08-16 16:34:25 +02:00
parent 7ec3f2e8df
commit fe205e360f
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
14 changed files with 260 additions and 79 deletions

View File

@ -288,14 +288,13 @@ impl TypedFunction {
}
pub fn validator_arity(&self) -> usize {
if self.name == HANDLER_SPEND
|| self.name == HANDLER_PUBLISH
|| self.name == HANDLER_PROPOSE
{
if self.name == HANDLER_SPEND {
4
} else if self.name == HANDLER_MINT
|| self.name == HANDLER_WITHDRAW
|| self.name == HANDLER_VOTE
|| self.name == HANDLER_PUBLISH
|| self.name == HANDLER_PROPOSE
{
3
} else {

View File

@ -320,6 +320,78 @@ impl<'a> CodeGenerator<'a> {
),
},
"publish" => TypedPattern::Constructor {
is_record: false,
location: Span::empty(),
name: well_known::SCRIPT_PURPOSE_PUBLISH.to_string(),
arguments: vec![CallArg {
label: None,
location: Span::empty(),
value: TypedPattern::Var {
name: "__purpose_arg__".to_string(),
location: Span::empty(),
},
}],
module: None,
constructor: PatternConstructor::Record {
name: well_known::SCRIPT_PURPOSE_PUBLISH.to_string(),
field_map: None,
},
spread_location: None,
tipo: Type::function(
vec![Type::data()],
Type::script_purpose(),
),
},
"vote" => TypedPattern::Constructor {
is_record: false,
location: Span::empty(),
name: well_known::SCRIPT_PURPOSE_VOTE.to_string(),
arguments: vec![CallArg {
label: None,
location: Span::empty(),
value: TypedPattern::Var {
name: "__purpose_arg__".to_string(),
location: Span::empty(),
},
}],
module: None,
constructor: PatternConstructor::Record {
name: well_known::SCRIPT_PURPOSE_VOTE.to_string(),
field_map: None,
},
spread_location: None,
tipo: Type::function(
vec![Type::data()],
Type::script_purpose(),
),
},
"propose" => TypedPattern::Constructor {
is_record: false,
location: Span::empty(),
name: well_known::SCRIPT_PURPOSE_PROPOSE.to_string(),
arguments: vec![CallArg {
label: None,
location: Span::empty(),
value: TypedPattern::Var {
name: "__purpose_arg__".to_string(),
location: Span::empty(),
},
}],
module: None,
constructor: PatternConstructor::Record {
name: well_known::SCRIPT_PURPOSE_PROPOSE.to_string(),
field_map: None,
},
spread_location: None,
tipo: Type::function(
vec![Type::data()],
Type::script_purpose(),
),
},
purpose => {
unreachable!("unexpected/unknown purpose: {:?}", purpose)
}

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@v2" = [{ secs_since_epoch = 1723751815, nanos_since_epoch = 69229000 }, "cdbbce58b61deb385e7ea787a2e0fc2dc8fe94db9999e0e6275bc9c70e5796be"]
"aiken-lang/stdlib@v2" = [{ secs_since_epoch = 1723818477, nanos_since_epoch = 540444000 }, "cdbbce58b61deb385e7ea787a2e0fc2dc8fe94db9999e0e6275bc9c70e5796be"]

View File

@ -93,7 +93,7 @@
]
, [ 2
, [ 1
, h'{{ certificates.script.hash }}'
, h'{{ certificates.purposes_publish.hash }}'
]
, h'11111111111111111111111111111111111111111111111111111111'
]
@ -109,7 +109,7 @@
{ 5: [[2, 20, 121([]), [1000000, 100000000]]]
, 7: [h'{{ certificates.script.cbor }}']
, 7: [h'{{ certificates.purposes_publish.cbor }}']
},
true,

View File

@ -41,7 +41,7 @@
, h'F000000000000000000000000000000000000000000000000000000000'
, [ 2
, { h'E022222222222222222222222222222222222222222222222222222222': 1000000 }
, h'{{ proposing_all.guardrails.hash }}'
, h'{{ proposing_all.guardrails_propose.hash }}'
]
, [ "https://aiken-lang.org"
, h'0000000000000000000000000000000000000000000000000000000000000000'
@ -112,7 +112,7 @@
{ 5: [[5, 3, 121([]), [1000000, 100000000]]]
, 7: [h'{{ proposing_all.guardrails.cbor }}']
, 7: [h'{{ proposing_all.guardrails_propose.cbor }}']
},
true,

View File

@ -61,7 +61,7 @@
, 32: 20
, 33: 30([15, 1])
}
, h'{{ proposing_pparams.guardrails.hash }}'
, h'{{ proposing_pparams.guardrails_propose.hash }}'
]
, [ "https://aiken-lang.org"
, h'0000000000000000000000000000000000000000000000000000000000000000'
@ -73,7 +73,7 @@
{ 5: [[5, 0, 121([]), [1000000, 100000000]]]
, 7: [h'{{ proposing_pparams.guardrails.cbor }}']
, 7: [h'{{ proposing_pparams.guardrails_propose.cbor }}']
},
true,

View File

@ -25,7 +25,7 @@
, [ h'7777777777777777777777777777777777777777777777777777777777777777', 2 ]: [ 2, null ]
}
, [ 3, h'{{ voting.script.hash }}' ]:
, [ 3, h'{{ voting.purposes_vote.hash }}' ]:
{ [ h'9999999999999999999999999999999999999999999999999999999999999999', 3 ]: [ 0, null ]
}
@ -33,7 +33,7 @@
{ [ h'9999999999999999999999999999999999999999999999999999999999999999', 4 ]: [ 1, null ]
}
, [ 1, h'{{ voting.script.hash }}' ]:
, [ 1, h'{{ voting.purposes_vote.hash }}' ]:
{ [ h'9999999999999999999999999999999999999999999999999999999999999999', 1 ]: [ 1, null ]
}
}
@ -43,7 +43,7 @@
, [4, 0, 121([42]), [1000000, 100000000]]
]
, 7: [h'{{ voting.script.cbor }}']
, 7: [h'{{ voting.purposes_vote.cbor }}']
},
true,

View File

@ -31,7 +31,7 @@
]
},
{ 5: [ [0, 0, 122([121([])]), [1000000, 100000000]]
{ 5: [ [0, 0, 121([]), [1000000, 100000000]]
, [3, 0, 121([]), [1000000, 100000000]]
]
},

File diff suppressed because one or more lines are too long

View File

@ -1,14 +1,14 @@
use aiken/collection/list
use cardano/certificate.{
AlwaysAbstain, AlwaysNoConfidence, AuthorizeConstitutionalCommitteeProxy,
DelegateBlockProduction, DelegateBoth, DelegateCredential, DelegateVote,
RegisterAndDelegateCredential, RegisterCredential,
Certificate, DelegateBlockProduction, DelegateBoth, DelegateCredential,
DelegateVote, RegisterAndDelegateCredential, RegisterCredential,
RegisterDelegateRepresentative, RegisterStakePool, Registered,
RetireFromConstitutionalCommittee, RetireStakePool, UnregisterCredential,
UnregisterDelegateRepresentative, UpdateDelegateRepresentative,
}
use cardano/credential.{Script, VerificationKey}
use cardano/transaction.{Publishing, ScriptContext, ScriptInfo}
use cardano/transaction.{Transaction}
const only0s = #"00000000000000000000000000000000000000000000000000000000"
@ -19,15 +19,19 @@ const only2s = #"22222222222222222222222222222222222222222222222222222222"
const only9s =
#"9999999999999999999999999999999999999999999999999999999999999999"
validator {
fn script(_tmp1: Void, ctx: ScriptContext) -> Bool {
assert_script_info(ctx.info)
validator purposes {
publish(
_redeemer: Void,
certificate: Certificate,
transaction: Transaction,
) -> Bool {
assert_script_info(certificate)
let certificates = ctx.transaction.certificates
let certificates = transaction.certificates
expect Some(10_000_000) = ctx.transaction.current_treasury_amount
expect Some(10_000_000) = transaction.current_treasury_amount
expect Some(14) = ctx.transaction.treasury_donation
expect Some(14) = transaction.treasury_donation
expect
Some(RegisterCredential { credential: Script(only2s), deposit: None }) == list.at(
@ -197,10 +201,14 @@ validator {
True
}
else(_ctx) {
fail
}
}
fn assert_script_info(info: ScriptInfo) {
expect Publishing(20, DelegateCredential { credential, delegate }) = info
fn assert_script_info(certificate: Certificate) {
expect DelegateCredential { credential, delegate } = certificate
expect DelegateBlockProduction { stake_pool: only1s } == delegate
expect Script(..) = credential
Void

View File

@ -123,9 +123,18 @@ fn assert_mint(mint: Value, our_policy_id: PolicyId, other_policy_id: PolicyId)
Void
}
// NOTE: It is imperative that test2 has a lower hash value than test1; as
// otherwise the redeemer will point to the wrong redeemer. So the trace
// below is meant to generate a small-enough hash... If this test fails
// after some code-gen changes, it's probably because the new hash is
// larger.
///
// How to fix?
// Change the traced string down below in hope to get a
// smaller hash.
validator test_2 {
mint(_tmp2: Void, _policy_id: PolicyId, _transaction: Transaction) {
trace @"_____mint_2_____"
trace @"slfhioer7w8yru"
True
}

View File

@ -6,18 +6,22 @@ use cardano/governance.{
HardFork, NewConstitution, NicePoll, NoConfidence, ProposalProcedure,
ProtocolVersion, TreasuryWithdrawal,
}
use cardano/transaction.{Propose, Redeemer, ScriptContext, ScriptPurpose}
use cardano/transaction.{Propose, Redeemer, ScriptPurpose, Transaction}
const null28 = #"00000000000000000000000000000000000000000000000000000000"
const null32 =
#"0000000000000000000000000000000000000000000000000000000000000000"
validator {
fn guardrails(_tmp1: Void, ctx: ScriptContext) -> Bool {
let procedures = ctx.transaction.proposal_procedures
validator guardrails {
propose(
_redeemer: Void,
_: ProposalProcedure,
transaction: Transaction,
) -> Bool {
let procedures = transaction.proposal_procedures
assert_redeemers(ctx.transaction.redeemers)
assert_redeemers(transaction.redeemers)
assert_proposal_procedure(
list.at(procedures, 0),
@ -118,6 +122,10 @@ validator {
True
}
else(_ctx) {
fail
}
}
fn assert_redeemers(redeemers: Pairs<ScriptPurpose, Redeemer>) -> Void {

View File

@ -17,21 +17,22 @@ use cardano/governance/protocol_parameters.{
stake_pool_operator_voting_thresholds, stake_pool_pledge_influence,
stake_pool_retirement_horizon, treasury_expansion,
}
use cardano/transaction.{Proposing, ScriptContext}
use cardano/transaction.{Transaction}
validator {
fn guardrails(_tmp1: Void, ctx: ScriptContext) -> Bool {
expect Proposing(
0,
ProposalProcedure {
validator guardrails {
propose(
_redeemer: Void,
proposal: ProposalProcedure,
_transaction: Transaction,
) -> Bool {
expect ProposalProcedure {
governance_action: ProtocolParameters {
ancestor: None,
guardrails: Some(..),
new_parameters,
},
..
},
) = ctx.info
} = proposal
expect ( new_parameters |> min_fee_coefficient ) == Some(44)
@ -127,6 +128,10 @@ validator {
True
}
else(_ctx) {
fail
}
}
fn expect_rational(numerator: Int, denominator: Int) -> Rational {

View File

@ -2,9 +2,9 @@ use aiken/collection/list
use cardano/credential.{Script, VerificationKey}
use cardano/governance.{
Abstain, ConstitutionalCommitteeMember, DelegateRepresentative,
GovernanceActionId, No, StakePool, Yes,
GovernanceActionId, No, StakePool, Voter, Yes,
}
use cardano/transaction.{ScriptContext}
use cardano/transaction.{Transaction}
type Foo {
Foo(Int)
@ -21,11 +21,11 @@ const only8s =
const only9s =
#"9999999999999999999999999999999999999999999999999999999999999999"
validator {
fn script(_tmp0: Data, ctx: ScriptContext) {
assert_redeemer(ctx.redeemer)
validator purposes {
vote(redeemer: Data, _voter: Voter, transaction: Transaction) {
assert_redeemer(redeemer)
let votes = ctx.transaction.votes
let votes = transaction.votes
expect Some(
Pair(ConstitutionalCommitteeMember(Script(..)),
@ -35,14 +35,18 @@ validator {
expect
Some(
Pair(ConstitutionalCommitteeMember(VerificationKey(only0s)),
Pair(
ConstitutionalCommitteeMember(VerificationKey(only0s)),
[
Pair(GovernanceActionId {
Pair(
GovernanceActionId {
transaction: only9s,
proposal_procedure: 152,
},
No),
]),
No,
),
],
),
) == list.at(votes, 1)
expect Some(Pair(DelegateRepresentative(Script(..)), [_, ..])) =
@ -50,15 +54,23 @@ validator {
expect
Some(
Pair(DelegateRepresentative(VerificationKey(only0s)),
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(
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)
@ -66,6 +78,10 @@ validator {
True
}
else(_ctx) {
fail
}
}
fn assert_redeemer(data: Data) {