Skip to content

Commit 4969ae4

Browse files
committed
Add CertsSpec and some withdrawals-related tests
1 parent 4b8e287 commit 4969ae4

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ library testlib
118118
Test.Cardano.Ledger.Conway.ImpTest
119119
Test.Cardano.Ledger.Conway.Imp
120120
Test.Cardano.Ledger.Conway.Imp.BbodySpec
121+
Test.Cardano.Ledger.Conway.Imp.CertsSpec
121122
Test.Cardano.Ledger.Conway.Imp.DelegSpec
122123
Test.Cardano.Ledger.Conway.Imp.EpochSpec
123124
Test.Cardano.Ledger.Conway.Imp.EnactSpec

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import Cardano.Ledger.BaseTypes (Inject, natVersion)
2020
import Cardano.Ledger.Conway.Core
2121
import Cardano.Ledger.Conway.Rules (
2222
ConwayBbodyPredFailure,
23+
ConwayCertsPredFailure,
2324
ConwayDelegPredFailure,
2425
ConwayEpochEvent,
2526
ConwayGovCertPredFailure,
@@ -33,6 +34,7 @@ import Data.Typeable (Typeable)
3334
import qualified Test.Cardano.Ledger.Babbage.Imp as BabbageImp
3435
import Test.Cardano.Ledger.Common
3536
import qualified Test.Cardano.Ledger.Conway.Imp.BbodySpec as Bbody
37+
import qualified Test.Cardano.Ledger.Conway.Imp.CertsSpec as Certs
3638
import qualified Test.Cardano.Ledger.Conway.Imp.DelegSpec as Deleg
3739
import qualified Test.Cardano.Ledger.Conway.Imp.EnactSpec as Enact
3840
import qualified Test.Cardano.Ledger.Conway.Imp.EpochSpec as Epoch
@@ -50,6 +52,7 @@ spec ::
5052
, ConwayEraImp era
5153
, EraSegWits era
5254
, InjectRuleFailure "LEDGER" ConwayGovPredFailure era
55+
, InjectRuleFailure "LEDGER" ConwayCertsPredFailure era
5356
, Inject (BabbageContextError era) (ContextError era)
5457
, Inject (ConwayContextError era) (ContextError era)
5558
, InjectRuleFailure "LEDGER" BabbageUtxoPredFailure era
@@ -89,6 +92,7 @@ spec = do
8992
describe "ConwayImpSpec - bootstrap phase (protocol version 9)" $
9093
withImpState @era $ do
9194
describe "BBODY" $ Bbody.spec @era
95+
describe "CERTS" $ Certs.spec @era
9296
describe "DELEG" $ Deleg.spec @era
9397
describe "ENACT" $ Enact.relevantDuringBootstrapSpec @era
9498
describe "EPOCH" $ Epoch.relevantDuringBootstrapSpec @era
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE FlexibleContexts #-}
3+
{-# LANGUAGE NumericUnderscores #-}
4+
{-# LANGUAGE OverloadedLists #-}
5+
{-# LANGUAGE OverloadedStrings #-}
6+
{-# LANGUAGE RankNTypes #-}
7+
{-# LANGUAGE ScopedTypeVariables #-}
8+
{-# LANGUAGE TypeApplications #-}
9+
{-# LANGUAGE TypeFamilies #-}
10+
11+
module Test.Cardano.Ledger.Conway.Imp.CertsSpec (
12+
spec,
13+
) where
14+
15+
import Cardano.Ledger.BaseTypes (EpochInterval (..))
16+
import Cardano.Ledger.Coin (Coin (..))
17+
import Cardano.Ledger.Conway.Core
18+
import Cardano.Ledger.Conway.Rules (ConwayCertsPredFailure (..))
19+
import Cardano.Ledger.Credential (Credential (..))
20+
import Cardano.Ledger.Val (Val (..))
21+
import Lens.Micro ((&), (.~))
22+
import Test.Cardano.Ledger.Conway.Arbitrary ()
23+
import Test.Cardano.Ledger.Conway.ImpTest
24+
import Test.Cardano.Ledger.Imp.Common
25+
26+
spec ::
27+
forall era.
28+
( ConwayEraImp era
29+
, InjectRuleFailure "LEDGER" ConwayCertsPredFailure era
30+
) =>
31+
SpecWith (ImpTestState era)
32+
spec = do
33+
describe "Withdrawals" $ do
34+
it "Withdrawing from an unregistered reward account" $ do
35+
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 2
36+
37+
rwdAccount <- KeyHashObj <$> freshKeyHash >>= getRewardAccountFor
38+
submitFailingTx
39+
( mkBasicTx $
40+
mkBasicTxBody
41+
& withdrawalsTxBodyL
42+
.~ Withdrawals
43+
[(rwdAccount, Coin 20)]
44+
)
45+
[injectFailure $ WithdrawalsNotInRewardsCERTS [(rwdAccount, Coin 20)]]
46+
47+
(registeredRwdAccount, reward) <- setupRewardAccount
48+
submitFailingTx
49+
( mkBasicTx $
50+
mkBasicTxBody
51+
& withdrawalsTxBodyL
52+
.~ Withdrawals
53+
[(rwdAccount, zero), (registeredRwdAccount, reward)]
54+
)
55+
[injectFailure $ WithdrawalsNotInRewardsCERTS [(rwdAccount, zero)]]
56+
57+
it "Withdrawing the wrong amount" $ do
58+
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 2
59+
60+
(rwdAccount1, reward1) <- setupRewardAccount
61+
(rwdAccount2, reward2) <- setupRewardAccount
62+
submitFailingTx
63+
( mkBasicTx $
64+
mkBasicTxBody
65+
& withdrawalsTxBodyL
66+
.~ Withdrawals
67+
[ (rwdAccount1, reward1 <+> Coin 1)
68+
, (rwdAccount2, reward2)
69+
]
70+
)
71+
[injectFailure $ WithdrawalsNotInRewardsCERTS [(rwdAccount1, reward1 <+> Coin 1)]]
72+
73+
submitFailingTx
74+
( mkBasicTx $
75+
mkBasicTxBody
76+
& withdrawalsTxBodyL
77+
.~ Withdrawals
78+
[(rwdAccount1, zero)]
79+
)
80+
[injectFailure $ WithdrawalsNotInRewardsCERTS [(rwdAccount1, zero)]]
81+
where
82+
setupRewardAccount = do
83+
cred <- KeyHashObj <$> freshKeyHash
84+
ra <- registerStakeCredential cred
85+
submitAndExpireProposalToMakeReward cred
86+
rw <- lookupReward cred
87+
pure (ra, rw)

0 commit comments

Comments
 (0)