Test proposal procedures through Aiken.
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
use aiken/dict.{Dict}
|
||||
use aiken/list
|
||||
use aiken/transaction.{
|
||||
use aiken/collection/dict.{Dict}
|
||||
use aiken/collection/list
|
||||
use cardano/assets.{PolicyId, Value}
|
||||
use cardano/credential
|
||||
use cardano/transaction.{
|
||||
DatumHash, Input, Mint, Minting, NoDatum, Output, OutputReference,
|
||||
ScriptContext, ScriptInfo, ScriptPurpose,
|
||||
}
|
||||
use aiken/transaction/credential
|
||||
use aiken/transaction/value.{PolicyId, Value}
|
||||
|
||||
const null28 = #"00000000000000000000000000000000000000000000000000000000"
|
||||
|
||||
@@ -37,7 +37,7 @@ fn assert_reference_inputs(inputs: List<Input>) -> Void {
|
||||
},
|
||||
output: Output {
|
||||
address: credential.from_verification_key(null28),
|
||||
value: value.from_lovelace(1_000_000),
|
||||
value: assets.from_lovelace(1_000_000),
|
||||
datum: NoDatum,
|
||||
reference_script: None,
|
||||
},
|
||||
@@ -74,7 +74,7 @@ fn assert_outputs(
|
||||
Some(
|
||||
Output {
|
||||
address: credential.from_verification_key(null28),
|
||||
value: value.from_lovelace(1_000_000),
|
||||
value: assets.from_lovelace(1_000_000),
|
||||
datum: DatumHash(void_hash),
|
||||
reference_script: None,
|
||||
},
|
||||
@@ -85,9 +85,9 @@ fn assert_outputs(
|
||||
Output {
|
||||
address: credential.from_verification_key(null28)
|
||||
|> credential.with_delegation_key(null28),
|
||||
value: value.from_lovelace(1_000_000)
|
||||
|> value.add(our_policy_id, "tuna", 100000000000000)
|
||||
|> value.add(other_policy_id, "aiken", 42),
|
||||
value: assets.from_lovelace(1_000_000)
|
||||
|> assets.add(our_policy_id, "tuna", 100000000000000)
|
||||
|> assets.add(other_policy_id, "aiken", 42),
|
||||
datum: NoDatum,
|
||||
reference_script: None,
|
||||
},
|
||||
@@ -98,8 +98,8 @@ fn assert_outputs(
|
||||
Output {
|
||||
address: credential.from_script(null28)
|
||||
|> credential.with_delegation_key(null28),
|
||||
value: value.from_lovelace(1_000_000)
|
||||
|> value.add(other_policy_id, "cardano", 1),
|
||||
value: assets.from_lovelace(1_000_000)
|
||||
|> assets.add(other_policy_id, "cardano", 1),
|
||||
datum: NoDatum,
|
||||
reference_script: Some(
|
||||
#"68ad54b3a8124d9fe5caaaf2011a85d72096e696a2fb3d7f86c41717",
|
||||
@@ -116,7 +116,7 @@ fn assert_mint(mint: Value, our_policy_id: PolicyId, other_policy_id: PolicyId)
|
||||
(other_policy_id, "aiken", -14),
|
||||
(other_policy_id, "cardano", 1),
|
||||
(our_policy_id, "tuna", 100000000000000),
|
||||
] == value.flatten(mint)
|
||||
] == assets.flatten(mint)
|
||||
Void
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
use aiken/collection/list
|
||||
use aiken/math/rational
|
||||
use cardano/credential.{Script, VerificationKey}
|
||||
use cardano/governance.{
|
||||
Constitution, ConstitutionalCommittee, GovernanceAction, GovernanceActionId,
|
||||
HardForkInitiation, NewConstitution, NicePoll, NoConfidence, ProposalProcedure,
|
||||
ProtocolVersion, TreasuryWithdrawal,
|
||||
}
|
||||
use cardano/transaction.{Propose, Redeemer, ScriptContext, ScriptPurpose}
|
||||
|
||||
const null28 = #"00000000000000000000000000000000000000000000000000000000"
|
||||
|
||||
const null32 =
|
||||
#"0000000000000000000000000000000000000000000000000000000000000000"
|
||||
|
||||
validator {
|
||||
fn guardrails(_tmp1: Void, ctx: ScriptContext) -> Bool {
|
||||
let procedures = ctx.transaction.proposal_procedures
|
||||
|
||||
assert_redeemers(ctx.transaction.redeemers)
|
||||
|
||||
assert_proposal_procedure(
|
||||
list.at(procedures, 0),
|
||||
fn(action) {
|
||||
expect
|
||||
HardForkInitiation {
|
||||
ancestor: None,
|
||||
new_version: ProtocolVersion(10, 0),
|
||||
} == action
|
||||
Void
|
||||
},
|
||||
)
|
||||
|
||||
assert_proposal_procedure(
|
||||
list.at(procedures, 1),
|
||||
fn(action) {
|
||||
expect
|
||||
HardForkInitiation {
|
||||
ancestor: Some(GovernanceActionId(null32, 0)),
|
||||
new_version: ProtocolVersion(11, 0),
|
||||
} == action
|
||||
Void
|
||||
},
|
||||
)
|
||||
|
||||
assert_proposal_procedure(
|
||||
list.at(procedures, 2),
|
||||
fn(action) {
|
||||
expect
|
||||
TreasuryWithdrawal {
|
||||
beneficiaries: [
|
||||
Pair(VerificationKey(
|
||||
#"11111111111111111111111111111111111111111111111111111111",
|
||||
),
|
||||
1_000_000),
|
||||
],
|
||||
guardrails: None,
|
||||
} == action
|
||||
Void
|
||||
},
|
||||
)
|
||||
|
||||
assert_proposal_procedure(
|
||||
list.at(procedures, 3),
|
||||
fn(action) {
|
||||
expect TreasuryWithdrawal { guardrails: Some(..), .. } = action
|
||||
Void
|
||||
},
|
||||
)
|
||||
|
||||
assert_proposal_procedure(
|
||||
list.at(procedures, 4),
|
||||
fn(action) {
|
||||
expect NoConfidence { ancestor: None } == action
|
||||
Void
|
||||
},
|
||||
)
|
||||
|
||||
assert_proposal_procedure(
|
||||
list.at(procedures, 5),
|
||||
fn(action) {
|
||||
expect Some(quorum) = rational.new(1, 2)
|
||||
expect
|
||||
ConstitutionalCommittee {
|
||||
ancestor: None,
|
||||
evicted_members: [VerificationKey(null28)],
|
||||
added_members: [Pair(VerificationKey(null28), 500)],
|
||||
quorum,
|
||||
} == action
|
||||
Void
|
||||
},
|
||||
)
|
||||
|
||||
assert_proposal_procedure(
|
||||
list.at(procedures, 6),
|
||||
fn(action) {
|
||||
expect
|
||||
NewConstitution {
|
||||
ancestor: None,
|
||||
constitution: Constitution { guardrails: None },
|
||||
} == action
|
||||
Void
|
||||
},
|
||||
)
|
||||
|
||||
assert_proposal_procedure(
|
||||
list.at(procedures, 7),
|
||||
fn(action) {
|
||||
expect
|
||||
NewConstitution {
|
||||
ancestor: None,
|
||||
constitution: Constitution { guardrails: Some(null28) },
|
||||
} == action
|
||||
Void
|
||||
},
|
||||
)
|
||||
|
||||
assert_last_proposal_procedure(list.at(procedures, 8))
|
||||
|
||||
True
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_redeemers(redeemers: Pairs<ScriptPurpose, Redeemer>) -> Void {
|
||||
expect [
|
||||
Pair(Propose(
|
||||
3,
|
||||
ProposalProcedure { deposit, return_address, governance_action },
|
||||
),
|
||||
data),
|
||||
] = redeemers
|
||||
expect deposit == 2_000_000
|
||||
expect return_address == Script(null28)
|
||||
expect TreasuryWithdrawal { .. } = governance_action
|
||||
expect Void = data
|
||||
Void
|
||||
}
|
||||
|
||||
fn assert_proposal_procedure(
|
||||
procedure: Option<ProposalProcedure>,
|
||||
with: fn(GovernanceAction) -> Void,
|
||||
) -> Void {
|
||||
expect Some(procedure) = procedure
|
||||
expect procedure.deposit == 2_000_000
|
||||
expect procedure.return_address == Script(null28)
|
||||
with(procedure.governance_action)
|
||||
}
|
||||
|
||||
fn assert_last_proposal_procedure(procedure: Option<ProposalProcedure>) -> Void {
|
||||
expect Some(procedure) = procedure
|
||||
expect procedure.deposit == 2_000_000
|
||||
expect procedure.return_address == VerificationKey(null28)
|
||||
expect procedure.governance_action == NicePoll
|
||||
Void
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
use aiken/dict
|
||||
use aiken/transaction.{
|
||||
use aiken/collection/dict
|
||||
use cardano/assets
|
||||
use cardano/credential.{Address, Script}
|
||||
use cardano/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) {
|
||||
@@ -64,12 +64,10 @@ fn assert_inputs(inputs: List<Input>) {
|
||||
expect
|
||||
transaction_id == #"0000000000000000000000000000000000000000000000000000000000000000"
|
||||
|
||||
expect resolved_input_value == value.from_lovelace(1000000000)
|
||||
expect resolved_input_value == assets.from_lovelace(1000000000)
|
||||
|
||||
expect Address {
|
||||
payment_credential: ScriptCredential(_),
|
||||
stake_credential: None,
|
||||
} = address
|
||||
expect Address { payment_credential: Script(_), stake_credential: None } =
|
||||
address
|
||||
|
||||
Void
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user