Introducing Test Scenarios in SmartPy.io

An example

import smartpy as sp# A class of contracts
class MyContract(sp.Contract):
def __init__(self, myParameter1, myParameter2):
self.init(myParameter1 = myParameter1,
myParameter2 = myParameter2)
# An entry point, i.e., a message receiver
# (contracts react to messages)
@sp.entryPoint
def myEntryPoint(self, params):
sp.verify(self.data.myParameter1 <= 123)
self.data.myParameter1 += params
@addTest(name = "First test")
def test():
# We define a test scenario, called scenario,
# together with some outputs and checks
scenario = sp.testScenario()
# We first define a contract and add it to the scenario
c1 = MyContract(12, 123)
scenario += c1
# And send messages to some entry points of c1
scenario += c1.myEntryPoint(12)
scenario += c1.myEntryPoint(13)
scenario += c1.myEntryPoint(14)
scenario += c1.myEntryPoint(50)
scenario += c1.myEntryPoint(50)
scenario += c1.myEntryPoint(50) ### This will be refused
# Finally, we check the final storage of c1
scenario.verify(c1.data.myParameter1 == 151)

Scenarios

  • Registering and displaying contracts.
scenario += c1# This is identical to doing
scenario.register(c1, show = True)
# To only register the smart contract but not show it
scenario.register(c1)
  • Registering and displaying calls to entry points.
scenario += c1.myEntryPoint(12)
scenario += c1.myEntryPoint(...).run(sender = ..., amount = ..., now = ...)
# To only execute a call to an entry point but not show it
scenario.register(c1.myEntryPoint(12))
  • Adding document informations
scenario.h1("a title")
scenario.h2("a subtitle")
scenario.h3(..)
scenario.h4(..)
scenario.p("Some text")
  • Computing expressions.
scenario.compute(c1.data.myParameter1 * 12)
scenario.compute(c1.data)
  • Checking assertions.
scenario.verify(self.data.myParameter == 51)

--

--

--

An intuitive and effective smart contracts language and development platform for Tezos. In Python.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
SmartPy.io

SmartPy.io

An intuitive and effective smart contracts language and development platform for Tezos. In Python.

More from Medium

Our first update of 2022!

The quirks of creating an indie game with a one man army (and how it’s possible)

Add Attributes to Existing NFT

Report Redux: Blame It On Denny’s