Test proposal procedures through Aiken.

This commit is contained in:
KtorZ
2024-08-11 00:53:19 +02:00
parent cfca0da4e9
commit 50dad1fdfe
14 changed files with 364 additions and 72 deletions

View File

@@ -25,7 +25,7 @@ for convenience.
- [ ] withdraw
- [ ] publish
- [ ] voting
- [ ] proposing
- [x] proposing
- Transaction body
- [x] inputs
@@ -38,7 +38,7 @@ for convenience.
- [x] fee
- [x] mint
- certificates
- [ ] none
- [x] none
- some
- Register credential
- [ ] no deposit
@@ -56,26 +56,26 @@ for convenience.
- [ ] Delegate CC
- [ ] Retire CC
- withdrawals
- [ ] none
- [x] none
- [ ] some
- [ ] validity range
- extra signatories
- [x] none
- [ ] some
- [ ] redeemers
- [x] redeemers
- [x] datums
- votes
- [ ] none
- [x] none
- [ ] some
- proposal procedures
- [ ] none
- [ ] some
- [x] none
- [x] some
- current treasury
- [ ] with
- [ ] without
- [x] without
- treasury donation
- [ ] with
- [ ] without
- [x] without
- Address
- [x] type-0 (key | key)
@@ -105,21 +105,21 @@ for convenience.
- [ ] with action id
- [ ] without action id
- hardfork initiation
- [ ] with action id
- [ ] without action id
- [x] with action id
- [x] without action id
- treasuryWithdrawals
- [ ] with constitution
- [ ] without constitution
- [x] with constitution
- [x] without constitution
- no confidence
- [ ] with action id
- [ ] without action id
- [x] with action id
- [x] without action id
- update committee
- [ ] with action id
- [ ] without action id
- [x] with action id
- [x] without action id
- new constitution
- [ ] with action id
- [ ] without action id
- [ ] info action
- [x] with action id
- [x] without action id
- [x] info action
- Vote
- [ ] No
@@ -164,11 +164,11 @@ for convenience.
- [ ] 33 : nonnegative_interval}
- Constitution
- [ ] with guardrail script
- [ ] without guardrail script
- [x] with guardrail script
- [x] without guardrail script
- Credential
- [ ] key
- [x] key
- [x] script
- Delegatee

View File

@@ -0,0 +1,5 @@
[
{ 0: h'6000000000000000000000000000000000000000000000000000000000'
, 1: 1000000
}
]

View File

@@ -0,0 +1,122 @@
[
{ 0:
[ [h'0000000000000000000000000000000000000000000000000000000000000000', 0]
]
, 1:
[]
, 2: 42
, 20: 258(
[
[ 2000000
, h'F000000000000000000000000000000000000000000000000000000000'
, [ 1, null, [ 10, 0 ] ]
, [ "https://aiken-lang.org"
, h'0000000000000000000000000000000000000000000000000000000000000000'
]
]
, [ 2000000
, h'F000000000000000000000000000000000000000000000000000000000'
, [ 1, [ h'0000000000000000000000000000000000000000000000000000000000000000', 0 ] , [ 11, 0 ] ]
, [ "https://aiken-lang.org"
, h'0000000000000000000000000000000000000000000000000000000000000000'
]
]
, [ 2000000
, h'F000000000000000000000000000000000000000000000000000000000'
, [ 2
, { h'E011111111111111111111111111111111111111111111111111111111': 1000000 }
, null
]
, [ "https://aiken-lang.org"
, h'0000000000000000000000000000000000000000000000000000000000000000'
]
]
, [ 2000000
, h'F000000000000000000000000000000000000000000000000000000000'
, [ 2
, { h'E022222222222222222222222222222222222222222222222222222222': 1000000 }
, h'{{ proposing_all.guardrails.hash }}'
]
, [ "https://aiken-lang.org"
, h'0000000000000000000000000000000000000000000000000000000000000000'
]
]
, [ 2000000
, h'F000000000000000000000000000000000000000000000000000000000'
, [ 3, null ]
, [ "https://aiken-lang.org"
, h'0000000000000000000000000000000000000000000000000000000000000000'
]
]
, [ 2000000
, h'F000000000000000000000000000000000000000000000000000000000'
, [ 4
, null
, [ [0, h'00000000000000000000000000000000000000000000000000000000'] ]
, { [0, h'00000000000000000000000000000000000000000000000000000000']: 500 }
, 30([1, 2])
]
, [ "https://aiken-lang.org"
, h'0000000000000000000000000000000000000000000000000000000000000000'
]
]
, [ 2000000
, h'F000000000000000000000000000000000000000000000000000000000'
, [ 5
, null
, [ [ "https://constitution.cardano.org"
, h'0000000000000000000000000000000000000000000000000000000000000000'
]
, null
]
]
, [ "https://aiken-lang.org"
, h'0000000000000000000000000000000000000000000000000000000000000000'
]
]
, [ 2000000
, h'F000000000000000000000000000000000000000000000000000000000'
, [ 5
, null
, [ [ "https://constitution.cardano.org"
, h'0000000000000000000000000000000000000000000000000000000000000000'
]
, h'00000000000000000000000000000000000000000000000000000000'
]
]
, [ "https://aiken-lang.org"
, h'0000000000000000000000000000000000000000000000000000000000000000'
]
]
, [ 2000000
, h'E000000000000000000000000000000000000000000000000000000000'
, [ 6 ]
, [ "https://aiken-lang.org"
, h'0000000000000000000000000000000000000000000000000000000000000000'
]
]
]
)
},
{ 5: [[5, 3, 121([]), [1000000, 100000000]]]
, 7: [h'{{ proposing_all.guardrails.cbor }}']
},
true,
null
]

View File

@@ -0,0 +1 @@
../../../../../stdlib/lib

View File

@@ -1 +0,0 @@
../../../../../../stdlib/lib/aiken

File diff suppressed because one or more lines are too long

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}