@@ -28,15 +28,18 @@ import Cardano.Ledger.Conway.Core
2828import Cardano.Ledger.Conway.Governance
2929import Cardano.Ledger.Conway.Rules (ConwayDelegPredFailure (.. ))
3030import Cardano.Ledger.Conway.State hiding (balance )
31+ import Cardano.Ledger.Conway.Transition (conwayRegisterInitialAccounts )
3132import Cardano.Ledger.Conway.TxCert
3233import Cardano.Ledger.Credential (Credential (.. ))
3334import Cardano.Ledger.DRep
3435import Cardano.Ledger.Plutus (
3536 SLanguage (.. ),
3637 hashPlutusScript ,
3738 )
39+ import Cardano.Ledger.Shelley.Genesis (ShelleyGenesisStaking (.. ))
3840import Cardano.Ledger.Shelley.LedgerState
3941import Cardano.Ledger.Val (Val (.. ))
42+ import qualified Data.ListMap as LM
4043import qualified Data.Map.Strict as Map
4144import qualified Data.Sequence.Strict as SSeq
4245import qualified Data.Set as Set
@@ -531,6 +534,29 @@ spec = do
531534 expectDelegatedToPool cred poolKh'
532535 expectNotDelegatedToPool cred poolKh
533536 expectDelegatedVote cred (DRepCredential drepCred)
537+
538+ it " Transition creates the delegations correctly" $ do
539+ pool1 <- freshKeyHash >>= \ kh -> kh <$ registerPool kh
540+ pool2 <- freshKeyHash >>= \ kh -> kh <$ registerPool kh
541+ pool3 <- freshKeyHash >>= \ kh -> kh <$ registerPool kh
542+ poolParams <- freshKeyHash >>= \ kh -> registerRewardAccount >>= freshPoolParams kh
543+ deleg1 <- freshKeyHash >>= \ kh -> kh <$ registerStakeCredential (KeyHashObj kh)
544+ deleg2 <- freshKeyHash >>= \ kh -> kh <$ registerStakeCredential (KeyHashObj kh)
545+ deleg3 <- freshKeyHash >>= \ kh -> kh <$ registerStakeCredential (KeyHashObj kh)
546+ nes <- getsNES id
547+ let sgs =
548+ ShelleyGenesisStaking
549+ { sgsPools = LM. ListMap [(pool1, poolParams), (pool2, poolParams), (pool3, poolParams)]
550+ , sgsStake = LM. ListMap [(deleg1, pool1), (deleg2, pool1), (deleg3, pool2)]
551+ }
552+ let updatedNES = conwayRegisterInitialAccounts sgs nes
553+ delegateStake (KeyHashObj deleg1) pool1
554+ delegateStake (KeyHashObj deleg2) pool1
555+ delegateStake (KeyHashObj deleg3) pool2
556+ getPoolsState <$> (getsNES id ) `shouldReturn` getPoolsState updatedNES
557+ getDelegs deleg1 updatedNES `shouldReturn` Just pool1
558+ getDelegs deleg2 updatedNES `shouldReturn` Just pool1
559+ getDelegs deleg3 updatedNES `shouldReturn` Just pool2
534560 where
535561 expectDelegatedVote :: HasCallStack => Credential 'Staking -> DRep -> ImpTestM era ()
536562 expectDelegatedVote cred drep = do
@@ -561,6 +587,10 @@ spec = do
561587 assertBool
562588 (" Expected no drep state delegation to contain the stake credential: " <> show cred)
563589 (all (Set. notMember cred . drepDelegs) (Map. elems dreps))
590+ getDelegs kh nes = do
591+ let accounts = nes ^. nesEsL . esLStateL . lsCertStateL . certDStateL . accountsL . accountsMapL
592+ pure $ Map. lookup (KeyHashObj kh) accounts >>= (^. stakePoolDelegationAccountStateL)
593+ getPoolsState nes = nes ^. nesEsL . esLStateL . lsCertStateL . certPStateL . psStakePoolsL
564594
565595conwayEraSpecificSpec :: SpecWith (ImpInit (LedgerSpec ConwayEra ))
566596conwayEraSpecificSpec = do
0 commit comments