Skip to content

Commit 2d1e94c

Browse files
Dependency injection to split up more of the big balls of hair in
constrained-generators
1 parent 25876dc commit 2d1e94c

File tree

25 files changed

+750
-616
lines changed

25 files changed

+750
-616
lines changed

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import Test.Cardano.Ledger.Conway.Arbitrary ()
4545

4646
import Cardano.Ledger.Conway (ConwayEra)
4747
import Constrained.API (
48-
Specification (..),
4948
assert,
5049
constrained,
5150
constrained',
@@ -119,7 +118,7 @@ instance ExecSpecRule "LEDGER" ConwayEra where
119118

120119
genExecContext = do
121120
ctx <- arbitrary
122-
env <- genFromSpec TrueSpec
121+
env <- genFromSpec mempty
123122
ConwayLedgerExecContext
124123
<$> arbitrary
125124
<*> genFromSpec (enactStateSpec ctx env)

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module Test.Cardano.Ledger.Conformance.ExecSpecRule.Conway.Ledgers () where
1010

1111
import Cardano.Ledger.Conway (ConwayEra)
1212
import Cardano.Ledger.Conway.Governance (EnactState)
13-
import Constrained.API (Specification (..))
13+
import Constrained.API ()
1414
import qualified MAlonzo.Code.Ledger.Foreign.API as Agda
1515
import Test.Cardano.Ledger.Conformance (
1616
ExecSpecRule (..),
@@ -21,7 +21,7 @@ import Test.Cardano.Ledger.Conformance.SpecTranslate.Conway ()
2121
instance ExecSpecRule "LEDGERS" ConwayEra where
2222
type ExecContext "LEDGERS" ConwayEra = EnactState ConwayEra
2323

24-
environmentSpec _ = TrueSpec
25-
stateSpec _ _ = TrueSpec
26-
signalSpec _ _ _ = TrueSpec
24+
environmentSpec _ = mempty
25+
stateSpec _ _ = mempty
26+
signalSpec _ _ _ = mempty
2727
runAgdaRule env st sig = unComputationResult $ Agda.ledgersStep env st sig

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ epochStateSpec epochNo = constrained $ \es ->
6464
reify proposals (toInteger . proposalsSize) $ \ [var|sz|] ->
6565
[ ifElse
6666
(sz <=. 0)
67-
(expired ==. (Lit mempty))
67+
(expired ==. mempty)
6868
(sizeOf_ expired <. sz)
6969
]
7070
, forAll expired $ \ [var| gasId |] ->

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

+1
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ instance Typeable a => HasSimpleRep (THKD tag Identity a) where
874874
type SimpleRep (THKD tag Identity a) = a
875875
fromSimpleRep = THKD
876876
toSimpleRep (THKD a) = a
877+
877878
instance
878879
( IsNormalType a
879880
, Typeable tag

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ witShelleyTxCert univ =
429429
(caseOn txcert)
430430
( branchW 5 $ \delegcert ->
431431
(caseOn delegcert)
432-
(branch $ \_register -> TruePred)
432+
(branch $ \_register -> TruePred :: Pred)
433433
(branch $ \unregisterAuthor -> satisfies unregisterAuthor (witCredSpec univ))
434434
(branch $ \delegateAuthor _ -> satisfies delegateAuthor (witCredSpec univ))
435435
)
@@ -440,7 +440,7 @@ witShelleyTxCert univ =
440440
)
441441
( branchW 1 $ \genesiscert -> match genesiscert $ \authorkey _ _ -> satisfies authorkey (witKeyHashSpec univ)
442442
)
443-
(branchW 1 $ \_mircert -> FalsePred (pure "NO MIR"))
443+
(branchW 1 $ \_mircert -> FalsePred (pure "NO MIR") :: Pred)
444444

445445
-- | Constrains all the Certificate Authors. Sometimes thay are keyHashes, and sometimes Credentials
446446
witConwayTxCert ::
@@ -455,7 +455,7 @@ witConwayTxCert univ =
455455
(caseOn delegcert)
456456
( branch $ \registerAuthor deposit ->
457457
(caseOn deposit)
458-
(branch $ \_ -> TruePred)
458+
(branch $ \_ -> TruePred :: Pred)
459459
(branch $ \_ -> satisfies registerAuthor (witCredSpec univ))
460460
)
461461
(branch $ \unregisterAuthor _ -> satisfies unregisterAuthor (witCredSpec univ))

libs/constrained-generators/constrained-generators.cabal

+4
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ source-repository head
1919
library
2020
exposed-modules:
2121
Constrained.API
22+
Constrained.AbstractSyntax
2223
Constrained.Base
2324
Constrained.Conformance
2425
Constrained.Core
26+
Constrained.DependencyInjection
2527
Constrained.Env
2628
Constrained.Examples
2729
Constrained.Examples.Basic
@@ -32,11 +34,13 @@ library
3234
Constrained.Examples.Map
3335
Constrained.Examples.Set
3436
Constrained.Examples.Tree
37+
Constrained.FunctionSymbol
3538
Constrained.GenT
3639
Constrained.Generic
3740
Constrained.Graph
3841
Constrained.List
3942
Constrained.NumSpec
43+
Constrained.PrettyUtils
4044
Constrained.Properties
4145
Constrained.Spec.Map
4246
Constrained.Spec.Set

libs/constrained-generators/src/Constrained/API.hs

+13-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
{-# LANGUAGE ViewPatterns #-}
66

77
module Constrained.API (
8+
PredD (..),
9+
TermD (..),
10+
SpecificationD (..),
811
GenericallyInstantiated,
912
Logic (..),
1013
Semantics (..),
@@ -13,12 +16,13 @@ module Constrained.API (
1316
NumSpec (..),
1417
MaybeBounded (..),
1518
NonEmpty ((:|)),
16-
Specification (..),
17-
Term (..),
19+
Specification,
20+
pattern TypeSpec,
21+
Term,
1822
Fun (..),
1923
name,
2024
named,
21-
Pred (..),
25+
Pred,
2226
HasSpec (..),
2327
HasSimpleRep (..),
2428
OrdLike (..),
@@ -143,16 +147,15 @@ module Constrained.API (
143147
)
144148
where
145149

150+
import Constrained.AbstractSyntax
146151
import Constrained.Base (
147152
Fun (..),
148153
GenericallyInstantiated,
149154
HasSpec (..),
150155
Logic (..),
151-
Pred (..),
152-
Semantics (..),
153-
Specification (..),
154-
Syntax (..),
155-
Term (..),
156+
Pred,
157+
Specification,
158+
Term,
156159
constrained,
157160
equalSpec,
158161
fromGeneric_,
@@ -164,6 +167,7 @@ import Constrained.Base (
164167
toGeneric_,
165168
pattern FromGeneric,
166169
pattern ToGeneric,
170+
pattern TypeSpec,
167171
pattern Unary,
168172
pattern (:<:),
169173
pattern (:>:),
@@ -174,6 +178,7 @@ import Constrained.Conformance (
174178
satisfies,
175179
)
176180
import Constrained.Core (NonEmpty ((:|)))
181+
import Constrained.FunctionSymbol
177182
import Constrained.Generic (HasSimpleRep (..), Prod (..))
178183
import Constrained.NumSpec (
179184
MaybeBounded (..),

0 commit comments

Comments
 (0)