Skip to content

Commit

Permalink
PLT-4168 Tested that Merkleization continues as expected.
Browse files Browse the repository at this point in the history
  • Loading branch information
bwbush committed Mar 15, 2023
1 parent ee2e522 commit f33fc72
Showing 1 changed file with 61 additions and 3 deletions.
64 changes: 61 additions & 3 deletions marlowe-test/src/Spec/Marlowe/Semantics/Compute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import Language.Marlowe.Core.V1.Semantics.Types
, Accounts
, Action(Choice, Deposit, Notify)
, Bound(..)
, Case(Case)
, Case(..)
, ChoiceId
, ChosenNum
, Contract(..)
Expand All @@ -71,7 +71,8 @@ import Language.Marlowe.Core.V1.Semantics.Types
, getInputContent
)
import Language.Marlowe.FindInputs (getAllInputs)
import Plutus.V2.Ledger.Api (CurrencySymbol, POSIXTime(..), TokenName)
import Plutus.Script.Utils.Scripts (datumHash)
import Plutus.V2.Ledger.Api (CurrencySymbol, Datum(..), DatumHash(..), POSIXTime(..), TokenName, toBuiltinData)
import Spec.Marlowe.Semantics.Arbitrary
( Context
, SemiArbitrary(semiArbitrary)
Expand Down Expand Up @@ -299,6 +300,27 @@ simpleNotify =
simpleTransaction context modifyContract pure modifyInput


-- | Generate a simple notification.
simpleMerkleization :: Gen MarloweContext
simpleMerkleization =
do
context <- arbitrary
mcState <- semiArbitrary context
intervalStart <- (getPOSIXTime (minTime mcState) +) <$> arbitraryPositiveInteger
intervalEnd <- (intervalStart +) <$> arbitraryPositiveInteger
let
interval = (POSIXTime intervalStart, POSIXTime intervalEnd)
timeout <- (intervalEnd +) <$> arbitraryPositiveInteger
contract <- When [] (POSIXTime timeout) <$> semiArbitrary context
let
DatumHash hash = datumHash . Datum $ toBuiltinData contract
mcInput = TransactionInput interval [MerkleizedInput INotify hash contract]
mcContract <- When [MerkleizedCase (Notify TrueObs) hash] (POSIXTime timeout) <$> semiArbitrary context
let
mcOutput = computeTransaction mcInput mcState mcContract
pure MarloweContext{..}


-- | Recompute the output of a Marlowe transaction in an transaction context.
updateOutput :: MarloweContext -> MarloweContext
updateOutput mc@MarloweContext{..} =
Expand Down Expand Up @@ -1082,7 +1104,41 @@ depositContinues =
, generator = simpleDeposit
, postcondition = view preContract >>=
\case
When [Case (Deposit _ _ _ _) contract] _ _ -> checkContinuation contract
When [Case Deposit{} contract] _ _ -> checkContinuation contract
_ -> throwError "Test setup failed."
}


-- | Test that deposit continues as expected.
merkleizationContinues :: TransactionTest
merkleizationContinues =
def
{
name = "Merkleization continues as expected"
, allowShrinkage = False
, generator = simpleMerkleization
, postcondition = view inputs >>=
\case
[MerkleizedInput INotify _ contract] -> checkContinuation contract
_ -> throwError "Test setup failed."
}


-- | Test that deposit continues as expected.
choiceSets :: TransactionTest
choiceSets =
def
{
name = "Choice records the value of the choice"
, allowShrinkage = False
, generator = simpleChoice
, postcondition = view inputs >>=
\case
[NormalInput (IChoice choiceId value)] ->
do
choices' <- choices <$> view postState
unless (AM.lookup choiceId choices' == Just value)
$ throwError "Choice missing from state"
_ -> throwError "Test setup failed."
}

Expand All @@ -1109,4 +1165,6 @@ tests =
, depositContinues
, choiceContinues
, notifyContinues
, choiceSets
, merkleizationContinues
]

0 comments on commit f33fc72

Please sign in to comment.