|
5 | 5 | {-# LANGUAGE OverloadedStrings #-} |
6 | 6 | {-# LANGUAGE RankNTypes #-} |
7 | 7 | {-# LANGUAGE ScopedTypeVariables #-} |
| 8 | +{-# LANGUAGE TypeApplications #-} |
8 | 9 | {-# LANGUAGE TypeFamilies #-} |
9 | 10 |
|
10 | 11 | module Test.Cardano.Ledger.Conway.Imp.DelegSpec ( |
11 | 12 | spec, |
12 | 13 | ) where |
13 | 14 |
|
14 | 15 | import Cardano.Ledger.Address (RewardAccount (..)) |
15 | | -import Cardano.Ledger.BaseTypes (EpochInterval (..), StrictMaybe (..), addEpochInterval) |
| 16 | +import Cardano.Ledger.BaseTypes ( |
| 17 | + EpochInterval (..), |
| 18 | + ProtVer (..), |
| 19 | + StrictMaybe (..), |
| 20 | + addEpochInterval, |
| 21 | + natVersion, |
| 22 | + ) |
16 | 23 | import Cardano.Ledger.Coin (Coin (..)) |
17 | 24 | import Cardano.Ledger.Conway.Core |
18 | 25 | import Cardano.Ledger.Conway.Governance |
@@ -477,6 +484,83 @@ spec = do |
477 | 484 | .~ [UnRegDepositTxCert cred expectedDeposit] |
478 | 485 | expectNotRegistered cred |
479 | 486 | expectNotDelegatedVote cred |
| 487 | + disableImpInitExpectLedgerRuleConformance $ |
| 488 | + it "Delegate vote and unregister after hardfork" $ do |
| 489 | + let |
| 490 | + bootstrapVer = ProtVer (natVersion @9) 0 |
| 491 | + setProtVer pv = modifyNES $ nesEsL . curPParamsEpochStateL . ppProtocolVersionL .~ pv |
| 492 | + initialProtVer <- getProtVer |
| 493 | + (_, ccCred, _) <- impAnn "Set up a committee" $ do |
| 494 | + -- Temporarily set protver to 10 to elect a committee |
| 495 | + setProtVer $ ProtVer (natVersion @10) 0 |
| 496 | + res <- electBasicCommittee |
| 497 | + setProtVer initialProtVer |
| 498 | + pure res |
| 499 | + (khSPO, _, _) <- setupPoolWithStake $ Coin 10_000_000 |
| 500 | + -- Using an irrefutable pattern here to prevent evaluation of tuple |
| 501 | + -- unless we actually need a value from it |
| 502 | + ~(drepCred, _, _) <- |
| 503 | + if initialProtVer > bootstrapVer |
| 504 | + then setupSingleDRep 100_000_000 |
| 505 | + else pure $ error "drepCred should not be accessed before protver 10" |
| 506 | + passNEpochs 3 |
| 507 | + expectedDeposit <- getsNES $ nesEsL . curPParamsEpochStateL . ppKeyDepositL |
| 508 | + cred <- KeyHashObj <$> freshKeyHash |
| 509 | + submitTx_ $ |
| 510 | + mkBasicTx mkBasicTxBody |
| 511 | + & bodyTxL . certsTxBodyL |
| 512 | + .~ [RegDepositDelegTxCert cred (DelegVote DRepAlwaysAbstain) expectedDeposit] |
| 513 | + registerAndRetirePoolToMakeReward cred |
| 514 | + expectRegistered cred |
| 515 | + expectDelegatedVote cred DRepAlwaysAbstain |
| 516 | + impAnn "Version should be unchanged" $ |
| 517 | + getProtVer `shouldReturn` initialProtVer |
| 518 | + let nextVer = majorFollow initialProtVer |
| 519 | + hfGaid <- submitGovAction $ HardForkInitiation SNothing nextVer |
| 520 | + submitVote_ VoteYes (StakePoolVoter khSPO) hfGaid |
| 521 | + submitVote_ VoteYes (CommitteeVoter ccCred) hfGaid |
| 522 | + when (initialProtVer > bootstrapVer) $ |
| 523 | + submitVote_ VoteYes (DRepVoter drepCred) hfGaid |
| 524 | + passNEpochs 3 |
| 525 | + logRatificationChecks hfGaid |
| 526 | + impAnn "Version should be bumped" $ |
| 527 | + getProtVer `shouldReturn` nextVer |
| 528 | + withdrawalAmount <- getsPParams ppPoolDepositL |
| 529 | + rewardAccount <- getRewardAccountFor cred |
| 530 | + submitTx_ $ |
| 531 | + mkBasicTx mkBasicTxBody |
| 532 | + & bodyTxL . certsTxBodyL .~ [UnRegTxCert cred] |
| 533 | + & bodyTxL . withdrawalsTxBodyL |
| 534 | + .~ Withdrawals (Map.singleton rewardAccount withdrawalAmount) |
| 535 | + expectNotRegistered cred |
| 536 | + expectNotDelegatedVote cred |
| 537 | + it "Delegate vote and undelegate after delegating to some stake pools" $ do |
| 538 | + (khSPO, _, _) <- setupPoolWithStake $ Coin 1_000_000 |
| 539 | + expectedDeposit <- getsNES $ nesEsL . curPParamsEpochStateL . ppKeyDepositL |
| 540 | + cred <- KeyHashObj <$> freshKeyHash |
| 541 | + submitTx_ $ |
| 542 | + mkBasicTx mkBasicTxBody |
| 543 | + & bodyTxL . certsTxBodyL |
| 544 | + .~ [RegDepositDelegTxCert cred (DelegVote DRepAlwaysAbstain) expectedDeposit] |
| 545 | + registerAndRetirePoolToMakeReward cred |
| 546 | + expectRegistered cred |
| 547 | + expectDelegatedVote cred DRepAlwaysAbstain |
| 548 | + forM_ @[] [1 .. 3 :: Int] $ \_ -> do |
| 549 | + submitTx_ $ |
| 550 | + mkBasicTx mkBasicTxBody |
| 551 | + & bodyTxL . certsTxBodyL |
| 552 | + .~ [DelegTxCert cred (DelegStake khSPO)] |
| 553 | + passNEpochs 3 |
| 554 | + withdrawalAmount <- getsPParams ppPoolDepositL |
| 555 | + rewardAccount <- getRewardAccountFor cred |
| 556 | + submitTx_ $ |
| 557 | + mkBasicTx mkBasicTxBody |
| 558 | + & bodyTxL . certsTxBodyL |
| 559 | + .~ [UnRegTxCert cred] |
| 560 | + & bodyTxL . withdrawalsTxBodyL |
| 561 | + .~ Withdrawals (Map.singleton rewardAccount withdrawalAmount) |
| 562 | + expectNotRegistered cred |
| 563 | + expectNotDelegatedVote cred |
480 | 564 |
|
481 | 565 | describe "Delegate both stake and vote - separated out for conformance mismatch" $ |
482 | 566 | -- https://github.com/IntersectMBO/formal-ledger-specifications/issues/640 |
|
0 commit comments