I see the following example of contract Testing contracts | SmartPy but it doesn’t work at SmartPy
Especially I’m interesting in sp.result, but I have
sp.result is undefined or wrong number of arguments
sp.result
is now replaced by return
.
Here is an example:
import smartpy as sp
@sp.module
def main():
class C(sp.Contract):
def __init__(self):
self.data.x = 10
@sp.entrypoint
def set_x(self, x):
self.data.x = x
@sp.onchain_view()
def get_x(self):
return self.data.x
@sp.add_test(name="Test")
def test():
s = sp.test_scenario(main)
c = main.C()
s += c
s.verify(c.get_x() == 10)
c.set_x(42)
s.verify(c.get_x() == 42)
Notice that
return
can only be used in views. Have a look here for alternatives: Returning a value from an entrypoint