Skip to content

Commit

Permalink
Refactor function to delegate to automatic DReps
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed May 3, 2024
1 parent 6268c52 commit fa3e340
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
{-# LANGUAGE TypeApplications #-}

module Cardano.Testnet.Test.LedgerEvents.Gov.PredefinedAbstainDRep
( hprop_check_predefined_abstain_drep
( AutomaticDRepFlag(..)
, hprop_check_predefined_abstain_drep
, delegateToAutomaticDRep
, desiredPoolNumberProposalTest
, getDesiredPoolNumberValue
Expand Down Expand Up @@ -120,37 +121,22 @@ hprop_check_predefined_abstain_drep = H.integrationWorkspace "test-activity" $ \
void $ desiredPoolNumberProposalTest execConfig epochStateView configurationFile socketPath ceo gov "firstProposal"
wallet0 Nothing [(1, "yes")] newNumberOfDesiredPools 3 (Just initialDesiredNumberOfPools) 10

-- Take the last two stake delegators and delegate them to "Abstain".
delegateToAlwaysAbstain execConfig epochStateView configurationFile socketPath sbe gov "delegateToAbstain1"
wallet1 (defaultDelegatorStakeKeyPair 2)
delegateToAlwaysAbstain execConfig epochStateView configurationFile socketPath sbe gov "delegateToAbstain2"
wallet2 (defaultDelegatorStakeKeyPair 3)
-- Take the last two stake delegators and delegate them to "AlwaysAbstainDRep".
delegateToAutomaticDRep execConfig epochStateView configurationFile socketPath sbe gov "delegateToAbstain1"
AlwaysAbstainDRep wallet1 (defaultDelegatorStakeKeyPair 2)
delegateToAutomaticDRep execConfig epochStateView configurationFile socketPath sbe gov "delegateToAbstain2"
AlwaysAbstainDRep wallet2 (defaultDelegatorStakeKeyPair 3)

-- Do some other proposal and vote yes with first DRep only
-- and assert the new proposal passes now.
let newNumberOfDesiredPools2 = newNumberOfDesiredPools + 1
void $ desiredPoolNumberProposalTest execConfig epochStateView configurationFile socketPath ceo gov "secondProposal"
wallet0 Nothing [(1, "yes")] newNumberOfDesiredPools2 0 (Just newNumberOfDesiredPools2) 10

-- | Delegates a staking key pair to the "always abstain" automated DRep
delegateToAlwaysAbstain
:: (HasCallStack, MonadTest m, MonadIO m, H.MonadAssertion m, MonadCatch m)
=> H.ExecConfig -- ^ Specifies the CLI execution configuration.
-> EpochStateView -- ^ Current epoch state view for transaction building. It can be obtained
-- using the 'getEpochStateView' function.
-> FilePath -- ^ Path to the node configuration file as returned by 'cardanoTestnetDefault'.
-> FilePath -- ^ Path to the cardano-node unix socket file.
-> ShelleyBasedEra ConwayEra -- ^ The Shelley based era witness for ConwayEra
-> FilePath -- ^ Base directory path where generated files will be stored.
-> String -- ^ Name for the subfolder that will be created under 'work' folder.
-> PaymentKeyInfo -- ^ Wallet that will pay for the transaction.
-> StakingKeyPair -- ^ Staking key pair used for delegation.
-> m ()
delegateToAlwaysAbstain execConfig epochStateView configurationFile socketPath sbe work prefix =
delegateToAutomaticDRep execConfig epochStateView configurationFile socketPath sbe work prefix
"--always-abstain"
-- | Which automatic DRep to delegate to
data AutomaticDRepFlag = AlwaysAbstainDRep
| NoConfidenceDRep

-- | Delegates a staking key pair to an automatic DRep.
delegateToAutomaticDRep
:: (HasCallStack, MonadTest m, MonadIO m, H.MonadAssertion m, MonadCatch m)
=> H.ExecConfig -- ^ Specifies the CLI execution configuration.
Expand All @@ -161,13 +147,11 @@ delegateToAutomaticDRep
-> ShelleyBasedEra ConwayEra -- ^ The Shelley based era witness for ConwayEra
-> FilePath -- ^ Base directory path where generated files will be stored.
-> String -- ^ Name for the subfolder that will be created under 'work' folder.
-> String -- ^ Additional command-line argument for the delegation.
-> AutomaticDRepFlag -- ^ Which type of automatic DRep to delegate to.
-> PaymentKeyInfo -- ^ Wallet that will pay for the transaction.
-> StakingKeyPair -- ^ Staking key pair used for delegation.
-> m ()
delegateToAutomaticDRep execConfig epochStateView configurationFile socketPath sbe work prefix
flag payingWallet skeyPair@(StakingKeyPair vKeyFile _sKeyFile) = do

delegateToAutomaticDRep execConfig epochStateView configurationFile socketPath sbe work prefix flag payingWallet skeyPair@(StakingKeyPair vKeyFile _sKeyFile) = do
let era = toCardanoEra sbe
cEra = AnyCardanoEra era

Expand All @@ -177,7 +161,9 @@ delegateToAutomaticDRep execConfig epochStateView configurationFile socketPath s
let voteDelegationCertificatePath = baseDir </> "delegation-certificate.delegcert"
void $ H.execCli' execConfig
[ "conway", "stake-address", "vote-delegation-certificate"
, flag
, case flag of
AlwaysAbstainDRep -> "--always-abstain"
NoConfidenceDRep -> "--always-no-confidence"
, "--stake-verification-key-file", vKeyFile
, "--out-file", voteDelegationCertificatePath
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import qualified Cardano.Ledger.Conway.Governance as L
import qualified Cardano.Ledger.Shelley.LedgerState as L
import Cardano.Testnet
import Cardano.Testnet.Test.LedgerEvents.Gov.PredefinedAbstainDRep
(delegateToAutomaticDRep, desiredPoolNumberProposalTest,
getDesiredPoolNumberValue, voteChangeProposal)
(desiredPoolNumberProposalTest,
getDesiredPoolNumberValue, voteChangeProposal, delegateToAutomaticDRep, AutomaticDRepFlag (..))

import Prelude

Expand Down Expand Up @@ -109,11 +109,11 @@ hprop_check_predefined_no_confidence_drep = H.integrationWorkspace "test-activit
firstProposalInfo <- desiredPoolNumberProposalTest execConfig epochStateView configurationFile socketPath ceo gov "firstProposal"
wallet1 Nothing [(3, "yes")] newNumberOfDesiredPools 0 (Just newNumberOfDesiredPools) 10

-- Take the last two stake delegators and delegate them to "No Confidence".
delegateToAlwaysNoConfidence execConfig epochStateView configurationFile socketPath sbe gov "delegateToNoConfidence1"
wallet2 (defaultDelegatorStakeKeyPair 2)
delegateToAlwaysNoConfidence execConfig epochStateView configurationFile socketPath sbe gov "delegateToNoConfidence2"
wallet2 (defaultDelegatorStakeKeyPair 3)
-- Take the last two stake delegators and delegate them to "No Confidence" automatic DRep.
delegateToAutomaticDRep execConfig epochStateView configurationFile socketPath sbe work
"delegateToNoConfidence1" NoConfidenceDRep wallet2 (defaultDelegatorStakeKeyPair 2)
delegateToAutomaticDRep execConfig epochStateView configurationFile socketPath sbe work
"delegateToNoConfidence2" NoConfidenceDRep wallet2 (defaultDelegatorStakeKeyPair 3)

-- Do some other proposal and vote yes with all the DReps
-- and assert the new proposal does NOT pass.
Expand Down Expand Up @@ -317,24 +317,6 @@ makeUpdateConstitutionalCommitteeProposal execConfig epochStateView configuratio

return (governanceActionTxId, governanceActionIndex)

-- | Delegate a staking key pair to the automated no confidence DRep.
delegateToAlwaysNoConfidence
:: (MonadTest m, MonadIO m, H.MonadAssertion m, MonadCatch m, HasCallStack)
=> H.ExecConfig -- ^ Specifies the CLI execution configuration.
-> EpochStateView -- ^ Current epoch state view for transaction building. It can be obtained
-- using the 'getEpochStateView' function.
-> FilePath -- ^ Path to the node configuration file as returned by 'cardanoTestnetDefault'.
-> FilePath -- ^ Path to the cardano-node unix socket file.
-> ShelleyBasedEra ConwayEra -- ^ The Shelley based era witness for ConwayEra
-> FilePath -- ^ Base directory path where generated files will be stored.
-> String -- ^ Name for the subfolder that will be created under 'work' folder.
-> PaymentKeyInfo -- ^ Wallet that will pay for the transaction.
-> StakingKeyPair -- ^ Staking key pair used for delegation.
-> m ()
delegateToAlwaysNoConfidence execConfig epochStateView configurationFile socketPath sbe work prefix =
delegateToAutomaticDRep execConfig epochStateView configurationFile socketPath sbe work prefix
"--always-no-confidence"

-- Run a no confidence motion and check the result. Vote "yes" with 3 SPOs. Check the no
-- confidence motion passes.
testNoConfidenceProposal
Expand Down

0 comments on commit fa3e340

Please sign in to comment.