Skip to content

Commit

Permalink
Use implicit fixtures, refactor poll and send, and add a new inva…
Browse files Browse the repository at this point in the history
…lid tx test

Implicit fixtures, i.e. using ImplicitParams to plumb test fixtures
around, may make the plumbing a bit easier.

Renamed polling and sending to `poll` and `send`. Now also they deal
in more useful types. Request keys are no longer returned by `send`,
because they can be computed by the caller.

`send` and `poll` now also include assertions which are always useful
to test.
  • Loading branch information
edmundnoble committed Dec 20, 2024
1 parent 0f68569 commit 706b29b
Show file tree
Hide file tree
Showing 3 changed files with 224 additions and 158 deletions.
1 change: 1 addition & 0 deletions chainweb.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ test-suite chainweb-tests
, pact-tng:pact-request-api
, pact-tng:test-utils
, patience >= 0.3
, prettyprinter
, property-matchers ^>= 0.2
, pretty-show
, quickcheck-instances >= 0.3
Expand Down
32 changes: 23 additions & 9 deletions test/unit/Chainweb/Test/Pact5/CutFixture.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{-# language
BangPatterns
, ConstraintKinds
, DataKinds
, DeriveAnyClass
, DerivingStrategies
, FlexibleContexts
, ImplicitParams
, ImportQualifiedPost
, LambdaCase
, NumericUnderscores
Expand All @@ -22,7 +24,10 @@
-- trigger mining on all chains at once.
module Chainweb.Test.Pact5.CutFixture
( Fixture(..)
, HasFixture
, mkFixture
, withFixture
, withFixture'
, fixtureCutDb
, fixturePayloadDb
, fixtureWebBlockHeaderDb
Expand Down Expand Up @@ -94,6 +99,8 @@ data Fixture = Fixture
}
makeLenses ''Fixture

type HasFixture = (?cutFixture :: IO Fixture)

mkFixture :: ChainwebVersion -> PactServiceConfig -> RocksDb -> ResourceT IO Fixture
mkFixture v pactServiceConfig baseRdb = do
logger <- liftIO getTestLogger
Expand All @@ -115,17 +122,25 @@ mkFixture v pactServiceConfig baseRdb = do
, _fixtureMempools = OnChains $ fst <$> perChain
, _fixturePactQueues = OnChains $ snd <$> perChain
}
_ <- liftIO $ advanceAllChains fixture
_ <- withFixture fixture $ liftIO advanceAllChains
return fixture

withFixture' :: IO Fixture -> (HasFixture => a) -> a
withFixture' fixture tests =
let ?cutFixture = fixture in tests

withFixture :: Fixture -> (HasFixture => a) -> a
withFixture fixture tests =
withFixture' (return fixture) tests

-- | Advance all chains by one block, filling that block with whatever is in
-- their mempools at the time.
--
advanceAllChains
:: HasCallStack
=> Fixture
-> IO (Cut, ChainMap (Vector (CommandResult Pact5.Hash Text)))
advanceAllChains Fixture{..} = do
:: (HasCallStack, HasFixture)
=> IO (Cut, ChainMap (Vector (CommandResult Pact5.Hash Text)))
advanceAllChains = do
Fixture{..} <- ?cutFixture
let v = _chainwebVersion _fixtureCutDb
latestCut <- liftIO $ _fixtureCutDb ^. cut
let blockHeights = fmap (view blockHeight) $ latestCut ^. cutMap
Expand All @@ -149,10 +164,9 @@ advanceAllChains Fixture{..} = do
return (finalCut, onChains perChainCommandResults)

advanceAllChains_
:: HasCallStack
=> Fixture
-> IO ()
advanceAllChains_ f = void $ advanceAllChains f
:: (HasCallStack, HasFixture)
=> IO ()
advanceAllChains_ = void advanceAllChains

withTestCutDb :: (Logger logger)
=> logger
Expand Down
Loading

0 comments on commit 706b29b

Please sign in to comment.