Skip to content

Commit

Permalink
Count votes in Propose Constitution test before ratification
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed May 7, 2024
1 parent 10b72f0 commit 00d5598
Showing 1 changed file with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Cardano.Testnet.Test.Gov.ProposeNewConstitution

import Cardano.Api as Api
import Cardano.Api.Error (displayError)
import Cardano.Api.Ledger (EpochInterval (..))

import qualified Cardano.Crypto.Hash as L
import qualified Cardano.Ledger.Conway.Governance as L
Expand All @@ -33,14 +34,14 @@ import Lens.Micro
import System.FilePath ((</>))

import Testnet.Components.Configuration
import Testnet.Components.DReps (createVotingTxBody, generateVoteFiles,
import Testnet.Components.DRep (createVotingTxBody, generateVoteFiles,
retrieveTransactionId, signTx, submitTx)
import Testnet.Components.Query
import Testnet.Components.TestWatchdog
import Testnet.Defaults
import qualified Testnet.Process.Cli as P
import qualified Testnet.Process.Run as H
import qualified Testnet.Property.Utils as H
import qualified Testnet.Property.Util as H
import Testnet.Runtime

import Hedgehog
Expand Down Expand Up @@ -198,20 +199,8 @@ hprop_ledger_events_propose_new_constitution = H.integrationWorkspace "propose-n
(paymentKeyInfoPair wallet0:[defaultDRepKeyPair n | (_, n) <- allVotes])
submitTx execConfig cEra voteTxFp

-- We check that constitution was succcessfully ratified

!eConstitutionAdopted
<- evalIO . runExceptT $ foldEpochState
(File configurationFile)
(File socketPath)
FullValidation
(EpochNo 10)
()
(\epochState _ _ -> foldBlocksCheckConstitutionWasRatified constitutionHash constitutionScriptHash epochState)

void $ evalEither eConstitutionAdopted
_ <- waitForEpochs epochStateView (EpochInterval 1)

-- Tally registered votes
govState <- getGovState epochStateView ceo
govActionState <- H.headM $ govState ^. L.cgsProposalsL . L.pPropsL . to toList
let votes = govActionState ^. L.gasDRepVotesL . to toList
Expand All @@ -221,6 +210,16 @@ hprop_ledger_events_propose_new_constitution = H.integrationWorkspace "propose-n
length (filter ((== L.Abstain) . snd) votes) === 2
length votes === numVotes

-- We check that constitution was succcessfully ratified
void . H.leftFailM . evalIO . runExceptT $
foldEpochState
(File configurationFile)
(File socketPath)
FullValidation
(EpochNo 10)
()
(\epochState _ _ -> foldBlocksCheckConstitutionWasRatified constitutionHash constitutionScriptHash epochState)

foldBlocksCheckConstitutionWasRatified
:: String -- submitted constitution hash
-> String -- submitted guard rail script hash
Expand All @@ -237,7 +236,7 @@ filterRatificationState
-> String -- ^ Submitted guard rail script hash
-> AnyNewEpochState
-> Bool
filterRatificationState c guardRailScriptHash (AnyNewEpochState sbe newEpochState) =
filterRatificationState c guardRailScriptHash (AnyNewEpochState sbe newEpochState) = do
caseShelleyToBabbageOrConwayEraOnwards
(const $ error "filterRatificationState: Only conway era supported")

Expand Down

0 comments on commit 00d5598

Please sign in to comment.