1import smartpy as sp
2
3# Various techniques to edit entrypoints
4
5
6@sp.module
7def main():
8 class MyContract(sp.Contract):
9 def __init__(self, x, y):
10 self.data.x = x
11 self.data.y = y
12 self.data.t = sp.Some(0)
13
14 @sp.entrypoint
15 def myEntryPoint(self, params):
16 assert self.data.x <= 100
17 self.data.x += params
18
19 @sp.entrypoint
20 def myEntryPointOther(self):
21 self.data.x += 10
22
23 @sp.entrypoint
24 def myEntryPointXXX(self, params):
25 assert self.data.x <= 1000
26 self.data.x += params
27
28 @sp.private(with_storage="read-write")
29 def some_helper(self, params):
30 sp.cast(params, sp.nat)
31 pass
32
33 class MyContract2(MyContract):
34 def __init__(self, x, y):
35 MyContract.__init__(self, 1, 2)
36 self.data.z = 42
37 self.data.t = None
38
39 # Replace an inherited entrypoint
40 @sp.entrypoint
41 def myEntryPoint(self, params):
42 self.data.y = 12345
43 self.some_helper(params + 2)
44
45 # Replace an inherited private lambda
46 @sp.private(with_storage="read-write")
47 def some_helper(self, params):
48 self.data.y += params
49
50 # Add a new entrypoint
51 @sp.entrypoint
52 def myEntryPoint2(self):
53 pass
54
55
56# Tests
57@sp.add_test()
58def test():
59 scenario = sp.test_scenario("Inheritance", main)
60 c1 = main.MyContract2(12, 15)
61 scenario += c1