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