diff --git a/cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Conway.hs b/cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Conway.hs index 1f1f679e0..f34ee4102 100644 --- a/cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Conway.hs +++ b/cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Conway.hs @@ -34,6 +34,8 @@ module Cardano.Mock.Forging.Tx.Conway ( mkDummyTxBody, mkRegDRepTx, mkNewCommitteeTx, + mkGovActionProposalTx, + mkGovActionVoteTx, mkTxDelegCert, mkRegTxCert, mkUnRegTxCert, @@ -94,6 +96,7 @@ 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) @@ -492,6 +495,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 -> @@ -508,7 +562,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) -> diff --git a/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Governance.hs b/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Governance.hs index 086f3d5e7..f1c2482e5 100644 --- a/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Governance.hs +++ b/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Governance.hs @@ -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 (..)) @@ -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