1import smartpy as sp
2
3
4@sp.module
5def main():
6 class A(sp.Contract):
7 def __init__(self):
8 self.data.x = 0
9
10 @sp.private(with_storage="read-write")
11 def aux(self, n):
12 self.data.x += n
13
14 @sp.private
15 def gett(self):
16 return 42
17
18 @sp.entrypoint
19 def ep(self):
20 self.aux(1)
21
22 class B(A):
23 def __init__(self):
24 A.__init__(self)
25 self.data.y = 0
26
27 # Override a private lambda
28 @sp.private(with_storage="read-write")
29 def aux(self, n):
30 self.data.x += 100 * n
31
32 @sp.entrypoint
33 def ep2(self, n):
34 self.aux(n)
35 self.data.y += 1
36
37
38@sp.add_test()
39def test():
40 s = sp.test_scenario("Test", main)
41
42 a = main.A()
43 s += a
44 s.verify(a.data == sp.record(x=0))
45 a.ep()
46 s.verify(a.data == sp.record(x=1))
47
48 b = main.B()
49 s += b
50 s.verify(b.data == sp.record(x=0, y=0))
51 b.ep()
52 s.verify(b.data == sp.record(x=100, y=0))
53 b.ep2(5)
54 s.verify(b.data == sp.record(x=600, y=1))