templates.test_failwith

 1import smartpy as sp
 2
 3
 4@sp.module
 5def main():
 6    class C1(sp.Contract):
 7        def __init__(self):
 8            self.data.f = None
 9
10        @sp.entrypoint
11        def ep(self):
12            def f(x):
13                if x == 0:
14                    raise "zero"
15                else:
16                    return 1
17
18            self.data.f = sp.Some(f)
19
20    class C2(sp.Contract):
21        @sp.entrypoint
22        def ep(self, params):
23            if params == 0:
24                raise "zero"
25            else:
26                raise "non-zero"
27
28    class C3(sp.Contract):
29        def __init__(self):
30            self.data.x = 1
31
32        @sp.entrypoint
33        def ep1(self):
34            raise "A"
35            raise "B"
36
37        @sp.entrypoint
38        def ep2(self):
39            raise "A"
40            self.data.x = 2
41
42    class C4(sp.Contract):
43        @sp.entrypoint
44        def ep1(self):
45            assert 1 == 2
46
47        @sp.entrypoint
48        def ep2(self):
49            assert 1 == 2
50
51
52@sp.add_test()
53def test():
54    scenario = sp.test_scenario("Test", main)
55    scenario += main.C1()
56    scenario += main.C2()
57    scenario += main.C3()
58    scenario += main.C4()