1import smartpy as sp
2
3
4@sp.module
5def M2():
6 @sp.effects(with_storage="read-write")
7 def f(x):
8 self.data.x = 100
9 if True:
10 return x + 1
11 else:
12 return 2
13
14 def g(x):
15 return x
16
17 f2 = sp.cast(
18 f, sp.lambda_(int, int, with_storage="read-write", with_operations=False)
19 )
20
21 class C1(sp.Contract):
22 def __init__(self):
23 self.data.x = f(42)
24 self.data.y = 100
25
26 @sp.entrypoint
27 def myEntryPoint(self, params):
28 assert params == "abc"
29
30 class C2(sp.Contract):
31 def __init__(self, x):
32 self.data.x = 42
33 self.data.y = 100
34 _ = f(
35 42
36 ) # f is inlined and can thus be used with different storage type each time
37 x.f(42) # x.f is unknown and thus defaults to no effects
38 self.private.policy = sp.record(name="owner")
39
40 @sp.entrypoint
41 def ep(self, params):
42 @sp.effects(with_storage="read-write")
43 def h(x):
44 pass
45
46 assert params == f(params)
47
48
49@sp.add_test()
50def test():
51 s = sp.test_scenario("Test", M2)
52 c1 = M2.C1()
53 s += c1
54 c2 = M2.C1()
55 s += c2
56 s.verify(c1.data.x == 43)