|
| 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