Skip to content

Commit a80dc14

Browse files
Soupstrawteodanciu
andcommitted
Added postEpochBoundaryHook
Also update the pulser when modifying the protocol version in Conway Co-authored-by: teodanciu <[email protected]>
1 parent af31396 commit a80dc14

File tree

17 files changed

+276
-125
lines changed

17 files changed

+276
-125
lines changed

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ source-repository-package
1616
subdir: hs
1717
-- !WARNING!:
1818
-- MAKE SURE THIS POINTS TO A COMMIT IN `*-artifacts` BEFORE MERGE!
19-
tag: d419ed67d4e5a5aa7b26f22785dd7b64f08de37a
19+
tag: 33cc4c0dccad41875ccb46749983d4b2c38bffe9
2020

2121
source-repository-package
2222
type: git

eras/allegra/impl/testlib/Test/Cardano/Ledger/Allegra/ImpTest.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ instance ShelleyEraImp AllegraEra where
4242

4343
fixupTx = shelleyFixupTx
4444
expectTxSuccess = impShelleyExpectTxSuccess
45+
modifyImpInitProtVer = shelleyModifyImpInitProtVer
4546

4647
impAllegraSatisfyNativeScript ::
4748
( AllegraEraScript era

eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/ImpTest.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ instance ShelleyEraImp AlonzoEra where
431431
impSatisfyNativeScript = impAllegraSatisfyNativeScript
432432
fixupTx = alonzoFixupTx
433433
expectTxSuccess = impAlonzoExpectTxSuccess
434+
modifyImpInitProtVer = shelleyModifyImpInitProtVer
434435

435436
instance MaryEraImp AlonzoEra
436437

eras/babbage/impl/testlib/Test/Cardano/Ledger/Babbage/ImpTest.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ instance ShelleyEraImp BabbageEra where
5353
impSatisfyNativeScript = impAllegraSatisfyNativeScript
5454
fixupTx = babbageFixupTx
5555
expectTxSuccess = impBabbageExpectTxSuccess
56+
modifyImpInitProtVer = shelleyModifyImpInitProtVer
5657

5758
babbageFixupTx ::
5859
( HasCallStack

eras/conway/impl/cardano-ledger-conway.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ library testlib
176176

177177
build-depends:
178178
FailT,
179+
ImpSpec,
179180
aeson,
180181
base,
181182
bytestring,

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/DelegSpec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ spec = do
490490
setProtVer initialProtVer
491491
pure res
492492
(khSPO, _, _) <- setupPoolWithStake $ Coin 10_000_000
493-
-- Using an irrefutable pattern here to prevent evaluation of tuple
493+
-- Using a lazy pattern match here to prevent evaluation of tuple
494494
-- unless we actually need a value from it
495495
~(drepCred, _, _) <-
496496
if initialProtVer > bootstrapVer

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/ImpTest.hs

Lines changed: 69 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
module Test.Cardano.Ledger.Conway.ImpTest (
2222
module Test.Cardano.Ledger.Babbage.ImpTest,
2323
ConwayEraImp,
24+
conwayModifyImpInitProtVer,
2425
enactConstitution,
2526
enactTreasuryWithdrawals,
2627
submitGovAction,
@@ -144,9 +145,11 @@ import Cardano.Ledger.Allegra.Scripts (Timelock)
144145
import Cardano.Ledger.BaseTypes (
145146
EpochInterval (..),
146147
EpochNo (..),
148+
ProtVer (..),
147149
ShelleyBase,
148150
StrictMaybe (..),
149151
UnitInterval,
152+
Version,
150153
addEpochInterval,
151154
binOpEpochNo,
152155
inject,
@@ -228,6 +231,7 @@ import Test.Cardano.Ledger.Core.Rational (IsRatio (..))
228231
import Test.Cardano.Ledger.Imp.Common
229232
import Test.Cardano.Ledger.Plutus (testingCostModel)
230233
import Test.Cardano.Ledger.Plutus.Guardrail (guardrailScript)
234+
import Test.ImpSpec
231235

232236
-- | Modify the PParams in the current state with the given function
233237
conwayModifyPParams ::
@@ -303,6 +307,24 @@ instance ShelleyEraImp ConwayEra where
303307

304308
fixupTx = babbageFixupTx
305309
expectTxSuccess = impBabbageExpectTxSuccess
310+
modifyImpInitProtVer = conwayModifyImpInitProtVer
311+
312+
conwayModifyImpInitProtVer ::
313+
forall era.
314+
ConwayEraImp era =>
315+
Version ->
316+
SpecWith (ImpInit (LedgerSpec era)) ->
317+
SpecWith (ImpInit (LedgerSpec era))
318+
conwayModifyImpInitProtVer ver =
319+
modifyImpInit $ \impInit ->
320+
impInit
321+
{ impInitState =
322+
impInitState impInit
323+
& impNESL . nesEsL . curPParamsEpochStateL . ppProtocolVersionL .~ ProtVer ver 0
324+
& impNESL . nesEsL %~ (\es -> setCompleteDRepPulsingState def (ratifyState es) es)
325+
}
326+
where
327+
ratifyState es = def & rsEnactStateL .~ mkEnactState (es ^. epochStateGovStateL)
306328

307329
instance MaryEraImp ConwayEra
308330

@@ -446,7 +468,7 @@ setupSingleDRep ::
446468
ConwayEraImp era =>
447469
Integer ->
448470
ImpTestM era (Credential 'DRepRole, Credential 'Staking, KeyPair 'Payment)
449-
setupSingleDRep stake = do
471+
setupSingleDRep stake = impAnn "Set up a single DRep" $ do
450472
drepKH <- registerDRep
451473
kh <- freshKeyHash
452474
(delegatorKH, spendingKP) <-
@@ -512,7 +534,7 @@ setupPoolWithStake ::
512534
ConwayEraImp era =>
513535
Coin ->
514536
ImpTestM era (KeyHash 'StakePool, Credential 'Payment, Credential 'Staking)
515-
setupPoolWithStake delegCoin = do
537+
setupPoolWithStake delegCoin = impAnn "Set up pool with stake" $ do
516538
khPool <- freshKeyHash
517539
registerPoolWithDeposit khPool
518540
credDelegatorPayment <- KeyHashObj <$> freshKeyHash
@@ -608,22 +630,23 @@ trySubmitVote ::
608630
GovActionId ->
609631
ImpTestM era (Either (NonEmpty (PredicateFailure (EraRule "LEDGER" era))) TxId)
610632
trySubmitVote vote voter gaId =
611-
fmap (bimap fst txIdTx) $
612-
trySubmitTx $
613-
mkBasicTx mkBasicTxBody
614-
& bodyTxL . votingProceduresTxBodyL
615-
.~ VotingProcedures
616-
( Map.singleton
617-
voter
618-
( Map.singleton
619-
gaId
620-
( VotingProcedure
621-
{ vProcVote = vote
622-
, vProcAnchor = SNothing
623-
}
624-
)
625-
)
626-
)
633+
impAnn ("Submitting vote (" <> show vote <> ")") $
634+
fmap (bimap fst txIdTx) $
635+
trySubmitTx $
636+
mkBasicTx mkBasicTxBody
637+
& bodyTxL . votingProceduresTxBodyL
638+
.~ VotingProcedures
639+
( Map.singleton
640+
voter
641+
( Map.singleton
642+
gaId
643+
( VotingProcedure
644+
{ vProcVote = vote
645+
, vProcAnchor = SNothing
646+
}
647+
)
648+
)
649+
)
627650

628651
submitProposal_ ::
629652
(ShelleyEraImp era, ConwayEraTxBody era, HasCallStack) =>
@@ -1230,7 +1253,7 @@ registerCommitteeHotKey ::
12301253
(ShelleyEraImp era, ConwayEraTxCert era) =>
12311254
Credential 'ColdCommitteeRole ->
12321255
ImpTestM era (Credential 'HotCommitteeRole)
1233-
registerCommitteeHotKey coldKey = do
1256+
registerCommitteeHotKey coldKey = impAnn "Register committee hot key" $ do
12341257
hotKey NE.:| [] <- registerCommitteeHotKeys (KeyHashObj <$> freshKeyHash) $ pure coldKey
12351258
pure hotKey
12361259

@@ -1306,33 +1329,36 @@ electBasicCommittee ::
13061329
, GovPurposeId 'CommitteePurpose
13071330
)
13081331
electBasicCommittee = do
1309-
logString "Setting up a DRep"
13101332
(drep, _, _) <- setupSingleDRep 1_000_000
1333+
logString $ "Registered DRep: " <> showExpr drep
1334+
13111335
(spoC, _, _) <- setupPoolWithStake $ Coin 1_000_000
1336+
logString $ "Registered SPO: " <> showExpr spoC
13121337

1313-
logString "Registering committee member"
1314-
coldCommitteeC <- KeyHashObj <$> freshKeyHash
1315-
startEpochNo <- getsNES nesELL
1316-
let
1317-
committeeAction =
1318-
UpdateCommittee
1319-
SNothing
1320-
mempty
1321-
(Map.singleton coldCommitteeC (addEpochInterval startEpochNo (EpochInterval 10)))
1322-
(1 %! 2)
1323-
(gaidCommitteeProp NE.:| _) <-
1324-
submitGovActions
1325-
[ committeeAction
1326-
, UpdateCommittee SNothing mempty mempty (1 %! 10)
1327-
]
1328-
submitYesVote_ (DRepVoter drep) gaidCommitteeProp
1329-
submitYesVote_ (StakePoolVoter spoC) gaidCommitteeProp
1330-
passNEpochs 2
1331-
committeeMembers <- getCommitteeMembers
1332-
impAnn "The committee should be enacted" $
1333-
committeeMembers `shouldSatisfy` Set.member coldCommitteeC
1334-
hotCommitteeC <- registerCommitteeHotKey coldCommitteeC
1335-
pure (drep, hotCommitteeC, GovPurposeId gaidCommitteeProp)
1338+
impAnn "Registering committee member" $ do
1339+
coldCommitteeC <- KeyHashObj <$> freshKeyHash
1340+
startEpochNo <- getsNES nesELL
1341+
let
1342+
committeeAction =
1343+
UpdateCommittee
1344+
SNothing
1345+
mempty
1346+
(Map.singleton coldCommitteeC (addEpochInterval startEpochNo (EpochInterval 10)))
1347+
(1 %! 2)
1348+
(gaidCommitteeProp NE.:| _) <-
1349+
impAnn "Submitting UpdateCommittee action" $
1350+
submitGovActions
1351+
[ committeeAction
1352+
, UpdateCommittee SNothing mempty mempty (1 %! 10)
1353+
]
1354+
submitYesVote_ (DRepVoter drep) gaidCommitteeProp
1355+
submitYesVote_ (StakePoolVoter spoC) gaidCommitteeProp
1356+
passNEpochs 2
1357+
committeeMembers <- getCommitteeMembers
1358+
impAnn "The committee should be enacted" $
1359+
committeeMembers `shouldSatisfy` Set.member coldCommitteeC
1360+
hotCommitteeC <- registerCommitteeHotKey coldCommitteeC
1361+
pure (drep, hotCommitteeC, GovPurposeId gaidCommitteeProp)
13361362

13371363
logCurPParams ::
13381364
( EraGov era

eras/dijkstra/testlib/Test/Cardano/Ledger/Dijkstra/ImpTest.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ instance ShelleyEraImp DijkstraEra where
5555

5656
fixupTx = babbageFixupTx
5757
expectTxSuccess = impBabbageExpectTxSuccess
58+
modifyImpInitProtVer = conwayModifyImpInitProtVer
5859

5960
instance MaryEraImp DijkstraEra
6061

eras/mary/impl/testlib/Test/Cardano/Ledger/Mary/ImpTest.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ instance ShelleyEraImp MaryEra where
2727
impSatisfyNativeScript = impAllegraSatisfyNativeScript
2828
fixupTx = shelleyFixupTx
2929
expectTxSuccess = impShelleyExpectTxSuccess
30+
modifyImpInitProtVer = shelleyModifyImpInitProtVer
3031

3132
class
3233
( ShelleyEraImp era

0 commit comments

Comments
 (0)