Skip to content

Commit

Permalink
Add CertsSpec and some withdrawals-related tests
Browse files Browse the repository at this point in the history
  • Loading branch information
teodanciu committed Sep 18, 2024
1 parent 649f002 commit 094672b
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions eras/conway/impl/cardano-ledger-conway.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ library testlib
Test.Cardano.Ledger.Conway.ImpTest
Test.Cardano.Ledger.Conway.Imp
Test.Cardano.Ledger.Conway.Imp.BbodySpec
Test.Cardano.Ledger.Conway.Imp.CertsSpec
Test.Cardano.Ledger.Conway.Imp.DelegSpec
Test.Cardano.Ledger.Conway.Imp.EpochSpec
Test.Cardano.Ledger.Conway.Imp.EnactSpec
Expand Down
4 changes: 4 additions & 0 deletions eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Cardano.Ledger.BaseTypes (Inject, natVersion)
import Cardano.Ledger.Conway.Core
import Cardano.Ledger.Conway.Rules (
ConwayBbodyPredFailure,
ConwayCertsPredFailure,
ConwayDelegPredFailure,
ConwayEpochEvent,
ConwayGovCertPredFailure,
Expand All @@ -33,6 +34,7 @@ import Data.Typeable (Typeable)
import qualified Test.Cardano.Ledger.Babbage.Imp as BabbageImp
import Test.Cardano.Ledger.Common
import qualified Test.Cardano.Ledger.Conway.Imp.BbodySpec as Bbody
import qualified Test.Cardano.Ledger.Conway.Imp.CertsSpec as Certs
import qualified Test.Cardano.Ledger.Conway.Imp.DelegSpec as Deleg
import qualified Test.Cardano.Ledger.Conway.Imp.EnactSpec as Enact
import qualified Test.Cardano.Ledger.Conway.Imp.EpochSpec as Epoch
Expand All @@ -50,6 +52,7 @@ spec ::
, ConwayEraImp era
, EraSegWits era
, InjectRuleFailure "LEDGER" ConwayGovPredFailure era
, InjectRuleFailure "LEDGER" ConwayCertsPredFailure era
, Inject (BabbageContextError era) (ContextError era)
, Inject (ConwayContextError era) (ContextError era)
, InjectRuleFailure "LEDGER" BabbageUtxoPredFailure era
Expand Down Expand Up @@ -89,6 +92,7 @@ spec = do
describe "ConwayImpSpec - bootstrap phase (protocol version 9)" $
withImpState @era $ do
describe "BBODY" $ Bbody.spec @era
describe "CERTS" $ Certs.spec @era
describe "DELEG" $ Deleg.spec @era
describe "ENACT" $ Enact.relevantDuringBootstrapSpec @era
describe "EPOCH" $ Epoch.relevantDuringBootstrapSpec @era
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

module Test.Cardano.Ledger.Conway.Imp.CertsSpec (
spec,
) where

import Cardano.Ledger.BaseTypes (EpochInterval (..))
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Conway.Core
import Cardano.Ledger.Conway.Rules (ConwayCertsPredFailure (..))
import Cardano.Ledger.Credential (Credential (..))
import Cardano.Ledger.Val (Val (..))
import Lens.Micro ((&), (.~))
import Test.Cardano.Ledger.Conway.Arbitrary ()
import Test.Cardano.Ledger.Conway.ImpTest
import Test.Cardano.Ledger.Imp.Common

spec ::
forall era.
( ConwayEraImp era
, InjectRuleFailure "LEDGER" ConwayCertsPredFailure era
) =>
SpecWith (ImpTestState era)
spec = do
describe "Withdrawals" $ do
it "Withdrawing from an unregistered reward account" $ do
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 2

rwdAccount <- KeyHashObj <$> freshKeyHash >>= getRewardAccountFor
submitFailingTx
( mkBasicTx $
mkBasicTxBody
& withdrawalsTxBodyL
.~ Withdrawals
[(rwdAccount, Coin 20)]
)
[injectFailure $ WithdrawalsNotInRewardsCERTS [(rwdAccount, Coin 20)]]

(registeredRwdAccount, reward) <- setupRewardAccount
submitFailingTx
( mkBasicTx $
mkBasicTxBody
& withdrawalsTxBodyL
.~ Withdrawals
[(rwdAccount, zero), (registeredRwdAccount, reward)]
)
[injectFailure $ WithdrawalsNotInRewardsCERTS [(rwdAccount, zero)]]

it "Withdrawing the wrong amount" $ do
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 2

(rwdAccount1, reward1) <- setupRewardAccount
(rwdAccount2, reward2) <- setupRewardAccount
submitFailingTx
( mkBasicTx $
mkBasicTxBody
& withdrawalsTxBodyL
.~ Withdrawals
[ (rwdAccount1, reward1 <+> Coin 1)
, (rwdAccount2, reward2)
]
)
[injectFailure $ WithdrawalsNotInRewardsCERTS [(rwdAccount1, reward1 <+> Coin 1)]]

submitFailingTx
( mkBasicTx $
mkBasicTxBody
& withdrawalsTxBodyL
.~ Withdrawals
[(rwdAccount1, zero)]
)
[injectFailure $ WithdrawalsNotInRewardsCERTS [(rwdAccount1, zero)]]
where
setupRewardAccount = do
cred <- KeyHashObj <$> freshKeyHash
ra <- registerStakeCredential cred
submitAndExpireProposalToMakeReward cred
rw <- lookupReward cred
pure (ra, rw)

0 comments on commit 094672b

Please sign in to comment.