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

  • scenario function. Introduces a series of transactions to be submitted to the ledger.

Submit

  • submit keyword.
  • 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

  • submitMustFail keyword.
  • 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

Updates

  • Usually create and exercise. But you can also use other updates, like assert and fetch.
  • Parties can only be named explicitly in scenarios.

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).