Skip to content

Commit

Permalink
ChainDB.StateMachine: reuse q-s-m infrastructure
Browse files Browse the repository at this point in the history
Use the infrastructure we wrote that has since been integrated in q-s-m.
  • Loading branch information
mrBliss committed Mar 3, 2020
1 parent 33484c4 commit 6bf3001
Showing 1 changed file with 7 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import qualified Generics.SOP as SOP
import Test.QuickCheck
import qualified Test.QuickCheck.Monadic as QC
import Test.StateMachine
import Test.StateMachine.Labelling
import qualified Test.StateMachine.Sequential as QSM
import qualified Test.StateMachine.Types as QSM
import qualified Test.StateMachine.Types.Rank2 as Rank2
Expand Down Expand Up @@ -634,24 +635,17 @@ instance Bitraversable (t blk) => Rank2.Traversable (At t blk m) where

-- | An event records the model before and after a command along with the
-- command itself, and the response.
data Event blk m r = Event
{ eventBefore :: Model blk m r
, eventCmd :: At Cmd blk m r
, eventAfter :: Model blk m r
, eventResp :: At Resp blk m r
}

deriving instance (TestConstraints blk, Show1 r) => Show (Event blk m r)
type ChainDBEvent blk m = Event (Model blk m) (At Cmd blk m) (At Resp blk m)

eventMockResp :: Eq1 r => Event blk m r -> Resp blk IteratorId ReaderId
eventMockResp :: Eq1 r => ChainDBEvent blk m r -> Resp blk IteratorId ReaderId
eventMockResp Event{..} = toMock eventAfter eventResp

-- | Construct an event
lockstep :: (TestConstraints blk, Eq1 r, Show1 r)
=> Model blk m r
-> At Cmd blk m r
-> At Resp blk m r
-> Event blk m r
=> Model blk m r
-> At Cmd blk m r
-> At Resp blk m r
-> ChainDBEvent blk m r
lockstep model@Model {..} cmd (At resp) = Event
{ eventBefore = model
, eventCmd = cmd
Expand Down

0 comments on commit 6bf3001

Please sign in to comment.