Skip to content

Instantly share code, notes, and snippets.

@frankhillard
Created November 25, 2019 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frankhillard/1c1206587e962f4a9f0284d2ac21a5ec to your computer and use it in GitHub Desktop.
Save frankhillard/1c1206587e962f4a9f0284d2ac21a5ec to your computer and use it in GitHub Desktop.
counter in smartpy
import smartpy as sp
class Counter(sp.Contract):
def __init__(self):
self.init(counter = 0)
@sp.entryPoint
def increaseCounterBy(self, params):
self.data.counter = self.data.counter + params.value
@sp.entryPoint
def decreaseCounterBy(self, params):
self.data.counter = self.data.counter - 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(c1.data.counter == 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment