Skip to content

Commit

Permalink
PLT-4168 Test that choice produces expected continuation.
Browse files Browse the repository at this point in the history
  • Loading branch information
bwbush committed Mar 15, 2023
1 parent 477284c commit 333eee2
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions marlowe-test/src/Spec/Marlowe/Semantics/Compute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import Language.Marlowe.Core.V1.Semantics.Types
, Input(..)
, InputContent(IChoice, IDeposit, INotify)
, IntervalError(IntervalInPastError, InvalidInterval)
, Observation
, Observation(TrueObs)
, Payee(Party)
, State(..)
, TimeInterval
Expand Down Expand Up @@ -262,6 +262,22 @@ simpleDeposit =
simpleTransaction context modifyContract pure modifyInput


-- | Generate a simple notification.
simpleNotify :: Gen MarloweContext
simpleNotify =
do
context <- arbitrary
let
modifyContract (_, POSIXTime intervalEnd) contract =
do
let
timeout = POSIXTime $ intervalEnd + 1
contract' <- When [] timeout <$> semiArbitrary context
pure $ When [Case (Notify TrueObs) contract'] timeout contract
modifyInput (TransactionInput interval _) = pure $ TransactionInput interval [NormalInput INotify]
simpleTransaction context modifyContract pure modifyInput


-- | Recompute the output of a Marlowe transaction in an transaction context.
updateOutput :: MarloweContext -> MarloweContext
updateOutput mc@MarloweContext{..} =
Expand Down Expand Up @@ -981,7 +997,7 @@ payingSubtractsFromAccount =
$ AM.unionWith (+)
<$> view preAccounts
<*> (AM.fromList . fmap (second negate) . AM.toList <$> view postAccounts)
require "Only one balance changes" ((== 1) . length . AM.toList) delta
require "Only one balance changes." ((== 1) . length . AM.toList) delta
require "Some balance decreases." (all (> 0) . AM.elems) delta
}

Expand All @@ -1000,11 +1016,30 @@ depositAddsToAccount =
$ AM.unionWith (+)
<$> view postAccounts
<*> (AM.fromList . fmap (second negate) . AM.toList <$> view preAccounts)
require "Only one balance changes" ((== 1) . length . AM.toList) delta
require "Only one balance changes." ((== 1) . length . AM.toList) delta
require "Some balance increases." (all (> 0) . AM.elems) delta
}


-- | Test that deposits add value to internal accounts.
notifyContinues :: TransactionTest
notifyContinues =
def
{
name = "Notify continues as expected"
, allowShrinkage = False
, generator = simpleNotify
, postcondition = do
let
check (When [Case (Notify TrueObs) contract] _ _) contract' =
require "Incorrect continuation." (== contract) contract'
check _ _ = throwError "Test setup failed."
pre <- view preContract
post <- view postContract
check pre post
}


-- | Run the tests.
tests :: TestTree
tests =
Expand All @@ -1024,4 +1059,5 @@ tests =
, anyInput
, payingSubtractsFromAccount
, depositAddsToAccount
, notifyContinues
]

0 comments on commit 333eee2

Please sign in to comment.