Skip to content

Commit

Permalink
Fixed the CERTS rule generators for differences bewteen implementatio…
Browse files Browse the repository at this point in the history
…n and spec.

Added Minitrace CERTS tests.
Added fixup on CERTS conformance tests, because Spec zeros out rewards for withdrawals, and the Haskell code does not.
  • Loading branch information
TimSheard committed Sep 6, 2024
1 parent e7be63c commit d95682d
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ genNextDelta
vkeyPairs
(mkScriptWits @era msigPairs mempty)
(hashAnnotated txBody)
pure
pure $
delta
{ extraWitnesses = extraWitnesses <> newWits
, extraInputs = extraInputs <> Set.fromList inputs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,10 @@ inputsGenerateWithin timeout =
where
aName = show (typeRep $ Proxy @rule)

-- | Translate a Haksell type 'a' whose translation context is 'ctx' into its Agda type, in the ImpTest monad.
-- | Translate a Haskell type 'a' whose translation context is 'ctx' into its Agda type, in the ImpTest monad.
translateWithContext :: SpecTranslate ctx a => ctx -> a -> ImpTestM era (SpecRep a)
translateWithContext ctx x = do
let
expectRight' (Right y) = pure y
expectRight' (Left e) = assertFailure (T.unpack e)
ans <- expectRight' . runSpecTransM ctx $ toSpecRep x
pure ans
expectRight' . runSpecTransM ctx $ toSpecRep x
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ spec = do
prop "POOL" $ conformsToImpl @"POOL" @ConwayFn @Conway
prop "CERT" $ conformsToImpl @"CERT" @ConwayFn @Conway
prop "CERTS" $ conformsToImpl @"CERTS" @ConwayFn @Conway
prop "GOV" $ conformsToImpl @"GOV" @ConwayFn @Conway
-- FIX ME when the order of proposals is sorted correctly
-- PR 4584 change (xprop "GOV") to (prop "GOV")
xprop "GOV" $ conformsToImpl @"GOV" @ConwayFn @Conway

xprop "UTXO" $ conformsToImpl @"UTXO" @ConwayFn @Conway
describe "ImpTests" $ do
RatifyImp.spec
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ certEnvSpec ::
Specification fn (CertEnv (ConwayEra StandardCrypto))
certEnvSpec =
constrained $ \ce ->
match ce $ \_slot pp _currEpoch _currCommittee proposals ->
match ce $ \_slot pp _currEpoch _currCommittee _proposals ->
[ satisfies pp pparamsSpec
, assert $ genHint 0 proposals
]

certStateSpec ::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
module Test.Cardano.Ledger.Constrained.Conway.Certs where

import Cardano.Ledger.Alonzo.Tx (AlonzoTx (..), IsValid (..))
import Cardano.Ledger.BaseTypes (Network (..), StrictMaybe (..))
import Cardano.Ledger.BaseTypes (Network (..))
import Cardano.Ledger.CertState
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Conway (Conway)
Expand Down Expand Up @@ -105,11 +105,10 @@ certsEnvSpec ::
IsConwayUniv fn =>
Specification fn (CertsEnv Conway)
certsEnvSpec = constrained $ \ce ->
match ce $ \tx pp _ _ a b ->
match ce $ \tx pp _slot _currepoch _currcommittee commproposals ->
[ satisfies pp pparamsSpec
, assert $ tx ==. lit txZero
, assert $ a ==. lit SNothing
, assert $ sizeOf_ b ==. 0
, genHint 3 commproposals
]

-- | Project a CertEnv out of a CertsEnv (i.e drop the Tx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
-- for the GOVCERT rule
module Test.Cardano.Ledger.Constrained.Conway.GovCert where

import Cardano.Ledger.BaseTypes (EpochNo (..))
import Cardano.Ledger.CertState
import Cardano.Ledger.Conway (ConwayEra)
import Cardano.Ledger.Conway.Governance
Expand All @@ -23,13 +22,19 @@ import Lens.Micro
import Test.Cardano.Ledger.Constrained.Conway.Instances
import Test.Cardano.Ledger.Constrained.Conway.PParams

vStateSpec :: Specification fn (VState (ConwayEra StandardCrypto))
vStateSpec = TrueSpec

{- There are no hard constraints on VState, but sometimes when something fails we want to
-- limit how big some of the fields of VState are. In that case one might use something
-- like this. Note that genHint limits the size, but does not require an exact size.
vStateSpec :: IsConwayUniv fn => Specification fn (VState (ConwayEra StandardCrypto))
-- vStateSpec = TrueSpec
vStateSpec = constrained' $ \x y z ->
[ assert $ sizeOf_ x ==. 1
, match y $ \cs -> assert $ sizeOf_ cs ==. 1
, assert $ z ==. lit (EpochNo 4)
vStateSpec = constrained' $ \ [var|_dreps|] [var|_commstate|] [var|dormantepochs|] ->
[ genHint 5 dreps -- assert $ sizeOf_ dreps >=. 1
, match commstate $ \ [var|committeestate|] -> genHint 5 committeestate
, assert $ dormantepochs >=. lit (EpochNo 4)
]
-}

govCertSpec ::
IsConwayUniv fn =>
Expand Down Expand Up @@ -65,7 +70,7 @@ govCertSpec ConwayGovCertEnv {..} vs =
assert $ elem_ (pair_ credUnreg coinUnreg) (lit (Map.toList deposits))
)
-- ConwayUpdateDRep
( branchW 1 $ \keyupdate _ ->
( branchW 1 $ \ [var|keyupdate|] _ ->
member_ keyupdate reps
)
-- ConwayAuthCommitteeHotKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ pStateSpec ::
Specification fn (PState (ConwayEra StandardCrypto))
pStateSpec = constrained $ \ps ->
match ps $ \stakePoolParams futureStakePoolParams retiring deposits ->
[ assert $ sizeOf_ stakePoolParams ==. lit 3
, assert $ sizeOf_ futureStakePoolParams ==. lit 1
, assertExplain (pure "dom of retiring is a subset of dom of stakePoolParams") $
[ assertExplain (pure "dom of retiring is a subset of dom of stakePoolParams") $
dom_ retiring `subset_` dom_ stakePoolParams
, assertExplain (pure "dom of deposits is dom of stakePoolParams") $
dom_ deposits ==. dom_ stakePoolParams
Expand Down
10 changes: 7 additions & 3 deletions libs/cardano-ledger-test/src/Test/Cardano/Ledger/STS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ stsPropertyV2 specEnv specState specSig prop =
pure $ case res of
Left pfailures -> counterexample (show $ prettyA pfailures) $ property False
Right st' ->
counterexample (show $ ppString "st' = " <> prettyA st') $
conformsToSpec @fn st' (specState env)
.&&. prop env st sig st'
counterexample
( show $
ppString "st' = "
<> prettyA st'
<> ppString ("\nspec = \n" ++ show (specState env))
)
$ conformsToSpec @fn st' (specState env) .&&. prop env st sig st'

-- STS properties ---------------------------------------------------------

Expand Down

0 comments on commit d95682d

Please sign in to comment.