Skip to content

Commit 8dd08ce

Browse files
committed
Adjust Shelley PoolSpec for Dijkstra era
* Move tests that are reliant on certs w/out deposits and only run them pre-Dijkstra
1 parent 92a7b5e commit 8dd08ce

File tree

8 files changed

+87
-38
lines changed
  • eras
    • allegra/impl/testlib/Test/Cardano/Ledger/Allegra
    • alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo
    • babbage/impl/testlib/Test/Cardano/Ledger/Babbage
    • conway/impl/testlib/Test/Cardano/Ledger/Conway
    • dijkstra/testlib/Test/Cardano/Ledger/Dijkstra
    • mary/impl/testlib/Test/Cardano/Ledger/Mary
    • shelley/impl/testlib/Test/Cardano/Ledger/Shelley

8 files changed

+87
-38
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ spec = do
3434
describe "AllegraImpSpec" . withEachEraVersion @era $
3535
UtxowSpec.spec
3636

37-
instance EraSpecificSpec AllegraEra
37+
instance EraSpecificSpec AllegraEra where
38+
eraSpecificSpec = ShelleyImp.shelleyEraSpecificSpec

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import qualified Test.Cardano.Ledger.Alonzo.Imp.UtxowSpec as Utxow
2727
import Test.Cardano.Ledger.Alonzo.ImpTest
2828
import Test.Cardano.Ledger.Imp.Common
2929
import qualified Test.Cardano.Ledger.Mary.Imp as MaryImp
30+
import qualified Test.Cardano.Ledger.Shelley.Imp.PoolSpec as ShelleyImp
3031

3132
spec ::
3233
forall era.
@@ -63,4 +64,4 @@ alonzoEraSpecificSpec = do
6364
Utxow.alonzoEraSpecificSpec
6465

6566
instance EraSpecificSpec AlonzoEra where
66-
eraSpecificSpec = alonzoEraSpecificSpec
67+
eraSpecificSpec = ShelleyImp.shelleyEraSpecificSpec >> alonzoEraSpecificSpec

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{-# LANGUAGE TypeFamilies #-}
77
{-# OPTIONS_GHC -Wno-orphans #-}
88

9-
module Test.Cardano.Ledger.Babbage.Imp (spec) where
9+
module Test.Cardano.Ledger.Babbage.Imp (spec, babbageEraSpecificSpec) where
1010

1111
import Cardano.Ledger.Alonzo.Plutus.Context (ContextError)
1212
import Cardano.Ledger.Alonzo.Rules (
@@ -15,12 +15,11 @@ import Cardano.Ledger.Alonzo.Rules (
1515
AlonzoUtxowPredFailure,
1616
)
1717
import Cardano.Ledger.Babbage (BabbageEra)
18-
import Cardano.Ledger.Babbage.Core (BabbageEraTxBody, InjectRuleFailure)
18+
import Cardano.Ledger.Babbage.Core (BabbageEraTxBody, InjectRuleFailure, ShelleyEraTxCert)
1919
import Cardano.Ledger.Babbage.Rules (BabbageUtxoPredFailure, BabbageUtxowPredFailure)
2020
import Cardano.Ledger.Babbage.TxInfo (BabbageContextError)
2121
import Cardano.Ledger.BaseTypes (Inject)
2222
import Cardano.Ledger.Shelley.Rules (
23-
ShelleyDelegPredFailure,
2423
ShelleyPoolPredFailure,
2524
ShelleyUtxoPredFailure,
2625
ShelleyUtxowPredFailure,
@@ -31,13 +30,13 @@ import qualified Test.Cardano.Ledger.Babbage.Imp.UtxoSpec as Utxo
3130
import qualified Test.Cardano.Ledger.Babbage.Imp.UtxosSpec as Utxos
3231
import qualified Test.Cardano.Ledger.Babbage.Imp.UtxowSpec as Utxow
3332
import Test.Cardano.Ledger.Imp.Common
33+
import qualified Test.Cardano.Ledger.Shelley.Imp.PoolSpec as ShelleyImp
3434

3535
spec ::
3636
forall era.
3737
( AlonzoEraImp era
3838
, EraSpecificSpec era
3939
, BabbageEraTxBody era
40-
, InjectRuleFailure "LEDGER" ShelleyDelegPredFailure era
4140
, InjectRuleFailure "LEDGER" ShelleyPoolPredFailure era
4241
, InjectRuleFailure "LEDGER" ShelleyUtxoPredFailure era
4342
, InjectRuleFailure "LEDGER" AlonzoUtxoPredFailure era
@@ -57,7 +56,20 @@ spec = do
5756
Utxow.spec
5857
Utxos.spec @era
5958

59+
babbageEraSpecificSpec ::
60+
forall era.
61+
( AlonzoEraImp era
62+
, ShelleyEraTxCert era
63+
, BabbageEraTxBody era
64+
) =>
65+
SpecWith (ImpInit (LedgerSpec era))
66+
babbageEraSpecificSpec = do
67+
describe "Babbage era specific Imp spec" $
68+
describe "Certificates without deposits" $
69+
describe "UTXOW" Utxow.babbageEraSpecificSpec
70+
6071
instance EraSpecificSpec BabbageEra where
6172
eraSpecificSpec =
62-
AlonzoImp.alonzoEraSpecificSpec
63-
>> Utxow.babbageEraSpecificSpec
73+
ShelleyImp.shelleyEraSpecificSpec
74+
>> AlonzoImp.alonzoEraSpecificSpec
75+
>> babbageEraSpecificSpec

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import qualified Test.Cardano.Ledger.Conway.Imp.UtxosSpec as Utxos
5959
import qualified Test.Cardano.Ledger.Conway.Imp.UtxowSpec as Utxow
6060
import Test.Cardano.Ledger.Conway.ImpTest
6161
import Test.Cardano.Ledger.Imp.Common
62+
import qualified Test.Cardano.Ledger.Shelley.Imp as ShelleyImp
6263

6364
spec ::
6465
forall era.
@@ -156,5 +157,7 @@ conwayEraSpecificSpec = do
156157

157158
instance EraSpecificSpec ConwayEra where
158159
eraSpecificSpec =
159-
AlonzoImp.alonzoEraSpecificSpec
160+
ShelleyImp.shelleyEraSpecificSpec
161+
>> AlonzoImp.alonzoEraSpecificSpec
162+
>> BabbageImp.babbageEraSpecificSpec
160163
>> conwayEraSpecificSpec

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ spec ::
3737
, InjectRuleFailure "LEDGER" AlonzoUtxoPredFailure era
3838
, InjectRuleFailure "LEDGER" AlonzoUtxosPredFailure era
3939
, InjectRuleFailure "LEDGER" AlonzoUtxowPredFailure era
40+
, InjectRuleFailure "LEDGER" ShelleyPoolPredFailure era
4041
, InjectRuleFailure "LEDGER" ShelleyUtxoPredFailure era
4142
, InjectRuleFailure "LEDGER" ShelleyUtxowPredFailure era
4243
, InjectRuleFailure "LEDGER" ConwayDelegPredFailure era

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import qualified Test.Cardano.Ledger.Allegra.Imp as AllegraImp
1919
import Test.Cardano.Ledger.Imp.Common
2020
import qualified Test.Cardano.Ledger.Mary.Imp.UtxoSpec as Utxo
2121
import Test.Cardano.Ledger.Mary.ImpTest
22+
import qualified Test.Cardano.Ledger.Shelley.Imp as ShelleyImp
2223

2324
spec ::
2425
forall era.
@@ -35,4 +36,5 @@ spec = do
3536
withEachEraVersion @era $
3637
Utxo.spec
3738

38-
instance EraSpecificSpec MaryEra
39+
instance EraSpecificSpec MaryEra where
40+
eraSpecificSpec = ShelleyImp.shelleyEraSpecificSpec

eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/Imp.hs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{-# LANGUAGE TypeApplications #-}
66
{-# OPTIONS_GHC -Wno-orphans #-}
77

8-
module Test.Cardano.Ledger.Shelley.Imp (spec) where
8+
module Test.Cardano.Ledger.Shelley.Imp (spec, shelleyEraSpecificSpec) where
99

1010
import Cardano.Ledger.Core
1111
import Cardano.Ledger.Shelley (ShelleyEra)
@@ -14,6 +14,7 @@ import Cardano.Ledger.Shelley.Rules (
1414
ShelleyUtxoPredFailure,
1515
ShelleyUtxowPredFailure,
1616
)
17+
import Cardano.Ledger.Shelley.TxCert (ShelleyEraTxCert)
1718
import Test.Cardano.Ledger.Imp.Common
1819
import qualified Test.Cardano.Ledger.Shelley.Imp.EpochSpec as Epoch
1920
import qualified Test.Cardano.Ledger.Shelley.Imp.LedgerSpec as Ledger
@@ -43,4 +44,16 @@ spec = do
4344
describe "ShelleyPureTests" $ do
4445
Instant.spec @era
4546

46-
instance EraSpecificSpec ShelleyEra
47+
shelleyEraSpecificSpec ::
48+
( ShelleyEraImp era
49+
, ShelleyEraTxCert era
50+
, InjectRuleFailure "LEDGER" ShelleyPoolPredFailure era
51+
) =>
52+
SpecWith (ImpInit (LedgerSpec era))
53+
shelleyEraSpecificSpec = do
54+
describe "Shelley era specific Imp spec" $
55+
describe "Certificates without deposits" $ do
56+
describe "POOL" Pool.shelleyEraSpecificSpec
57+
58+
instance EraSpecificSpec ShelleyEra where
59+
eraSpecificSpec = shelleyEraSpecificSpec

eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/Imp/PoolSpec.hs

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{-# LANGUAGE TypeApplications #-}
66
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
77

8-
module Test.Cardano.Ledger.Shelley.Imp.PoolSpec (spec) where
8+
module Test.Cardano.Ledger.Shelley.Imp.PoolSpec (spec, shelleyEraSpecificSpec) where
99

1010
import Cardano.Crypto.Hash.Class (sizeHash)
1111
import Cardano.Ledger.Address (RewardAccount (..))
@@ -15,7 +15,8 @@ import Cardano.Ledger.Core
1515
import Cardano.Ledger.Credential (Credential (..))
1616
import Cardano.Ledger.Shelley.LedgerState
1717
import Cardano.Ledger.Shelley.Rules (ShelleyPoolPredFailure (..))
18-
import Cardano.Ledger.State (PoolMetadata (..), ppCostL, ppMetadataL, ppVrfL, spsVrf)
18+
import Cardano.Ledger.Shelley.TxCert (ShelleyEraTxCert)
19+
import Cardano.Ledger.State (PoolMetadata (..), PoolParams, ppCostL, ppMetadataL, ppVrfL, spsVrf)
1920
import qualified Data.Map.Strict as Map
2021
import Data.Proxy
2122
import Lens.Micro
@@ -31,16 +32,6 @@ spec ::
3132
SpecWith (ImpInit (LedgerSpec era))
3233
spec = describe "POOL" $ do
3334
describe "Register and re-register pools" $ do
34-
it "register a pool with too low cost" $ do
35-
(kh, vrf) <- (,) <$> freshKeyHash <*> freshKeyHashVRF
36-
minPoolCost <- getsPParams ppMinPoolCostL
37-
tooLowCost <- Coin <$> choose (0, unCoin minPoolCost)
38-
let pps = (\p -> p & ppCostL .~ tooLowCost) <$> poolParams kh vrf
39-
registerPoolTx <$> pps >>= \tx ->
40-
submitFailingTx
41-
tx
42-
[injectFailure $ StakePoolCostTooLowPOOL $ Mismatch tooLowCost minPoolCost]
43-
4435
it "register a pool with a reward account having the wrong network id" $ do
4536
pv <- getsPParams ppProtocolVersionL
4637
rewardCredential <- KeyHashObj <$> freshKeyHash
@@ -58,6 +49,31 @@ spec = describe "POOL" $ do
5849
else
5950
submitFailingTx tx [injectFailure $ WrongNetworkPOOL (Mismatch Mainnet Testnet) kh]
6051

52+
describe "Retiring pools" $ do
53+
it "retire an unregistered pool" $ do
54+
khNew <- freshKeyHash
55+
retirePoolTx khNew (EpochInterval 10) >>= \tx ->
56+
submitFailingTx tx [injectFailure $ StakePoolNotRegisteredOnKeyPOOL khNew]
57+
58+
shelleyEraSpecificSpec ::
59+
forall era.
60+
( ShelleyEraImp era
61+
, ShelleyEraTxCert era
62+
, InjectRuleFailure "LEDGER" ShelleyPoolPredFailure era
63+
) =>
64+
SpecWith (ImpInit (LedgerSpec era))
65+
shelleyEraSpecificSpec = describe "POOL" $ do
66+
describe "Register and re-register pools" $ do
67+
it "register a pool with too low cost" $ do
68+
(kh, vrf) <- (,) <$> freshKeyHash <*> freshKeyHashVRF
69+
minPoolCost <- getsPParams ppMinPoolCostL
70+
tooLowCost <- Coin <$> choose (0, unCoin minPoolCost)
71+
let pps = (\p -> p & ppCostL .~ tooLowCost) <$> poolParams kh vrf
72+
registerPoolTx <$> pps >>= \tx ->
73+
submitFailingTx
74+
tx
75+
[injectFailure $ StakePoolCostTooLowPOOL $ Mismatch tooLowCost minPoolCost]
76+
6177
it "register a pool with too big metadata" $ do
6278
pv <- getsPParams ppProtocolVersionL
6379
let maxMetadataSize = sizeHash (Proxy :: Proxy HASH)
@@ -197,11 +213,6 @@ spec = describe "POOL" $ do
197213
submitFailingTx tx [injectFailure $ VRFKeyHashAlreadyRegistered khNew vrf]
198214

199215
describe "Retiring pools" $ do
200-
it "retire an unregistered pool" $ do
201-
khNew <- freshKeyHash
202-
retirePoolTx khNew (EpochInterval 10) >>= \tx ->
203-
submitFailingTx tx [injectFailure $ StakePoolNotRegisteredOnKeyPOOL khNew]
204-
205216
it "retire a pool with too high a retirement epoch" $ do
206217
(kh, _) <- registerNewPool
207218
maxRetireInterval <- getsPParams ppEMaxL
@@ -322,15 +333,6 @@ spec = describe "POOL" $ do
322333
registerPoolTx <$> poolParams kh vrf >>= submitTx_
323334
expectPool kh (Just vrf)
324335
pure (kh, vrf)
325-
registerPoolTx pps =
326-
mkBasicTx mkBasicTxBody
327-
& bodyTxL . certsTxBodyL .~ [RegPoolTxCert pps]
328-
retirePoolTx kh retirementInterval = do
329-
curEpochNo <- getsNES nesELL
330-
let retirement = addEpochInterval curEpochNo retirementInterval
331-
pure $
332-
mkBasicTx mkBasicTxBody
333-
& bodyTxL . certsTxBodyL .~ [RetirePoolTxCert kh retirement]
334336
expectPool poolKh mbVrf = do
335337
pps <- psStakePools <$> getPState
336338
spsVrf <$> Map.lookup poolKh pps `shouldBe` mbVrf
@@ -349,3 +351,17 @@ spec = describe "POOL" $ do
349351
pps <- registerRewardAccount >>= freshPoolParams kh
350352
pure $ pps & ppVrfL .~ vrf
351353
getPState = getsNES @era $ nesEsL . esLStateL . lsCertStateL . certPStateL
354+
355+
registerPoolTx :: ShelleyEraImp era => PoolParams -> Tx era
356+
registerPoolTx pps =
357+
mkBasicTx mkBasicTxBody
358+
& bodyTxL . certsTxBodyL .~ [RegPoolTxCert pps]
359+
360+
retirePoolTx ::
361+
ShelleyEraImp era => KeyHash 'StakePool -> EpochInterval -> ImpM (LedgerSpec era) (Tx era)
362+
retirePoolTx kh retirementInterval = do
363+
curEpochNo <- getsNES nesELL
364+
let retirement = addEpochInterval curEpochNo retirementInterval
365+
pure $
366+
mkBasicTx mkBasicTxBody
367+
& bodyTxL . certsTxBodyL .~ [RetirePoolTxCert kh retirement]

0 commit comments

Comments
 (0)