templates.test_modules8

 1import smartpy as sp
 2
 3
 4@sp.module
 5def main():
 6    class A1(sp.Contract):
 7        def __init__(self, x):
 8            self.data.x = x
 9
10        @sp.private(with_storage="read-write")
11        def f(self, _):
12            self.data.x += 1
13
14        @sp.entrypoint
15        def ep(self):
16            self.data.x += 10
17
18    class A2(sp.Contract):
19        def __init__(self, y):
20            self.data.y = y
21
22        @sp.private(with_storage="read-write")
23        def f(self, _):
24            self.data.y -= 1
25
26        @sp.entrypoint
27        def ep(self):
28            self.data.y -= 10
29
30    class B(A1, A2):
31        def __init__(self, x, y):
32            A1.__init__(self, x)
33            if True:
34                A2.__init__(self, y)
35            else:
36                A2.__init__(self, y)
37
38        @sp.entrypoint
39        def run_f(self):
40            self.f()
41
42
43@sp.add_test()
44def test():
45    s = sp.test_scenario("Test", main)
46
47    a1 = main.A1(1000)
48    s += a1
49    s.verify(a1.data == sp.record(x=1000))
50    a1.ep()
51    s.verify(a1.data == sp.record(x=1010))
52
53    a2 = main.A2(1020)
54    s += a2
55    s.verify(a2.data == sp.record(y=1020))
56    a2.ep()
57    s.verify(a2.data == sp.record(y=1010))
58
59    b = main.B(1000, 1)
60    s += b
61    s.verify(b.data == sp.record(x=1000, y=1))
62    b.ep()
63    s.verify(b.data == sp.record(x=1010, y=1))
64    b.run_f()
65    s.verify(b.data == sp.record(x=1011, y=1))