Skip to content

Commit

Permalink
Extract function for activity change proposals in DRepActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Apr 23, 2024
1 parent bfa6df3 commit b0b1ebd
Showing 1 changed file with 45 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Data.ByteString.Lazy.Char8 (pack)
import qualified Data.Map as Map
import Data.String
import qualified Data.Text as Text
import Data.Word (Word32)
import Data.Word (Word32, Word64)
import GHC.Stack (callStack)
import Lens.Micro ((^?))
import System.FilePath ((</>))
Expand Down Expand Up @@ -96,88 +96,77 @@ hprop_check_drep_activity = H.integrationWorkspace "test-activity" $ \tempAbsBas
dRepActivityBeforeFirstProp <- getDRepActivityValue execConfig
dRepActivityBeforeFirstProp === 100 -- This is the default value

let firstPropVotes :: [(String, Int)]
firstPropVotes = zip (concatMap (uncurry replicate) [(6, "yes"), (4, "no")]) [1..]
annotateShow firstPropVotes

fgaInfo@(firstGovernanceActionTxId, firstGovernanceActionIndex) <-
makeActivityChangeProposal execConfig epochStateView (File configurationFile) (File socketPath)
sbe gov "proposal1" Nothing 4 wallet0

voteChangeProposal execConfig epochStateView sbe gov "vote1"
firstGovernanceActionTxId firstGovernanceActionIndex firstPropVotes wallet0

(EpochNo epochAfterFirstProp) <- getCurrentEpochNo epochStateView sbe
H.note_ $ "Epoch after first prop: " <> show epochAfterFirstProp

void $ waitUntilEpoch (File configurationFile) (File socketPath) (EpochNo (epochAfterFirstProp + 2))
dRepActivityAfterFirstProp <- getDRepActivityValue execConfig

dRepActivityAfterFirstProp === 4 -- This is what we just set, should work

result1 <- checkDRepState sbe (File configurationFile) (File socketPath) execConfig
(Just . map (drepExpiry . snd) . Map.toList)
H.note_ $ "DRep expiration dates: " <> show result1
-- This proposal should pass
firstProposalInfo <- activityChangeProposalTest execConfig epochStateView configurationFile socketPath sbe gov
"firstProposal" wallet0 Nothing [(6, "yes"), (4, "no")] 4 4 2

-- Second proposal (set activity to something else and it should fail, because of percentage being under 51)
let secondPropVotes :: [(String, Int)]
secondPropVotes = zip (concatMap (uncurry replicate) [(4, "yes")]) [1..]
annotateShow secondPropVotes

(secondGovernanceActionTxId, secondGovernanceActionIndex) <-
makeActivityChangeProposal execConfig epochStateView (File configurationFile) (File socketPath)
sbe gov "proposal2" (Just fgaInfo) 7 wallet1
-- We expect to get what we set in first prop, second prop should fail
void $ activityChangeProposalTest execConfig epochStateView configurationFile socketPath sbe gov
"secondProposal" wallet1 (Just firstProposalInfo) [(4, "yes")] 7 4 5

voteChangeProposal execConfig epochStateView sbe gov "vote2"
secondGovernanceActionTxId secondGovernanceActionIndex secondPropVotes wallet1

(EpochNo epochAfterSecondProp) <- getCurrentEpochNo epochStateView sbe
H.note_ $ "Epoch after second prop: " <> show epochAfterSecondProp
-- Third proposal (set activity to something else again and it should pass, because of inactivity)
-- Because 6 out of 10 were inactive, prop should pass
void $ activityChangeProposalTest execConfig epochStateView configurationFile socketPath sbe gov
"thirdProposal" wallet2 (Just firstProposalInfo) [(4, "yes")] 8 8 2

void $ waitUntilEpoch (File configurationFile) (File socketPath) (EpochNo (epochAfterSecondProp + 5))
dRepActivityAfterSecondProp <- getDRepActivityValue execConfig

dRepActivityAfterSecondProp === 4 -- This is what we set in first prop, second prop should fail
activityChangeProposalTest
:: (MonadTest m, MonadIO m, H.MonadAssertion m, MonadCatch m, Foldable t)
=> H.ExecConfig
-> EpochStateView
-> FilePath
-> FilePath
-> ShelleyBasedEra ConwayEra
-> FilePath
-> FilePath
-> PaymentKeyInfo
-> Maybe (String, Word32)
-> t (Int, String)
-> Word32
-> Integer
-> Word64
-> m (String, Word32)
activityChangeProposalTest execConfig epochStateView configurationFile socketPath sbe work prefix
wallet previousProposalInfo votes change expected epochsToWait = do

result2 <- checkDRepState sbe (File configurationFile) (File socketPath) execConfig
(Just . map (drepExpiry . snd) . Map.toList)
H.note_ $ "DRep expiration dates: " <> show result2
baseDir <- H.createDirectoryIfMissing $ work </> prefix

-- Third proposal (set activity to something else again and it should pass, because of inactivity)
let thirdPropVotes :: [(String, Int)]
thirdPropVotes = zip (concatMap (uncurry replicate) [(4, "yes")]) [1..]
annotateShow thirdPropVotes
let propVotes :: [(String, Int)]
propVotes = zip (concatMap (uncurry replicate) votes) [1..]
annotateShow propVotes

(thirdGovernanceActionTxId, thirdGovernanceActionIndex) <-
thisProposal@(governanceActionTxId, governanceActionIndex) <-
makeActivityChangeProposal execConfig epochStateView (File configurationFile) (File socketPath)
sbe gov "proposal3" (Just fgaInfo) 8 wallet2
sbe baseDir "proposal" previousProposalInfo change wallet

voteChangeProposal execConfig epochStateView sbe gov "vote3"
thirdGovernanceActionTxId thirdGovernanceActionIndex thirdPropVotes wallet2
voteChangeProposal execConfig epochStateView sbe baseDir "vote"
governanceActionTxId governanceActionIndex propVotes wallet

(EpochNo epochAfterThirdProp) <- getCurrentEpochNo epochStateView sbe
H.note_ $ "Epoch after third prop: " <> show epochAfterThirdProp
(EpochNo epochAfterProp) <- getCurrentEpochNo epochStateView sbe
H.note_ $ "Epoch after \"" <> prefix <> "\" prop: " <> show epochAfterProp

void $ waitUntilEpoch (File configurationFile) (File socketPath) (EpochNo (epochAfterThirdProp + 2))
dRepActivityAfterThirdProp <- getDRepActivityValue execConfig
void $ waitUntilEpoch (File configurationFile) (File socketPath) (EpochNo (epochAfterProp + epochsToWait))
dRepActivityAfterProp <- getDRepActivityValue execConfig

dRepActivityAfterThirdProp === 8 -- Because 6 out of 10 were inactive, third prop should pass
dRepActivityAfterProp === expected

result3 <- checkDRepState sbe (File configurationFile) (File socketPath) execConfig
(Just . map (drepExpiry . snd) . Map.toList)
H.note_ $ "DRep expiration dates: " <> show result3

return thisProposal

makeActivityChangeProposal
:: (H.MonadAssertion m, MonadTest m, MonadCatch m, MonadIO m, Foldable f)
:: (H.MonadAssertion m, MonadTest m, MonadCatch m, MonadIO m)
=> H.ExecConfig
-> EpochStateView
-> NodeConfigFile 'In
-> SocketPath
-> ShelleyBasedEra ConwayEra
-> FilePath
-> String
-> f (String, Word32)
-> Maybe (String, Word32)
-> Word32
-> PaymentKeyInfo
-> m (String, Word32)
Expand All @@ -192,7 +181,6 @@ makeActivityChangeProposal execConfig epochStateView configurationFile socketPat
let stakeVkeyFp = baseDir </> "stake.vkey"
stakeSKeyFp = baseDir </> "stake.skey"


_ <- P.cliStakeAddressKeyGen baseDir
$ P.KeyNames { P.verificationKeyFile = stakeVkeyFp
, P.signingKeyFile = stakeSKeyFp
Expand Down

0 comments on commit b0b1ebd

Please sign in to comment.