Skip to content

Commit 954cecb

Browse files
committed
Trying to get the tests to pass
Reworked some messages when things fail. Removed some unused imports that were not necessary. Changed Test.Cardano.Ledger.Constrained.Conway.LedgerTypes.Specs, by changing conwayCertStateSpec to pass one component of PState through reify to DState and then pass one component of DState though reify to VState. This replaces the use of two exists. Made some small chages to MiniTrace. Added Witnessing the rng of a map that was ConwayAccountState. Added some Winessed instances that deal with AccountState type family and its instances.
1 parent a13c12b commit 954cecb

File tree

15 files changed

+236
-138
lines changed

15 files changed

+236
-138
lines changed

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/ImpTest.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ import Cardano.Ledger.BaseTypes (
149149
textToUrl,
150150
)
151151
import Cardano.Ledger.Coin (Coin (..))
152-
import Cardano.Ledger.Conway (ConwayEra, hardforkConwayBootstrapPhase)
153152
import Cardano.Ledger.Compactible (fromCompact)
153+
import Cardano.Ledger.Conway (ConwayEra, hardforkConwayBootstrapPhase)
154154
import Cardano.Ledger.Conway.Core
155155
import Cardano.Ledger.Conway.Genesis (ConwayGenesis (..))
156156
import Cardano.Ledger.Conway.Governance

libs/cardano-ledger-conformance/src/Test/Cardano/Ledger/Conformance/ExecSpecRule/Conway/Certs.hs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import Test.Cardano.Ledger.Conformance
2424
import Test.Cardano.Ledger.Conformance.ExecSpecRule.Conway.Base
2525
import Test.Cardano.Ledger.Conformance.ExecSpecRule.Conway.GovCert ()
2626
import Test.Cardano.Ledger.Constrained.Conway hiding (conwayCertStateSpec)
27-
import Test.Cardano.Ledger.Constrained.Conway.LedgerTypes.Specs
27+
import Test.Cardano.Ledger.Constrained.Conway.LedgerTypes.Specs (conwayCertStateSpec)
2828
import Test.Cardano.Ledger.Constrained.Conway.WitnessUniverse
2929
import Test.Cardano.Ledger.Imp.Common hiding (context)
3030

@@ -38,17 +38,9 @@ instance ExecSpecRule "CERTS" ConwayEra where
3838

3939
environmentSpec _ = certsEnvSpec
4040

41-
stateSpec (univ, context) _ =
41+
stateSpec (univ, _context) _ =
4242
conwayCertStateSpec univ (lit (EpochNo 100))
4343

44-
-- constrained $ \x ->
45-
-- match x $ \vstate pstate dstate ->
46-
-- [ satisfies vstate (vStateSpec @ConwayEra univ (ccecDelegatees context))
47-
-- , satisfies pstate (pStateSpec @ConwayEra univ)
48-
-- , -- temporary workaround because Spec does some extra tests, that the implementation does not, in the bootstrap phase.
49-
-- satisfies dstate (conwayDStateSpec univ (ccecDelegatees context) (ccecWithdrawals context))
50-
-- ]
51-
5244
signalSpec (univ, _) env state = txCertsSpec @ConwayEra univ env state
5345

5446
runAgdaRule env st sig = unComputationResult $ Agda.certsStep env st sig

libs/cardano-ledger-conformance/test/Test/Cardano/Ledger/Conformance/ExecSpecRule/MiniTrace.hs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ import Cardano.Ledger.Conway.Governance (
2222
import Cardano.Ledger.Conway.Rules (GovSignal (..))
2323
import Cardano.Ledger.Core
2424
import Constrained.API
25+
-- \| This is where most of the ExecSpecRule instances are defined
26+
27+
import Constrained.PrettyUtils (showType)
2528
import Control.State.Transition.Extended (STS (..))
2629
import qualified Data.List.NonEmpty as NE
2730
import qualified Data.Map.Strict as Map
2831
import qualified Data.OSet.Strict as OSet
2932
import Data.Proxy
3033
import Test.Cardano.Ledger.Common
3134
import Test.Cardano.Ledger.Conformance
32-
-- \| This is where most of the ExecSpecRule instances are defined
3335
import Test.Cardano.Ledger.Conformance.ExecSpecRule.Conway (
3436
nameCerts,
3537
nameDelegCert,
@@ -56,15 +58,17 @@ minitraceEither ::
5658
Int ->
5759
Gen (Either [String] [Signal (EraRule s e)])
5860
minitraceEither witrule n0 = do
59-
ctxt <- genExecContext @s @e
60-
env <- genFromSpec @(ExecEnvironment s e) (environmentSpec @s @e ctxt)
61+
!ctxt <- genExecContext @s @e
62+
63+
!env <- genFromSpec @(ExecEnvironment s e) (environmentSpec @s @e ctxt)
6164
let env2 :: Environment (EraRule s e)
6265
env2 = inject env
6366
!state0 <- genFromSpec @(ExecState s e) (stateSpec @s @e ctxt env)
67+
6468
let go :: State (EraRule s e) -> Int -> Gen (Either [String] [Signal (EraRule s e)])
6569
go _ 0 = pure (Right [])
6670
go state n = do
67-
signal <- genFromSpec @(ExecSignal s e) (signalSpec @s @e ctxt env state)
71+
!signal <- genFromSpec @(ExecSignal s e) (signalSpec @s @e ctxt env state)
6872
let signal2 :: Signal (EraRule s e)
6973
signal2 = inject signal
7074
goSTS @s @e @(Gen (Either [String] [Signal (EraRule s e)]))
@@ -169,12 +173,14 @@ spec = do
169173
prop
170174
"CERT"
171175
(withMaxSuccess 50 (minitraceProp (CERT Conway) 50 nameTxCert))
176+
172177
prop
173178
"CERTS"
174179
( withMaxSuccess
175180
50
176181
(minitraceProp (CERTS Conway) 50 nameCerts)
177182
)
183+
178184
prop
179185
"RATIFY"
180186
(withMaxSuccess 50 (minitraceProp (RATIFY Conway) 50 nameRatify))

libs/cardano-ledger-test/src/Test/Cardano/Ledger/Constrained/Conway/Certs.hs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@
1111
-- for the CERTS rule
1212
module Test.Cardano.Ledger.Constrained.Conway.Certs where
1313

14-
import Cardano.Ledger.Address (RewardAccount (..))
15-
import Cardano.Ledger.Coin (Coin (..))
14+
-- import Cardano.Ledger.Address (RewardAccount (..))
15+
-- import Cardano.Ledger.Coin (Coin (..))
1616
import Cardano.Ledger.Conway.Rules
1717
import Cardano.Ledger.Core
18-
import Cardano.Ledger.Credential (Credential (..), credKeyHash, credScriptHash)
18+
-- import Cardano.Ledger.Credential (Credential (..), credKeyHash, credScriptHash)
1919
import Cardano.Ledger.State
2020
import Constrained.API
2121
import Data.Foldable (toList)
22-
import Data.Map.Strict (Map)
22+
-- import Data.Map.Strict (Map)
2323
import Data.Sequence (Seq, fromList)
2424
import Data.Set (Set)
2525
import qualified Data.Set as Set
2626
import Test.Cardano.Ledger.Constrained.Conway.Cert
27-
import Test.Cardano.Ledger.Constrained.Conway.Deleg (
28-
hasGenDelegs,
29-
keyHashWdrl,
30-
)
27+
-- import Test.Cardano.Ledger.Constrained.Conway.Deleg (
28+
-- hasGenDelegs,
29+
-- keyHashWdrl,
30+
-- )
3131
import Test.Cardano.Ledger.Constrained.Conway.Instances
3232
import Test.Cardano.Ledger.Constrained.Conway.PParams (pparamsSpec)
33-
import Test.Cardano.Ledger.Constrained.Conway.ParametricSpec (EraSpecTxOut (..))
33+
-- import Test.Cardano.Ledger.Constrained.Conway.ParametricSpec (EraSpecTxOut (..))
3434
import Test.Cardano.Ledger.Constrained.Conway.WitnessUniverse
3535

3636
-- =======================================================

libs/cardano-ledger-test/src/Test/Cardano/Ledger/Constrained/Conway/Deleg.hs

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Cardano.Ledger.Address
1818
import Cardano.Ledger.Allegra (AllegraEra)
1919
import Cardano.Ledger.Alonzo (AlonzoEra)
2020
import Cardano.Ledger.Babbage (BabbageEra)
21-
import Cardano.Ledger.BaseTypes (StrictMaybe (..), maybeToStrictMaybe)
21+
import Cardano.Ledger.BaseTypes (StrictMaybe (..))
2222
import Cardano.Ledger.Coin
2323
import Cardano.Ledger.Compactible (fromCompact)
2424
import Cardano.Ledger.Conway (ConwayEra)
@@ -28,6 +28,7 @@ import Cardano.Ledger.Conway.TxCert
2828
import Cardano.Ledger.Core
2929
import Cardano.Ledger.Credential
3030
import Cardano.Ledger.Mary (MaryEra)
31+
import Cardano.Ledger.PoolParams (PoolParams (..))
3132
import Cardano.Ledger.Shelley (ShelleyEra)
3233
import Cardano.Ledger.Shelley.TxCert
3334
import Constrained.API
@@ -62,6 +63,7 @@ accountBalanceSpec balance =
6263
(3, constrained (const True))
6364
)
6465

66+
{-
6567
stakePoolDelegationPred ::
6668
Map (KeyHash 'StakePool) a ->
6769
Term (StrictMaybe (KeyHash 'StakePool)) ->
@@ -81,6 +83,8 @@ dRepDelegationPred dReps dRepDelegation =
8183
(branch (const True))
8284
(branch (dRepMembershipPred dReps))
8385
86+
-}
87+
8488
dRepMembershipPred :: Map (Credential 'DRepRole) a -> Term DRep -> Pred
8589
dRepMembershipPred dRepsMap dRep =
8690
assert $
@@ -90,8 +94,19 @@ dRepMembershipPred dRepsMap dRep =
9094
(branchW 1 $ const True)
9195
(branchW 1 $ const True)
9296
where
97+
dRepsSet :: Ord a => (Credential 'DRepRole -> Maybe a) -> Set a
9398
dRepsSet f = Set.fromList [k' | k <- Map.keys dRepsMap, Just k' <- [f k]]
9499

100+
-- | The DState needs a witnessed set of delegations to be usefull. Use this Spec to obtain a random one
101+
witnessedKeyHashPoolParamMapSpec ::
102+
Era era => WitUniv era -> Specification (Map (KeyHash StakePool) PoolParams)
103+
witnessedKeyHashPoolParamMapSpec univ =
104+
( constrained $ \keyPoolParamMap ->
105+
[witness univ (dom_ keyPoolParamMap), witness univ (rng_ keyPoolParamMap)]
106+
)
107+
108+
{- I don't think these are necessary
109+
95110
shelleyAccountStatePred ::
96111
Era era =>
97112
Map (KeyHash 'StakePool) a ->
@@ -175,13 +190,45 @@ conwayAccountsSpec ::
175190
conwayAccountsSpec univ stakePoolDelegations dRepDelegations =
176191
constrained $ \ [var|conwayAccountState|] ->
177192
match conwayAccountState $ \ [var|conwayAccountsMap|] ->
178-
[ witness univ (dom_ conwayAccountsMap)
193+
[ witness univ conwayAccountsMap
179194
, forAll conwayAccountsMap $ \ [var|accountPair|] ->
180195
match accountPair $ \ [var|cred|] [var|accountState|] ->
181196
reify (lookup_ cred stakePoolDelegations) maybeToStrictMaybe $ \stakePoolDelegationStrict ->
182197
reify (lookup_ cred dRepDelegations) maybeToStrictMaybe $ \dRepRepDelegationStrict ->
183198
conwayAccountStatePred'' stakePoolDelegationStrict dRepRepDelegationStrict accountState
184199
]
200+
-}
201+
202+
conwayAccountsSpec ::
203+
Era era =>
204+
WitUniv era ->
205+
Term (Map (KeyHash 'StakePool) PoolParams) ->
206+
Specification (ConwayAccounts era)
207+
conwayAccountsSpec univ poolreg = constrained $ \ [var|conwayAccounts|] ->
208+
match conwayAccounts $ \ [var|accountmap|] ->
209+
[ witness univ (dom_ accountmap)
210+
, forAll accountmap $ \ [var|pair|] ->
211+
match pair $ \ [var|stakecred|] [var|accountstate|] ->
212+
[ witness univ stakecred
213+
, witness univ accountstate
214+
, match accountstate $ \ [var|_rewardbal|] [var|_depositbal|] [var|mStakeDelegKeyhash|] [var|mDRep|] ->
215+
[ ( caseOn
216+
(mStakeDelegKeyhash :: Term (StrictMaybe (KeyHash 'StakePool)))
217+
(branchW 1 $ \_ -> True)
218+
(branchW 3 $ \ [var|stakekeyhash|] -> mapMember_ stakekeyhash poolreg)
219+
)
220+
, (caseOn mDRep) -- This case only adds frequency info, the (witness univ accountstate) ensures witnessing
221+
(branchW 1 $ \_ -> True)
222+
( branchW 3 $ \(drep :: Term DRep) ->
223+
(caseOn drep)
224+
(branchW 3 $ \_keyhash -> True)
225+
(branchW 3 $ \_scripthash -> True)
226+
(branchW 1 $ \_abstain -> True)
227+
(branchW 1 $ \_noconfidence -> True)
228+
)
229+
]
230+
]
231+
]
185232

186233
stakePoolDelegationsSpec ::
187234
Era era =>
@@ -206,19 +253,6 @@ dRepDelegationsSpec univ =
206253
(branchW 1 $ const True)
207254
]
208255

209-
conwayAccountsSpec' ::
210-
Era era =>
211-
WitUniv era ->
212-
Map (KeyHash 'StakePool) a ->
213-
Map (Credential 'DRepRole) b ->
214-
Specification (ConwayAccounts era)
215-
conwayAccountsSpec' univ stakePools dReps =
216-
constrained $ \ [var|conwayAccountState|] ->
217-
match conwayAccountState $ \ [var|conwayAccountsMap|] ->
218-
[ witness univ (dom_ conwayAccountsMap)
219-
, forAll (rng_ conwayAccountsMap) (conwayAccountStatePred stakePools dReps)
220-
]
221-
222256
dStateSpec ::
223257
(Era era, HasSpec (Accounts era), IsNormalType (Accounts era)) =>
224258
WitUniv era ->

libs/cardano-ledger-test/src/Test/Cardano/Ledger/Constrained/Conway/GovCert.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ vStateSpec ::
3939
Set (Credential 'DRepRole) ->
4040
Specification (VState era)
4141
vStateSpec univ delegatees = constrained $ \ [var|vstate|] ->
42-
match vstate $ \ [var|dreps|] [var|committeestate|] [var|_numdormant|] ->
42+
match vstate $ \ [var|dreps2|] [var|committeestate|] [var|_numdormant|] ->
4343
[ match committeestate $ \ [var|committeemap|] -> witness univ (dom_ committeemap)
44-
, assert $ dom_ dreps ==. lit delegatees -- TODO, there are missing constraints about the (rng_ dreps)
45-
, forAll dreps $ \ [var|pair|] ->
44+
, assert $ dom_ dreps2 ==. lit delegatees -- TODO, there are missing constraints about the (rng_ dreps)
45+
, forAll dreps2 $ \ [var|pair|] ->
4646
match pair $ \ [var|drep|] [var|drepstate|] ->
4747
[ dependsOn drepstate drep
4848
, witness univ drep

0 commit comments

Comments
 (0)