Skip to content

Commit b065c65

Browse files
committed
Add shelley-specific DELEG tests
and run them in all eras until Conway
1 parent 776956c commit b065c65

File tree

7 files changed

+109
-10
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
    • mary/impl/testlib/Test/Cardano/Ledger/Mary
    • shelley/impl/testlib/Test/Cardano/Ledger/Shelley

7 files changed

+109
-10
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
@@ -20,4 +20,5 @@ spec = do
2020
describe "AllegraImpSpec" . withEachEraVersion @era $
2121
UtxowSpec.spec
2222

23-
instance EraSpecificSpec AllegraEra
23+
instance EraSpecificSpec AllegraEra where
24+
eraSpecificSpec = ShelleyImp.shelleyEraSpecificSpec

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import qualified Test.Cardano.Ledger.Alonzo.Imp.UtxowSpec as Utxow
1616
import Test.Cardano.Ledger.Alonzo.ImpTest
1717
import Test.Cardano.Ledger.Imp.Common
1818
import qualified Test.Cardano.Ledger.Mary.Imp as MaryImp
19+
import qualified Test.Cardano.Ledger.Shelley.Imp as ShelleyImp
1920

2021
spec ::
2122
forall era.
@@ -40,4 +41,5 @@ alonzoEraSpecificSpec = do
4041
Utxow.alonzoEraSpecificSpec
4142

4243
instance EraSpecificSpec AlonzoEra where
43-
eraSpecificSpec = alonzoEraSpecificSpec
44+
eraSpecificSpec =
45+
ShelleyImp.shelleyEraSpecificSpec >> alonzoEraSpecificSpec

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import qualified Test.Cardano.Ledger.Babbage.Imp.UtxosSpec as Utxos
1616
import qualified Test.Cardano.Ledger.Babbage.Imp.UtxowSpec as Utxow
1717
import Test.Cardano.Ledger.Babbage.ImpTest (BabbageEraImp)
1818
import Test.Cardano.Ledger.Imp.Common
19+
import qualified Test.Cardano.Ledger.Shelley.Imp as ShelleyImp
1920

2021
spec :: forall era. (BabbageEraImp era, EraSpecificSpec era) => Spec
2122
spec = do
@@ -28,4 +29,4 @@ spec = do
2829

2930
instance EraSpecificSpec BabbageEra where
3031
eraSpecificSpec =
31-
AlonzoImp.alonzoEraSpecificSpec
32+
ShelleyImp.shelleyEraSpecificSpec >> AlonzoImp.alonzoEraSpecificSpec

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,9 @@ conwayEraGenericSpec = do
7373

7474
conwayEraSpecificSpec :: SpecWith (ImpInit (LedgerSpec ConwayEra))
7575
conwayEraSpecificSpec = do
76-
describe "Conway era specific Imp spec" $
77-
describe "Certificates without deposits" $ do
78-
describe "DELEG" Deleg.conwayEraSpecificSpec
79-
describe "UTXO" Utxo.conwayEraSpecificSpec
76+
describe "Conway era specific Imp spec" $ do
77+
describe "DELEG" Deleg.conwayEraSpecificSpec
78+
describe "UTXO" Utxo.conwayEraSpecificSpec
8079

8180
instance EraSpecificSpec ConwayEra where
8281
eraSpecificSpec =

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import qualified Test.Cardano.Ledger.Allegra.Imp as AllegraImp
1313
import Test.Cardano.Ledger.Imp.Common
1414
import qualified Test.Cardano.Ledger.Mary.Imp.UtxoSpec as Utxo
1515
import Test.Cardano.Ledger.Mary.ImpTest
16+
import qualified Test.Cardano.Ledger.Shelley.Imp as ShelleyImp
1617

1718
spec :: forall era. (MaryEraImp era, EraSpecificSpec era) => Spec
1819
spec = do
@@ -21,4 +22,5 @@ spec = do
2122
withEachEraVersion @era $
2223
Utxo.spec
2324

24-
instance EraSpecificSpec MaryEra
25+
instance EraSpecificSpec MaryEra where
26+
eraSpecificSpec = ShelleyImp.shelleyEraSpecificSpec

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
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.Shelley (ShelleyEra)
11+
import Cardano.Ledger.Shelley.Core
12+
import Cardano.Ledger.Shelley.Rules
1113
import Test.Cardano.Ledger.Imp.Common
1214
import qualified Test.Cardano.Ledger.Shelley.Imp.DelegSpec as Deleg
1315
import qualified Test.Cardano.Ledger.Shelley.Imp.EpochSpec as Epoch
@@ -36,4 +38,17 @@ spec = do
3638
describe "ShelleyPureTests" $ do
3739
Instant.spec @era
3840

39-
instance EraSpecificSpec ShelleyEra
41+
shelleyEraSpecificSpec ::
42+
forall era.
43+
( ShelleyEraImp era
44+
, InjectRuleFailure "LEDGER" ShelleyDelegsPredFailure era
45+
) =>
46+
SpecWith (ImpInit (LedgerSpec era))
47+
shelleyEraSpecificSpec = do
48+
describe "Shelley era specific Imp spec" $
49+
describe "DELEG" $
50+
Deleg.shelleyEraSpecificSpec
51+
52+
instance EraSpecificSpec ShelleyEra where
53+
eraSpecificSpec =
54+
describe "DELEG" Deleg.shelleyEraSpecificSpec

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

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,98 @@
88
{-# LANGUAGE TypeFamilies #-}
99

1010
module Test.Cardano.Ledger.Shelley.Imp.DelegSpec (
11+
shelleyEraSpecificSpec,
1112
spec,
1213
) where
1314

1415
import Cardano.Ledger.BaseTypes
16+
import Cardano.Ledger.Coin (Coin (Coin))
1517
import Cardano.Ledger.Credential (Credential (..))
1618
import Cardano.Ledger.Shelley.Core
1719
import Cardano.Ledger.Shelley.Rules
1820
import Cardano.Ledger.Shelley.Scripts
21+
import qualified Data.Map.Strict as Map
1922
import Lens.Micro
2023
import Test.Cardano.Ledger.Imp.Common
2124
import Test.Cardano.Ledger.Shelley.Arbitrary ()
2225
import Test.Cardano.Ledger.Shelley.ImpTest
2326

27+
shelleyEraSpecificSpec ::
28+
( ShelleyEraImp era
29+
, InjectRuleFailure "LEDGER" ShelleyDelegsPredFailure era
30+
) =>
31+
SpecWith (ImpInit (LedgerSpec era))
32+
shelleyEraSpecificSpec = do
33+
it "Twice the same certificate in the same transaction" $ do
34+
freshKeyHash >>= \kh -> do
35+
regTxCert <- genRegTxCert (KeyHashObj kh)
36+
submitFailingTx
37+
( mkBasicTx mkBasicTxBody
38+
& bodyTxL . certsTxBodyL
39+
.~ [regTxCert, regTxCert]
40+
)
41+
[injectFailure $ StakeKeyAlreadyRegisteredDELEG (KeyHashObj kh)]
42+
expectStakeCredNotRegistered (KeyHashObj kh)
43+
44+
it "Delegate to unregistered pool" $ do
45+
cred <- KeyHashObj <$> freshKeyHash
46+
regTxCert <- genRegTxCert cred
47+
submitTx_ $
48+
mkBasicTx mkBasicTxBody
49+
& bodyTxL . certsTxBodyL .~ [regTxCert]
50+
51+
poolKh <- freshKeyHash
52+
submitFailingTx
53+
( mkBasicTx mkBasicTxBody
54+
& bodyTxL . certsTxBodyL .~ [delegStakeTxCert cred poolKh]
55+
)
56+
[injectFailure $ DelegateeNotRegisteredDELEG poolKh]
57+
expectNotDelegatedToPool cred
58+
59+
it "Deregistering returns the deposit" $ do
60+
let keyDeposit = Coin 2
61+
-- This is paid out as the reward
62+
let poolDeposit = Coin 3
63+
modifyPParams $ \pp ->
64+
pp
65+
& ppKeyDepositL .~ keyDeposit
66+
& ppPoolDepositL .~ poolDeposit
67+
stakeCred <- KeyHashObj <$> freshKeyHash
68+
rewardAccount <- getRewardAccountFor stakeCred
69+
otherStakeCred <- KeyHashObj <$> freshKeyHash
70+
otherRewardAccount <- getRewardAccountFor otherStakeCred
71+
khStakePool <- freshKeyHash
72+
registerPool khStakePool
73+
stakeCredRegTxCert <- genRegTxCert stakeCred
74+
otherStakeCredRegTxCert <- genRegTxCert otherStakeCred
75+
submitTx_ . mkBasicTx $
76+
mkBasicTxBody
77+
& certsTxBodyL
78+
.~ [ stakeCredRegTxCert
79+
, delegStakeTxCert stakeCred khStakePool
80+
, otherStakeCredRegTxCert
81+
, delegStakeTxCert otherStakeCred khStakePool
82+
]
83+
expectRegisteredRewardAddress rewardAccount
84+
expectRegisteredRewardAddress otherRewardAccount
85+
registerAndRetirePoolToMakeReward otherStakeCred
86+
87+
getBalance otherStakeCred `shouldReturn` poolDeposit
88+
unRegTxCert <- genUnRegTxCert stakeCred
89+
90+
submitTx_ . mkBasicTx $
91+
mkBasicTxBody
92+
& certsTxBodyL .~ [unRegTxCert]
93+
& withdrawalsTxBodyL
94+
.~ Withdrawals
95+
( Map.fromList
96+
[ (rewardAccount, Coin 0)
97+
, (otherRewardAccount, poolDeposit)
98+
]
99+
)
100+
getBalance otherStakeCred `shouldReturn` Coin 0
101+
expectNotRegisteredRewardAddress rewardAccount
102+
24103
spec ::
25104
ShelleyEraImp era =>
26105
SpecWith (ImpInit (LedgerSpec era))

0 commit comments

Comments
 (0)