1import smartpy as sp
2
3
4@sp.module
5def main():
6 class C(sp.Contract):
7 def __init__(self):
8 self.data.m = {"abc": sp.record(a=10, b=20)}
9 self.data.out = "z"
10
11 @sp.entrypoint
12 def ep1(self, params):
13 (x, y) = params
14 assert x == "x"
15 assert y == 2
16
17 @sp.entrypoint
18 def ep2(self, params):
19 (x, y, z) = params
20 assert x == "x"
21 assert y == 2
22 assert z
23
24 @sp.entrypoint
25 def ep3(self, params):
26 sp.cast(params, sp.record(x=sp.string, y=int, z=bool))
27 record(x=x, z=z).match = params
28 assert x == "x"
29 assert z
30
31 @sp.entrypoint
32 def ep4(self, params):
33 sp.cast(params.x01, sp.int)
34 sp.cast(params.x02, sp.key)
35 sp.cast(params.x03, sp.string)
36 sp.cast(params.x04, sp.timestamp)
37 sp.cast(params.x05, sp.bytes)
38 sp.cast(params.x06, sp.address)
39 sp.cast(params.x07, sp.bool)
40 sp.cast(params.x08, sp.key_hash)
41 sp.cast(params.x09, sp.signature)
42 sp.cast(params.x10, sp.mutez)
43 record(x07, x03).match = params
44 assert x03 == "x"
45 assert x07
46
47 @sp.entrypoint
48 def ep5(self, params):
49 (a, b, c, d) = params
50 assert a * b + c * d == 12
51
52 @sp.entrypoint
53 def ep6(self, params):
54 (a, b, c, d) = params
55 sp.cast(c, int)
56 assert a * b + d == 12
57
58 @sp.entrypoint
59 def ep7(self):
60 k = "abc"
61 with sp.modify_record(self.data.m[k]) as data:
62 k = "xyz" + k
63 self.data.out = k
64
65
66@sp.add_test()
67def test():
68 s = sp.test_scenario("Match", main)
69 c = main.C()
70 s += c
71 c.ep1(("x", 2))
72 c.ep2(("x", 2, True))
73 c.ep3(x="x", y=2, z=True)
74 c.ep5((1, 6, 2, 3))
75 c.ep6((1, 6, 2, 6))
76 c.ep7()