templates.test_modules11

 1import smartpy as sp
 2
 3
 4@sp.module
 5def aux():
 6    class A(sp.Contract):
 7        def __init__(self, a):
 8            self.data.a = a
 9
10        @sp.entrypoint
11        def double_a(self):
12            self.data.a *= 2
13
14    class B(sp.Contract):
15        def __init__(self, b):
16            self.data.b = b
17
18        @sp.entrypoint
19        def double_b(self):
20            self.data.b *= 2
21
22
23@sp.module
24def main():
25    class C(aux.A, aux.B):
26        def __init__(self, a, b):
27            aux.A.__init__(self, a)
28            aux.B.__init__(self, b)
29            self.data.c = a + b
30
31
32@sp.add_test()
33def test():
34    s = sp.test_scenario("Test", [aux, main])
35
36    c = main.C(2, 3)
37    s += c
38    s.verify(c.data.a == 2)
39    s.verify(c.data.b == 3)
40    s.verify(c.data.c == 5)
41
42    c.double_a()
43    s.verify(c.data.a == 4)
44    s.verify(c.data.b == 3)
45    s.verify(c.data.c == 5)
46
47    c.double_b()
48    s.verify(c.data.a == 4)
49    s.verify(c.data.b == 6)
50    s.verify(c.data.c == 5)