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 and implicitly in compilation targets.

Tests

@sp.add_test(name, shortname=None, profile=False, is_default=True) → 

It decorates a test function.

PropertyDescriptionDefault Value
nameTest Namerequired
shortnameAn optional parameter. Short names need to be unique. Used in smartpy-cli outputs.None
profileComputes and pretty-prints profiling data.False
is_defaultDetermines if the test is performed by default when evaluating all tests.True

Test Example

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

@sp.add_test(name = "First test")
def test():
    # We define a test scenario, called sc,
    # together with some outputs and checks
    sc = sp.test_scenario(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).run(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))