templates.test_option

 1import smartpy as sp
 2
 3
 4@sp.module
 5def main():
 6    class C(sp.Contract):
 7        def __init__(self):
 8            self.data.x = sp.Some(sp.int(42))
 9
10        @sp.entrypoint
11        def set(self, x):
12            self.data.x = x
13
14        @sp.entrypoint
15        def map(self, f):
16            self.data.x = map(f, self.data.x)
17
18
19@sp.add_test()
20def test():
21    s = sp.test_scenario("Test", main)
22    c = main.C()
23    s += c
24    c.map(lambda x: x + 1)
25    s.verify(c.data.x == sp.Some(43))
26    c.map(lambda x: x + 2)
27    s.verify(c.data.x == sp.Some(45))
28
29    c.set(None)
30    c.map(lambda x: x - 1)
31    s.verify(c.data.x == None)