templates.test_type_abbrevs

 1import smartpy as sp
 2
 3
 4@sp.module
 5def M1():
 6    t: type = int
 7    u: type = sp.mutez
 8
 9
10@sp.module
11def M2():
12    t: type = bool
13    u: type = tuple[M1.t, M1.u, t]
14    v: type = sp.tuple[M1.t, M1.u, t]
15
16    class C(sp.Contract):
17        def __init__(self, y):
18            self.data.x = y
19
20        @sp.entrypoint
21        def myEntryPoint(self, params):
22            sp.cast(params, u)
23            sp.cast(params, tuple[int, sp.mutez, bool])
24
25
26@sp.module
27def M3():
28    class C(sp.Contract):
29        @sp.entrypoint
30        def myEntryPoint(self, params):
31            sp.cast(params, M2.u)
32            sp.cast(params, sp.tuple[sp.int, sp.mutez, sp.bool])
33
34
35@sp.add_test()
36def test():
37    s = sp.test_scenario("Abbrevs")
38
39    s.add_module(M1)
40    s.add_module(M2)
41    s.add_module(M3)
42
43    c = M3.C()
44    s += c
45    c.myEntryPoint(
46        sp.set_type_expr((1, sp.mutez(2), True), sp.tuple[sp.int, sp.mutez, sp.bool])
47    )
48    c.myEntryPoint(sp.set_type_expr((1, sp.mutez(2), True), M2.u))
49
50    c = M2.C(42)
51    s += c
52    c.myEntryPoint(sp.set_type_expr((1, sp.mutez(2), True), M2.u))