Reference: scenarios¶
This page gives reference information on scenario syntax, used for testing templates:
For an introduction to scenarios, see Testing using scenarios.
Scenario keyword¶
- scenariofunction. Introduces a series of transactions to be submitted to the ledger.
Submit¶
- submitkeyword.
- Submits an action (a create or an exercise) to the ledger.
- Takes two arguments, the party submitting followed by the expression, for example: submit bankOfEngland do create ...
submitMustFail¶
- submitMustFailkeyword.
- Like submit, but you’re asserting it should fail.
- Takes two arguments, the party submitting followed by the expression by a party, for example: submitMustFail bankOfEngland do create ...
Scenario body¶
Passing time¶
In a scenario, you may want time to pass so you can test something properly. You can do this with pass.
Here’s an example of passing time:
timeTravel =
  scenario do
    -- Get current ledger effective time
    t1 <- getTime
    assert (t1 == datetime 1970 Jan 1 0 0 0)
    -- Pass 1 day
    pass (days 1)
    -- Get new ledger effective time
    t2 <- getTime
    assert (t2 == datetime 1970 Jan 2 0 0 0)
Binding variables¶
As in choices, you can bind to variables. Usually, you’d bind commits to variables in order to get the returned value (usually the contract).