Skip to content

Commit

Permalink
Finish implementation of Predefined No Confidence DRep test
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed May 3, 2024
1 parent 6150499 commit 7fe700f
Show file tree
Hide file tree
Showing 3 changed files with 254 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ import GHC.Stack (HasCallStack, callStack)
import Lens.Micro ((^.))
import System.FilePath ((</>))

import qualified Testnet.Components.DReps as DRep
import Testnet.Components.DReps (createCertificatePublicationTxBody, createVotingTxBody,
generateVoteFiles, retrieveTransactionId, signTx, submitTx)
retrieveTransactionId, signTx, submitTx)
import Testnet.Components.Query (EpochStateView, findLargestUtxoForPaymentKey,
getCurrentEpochNo, getEpochStateView, getGovState, getMinDRepDeposit,
waitAndCheckNewEpochState)
import Testnet.Defaults (defaultDRepKeyPair, defaultDelegatorStakeKeyPair)
import qualified Testnet.Components.SPO as SPO
import Testnet.Defaults (defaultDRepKeyPair, defaultDelegatorStakeKeyPair, defaultSPOKeys)
import qualified Testnet.Process.Cli as P
import qualified Testnet.Process.Run as H
import qualified Testnet.Property.Utils as H
Expand Down Expand Up @@ -219,8 +221,6 @@ desiredPoolNumberProposalTest
-> m (String, Word32)
desiredPoolNumberProposalTest execConfig epochStateView configurationFile socketPath ceo work prefix
wallet previousProposalInfo votes change minWait mExpected maxWait = do
let sbe = conwayEraOnwardsToShelleyBasedEra ceo

baseDir <- H.createDirectoryIfMissing $ work </> prefix

let propVotes :: [DefaultDRepVote]
Expand All @@ -231,8 +231,8 @@ desiredPoolNumberProposalTest execConfig epochStateView configurationFile socket
makeDesiredPoolNumberChangeProposal execConfig epochStateView (File configurationFile) (File socketPath)
ceo baseDir "proposal" previousProposalInfo (fromIntegral change) wallet

voteChangeProposal execConfig epochStateView sbe baseDir "vote"
governanceActionTxId governanceActionIndex propVotes wallet
voteChangeProposal execConfig epochStateView ceo baseDir "vote"
governanceActionTxId governanceActionIndex propVotes [] wallet

(EpochNo epochAfterProp) <- getCurrentEpochNo epochStateView
H.note_ $ "Epoch after \"" <> prefix <> "\" prop: " <> show epochAfterProp
Expand Down Expand Up @@ -341,38 +341,60 @@ makeDesiredPoolNumberChangeProposal execConfig epochStateView configurationFile
-- a default DRep (from the ones created by 'cardanoTestnetDefault')
type DefaultDRepVote = (String, Int)

-- A pair of a vote string (i.e: "yes", "no", or "abstain") and the number of
-- a default SPO (from the ones created by 'cardanoTestnetDefault')
type DefaultSPOVote = (String, Int)

-- | Create and issue votes for (or against) a government proposal with default
-- Delegate Representative (DReps created by 'cardanoTestnetDefault') using @cardano-cli@.
-- Delegate Representative (DReps created by 'cardanoTestnetDefault') and
-- default Stake Pool Operatorsusing using @cardano-cli@.
voteChangeProposal :: (MonadTest m, MonadIO m, MonadCatch m, H.MonadAssertion m)
=> H.ExecConfig -- ^ Specifies the CLI execution configuration.
-> EpochStateView -- ^ Current epoch state view for transaction building. It can be obtained
-- using the 'getEpochStateView' function.
-> ShelleyBasedEra ConwayEra -- ^ The Shelley-based witness for ConwayEra (i.e: ShelleyBasedEraConway).
-> ConwayEraOnwards ConwayEra -- ^ The @ConwayEraOnwards@ witness for the Conway era.
-> FilePath -- ^ Base directory path where the subdirectory with the intermediate files will be created.
-> String -- ^ Name for the subdirectory that will be created for storing the intermediate files.
-> String -- ^ Transaction id of the governance action to vote.
-> Word32 -- ^ Index of the governance action to vote in the transaction.
-> [DefaultDRepVote] -- ^ List of votes to issue as pairs of the vote and the number of DRep that votes it.
-> [DefaultSPOVote] -- ^ List of votes to issue as pairs of the vote and the number of DRep that votes it.
-> PaymentKeyInfo -- ^ Wallet that will pay for the transactions
-> m ()
voteChangeProposal execConfig epochStateView sbe work prefix
governanceActionTxId governanceActionIndex votes wallet = do
voteChangeProposal execConfig epochStateView ceo work prefix
governanceActionTxId governanceActionIndex drepVotes spoVotes wallet = do
baseDir <- H.createDirectoryIfMissing $ work </> prefix

let era = toCardanoEra sbe
let sbe = conwayEraOnwardsToShelleyBasedEra ceo
era = toCardanoEra sbe
cEra = AnyCardanoEra era

voteFiles <- generateVoteFiles execConfig baseDir "vote-files"
governanceActionTxId governanceActionIndex
[(defaultDRepKeyPair idx, vote) | (vote, idx) <- votes]
drepVoteFiles <- DRep.generateVoteFiles execConfig baseDir "drep-vote-files"
governanceActionTxId governanceActionIndex
[(defaultDRepKeyPair idx, vote) | (vote, idx) <- drepVotes]

spoVoteFiles <- SPO.generateVoteFiles ceo execConfig baseDir "spo-vote-files"
governanceActionTxId governanceActionIndex
[(defaultSPOKeys idx, vote) | (vote, idx) <- spoVotes]

let voteFiles = drepVoteFiles ++ spoVoteFiles

voteTxBodyFp <- createVotingTxBody execConfig epochStateView sbe baseDir "vote-tx-body"
voteFiles wallet

voteTxFp <- signTx execConfig cEra baseDir "signed-vote-tx" voteTxBodyFp
(paymentKeyInfoPair wallet:[defaultDRepKeyPair n | (_, n) <- votes])
(paymentKeyInfoPair wallet:
[defaultDRepKeyPair n | (_, n) <- drepVotes] ++
[defaultSPOColdKeyPair n | (_, n) <- drepVotes]
)
submitTx execConfig cEra voteTxFp

defaultSPOColdKeyPair :: Int -> PaymentKeyPair
defaultSPOColdKeyPair n = PaymentKeyPair { paymentVKey = poolNodeKeysColdVkey spoKeys
, paymentSKey = poolNodeKeysColdSkey spoKeys
}
where spoKeys = defaultSPOKeys n

-- | Obtains the @desiredPoolNumberValue@ from the protocol parameters.
-- The @desiredPoolNumberValue@ or (@k@ in the spec) is the protocol parameter
-- that defines what is the optimal number of SPOs. It is a tradeoff between
Expand Down

0 comments on commit 7fe700f

Please sign in to comment.