Skip to content
On this page

Overview

Scenarios describe a sequence of actions:

  • Originating contracts;
  • Computing expressions;
  • Calling entrypoints;
  • and more.

They are directly used in tests.

Tests

@sp.add_test() → 

It decorates a test function.

Test Example

python
@sp.module
def main():
    class MyContract(sp.Contract):
        ...

@sp.add_test()
def test():
    # We define a test scenario, called sc,
    # together with some outputs and checks.
    # We provide it a name and the module or list of modules to import
    sc = sp.test_scenario("First test", main)
    # We first define a contract and add it to the scenario
    c1 = main.MyContract(12, 123)
    scenario += c1
    # And call some entrypoints of c1
    c1.my_entrypoint(12)
    c1.my_entrypoint(13)
    c1.my_entrypoint(14)
    c1.my_entrypoint(50)
    c1.my_entrypoint(50)
    c1.my_entrypoint(50, _valid=False) # this is expected to fail
    # Finally, we check the final storage of c1
    sc.verify(c1.data.myParameter1 == 151)
    # and its balance
    sc.verify(c1.balance, sp.tez(0))