Skip to content

Commit e358c21

Browse files
committed
[wip] - DelegSpec updates
1 parent e14a6cd commit e358c21

File tree

1 file changed

+52
-6
lines changed
  • eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp

1 file changed

+52
-6
lines changed

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/DelegSpec.hs

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,32 @@ spec = do
467467
impAnn "Check that unregistration of previous delegation does not affect current delegation" $ do
468468
unRegisterDRep drepCred
469469
-- we need to preserve the buggy behavior until the boostrap phase is over.
470-
ifBootstrap (expectNotDelegatedVote cred) (expectDelegatedVote cred (DRepCredential drepCred2))
470+
ifBootstrap
471+
( do
472+
-- we cannot `expectNotDelegatedVote` because the the delegation is still in the DRepState of the other pool
473+
accounts <- getsNES $ nesEsL . esLStateL . lsCertStateL . certDStateL . accountsL
474+
expectNothingExpr (lookupDRepDelegation cred accounts)
475+
)
476+
(expectDelegatedVote cred (DRepCredential drepCred2))
477+
478+
it "Redelegate vote to the same DRep" $ do
479+
expectedDeposit <- getsNES $ nesEsL . curPParamsEpochStateL . ppKeyDepositL
480+
481+
cred <- KeyHashObj <$> freshKeyHash
482+
drepCred <- KeyHashObj <$> registerDRep
483+
484+
submitTx_ $
485+
mkBasicTx mkBasicTxBody
486+
& bodyTxL . certsTxBodyL
487+
.~ [RegDepositDelegTxCert cred (DelegVote (DRepCredential drepCred)) expectedDeposit]
488+
expectDelegatedVote cred (DRepCredential drepCred)
489+
490+
submitTx_ $
491+
mkBasicTx mkBasicTxBody
492+
& bodyTxL . certsTxBodyL
493+
.~ [DelegTxCert cred (DelegVote (DRepCredential drepCred))]
494+
495+
expectDelegatedVote cred (DRepCredential drepCred)
471496

472497
it "Delegate vote and unregister stake credentials" $ do
473498
expectedDeposit <- getsNES $ nesEsL . curPParamsEpochStateL . ppKeyDepositL
@@ -658,6 +683,8 @@ spec = do
658683
& bodyTxL . certsTxBodyL
659684
.~ [UnRegDepositTxCert cred expectedDeposit]
660685
expectNotRegistered cred
686+
expectNotDelegatedVote cred
687+
expectNotDelegatedToPool cred
661688

662689
it "Delegate to DRep and SPO and change delegation to a different SPO" $ do
663690
expectedDeposit <- getsNES $ nesEsL . curPParamsEpochStateL . ppKeyDepositL
@@ -695,10 +722,15 @@ spec = do
695722

696723
expectNotDelegatedToPool :: Credential 'Staking -> ImpTestM era ()
697724
expectNotDelegatedToPool cred = do
698-
accounts <- getsNES $ nesEsL . esLStateL . lsCertStateL . certDStateL . accountsL
725+
certState <- getsNES $ nesEsL . esLStateL . lsCertStateL
726+
let accounts = certState ^. certDStateL . accountsL
727+
let pools = certState ^. certPStateL . psStakePoolsL
699728
impAnn (show cred <> " expected to not have delegated to a stake pool") $ do
700-
accountState <- expectJust $ lookupAccountState cred accounts
701-
expectNothingExpr (accountState ^. stakePoolDelegationAccountStateL)
729+
forM_ (lookupAccountState cred accounts) $ \accountState ->
730+
expectNothingExpr (accountState ^. stakePoolDelegationAccountStateL)
731+
assertBool
732+
("Expected no stake pool state delegation to contain the stake credential: " <> show cred)
733+
(all (Set.notMember cred . spsDelegs) (Map.elems pools))
702734

703735
expectDelegatedVote :: HasCallStack => Credential 'Staking -> DRep -> ImpTestM era ()
704736
expectDelegatedVote cred drep = do
@@ -723,8 +755,12 @@ spec = do
723755
expectNotDelegatedVote :: Credential 'Staking -> ImpTestM era ()
724756
expectNotDelegatedVote cred = do
725757
accounts <- getsNES $ nesEsL . esLStateL . lsCertStateL . certDStateL . accountsL
726-
impAnn (show cred <> " expected to not have their vote delegated") $
758+
dreps <- getsNES $ nesEsL . epochStateRegDrepL
759+
impAnn (show cred <> " expected to not have their vote delegated") $ do
727760
expectNothingExpr (lookupDRepDelegation cred accounts)
761+
assertBool
762+
("Expected no drep state delegation to contain the stake credential: " <> show cred)
763+
(all (Set.notMember cred . drepDelegs) (Map.elems dreps))
728764

729765
conwayEraSpecificSpec :: SpecWith (ImpInit (LedgerSpec ConwayEra))
730766
conwayEraSpecificSpec = do
@@ -764,7 +800,17 @@ expectRegistered cred = do
764800
expectDelegatedToPool ::
765801
(HasCallStack, ConwayEraImp era) => Credential 'Staking -> KeyHash 'StakePool -> ImpTestM era ()
766802
expectDelegatedToPool cred poolKh = do
767-
accounts <- getsNES $ nesEsL . esLStateL . lsCertStateL . certDStateL . accountsL
803+
certState <- getsNES $ nesEsL . esLStateL . lsCertStateL
804+
let accounts = certState ^. certDStateL . accountsL
805+
let pools = certState ^. certPStateL . psStakePoolsL
768806
impAnn (show cred <> " expected to have delegated to " <> show poolKh) $ do
769807
accountState <- expectJust $ lookupAccountState cred accounts
770808
accountState ^. stakePoolDelegationAccountStateL `shouldBe` Just poolKh
809+
case Map.lookup poolKh pools of
810+
Nothing ->
811+
assertFailure $
812+
"Expected stake pool state for: " <> show poolKh
813+
Just poolState ->
814+
assertBool
815+
("Expected pool delegations to contain the stake credential: " <> show cred)
816+
(cred `Set.member` (poolState ^. spsDelegsL))

0 commit comments

Comments
 (0)