Skip to content

Commit d98b886

Browse files
committed
Scale down tests to make test suites run faster
1 parent 416ade6 commit d98b886

4 files changed

Lines changed: 28 additions & 8 deletions

File tree

eras/dijkstra/impl/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171

7272
### testlib
7373

74+
* Add `genSmallDijkstraBlockBody`
7475
* Add to `Test.Cardano.Ledger.Dijkstra.Examples`:
7576
- `exampleDijkstraOnwardsEraPParams`
7677
- `exampleDijkstraOnwardsEraPParamsUpdate`

eras/dijkstra/impl/cddl/lib/Cardano/Ledger/Dijkstra/HuddleSpec.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,10 +975,13 @@ instance HuddleRule "block_body" DijkstraEra where
975975

976976
blockBodyGen :: CBORGen RuleTerm
977977
blockBodyGen = do
978-
numTxs <- liftGen . Gen.sized $ \s -> choose (0 :: Int, s)
978+
numTxs <- liftGen . Gen.sized $ \s -> choose (0 :: Int, s `div` 15)
979979
txs <-
980980
mapM
981-
(\i -> withAntiGen (withAnnotation (T.pack $ show i)) $ generateFromName "transaction")
981+
( \i ->
982+
withAntiGen (withAnnotation (T.pack $ show i)) . scale (`div` max 1 numTxs) $
983+
generateFromName "transaction"
984+
)
982985
[0 .. numTxs - 1]
983986
invalidIxIxs <-
984987
if numTxs == 0

eras/dijkstra/impl/test/Test/Cardano/Ledger/Dijkstra/Binary/CddlSpec.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ import Test.Cardano.Ledger.Core.Binary (
3535
fullCddlSpec,
3636
fullGenCddlSpec,
3737
)
38-
import Test.Cardano.Ledger.Dijkstra.Arbitrary (genNonEmptyAccountBalanceIntervals)
38+
import Test.Cardano.Ledger.Dijkstra.Arbitrary (
39+
genNonEmptyAccountBalanceIntervals,
40+
genSmallDijkstraBlockBody,
41+
)
3942
import Test.Cardano.Ledger.Dijkstra.Binary.Annotator ()
4043

4144
spec :: Spec
4245
spec = do
4346
describe "CDDL" $ do
4447
let v = eraProtVerHigh @DijkstraEra
4548
describe "Huddle" $ specWithHuddle dijkstraCDDL . noTwiddle $ do
46-
-- BlockBody
47-
xdescribe "fix transaction" $
48-
fullAnnCddlSpec @(BlockBody DijkstraEra) v "block_body"
49-
-- AccountBalanceInterval
49+
fullAnnGenCddlSpec @(BlockBody DijkstraEra) genSmallDijkstraBlockBody v "block_body"
5050
fullCddlSpec @(AccountBalanceInterval DijkstraEra) v "account_balance_interval"
5151
fullGenCddlSpec @(AccountBalanceIntervals DijkstraEra)
5252
genNonEmptyAccountBalanceIntervals

eras/dijkstra/impl/testlib/Test/Cardano/Ledger/Dijkstra/Arbitrary.hs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
{-# LANGUAGE UndecidableInstances #-}
1515
{-# OPTIONS_GHC -Wno-orphans #-}
1616

17-
module Test.Cardano.Ledger.Dijkstra.Arbitrary (genNonEmptyAccountBalanceIntervals) where
17+
module Test.Cardano.Ledger.Dijkstra.Arbitrary (genNonEmptyAccountBalanceIntervals, genSmallDijkstraBlockBody) where
1818

1919
import Cardano.Ledger.Allegra.Scripts (
2020
pattern RequireTimeExpire,
@@ -40,6 +40,7 @@ import Cardano.Ledger.Shelley.Scripts (pattern RequireSignature)
4040
import Data.Functor.Identity (Identity)
4141
import qualified Data.Map.Strict as Map
4242
import qualified Data.OMap.Strict as OMap
43+
import qualified Data.Sequence.Strict as SSeq
4344
import Data.Typeable (Typeable)
4445
import Generic.Random (genericArbitraryU)
4546
import Test.Cardano.Ledger.Allegra.Arbitrary (maxTimelockDepth)
@@ -303,6 +304,21 @@ instance
303304
where
304305
arbitrary = DijkstraBlockBody <$> arbitrary <*> arbitrary
305306

307+
genSmallDijkstraBlockBody ::
308+
( AlonzoEraTx era
309+
, Arbitrary (Tx TopTx era)
310+
) =>
311+
Gen (DijkstraBlockBody era)
312+
genSmallDijkstraBlockBody = DijkstraBlockBody <$> genFewTxs <*> arbitrary
313+
where
314+
genFewTxs = sized $ \sz -> do
315+
numTxs <-
316+
frequency
317+
[ (99, choose (1, max 1 $ sz `div` 20))
318+
, (1, pure 0)
319+
]
320+
SSeq.fromList <$> vectorOf numTxs (scale (`div` numTxs) arbitrary)
321+
306322
deriving newtype instance Arbitrary (ApplyTxError DijkstraEra)
307323

308324
instance Arbitrary (DijkstraMempoolPredFailure DijkstraEra) where

0 commit comments

Comments
 (0)