@@ -184,7 +184,7 @@ spec = do
184184 .~ [DelegTxCert cred (DelegStake poolKh)]
185185 )
186186 [injectFailure $ DelegateeStakePoolNotRegisteredDELEG poolKh]
187- expectNotDelegatedToPool cred
187+ expectNotDelegatedToAnyPool cred
188188
189189 describe " Delegate vote" $ do
190190 it " Delegate vote of registered stake credentials to registered drep" $ do
@@ -203,7 +203,7 @@ spec = do
203203 .~ [DelegTxCert cred (DelegVote (DRepCredential drepCred))]
204204
205205 expectDelegatedVote cred (DRepCredential drepCred)
206- expectNotDelegatedToPool cred
206+ expectNotDelegatedToAnyPool cred
207207 whenBootstrap $ do
208208 impAnn " Ensure DRep delegation is populated after bootstrap" $ do
209209 -- Clear out delegation, in order to check its repopulation from accounts.
@@ -223,6 +223,25 @@ spec = do
223223 getLastEnactedHardForkInitiation `shouldReturn` SJust (GovPurposeId gai)
224224 expectDelegatedVote cred (DRepCredential drepCred)
225225
226+ it " Redelegate vote to the same DRep" $ do
227+ expectedDeposit <- getsNES $ nesEsL . curPParamsEpochStateL . ppKeyDepositL
228+
229+ cred <- KeyHashObj <$> freshKeyHash
230+ drepCred <- KeyHashObj <$> registerDRep
231+
232+ submitTx_ $
233+ mkBasicTx mkBasicTxBody
234+ & bodyTxL . certsTxBodyL
235+ .~ [RegDepositDelegTxCert cred (DelegVote (DRepCredential drepCred)) expectedDeposit]
236+ expectDelegatedVote cred (DRepCredential drepCred)
237+
238+ submitTx_ $
239+ mkBasicTx mkBasicTxBody
240+ & bodyTxL . certsTxBodyL
241+ .~ [DelegTxCert cred (DelegVote (DRepCredential drepCred))]
242+
243+ expectDelegatedVote cred (DRepCredential drepCred)
244+
226245 it " Delegate vote of registered stake credentials to unregistered drep" $ do
227246 RewardAccount _ cred <- registerRewardAccount
228247 drepCred <- KeyHashObj <$> freshKeyHash
@@ -284,7 +303,13 @@ spec = do
284303 impAnn " Check that unregistration of previous delegation does not affect current delegation" $ do
285304 unRegisterDRep drepCred
286305 -- we need to preserve the buggy behavior until the boostrap phase is over.
287- ifBootstrap (expectNotDelegatedVote cred) (expectDelegatedVote cred (DRepCredential drepCred2))
306+ ifBootstrap
307+ ( do
308+ -- we cannot `expectNotDelegatedVote` because the the delegation is still in the DRepState of the other pool
309+ accounts <- getsNES $ nesEsL . esLStateL . lsCertStateL . certDStateL . accountsL
310+ expectNothingExpr (lookupDRepDelegation cred accounts)
311+ )
312+ (expectDelegatedVote cred (DRepCredential drepCred2))
288313
289314 it " Delegate vote and unregister stake credentials" $ do
290315 expectedDeposit <- getsNES $ nesEsL . curPParamsEpochStateL . ppKeyDepositL
@@ -300,6 +325,8 @@ spec = do
300325 .~ [UnRegDepositTxCert cred expectedDeposit]
301326 expectStakeCredNotRegistered cred
302327 expectNotDelegatedVote cred
328+ expectNotDelegatedToAnyPool cred
329+
303330 -- https://github.com/IntersectMBO/formal-ledger-specifications/issues/917
304331 -- TODO: Re-enable after issue is resolved, by removing this override
305332 disableInConformanceIt " Delegate vote and unregister after hardfork" $ do
@@ -412,9 +439,9 @@ spec = do
412439
413440 -- when pool is re-registered after its expiration, all delegations are cleared
414441 passNEpochs $ fromIntegral poolLifetime
415- expectNotDelegatedToPool cred
442+ expectNotDelegatedToAnyPool cred
416443 registerPoolWithRewardAccount poolKh rewardAccount
417- expectNotDelegatedToPool cred
444+ expectNotDelegatedToAnyPool cred
418445 -- the vote delegation is kept
419446 expectDelegatedVote cred (DRepCredential drepCred)
420447
@@ -502,6 +529,7 @@ spec = do
502529 & bodyTxL . certsTxBodyL
503530 .~ [DelegTxCert cred (DelegStake poolKh')]
504531 expectDelegatedToPool cred poolKh'
532+ expectNotDelegatedToPool cred poolKh
505533 expectDelegatedVote cred (DRepCredential drepCred)
506534 where
507535 expectDelegatedVote :: HasCallStack => Credential 'Staking -> DRep -> ImpTestM era ()
@@ -527,8 +555,12 @@ spec = do
527555 expectNotDelegatedVote :: Credential 'Staking -> ImpTestM era ()
528556 expectNotDelegatedVote cred = do
529557 accounts <- getsNES $ nesEsL . esLStateL . lsCertStateL . certDStateL . accountsL
530- impAnn (show cred <> " expected to not have their vote delegated" ) $
558+ dreps <- getsNES $ nesEsL . epochStateRegDrepL
559+ impAnn (show cred <> " expected to not have their vote delegated" ) $ do
531560 expectNothingExpr (lookupDRepDelegation cred accounts)
561+ assertBool
562+ (" Expected no drep state delegation to contain the stake credential: " <> show cred)
563+ (all (Set. notMember cred . drepDelegs) (Map. elems dreps))
532564
533565conwayEraSpecificSpec :: SpecWith (ImpInit (LedgerSpec ConwayEra ))
534566conwayEraSpecificSpec = do
0 commit comments