Skip to content

Commit a04f0b6

Browse files
committed
Add test showing the problem of retiring stake pool with duplicate vrfs
1 parent 74e2b99 commit a04f0b6

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ conwaySpec ::
117117
, InjectRuleFailure "LEDGER" ConwayLedgerPredFailure era
118118
, InjectRuleFailure "LEDGER" ConwayUtxoPredFailure era
119119
, InjectRuleFailure "LEDGER" ConwayUtxowPredFailure era
120+
, InjectRuleFailure "LEDGER" ShelleyPoolPredFailure era
120121
, InjectRuleFailure "BBODY" ConwayBbodyPredFailure era
121122
, InjectRuleEvent "TICK" ConwayEpochEvent era
122123
, Event (EraRule "EPOCH" era) ~ ConwayEpochEvent era

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Cardano.Ledger.Conway.Governance
1414
import Cardano.Ledger.Conway.PParams
1515
import Cardano.Ledger.Conway.State
1616
import Cardano.Ledger.Shelley.LedgerState
17+
import Cardano.Ledger.Shelley.Rules (ShelleyPoolPredFailure (..))
1718
import qualified Data.Set as Set
1819
import Lens.Micro
1920
import Test.Cardano.Ledger.Conway.ImpTest
@@ -22,7 +23,10 @@ import Test.Cardano.Ledger.Imp.Common
2223

2324
spec ::
2425
forall era.
25-
ConwayEraImp era => SpecWith (ImpInit (LedgerSpec era))
26+
( ConwayEraImp era
27+
, InjectRuleFailure "LEDGER" ShelleyPoolPredFailure era
28+
) =>
29+
SpecWith (ImpInit (LedgerSpec era))
2630
spec = do
2731
it "VRF Keyhashes get populated at v11 HardFork" $ do
2832
-- Since we're testing the HardFork to 11, the test only makes sense for protocol version 10
@@ -49,6 +53,29 @@ spec = do
4953
expectVRFs [] -- VRF keyhashes in PState is not yet populated
5054
enactHardForkV11
5155
expectVRFs [vrf2, vrf3, vrf5]
56+
57+
it "Retiring a stake pool with a duplicate VRF Keyhash after v11 HardFork" $ do
58+
whenMajorVersion @10 $ do
59+
-- register two pools with the same vrf keyhash before the hard fork
60+
(kh1, vrf) <- (,) <$> freshKeyHash <*> freshKeyHashVRF
61+
registerStakePool kh1 vrf
62+
kh2 <- freshKeyHash
63+
registerStakePool kh2 vrf
64+
65+
enactHardForkV11
66+
expectVRFs [vrf]
67+
-- retire one of the pools after the hard fork
68+
retireStakePool kh1 (EpochInterval 1)
69+
passEpoch
70+
-- the vrf keyhash should still be present, since another pool is registered with it
71+
expectVRFs [vrf]
72+
73+
-- registration of the same vrf should be disallowed
74+
kh3 <- freshKeyHash
75+
registerStakePoolTx kh3 vrf >>= \tx ->
76+
submitFailingTx
77+
tx
78+
[injectFailure $ VRFKeyHashAlreadyRegistered kh3 vrf]
5279
where
5380
enactHardForkV11 = do
5481
modifyPParams $ \pp ->
@@ -61,11 +88,13 @@ spec = do
6188
submitYesVoteCCs_ committee govActionId
6289
passNEpochs 2
6390
getProtVer `shouldReturn` pv11
64-
registerStakePool kh vrf = do
91+
registerStakePoolTx kh vrf = do
6592
pps <- registerRewardAccount >>= freshPoolParams kh
66-
submitTx_ $
93+
pure $
6794
mkBasicTx mkBasicTxBody
6895
& bodyTxL . certsTxBodyL .~ [RegPoolTxCert $ pps & ppVrfL .~ vrf]
96+
registerStakePool kh vrf =
97+
registerStakePoolTx kh vrf >>= submitTx_
6998
retireStakePool kh retirementInterval = do
7099
curEpochNo <- getsNES nesELL
71100
let retirement = addEpochInterval curEpochNo retirementInterval

0 commit comments

Comments
 (0)