-
-
Save frankhillard/1c1206587e962f4a9f0284d2ac21a5ec to your computer and use it in GitHub Desktop.
counter in smartpy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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