Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a test #4888

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeApplications #-}

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

import Cardano.Ledger.Address (RewardAccount (..))
import Cardano.Ledger.BaseTypes (EpochInterval (..), StrictMaybe (..), addEpochInterval)
import Cardano.Ledger.BaseTypes (EpochInterval (..), StrictMaybe (..), addEpochInterval, ProtVer (..), mkVersion)
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Conway.Core
import Cardano.Ledger.Conway.Governance
Expand All @@ -36,6 +37,7 @@ import Test.Cardano.Ledger.Conway.Arbitrary ()
import Test.Cardano.Ledger.Conway.ImpTest
import Test.Cardano.Ledger.Imp.Common
import Test.Cardano.Ledger.Plutus.Examples (evenRedeemerNoDatum)
import Data.Maybe (fromJust)

spec ::
forall era.
Expand Down Expand Up @@ -477,6 +479,66 @@ spec = do
.~ [UnRegDepositTxCert cred expectedDeposit]
expectNotRegistered cred
expectNotDelegatedVote cred
disableImpInitExpectLedgerRuleConformance $
it "Delegate vote and unregister after hardfork" $ do
(_, ccCred, _) <- electBasicCommittee
let bootstrapVer = ProtVer (fromJust $ mkVersion @Int 9) 0
setProtVer bootstrapVer
(khSPO, _, _) <- setupPoolWithStake $ Coin 10_000_000
passNEpochs 3
expectedDeposit <- getsNES $ nesEsL . curPParamsEpochStateL . ppKeyDepositL
cred <- KeyHashObj <$> freshKeyHash
submitTx_ $
mkBasicTx mkBasicTxBody
& bodyTxL . certsTxBodyL
.~ [RegDepositDelegTxCert cred (DelegVote DRepAlwaysAbstain) expectedDeposit]
registerAndRetirePoolToMakeReward cred
expectRegistered cred
expectDelegatedVote cred DRepAlwaysAbstain
getProtVer `shouldReturn` bootstrapVer
let postBootstrapVer = ProtVer (fromJust $ mkVersion @Int 10) 0
hfGaid <- submitGovAction $ HardForkInitiation SNothing postBootstrapVer
submitVote_ VoteYes (StakePoolVoter khSPO) hfGaid
submitVote_ VoteYes (CommitteeVoter ccCred) hfGaid
passNEpochs 3
getProtVer `shouldReturn` postBootstrapVer
withdrawalAmount <- getsPParams ppPoolDepositL
rewardAccount <- getRewardAccountFor cred
submitTx_ $
mkBasicTx mkBasicTxBody
& bodyTxL . certsTxBodyL
.~ [UnRegTxCert cred]
& bodyTxL . withdrawalsTxBodyL
.~ Withdrawals (Map.singleton rewardAccount withdrawalAmount)
expectNotRegistered cred
expectNotDelegatedVote cred
it "Delegate vote and undelegate after delegating to some stake pools" $ do
(khSPO, _, _) <- setupPoolWithStake $ Coin 1_000_000
expectedDeposit <- getsNES $ nesEsL . curPParamsEpochStateL . ppKeyDepositL
cred <- KeyHashObj <$> freshKeyHash
submitTx_ $
mkBasicTx mkBasicTxBody
& bodyTxL . certsTxBodyL
.~ [RegDepositDelegTxCert cred (DelegVote DRepAlwaysAbstain) expectedDeposit]
registerAndRetirePoolToMakeReward cred
expectRegistered cred
expectDelegatedVote cred DRepAlwaysAbstain
forM_ @[] [1..3 :: Int] $ \_ -> do
submitTx_ $
mkBasicTx mkBasicTxBody
& bodyTxL . certsTxBodyL
.~ [DelegTxCert cred (DelegStake khSPO)]
passNEpochs 3
withdrawalAmount <- getsPParams ppPoolDepositL
rewardAccount <- getRewardAccountFor cred
submitTx_ $
mkBasicTx mkBasicTxBody
& bodyTxL . certsTxBodyL
.~ [UnRegTxCert cred]
& bodyTxL . withdrawalsTxBodyL
.~ Withdrawals (Map.singleton rewardAccount withdrawalAmount)
expectNotRegistered cred
expectNotDelegatedVote cred

describe "Delegate both stake and vote - separated out for conformance mismatch" $
-- https://github.com/IntersectMBO/formal-ledger-specifications/issues/640
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module Test.Cardano.Ledger.Shelley.ImpTest (
trySubmitTx,
modifyNES,
getProtVer,
setProtVer,
getsNES,
getUTxO,
impAddNativeScript,
Expand Down Expand Up @@ -1442,6 +1443,10 @@ getUTxO = getsNES utxoL
getProtVer :: EraGov era => ImpTestM era ProtVer
getProtVer = getsNES $ nesEsL . curPParamsEpochStateL . ppProtocolVersionL

setProtVer :: EraGov era => ProtVer -> ImpTestM era ()
setProtVer pv = modifyNES $
nesEsL . curPParamsEpochStateL . ppProtocolVersionL .~ pv

submitTxAnn ::
(HasCallStack, ShelleyEraImp era) =>
String ->
Expand Down
Loading