-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4630 from IntersectMBO/td/disallow-empty-withdrawals
Disallow empty withdrawals
- Loading branch information
Showing
13 changed files
with
227 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/CertsSpec.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
{-# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.