Skip to content

Instantly share code, notes, and snippets.


frankhillard/ Secret

Created Nov 25, 2019
What would you like to do?
counter in smartpy
import smartpy as sp
class Counter(sp.Contract):
def __init__(self):
self.init(counter = 0)
def increaseCounterBy(self, params): = + params.value
def decreaseCounterBy(self, params): = - params.value
if "templates" not in __name__:
@addTest(name = "Counter test")
def test():
c1 = Counter()
scenario = sp.testScenario()
scenario += c1
scenario += c1.increaseCounterBy(value = 2)
scenario += c1.decreaseCounterBy(value = 1)
scenario.verify( == 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment