Skip to content

Commit

Permalink
test(cardano-chain-sync): Try to ratify new cc member
Browse files Browse the repository at this point in the history
  • Loading branch information
sgillespie committed May 15, 2024
1 parent bea5738 commit 8e5b22f
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 6 deletions.
57 changes: 55 additions & 2 deletions cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Conway.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ module Cardano.Mock.Forging.Tx.Conway (
mkDummyTxBody,
mkRegDRepTx,
mkNewCommitteeTx,
mkGovActionProposalTx,
mkGovActionVoteTx,
mkTxDelegCert,
mkRegTxCert,
mkUnRegTxCert,
Expand Down Expand Up @@ -89,11 +91,11 @@ import Data.List (nub)
import qualified Data.List.NonEmpty as NonEmpty
import qualified Data.Map as Map
import Data.Maybe (fromJust)
import Data.Maybe.Strict (StrictMaybe (..), maybeToStrictMaybe)
import qualified Data.OSet.Strict as OSet
import Data.Sequence.Strict (StrictSeq ())
import qualified Data.Sequence.Strict as StrictSeq
import qualified Data.Set as Set
import Lens.Micro
import Ouroboros.Consensus.Cardano.Block (EraCrypto, LedgerState ())
import Ouroboros.Consensus.Shelley.Eras (StandardConway (), StandardCrypto ())
import Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock)
Expand Down Expand Up @@ -492,6 +494,57 @@ mkNewCommitteeTx =
, anchorDataHash = hashAnchorData (AnchorData mempty)
}

mkGovActionProposalTx :: Either ForgingError (AlonzoTx StandardConway)
mkGovActionProposalTx = Right (mkSimpleTx True txBody)
where
txBody =
mkDummyTxBody
{ ctbProposalProcedures = OSet.singleton proposal
}

proposal =
Governance.ProposalProcedure
{ Governance.pProcDeposit = Coin 50_000_000_000
, Governance.pProcReturnAddr =
RewardAccount Testnet (Prelude.head unregisteredStakeCredentials)
, Governance.pProcGovAction = govAction
, Governance.pProcAnchor = anchor
}

govAction =
Governance.ParameterChange
SNothing
pparamsUpdate
SNothing

pparamsUpdate = Core.emptyPParamsUpdate & Core.ppuMaxBBSizeL .~ SJust 131072

anchor =
Anchor
{ anchorUrl = fromJust (textToUrl 64 "cc")
, anchorDataHash = hashAnchorData (AnchorData mempty)
}

mkGovActionVoteTx ::
Governance.GovActionId StandardCrypto ->
Governance.Voter StandardCrypto ->
Either ForgingError (AlonzoTx StandardConway)
mkGovActionVoteTx govActionId voter = Right (mkSimpleTx True txBody)
where
txBody =
mkDummyTxBody
{ ctbVotingProcedures = Governance.VotingProcedures (Map.singleton voter votes)
}

votes =
Map.singleton govActionId vote

vote =
Governance.VotingProcedure
{ Governance.vProcVote = Governance.VoteYes
, Governance.vProcAnchor = SNothing
}

mkRegTxCert ::
StrictMaybe Coin ->
StakeCredential StandardCrypto ->
Expand All @@ -508,7 +561,7 @@ mkDelegTxCert ::
Delegatee StandardCrypto ->
StakeCredential StandardCrypto ->
ConwayTxCert StandardConway
mkDelegTxCert delegatee = mkTxDelegCert $ \cred -> ConwayDelegCert cred delegatee
mkDelegTxCert delegatee = mkTxDelegCert $ \cred -> ConwayRegDelegCert cred delegatee (Coin 0)

mkTxDelegCert ::
(StakeCredential StandardCrypto -> ConwayDelegCert StandardCrypto) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ module Test.Cardano.Db.Mock.Unit.Conway.Governance (

import Cardano.DbSync.Era.Shelley.Generic.Util (unCredentialHash)
import Cardano.Ledger.Address (Withdrawals (..))
import qualified Cardano.Ledger.Conway.Governance as Governance
import Cardano.Ledger.Conway.TxCert
import qualified Cardano.Ledger.Core as Core
import Cardano.Ledger.Credential (Credential (..))
import Cardano.Ledger.DRep (DRep (..))
import Cardano.Ledger.Keys (KeyHash (..))
Expand Down Expand Up @@ -90,14 +92,56 @@ newCommittee =
withFullConfig conwayConfigDir testLabel $ \interpreter server dbSync -> do
startDBSync dbSync

-- Propose a new constitutional committee member
void $ Api.registerAllStakeCreds interpreter server

-- Register a DRep
let drepIdHash = "0d94e174732ef9aae73f395ab44507bfa983d65023c11a951f0c32e4"
drepId = KeyHashObj (KeyHash drepIdHash)

void $
Api.withConwayFindLeaderAndSubmitTx interpreter server $
const Conway.mkNewCommitteeTx
Api.withConwayFindLeaderAndSubmitTx interpreter server $ \_ ->
Conway.mkRegDRepTx drepId

-- Delegate to the DRep above
let stakeCredHash = KeyHash "addfa484e8095ff53f45b25cf337923cf79abe6ec192fdf288d621f9"
stakeCred = KeyHashObj stakeCredHash

void $
Api.withConwayFindLeaderAndSubmitTx interpreter server $ \_ ->
let cert = Conway.mkDelegTxCert delegatee stakeCred
delegatee = DelegVote (DRepCredential drepId)
in Conway.mkDCertTx [cert] (Withdrawals mempty) Nothing

-- Propose and vote for a new constitutional committee member
void $
Api.withConwayFindLeaderAndSubmit interpreter server $ \_ -> do
-- Propose the CC member
propTx <- Conway.mkNewCommitteeTx

-- Vote for it
let govActionId =
Governance.GovActionId
{ Governance.gaidTxId = Core.txIdTx propTx
, Governance.gaidGovActionIx = Governance.GovActionIx 0
}

drepVote <- Conway.mkGovActionVoteTx govActionId (Governance.DRepVoter drepId)

spoVotes <-
mapM
(Conway.mkGovActionVoteTx govActionId . Governance.StakePoolVoter . KeyHash)
[ "58eef2925db2789f76ea057c51069e52c5e0a44550f853c6cdf620f8"
, "5af582399de8c226391bfd21424f34d0b053419c4d93975802b7d107"
, "9f1b441b9b781b3c3abb43b25679dc17dbaaf116dddca1ad09dc1de0"
]

pure ([propTx, drepVote] <> spoVotes)

-- TODO[sgillespie]: Why doesn't this ratify?

-- Wait for it to sync
epoch <- Api.fillUntilNextEpoch interpreter server
assertBlockNoBackoff dbSync (1 + length epoch)
assertBlockNoBackoff dbSync (4 + length epoch)

-- Should have a governance action proposal
-- TODO[sgillespie]: Should also ratify/enact
Expand Down

0 comments on commit 8e5b22f

Please sign in to comment.