|
| 1 | +{-# LANGUAGE BangPatterns #-} |
| 2 | +{-# LANGUAGE DataKinds #-} |
| 3 | +{-# LANGUAGE FlexibleContexts #-} |
| 4 | +{-# LANGUAGE OverloadedLists #-} |
| 5 | +{-# LANGUAGE ScopedTypeVariables #-} |
| 6 | +{-# LANGUAGE TypeApplications #-} |
| 7 | +{-# LANGUAGE TypeFamilies #-} |
| 8 | + |
| 9 | +module Test.Cardano.Ledger.Conway.Imp.HardForkSpec (spec) where |
| 10 | + |
| 11 | +import Cardano.Ledger.BaseTypes |
| 12 | +import Cardano.Ledger.Conway.Core |
| 13 | +import Cardano.Ledger.Conway.Governance |
| 14 | +import Cardano.Ledger.Conway.PParams |
| 15 | +import Cardano.Ledger.Conway.State |
| 16 | +import Cardano.Ledger.Shelley.LedgerState |
| 17 | +import qualified Data.Set as Set |
| 18 | +import Lens.Micro |
| 19 | +import Test.Cardano.Ledger.Conway.ImpTest |
| 20 | +import Test.Cardano.Ledger.Core.Rational |
| 21 | +import Test.Cardano.Ledger.Imp.Common |
| 22 | + |
| 23 | +spec :: |
| 24 | + forall era. |
| 25 | + ConwayEraImp era => SpecWith (ImpInit (LedgerSpec era)) |
| 26 | +spec = do |
| 27 | + it "VRF Keyhashes get populated at v11 HardFork" $ do |
| 28 | + -- Since we're testing the HardFork to 11, the test only makes sense for protocol version 10 |
| 29 | + whenMajorVersion @10 $ do |
| 30 | + (kh1, vrf1) <- (,) <$> freshKeyHash <*> freshKeyHashVRF |
| 31 | + registerStakePool kh1 vrf1 |
| 32 | + (kh2, vrf2) <- (,) <$> freshKeyHash <*> freshKeyHashVRF |
| 33 | + registerStakePool kh2 vrf2 |
| 34 | + vrf3 <- freshKeyHashVRF |
| 35 | + -- re-register with a new key, so vrf1 should not be present after the hard fork |
| 36 | + registerStakePool kh1 vrf3 |
| 37 | + -- register a new pool with an existing vrf |
| 38 | + kh3 <- freshKeyHash |
| 39 | + registerStakePool kh3 vrf2 |
| 40 | + -- register and retire a pool before the hard fork, so vrf4 should not be present after the hard fork |
| 41 | + (kh4, vrf4) <- (,) <$> freshKeyHash <*> freshKeyHashVRF |
| 42 | + registerStakePool kh4 vrf4 |
| 43 | + retireStakePool kh4 (EpochInterval 1) |
| 44 | + -- register and schedule retirement for after the hard fork, so vrf5 should be present after the hard fork |
| 45 | + (kh5, vrf5) <- (,) <$> freshKeyHash <*> freshKeyHashVRF |
| 46 | + registerStakePool kh5 vrf5 |
| 47 | + retireStakePool kh5 (EpochInterval 5) |
| 48 | + |
| 49 | + expectVRFs [] -- VRF keyhashes in PState is not yet populated |
| 50 | + enactHardForkV11 |
| 51 | + expectVRFs [vrf2, vrf3, vrf5] |
| 52 | + where |
| 53 | + enactHardForkV11 = do |
| 54 | + modifyPParams $ \pp -> |
| 55 | + pp |
| 56 | + & ppDRepVotingThresholdsL . dvtHardForkInitiationL .~ 0 %! 1 |
| 57 | + & ppPoolVotingThresholdsL . pvtHardForkInitiationL .~ 0 %! 1 |
| 58 | + let pv11 = ProtVer (natVersion @11) 0 |
| 59 | + committee <- registerInitialCommittee |
| 60 | + govActionId <- submitGovAction $ HardForkInitiation SNothing pv11 |
| 61 | + submitYesVoteCCs_ committee govActionId |
| 62 | + passNEpochs 2 |
| 63 | + getProtVer `shouldReturn` pv11 |
| 64 | + registerStakePool kh vrf = do |
| 65 | + pps <- registerRewardAccount >>= freshPoolParams kh |
| 66 | + submitTx_ $ |
| 67 | + mkBasicTx mkBasicTxBody |
| 68 | + & bodyTxL . certsTxBodyL .~ [RegPoolTxCert $ pps & ppVrfL .~ vrf] |
| 69 | + retireStakePool kh retirementInterval = do |
| 70 | + curEpochNo <- getsNES nesELL |
| 71 | + let retirement = addEpochInterval curEpochNo retirementInterval |
| 72 | + submitTx_ $ |
| 73 | + mkBasicTx mkBasicTxBody |
| 74 | + & bodyTxL . certsTxBodyL .~ [RetirePoolTxCert kh retirement] |
| 75 | + expectVRFs vrfs = |
| 76 | + psVRFKeyHashes <$> getPState `shouldReturn` Set.fromList vrfs |
| 77 | + getPState = getsNES @era $ nesEsL . esLStateL . lsCertStateL . certPStateL |
0 commit comments