@@ -16,8 +16,14 @@ import Cardano.Ledger.BaseTypes
1616import Cardano.Ledger.Coin (Coin (Coin ))
1717import Cardano.Ledger.Credential (Credential (.. ))
1818import Cardano.Ledger.Shelley.Core
19+ import Cardano.Ledger.Shelley.Genesis
20+ import Cardano.Ledger.Shelley.LedgerState
1921import Cardano.Ledger.Shelley.Rules
2022import Cardano.Ledger.Shelley.Scripts
23+ import Cardano.Ledger.Shelley.State (ShelleyEraAccounts )
24+ import Cardano.Ledger.Shelley.Transition (shelleyRegisterInitialAccounts )
25+ import Cardano.Ledger.State (accountsL , accountsMapL , stakePoolDelegationAccountStateL )
26+ import qualified Data.ListMap as LM
2127import qualified Data.Map.Strict as Map
2228import Lens.Micro
2329import Test.Cardano.Ledger.Imp.Common
@@ -26,6 +32,7 @@ import Test.Cardano.Ledger.Shelley.ImpTest
2632
2733shelleyEraSpecificSpec ::
2834 ( ShelleyEraImp era
35+ , ShelleyEraAccounts era
2936 , InjectRuleFailure " LEDGER" ShelleyDelegsPredFailure era
3037 ) =>
3138 SpecWith (ImpInit (LedgerSpec era ))
@@ -100,6 +107,34 @@ shelleyEraSpecificSpec = do
100107 getBalance otherStakeCred `shouldReturn` Coin 0
101108 expectNotRegisteredRewardAddress rewardAccount
102109
110+ it " Transition creates the delegations correctly" $ do
111+ pool1 <- freshKeyHash >>= \ kh -> kh <$ registerPool kh
112+ pool2 <- freshKeyHash >>= \ kh -> kh <$ registerPool kh
113+ pool3 <- freshKeyHash >>= \ kh -> kh <$ registerPool kh
114+ poolParams <- freshKeyHash >>= \ kh -> registerRewardAccount >>= freshPoolParams kh
115+ deleg1 <- freshKeyHash >>= \ kh -> kh <$ registerStakeCredential (KeyHashObj kh)
116+ deleg2 <- freshKeyHash >>= \ kh -> kh <$ registerStakeCredential (KeyHashObj kh)
117+ deleg3 <- freshKeyHash >>= \ kh -> kh <$ registerStakeCredential (KeyHashObj kh)
118+ nes <- getsNES id
119+ let sgs =
120+ ShelleyGenesisStaking
121+ { sgsPools = LM. ListMap [(pool1, poolParams), (pool2, poolParams), (pool3, poolParams)]
122+ , sgsStake = LM. ListMap [(deleg1, pool1), (deleg2, pool1), (deleg3, pool2)]
123+ }
124+ let updatedNES = shelleyRegisterInitialAccounts sgs nes
125+ delegateStake (KeyHashObj deleg1) pool1
126+ delegateStake (KeyHashObj deleg2) pool1
127+ delegateStake (KeyHashObj deleg3) pool2
128+ getPoolsState <$> (getsNES id ) `shouldReturn` getPoolsState updatedNES
129+ getDelegs deleg1 updatedNES `shouldReturn` Just pool1
130+ getDelegs deleg2 updatedNES `shouldReturn` Just pool1
131+ getDelegs deleg3 updatedNES `shouldReturn` Just pool2
132+ where
133+ getDelegs kh nes = do
134+ let accounts = nes ^. nesEsL . esLStateL . lsCertStateL . certDStateL . accountsL . accountsMapL
135+ pure $ Map. lookup (KeyHashObj kh) accounts >>= (^. stakePoolDelegationAccountStateL)
136+ getPoolsState nes = nes ^. nesEsL . esLStateL . lsCertStateL . certPStateL . psStakePoolsL
137+
103138spec ::
104139 ShelleyEraImp era =>
105140 SpecWith (ImpInit (LedgerSpec era ))
0 commit comments