1import smartpy as sp
2
3
4@sp.module
5def main():
6 class Default1(sp.Contract):
7 def __init__(self):
8 self.data.x = sp.tez(0)
9
10 @sp.entrypoint
11 def default(self):
12 self.data.x = sp.amount
13
14 class Default2(sp.Contract):
15 def __init__(self):
16 self.data.x = sp.tez(0)
17
18 @sp.entrypoint
19 def default(self):
20 self.data.x = sp.amount
21
22 @sp.entrypoint
23 def other(self):
24 pass
25
26 class Regular_annotation1(sp.Contract):
27 def __init__(self):
28 self.data.x = sp.tez(0)
29
30 @sp.entrypoint
31 def reg_annot(self):
32 self.data.x = sp.amount
33
34 class Regular_annotation2(sp.Contract):
35 def __init__(self):
36 self.data.x = sp.tez(0)
37
38 @sp.entrypoint
39 def reg_annot(self):
40 self.data.x = sp.amount
41
42 @sp.entrypoint
43 def other(self):
44 pass
45
46 class No_annotation(sp.Contract):
47 def __init__(self):
48 self.data.x = sp.tez(0)
49
50 @sp.entrypoint
51 def no_annot(self):
52 self.data.x = sp.amount
53
54 class Test(sp.Contract):
55 @sp.entrypoint
56 def send(self, address, amount):
57 sp.send(address, amount)
58
59
60@sp.add_test()
61def test():
62 scenario = sp.test_scenario("Test", main)
63 target_default1 = main.Default1()
64 target_default2 = main.Default2()
65 target_regular1 = main.Regular_annotation1()
66 target_regular2 = main.Regular_annotation2()
67 target_no_annot = main.No_annotation()
68
69 test = main.Test()
70 test.set_initial_balance(sp.tez(1))
71
72 scenario += target_default1
73 scenario += target_default2
74 scenario += target_regular1
75 scenario += target_regular2
76 scenario.add_flag("no-single-entrypoint-annotation")
77 scenario += target_no_annot
78 scenario.add_flag("single-entrypoint-annotation")
79 scenario += test
80
81 test.send(address=target_default1.address, amount=sp.mutez(1))
82 test.send(address=target_default2.address, amount=sp.mutez(2))
83 test.send(address=target_regular1.address, amount=sp.mutez(3))
84 test.send(
85 address=target_regular2.address,
86 amount=sp.mutez(4),
87 _valid=False,
88 _exception="Not the proper variant constructor [Some] != [None]",
89 )
90 test.send(address=target_no_annot.address, amount=sp.mutez(5))
91
92 test.send(
93 address=sp.to_address(
94 sp.contract(sp.unit, target_default1.address).unwrap_some()
95 ),
96 amount=sp.mutez(6),
97 )
98 test.send(
99 address=sp.to_address(
100 sp.contract(sp.unit, target_default2.address).unwrap_some()
101 ),
102 amount=sp.mutez(7),
103 )
104 test.send(
105 address=sp.to_address(
106 sp.contract(
107 sp.unit, target_regular1.address, entrypoint="reg_annot"
108 ).unwrap_some()
109 ),
110 amount=sp.mutez(8),
111 )
112 test.send(
113 address=sp.to_address(
114 sp.contract(
115 sp.unit, target_regular2.address, entrypoint="reg_annot"
116 ).unwrap_some()
117 ),
118 amount=sp.mutez(9),
119 )
120 # test.send(address=sp.to_address(sp.contract(sp.unit, target_no_annot.address, entrypoint="no_annot").unwrap_some()), amount=sp.mutez(10), _valid = False, exception="No annotation in contract")
121
122
123@sp.add_test()
124def test_option():
125 scenario = sp.test_scenario(name="Test_option")
126 scenario.add_module(main)
127
128 target_default1 = main.Default1()
129 target_default2 = main.Default2()
130 target_regular1 = main.Regular_annotation1()
131 target_regular2 = main.Regular_annotation2()
132 target_no_annot = main.No_annotation()
133
134 test = main.Test()
135 test.set_initial_balance(sp.tez(1))
136
137 scenario += target_default1
138 scenario += target_default2
139 scenario += target_regular1
140 scenario += target_regular2
141 scenario.add_flag("no-single-entrypoint-annotation")
142 scenario += target_no_annot
143 scenario.add_flag("single-entrypoint-annotation")
144 scenario += test
145
146 test.send(address=target_default1.address, amount=sp.mutez(1))
147 test.send(address=target_default2.address, amount=sp.mutez(2))
148 test.send(address=target_regular1.address, amount=sp.mutez(3))
149 test.send(
150 address=target_regular2.address,
151 amount=sp.mutez(4),
152 _valid=False,
153 _exception="Not the proper variant constructor [Some] != [None]",
154 )
155 test.send(address=target_no_annot.address, amount=sp.mutez(5))
156
157 test.send(
158 address=sp.to_address(
159 sp.contract(sp.unit, target_default1.address).unwrap_some()
160 ),
161 amount=sp.mutez(6),
162 )
163 test.send(
164 address=sp.to_address(
165 sp.contract(sp.unit, target_default2.address).unwrap_some()
166 ),
167 amount=sp.mutez(7),
168 )
169 test.send(
170 address=sp.to_address(
171 sp.contract(
172 sp.unit, target_regular1.address, entrypoint="reg_annot"
173 ).unwrap_some()
174 ),
175 amount=sp.mutez(8),
176 )
177 test.send(
178 address=sp.to_address(
179 sp.contract(
180 sp.unit, target_regular2.address, entrypoint="reg_annot"
181 ).unwrap_some()
182 ),
183 amount=sp.mutez(9),
184 )
185 # test.send(address=sp.to_address(sp.contract(sp.unit, target_no_annot.address).unwrap_some()), amount=sp.mutez(10), _valid = False, _exception="Not the proper variant constructor [Some] != [None]")