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 { pub fn validator_arity(&self) -> usize {
if self.name == HANDLER_SPEND if self.name == HANDLER_SPEND {
|| self.name == HANDLER_PUBLISH
|| self.name == HANDLER_PROPOSE
{
4 4
} else if self.name == HANDLER_MINT } else if self.name == HANDLER_MINT
|| self.name == HANDLER_WITHDRAW || self.name == HANDLER_WITHDRAW
|| self.name == HANDLER_VOTE || self.name == HANDLER_VOTE
|| self.name == HANDLER_PUBLISH
|| self.name == HANDLER_PROPOSE
{ {
3 3
} else { } 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 => { purpose => {
unreachable!("unexpected/unknown purpose: {:?}", purpose) unreachable!("unexpected/unknown purpose: {:?}", purpose)
} }

View File

@ -13,4 +13,4 @@ requirements = []
source = "github" source = "github"
[etags] [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 , [ 2
, [ 1 , [ 1
, h'{{ certificates.script.hash }}' , h'{{ certificates.purposes_publish.hash }}'
] ]
, h'11111111111111111111111111111111111111111111111111111111' , h'11111111111111111111111111111111111111111111111111111111'
] ]
@ -109,7 +109,7 @@
{ 5: [[2, 20, 121([]), [1000000, 100000000]]] { 5: [[2, 20, 121([]), [1000000, 100000000]]]
, 7: [h'{{ certificates.script.cbor }}'] , 7: [h'{{ certificates.purposes_publish.cbor }}']
}, },
true, true,

View File

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

View File

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

View File

@ -25,7 +25,7 @@
, [ h'7777777777777777777777777777777777777777777777777777777777777777', 2 ]: [ 2, null ] , [ h'7777777777777777777777777777777777777777777777777777777777777777', 2 ]: [ 2, null ]
} }
, [ 3, h'{{ voting.script.hash }}' ]: , [ 3, h'{{ voting.purposes_vote.hash }}' ]:
{ [ h'9999999999999999999999999999999999999999999999999999999999999999', 3 ]: [ 0, null ] { [ h'9999999999999999999999999999999999999999999999999999999999999999', 3 ]: [ 0, null ]
} }
@ -33,7 +33,7 @@
{ [ h'9999999999999999999999999999999999999999999999999999999999999999', 4 ]: [ 1, null ] { [ h'9999999999999999999999999999999999999999999999999999999999999999', 4 ]: [ 1, null ]
} }
, [ 1, h'{{ voting.script.hash }}' ]: , [ 1, h'{{ voting.purposes_vote.hash }}' ]:
{ [ h'9999999999999999999999999999999999999999999999999999999999999999', 1 ]: [ 1, null ] { [ h'9999999999999999999999999999999999999999999999999999999999999999', 1 ]: [ 1, null ]
} }
} }
@ -43,7 +43,7 @@
, [4, 0, 121([42]), [1000000, 100000000]] , [4, 0, 121([42]), [1000000, 100000000]]
] ]
, 7: [h'{{ voting.script.cbor }}'] , 7: [h'{{ voting.purposes_vote.cbor }}']
}, },
true, 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]] , [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 aiken/collection/list
use cardano/certificate.{ use cardano/certificate.{
AlwaysAbstain, AlwaysNoConfidence, AuthorizeConstitutionalCommitteeProxy, AlwaysAbstain, AlwaysNoConfidence, AuthorizeConstitutionalCommitteeProxy,
DelegateBlockProduction, DelegateBoth, DelegateCredential, DelegateVote, Certificate, DelegateBlockProduction, DelegateBoth, DelegateCredential,
RegisterAndDelegateCredential, RegisterCredential, DelegateVote, RegisterAndDelegateCredential, RegisterCredential,
RegisterDelegateRepresentative, RegisterStakePool, Registered, RegisterDelegateRepresentative, RegisterStakePool, Registered,
RetireFromConstitutionalCommittee, RetireStakePool, UnregisterCredential, RetireFromConstitutionalCommittee, RetireStakePool, UnregisterCredential,
UnregisterDelegateRepresentative, UpdateDelegateRepresentative, UnregisterDelegateRepresentative, UpdateDelegateRepresentative,
} }
use cardano/credential.{Script, VerificationKey} use cardano/credential.{Script, VerificationKey}
use cardano/transaction.{Publishing, ScriptContext, ScriptInfo} use cardano/transaction.{Transaction}
const only0s = #"00000000000000000000000000000000000000000000000000000000" const only0s = #"00000000000000000000000000000000000000000000000000000000"
@ -19,15 +19,19 @@ const only2s = #"22222222222222222222222222222222222222222222222222222222"
const only9s = const only9s =
#"9999999999999999999999999999999999999999999999999999999999999999" #"9999999999999999999999999999999999999999999999999999999999999999"
validator { validator purposes {
fn script(_tmp1: Void, ctx: ScriptContext) -> Bool { publish(
assert_script_info(ctx.info) _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 expect
Some(RegisterCredential { credential: Script(only2s), deposit: None }) == list.at( Some(RegisterCredential { credential: Script(only2s), deposit: None }) == list.at(
@ -197,10 +201,14 @@ validator {
True True
} }
else(_ctx) {
fail
}
} }
fn assert_script_info(info: ScriptInfo) { fn assert_script_info(certificate: Certificate) {
expect Publishing(20, DelegateCredential { credential, delegate }) = info expect DelegateCredential { credential, delegate } = certificate
expect DelegateBlockProduction { stake_pool: only1s } == delegate expect DelegateBlockProduction { stake_pool: only1s } == delegate
expect Script(..) = credential expect Script(..) = credential
Void Void

View File

@ -123,9 +123,18 @@ fn assert_mint(mint: Value, our_policy_id: PolicyId, other_policy_id: PolicyId)
Void 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 { validator test_2 {
mint(_tmp2: Void, _policy_id: PolicyId, _transaction: Transaction) { mint(_tmp2: Void, _policy_id: PolicyId, _transaction: Transaction) {
trace @"_____mint_2_____" trace @"slfhioer7w8yru"
True True
} }

View File

@ -6,18 +6,22 @@ use cardano/governance.{
HardFork, NewConstitution, NicePoll, NoConfidence, ProposalProcedure, HardFork, NewConstitution, NicePoll, NoConfidence, ProposalProcedure,
ProtocolVersion, TreasuryWithdrawal, ProtocolVersion, TreasuryWithdrawal,
} }
use cardano/transaction.{Propose, Redeemer, ScriptContext, ScriptPurpose} use cardano/transaction.{Propose, Redeemer, ScriptPurpose, Transaction}
const null28 = #"00000000000000000000000000000000000000000000000000000000" const null28 = #"00000000000000000000000000000000000000000000000000000000"
const null32 = const null32 =
#"0000000000000000000000000000000000000000000000000000000000000000" #"0000000000000000000000000000000000000000000000000000000000000000"
validator { validator guardrails {
fn guardrails(_tmp1: Void, ctx: ScriptContext) -> Bool { propose(
let procedures = ctx.transaction.proposal_procedures _redeemer: Void,
_: ProposalProcedure,
transaction: Transaction,
) -> Bool {
let procedures = transaction.proposal_procedures
assert_redeemers(ctx.transaction.redeemers) assert_redeemers(transaction.redeemers)
assert_proposal_procedure( assert_proposal_procedure(
list.at(procedures, 0), list.at(procedures, 0),
@ -118,6 +122,10 @@ validator {
True True
} }
else(_ctx) {
fail
}
} }
fn assert_redeemers(redeemers: Pairs<ScriptPurpose, Redeemer>) -> Void { 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_operator_voting_thresholds, stake_pool_pledge_influence,
stake_pool_retirement_horizon, treasury_expansion, stake_pool_retirement_horizon, treasury_expansion,
} }
use cardano/transaction.{Proposing, ScriptContext} use cardano/transaction.{Transaction}
validator { validator guardrails {
fn guardrails(_tmp1: Void, ctx: ScriptContext) -> Bool { propose(
expect Proposing( _redeemer: Void,
0, proposal: ProposalProcedure,
ProposalProcedure { _transaction: Transaction,
) -> Bool {
expect ProposalProcedure {
governance_action: ProtocolParameters { governance_action: ProtocolParameters {
ancestor: None, ancestor: None,
guardrails: Some(..), guardrails: Some(..),
new_parameters, new_parameters,
}, },
.. ..
}, } = proposal
) = ctx.info
expect ( new_parameters |> min_fee_coefficient ) == Some(44) expect ( new_parameters |> min_fee_coefficient ) == Some(44)
@ -127,6 +128,10 @@ validator {
True True
} }
else(_ctx) {
fail
}
} }
fn expect_rational(numerator: Int, denominator: Int) -> Rational { 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/credential.{Script, VerificationKey}
use cardano/governance.{ use cardano/governance.{
Abstain, ConstitutionalCommitteeMember, DelegateRepresentative, Abstain, ConstitutionalCommitteeMember, DelegateRepresentative,
GovernanceActionId, No, StakePool, Yes, GovernanceActionId, No, StakePool, Voter, Yes,
} }
use cardano/transaction.{ScriptContext} use cardano/transaction.{Transaction}
type Foo { type Foo {
Foo(Int) Foo(Int)
@ -21,11 +21,11 @@ const only8s =
const only9s = const only9s =
#"9999999999999999999999999999999999999999999999999999999999999999" #"9999999999999999999999999999999999999999999999999999999999999999"
validator { validator purposes {
fn script(_tmp0: Data, ctx: ScriptContext) { vote(redeemer: Data, _voter: Voter, transaction: Transaction) {
assert_redeemer(ctx.redeemer) assert_redeemer(redeemer)
let votes = ctx.transaction.votes let votes = transaction.votes
expect Some( expect Some(
Pair(ConstitutionalCommitteeMember(Script(..)), Pair(ConstitutionalCommitteeMember(Script(..)),
@ -35,14 +35,18 @@ validator {
expect expect
Some( Some(
Pair(ConstitutionalCommitteeMember(VerificationKey(only0s)), Pair(
ConstitutionalCommitteeMember(VerificationKey(only0s)),
[ [
Pair(GovernanceActionId { Pair(
GovernanceActionId {
transaction: only9s, transaction: only9s,
proposal_procedure: 152, proposal_procedure: 152,
}, },
No), No,
]), ),
],
),
) == list.at(votes, 1) ) == list.at(votes, 1)
expect Some(Pair(DelegateRepresentative(Script(..)), [_, ..])) = expect Some(Pair(DelegateRepresentative(Script(..)), [_, ..])) =
@ -50,15 +54,23 @@ validator {
expect expect
Some( Some(
Pair(DelegateRepresentative(VerificationKey(only0s)), Pair(
DelegateRepresentative(VerificationKey(only0s)),
[ [
Pair(GovernanceActionId { transaction: only7s, proposal_procedure: 2 }, Pair(
Abstain), GovernanceActionId { transaction: only7s, proposal_procedure: 2 },
Pair(GovernanceActionId { transaction: only8s, proposal_procedure: 1 }, Abstain,
Abstain), ),
Pair(GovernanceActionId { transaction: only9s, proposal_procedure: 0 }, Pair(
Abstain), GovernanceActionId { transaction: only8s, proposal_procedure: 1 },
]), Abstain,
),
Pair(
GovernanceActionId { transaction: only9s, proposal_procedure: 0 },
Abstain,
),
],
),
) == list.at(votes, 3) ) == list.at(votes, 3)
expect Some(Pair(StakePool(pool_id), [_, ..])) = list.at(votes, 4) expect Some(Pair(StakePool(pool_id), [_, ..])) = list.at(votes, 4)
@ -66,6 +78,10 @@ validator {
True True
} }
else(_ctx) {
fail
}
} }
fn assert_redeemer(data: Data) { fn assert_redeemer(data: Data) {