1import smartpy as sp
2
3
4@sp.module
5def main():
6 class A(sp.Contract):
7 def __init__(self, x):
8 self.data.a = 42
9 self.data.x = x
10
11 @sp.entrypoint
12 def ep1(self, x):
13 self.data.x = 42
14 assert x == "abc"
15
16 @sp.entrypoint
17 def ep2(self, x):
18 self.data.x = 42
19 assert x == "abc"
20
21 @sp.private(with_storage="read-write")
22 def f(self, x):
23 self.data.a = 123
24 return x + 1
25
26 class B(A):
27 def __init__(self, yy):
28 A.__init__(self, 2 * yy)
29 self.data.y = self.data.x + yy
30
31 @sp.entrypoint
32 def ep3(self, x):
33 assert self.f(x) == 43
34
35 class B2(A):
36 def __init__(self, yy):
37 A.__init__(self, 2 * yy)
38 self.data.xx = 0
39
40 class C(sp.Contract):
41 pass
42
43 class D(A, C):
44 def __init__(self):
45 A.__init__(self, 1)
46 C.__init__(self)
47 self.data.y = 1000
48
49 @sp.entrypoint
50 def ep4(self, x):
51 assert x == 42
52
53
54@sp.add_test()
55def test():
56 s = sp.test_scenario("Test", main)
57
58 a = main.A(123)
59 s += a
60 s.verify(a.data == sp.record(a=42, x=123))
61
62 b = main.B(3)
63 s += b
64 s.verify(b.data == sp.record(a=42, x=2 * 3, y=6 + 3))
65 b.ep3(42)
66 s.verify(b.data == sp.record(a=123, x=2 * 3, y=6 + 3))
67
68 b2 = main.B(3)
69 s += b2
70 s.verify(b2.data == sp.record(a=42, x=2 * 3, y=6 + 3))
71
72 d = main.D()
73 s += d
74 d.ep4(42)
75 s.verify(d.data == sp.record(a=42, x=1, y=1000))
76
77 c = s.compute(123)
78 a = main.A(c)
79 s += a