templates.test_type_errors

  1import smartpy as sp
  2
  3
  4@sp.module
  5def M():
  6    def x():
  7        return 42
  8
  9
 10@sp.module
 11def m001():
 12    _ = sp.cast(42, t)
 13
 14
 15@sp.module
 16def m002():
 17    _ = sp.cast(42, M.t)
 18
 19
 20@sp.module
 21def m003():
 22    _ = sp.cast(42, ABC.t)
 23
 24
 25@sp.module
 26def m004():
 27    x: type = sp.int
 28    x: type = sp.int
 29
 30
 31@sp.module
 32def m005():
 33    x: type = sp.int
 34    y = x
 35
 36
 37@sp.module
 38def m006():
 39    y = x
 40
 41
 42@sp.module
 43def m007():
 44    def f():
 45        pass
 46
 47    def f():
 48        pass
 49
 50
 51@sp.module
 52def m008():
 53    def f():
 54        x = 42
 55        x = "abc"
 56
 57
 58@sp.module
 59def m009():
 60    _ = sp.create_contract(AB.C, None, sp.mutez(0), ())
 61
 62
 63@sp.module
 64def m010():
 65    def f(x):
 66        x = 42
 67
 68
 69@sp.module
 70def m011():
 71    x = 42
 72
 73    def f():
 74        x = 42
 75
 76
 77@sp.module
 78def m012():
 79    def f(x):
 80        with sp.match(x):
 81            with sp.case.A as y:
 82                y = 42
 83
 84
 85@sp.module
 86def m013():
 87    def f(x):
 88        (x, y) = (1, 2)
 89
 90
 91@sp.module
 92def m014():
 93    def f():
 94        _ = sp.create_contract(C, None, sp.mutez(0), ())
 95
 96
 97@sp.module
 98def m015():
 99    def f():
100        return 42
101        x = 42
102
103
104@sp.module
105def m016():
106    class C(sp.Contract):
107        @sp.entrypoint
108        def ep(self):
109            self.__init__(self, 42)
110
111
112@sp.module
113def m017():
114    class A(sp.Contract):
115        pass
116
117    class C(sp.Contract):
118        def __init__(self):
119            A.__init__(self)
120
121
122@sp.module
123def m018():
124    def f():
125        with sp.modify_record(42) as y:
126            pass
127
128
129@sp.module
130def m019():
131    def f(x):
132        with sp.match(42):
133            with sp.case.A as y:
134                pass
135
136
137@sp.module
138def m020():
139    def f(x):
140        with sp.match(sp.variant.A(42)):
141            with sp.case.A as y:
142                assert y == "abc"
143
144
145@sp.module
146def m021():
147    def f():
148        with sp.modify_record(42) as y:
149            pass
150
151
152@sp.module
153def m022():
154    def f(x):
155        with sp.modify_record(x) as y:
156            return 42
157
158
159@sp.module
160def m023():
161    def f():
162        42
163
164
165@sp.module
166def m024():
167    def f():
168        (x, (y, z)) = (3, 4)
169
170
171@sp.module
172def m025():
173    def f():
174        (x, y) = 3
175
176
177@sp.module
178def m026():
179    def f():
180        record(a=a, b=b).match = 42
181
182
183@sp.module
184def m027():
185    t: type = int
186
187    def f():
188        t = 42
189
190
191@sp.module
192def m028():
193    def g():
194        x = sp.record(a=42)
195        x.a = "abc"
196
197
198@sp.module
199def m029():
200    def f():
201        for x in 42:
202            pass
203
204
205@sp.module
206def m030():
207    def f():
208        if "abc":
209            pass
210
211
212@sp.module
213def m031():
214    def f():
215        while "abc":
216            pass
217
218
219@sp.module
220def m032():
221    def f():
222        sp.cast(42, sp.string)
223
224
225@sp.module
226def m033():
227    def f():
228        assert 42
229
230
231@sp.module
232def m034():
233    def f():
234        x = {42}
235        x.add("abc")
236
237
238@sp.module
239def m035():
240    def f():
241        x = {42}
242        x.remove("abc")
243
244
245@sp.module
246def m036():
247    def f():
248        sp.never(42)
249
250
251@sp.module
252def m037():
253    class C(sp.Contract):
254        @sp.entrypoint
255        def ep(self):
256            _ = sp.self_entrypoint("abc")
257
258
259@sp.module
260def m038():
261    class Fibonacci(sp.Contract):
262        def __init__(self):
263            self.data.counter = 0
264            self.data.steps = []
265
266        @sp.entrypoint
267        def run(self, n):
268            self.data.steps.push(n)
269            if n > 1:
270                sp.transfer(n - 2, sp.mutez(0), sp.self_entrypoint("run"))
271                sp.transfer(n - 1, sp.mutez(0), sp.self_entrypoint("run"))
272            else:
273                self.data.counter += 1
274
275        @sp.entrypoint
276        def compute(self, n):
277            self.data.counter = 0
278            self.data.steps = []
279            sp.transfer(n, sp.mutez(0), sp.self_entrypoint("run"))
280
281
282@sp.module
283def m039():
284    def f():
285        _ = abs(True)
286
287
288@sp.module
289def m040():
290    def f():
291        _ = sp.sub_mutez(1, sp.mutez(2))
292
293
294@sp.module
295def m041():
296    def f():
297        _ = sp.sub_mutez(sp.mutez(1), 2)
298
299
300@sp.module
301def m042():
302    def f(k, s, b):
303        sp.cast(k, sp.unit)
304        sp.cast(s, sp.signature)
305        sp.cast(b, sp.bytes)
306        _ = sp.check_signature(k, s, b)
307
308
309@sp.module
310def m042():
311    def f(k, s, b):
312        sp.cast(k, sp.key)
313        sp.cast(s, sp.unit)
314        sp.cast(b, sp.bytes)
315        _ = sp.check_signature(k, s, b)
316
317
318@sp.module
319def m042():
320    def f(k, s, b):
321        sp.cast(k, sp.key)
322        sp.cast(s, sp.signature)
323        sp.cast(b, sp.unit)
324        _ = sp.check_signature(k, s, b)
325
326
327@sp.module
328def m043():
329    x = sp.sum(["a"])
330
331
332@sp.module
333def m044():
334    class C(sp.Contract):
335        @sp.entrypoint
336        def ep(self):
337            sp.set_delegate(42)
338
339
340@sp.module
341def m045():
342    _ = sp.unpack(42, int)
343
344
345@sp.module
346def m046():
347    _ = sp.implicit_account(42)
348
349
350@sp.module
351def m047():
352    _ = sp.to_nat("abc")
353
354
355@sp.module
356def m048():
357    _ = [1, "abc"]
358
359
360@sp.module
361def m049():
362    def f():
363        x = sp.nat(2) / sp.int(-3)
364
365
366@sp.module
367def m050():
368    def f():
369        x = "abc" / True
370
371
372@sp.module
373def m051():
374    def f():
375        x = "abc" + 2
376
377
378@sp.module
379def m052():
380    def f():
381        x = sp.mod("abc", 2)
382
383
384@sp.module
385def m053():
386    def f():
387        x = sp.mod(sp.nat(1), sp.int(2))
388
389
390@sp.module
391def m054():
392    def f():
393        pass
394
395
396@sp.module
397def m055():
398    def f():
399        pass
400
401
402@sp.module
403def m056():
404    def f():
405        pass
406
407
408@sp.module
409def m057():
410    def f():
411        pass
412
413
414@sp.module
415def m058():
416    def f():
417        pass
418
419
420@sp.module
421def m059():
422    def f():
423        pass
424
425
426@sp.module
427def m060():
428    def f():
429        pass
430
431
432@sp.module
433def m061():
434    def f():
435        pass
436
437
438@sp.module
439def m062():
440    def f():
441        pass
442
443
444@sp.module
445def m063():
446    def f():
447        pass
448
449
450@sp.module
451def m064():
452    def f():
453        pass
454
455
456@sp.module
457def m065():
458    def f():
459        pass
460
461
462@sp.module
463def m066():
464    def f():
465        pass
466
467
468@sp.module
469def m067():
470    def f():
471        pass
472
473
474@sp.module
475def m068():
476    def f():
477        pass
478
479
480@sp.module
481def m069():
482    def f():
483        pass
484
485
486@sp.module
487def m070():
488    def f():
489        pass
490
491
492@sp.module
493def m071():
494    def f():
495        pass
496
497
498@sp.module
499def m072():
500    def f():
501        pass
502
503
504@sp.module
505def m073():
506    def f():
507        pass
508
509
510@sp.module
511def m074():
512    def f():
513        pass
514
515
516@sp.module
517def m075():
518    def f():
519        pass
520
521
522@sp.module
523def m076():
524    def f():
525        pass
526
527
528@sp.module
529def m077():
530    def f():
531        pass
532
533
534@sp.module
535def m078():
536    def f():
537        pass
538
539
540@sp.module
541def m079():
542    def f():
543        pass
544
545
546@sp.module
547def m080():
548    def f():
549        pass
550
551
552@sp.module
553def m081():
554    def f():
555        pass
556
557
558@sp.module
559def m082():
560    def f():
561        pass
562
563
564@sp.module
565def m083():
566    def f():
567        pass
568
569
570@sp.module
571def m084():
572    def f():
573        pass
574
575
576@sp.module
577def m085():
578    def f():
579        pass
580
581
582@sp.module
583def m086():
584    def f():
585        pass
586
587
588@sp.module
589def m087():
590    def f():
591        pass
592
593
594@sp.module
595def m088():
596    def f():
597        pass
598
599
600@sp.module
601def m089():
602    def f():
603        pass
604
605
606def test_module(s, name, m):
607    try:
608        s.add_module(m)
609    except Exception as e:
610        print(name)
611        print(e)
612
613
614@sp.add_test()
615def test():
616    s = sp.test_scenario("s", M)
617    test_module(s, "m001", m001)
618    test_module(s, "m002", m002)
619    test_module(s, "m003", m003)
620    test_module(s, "m004", m004)
621    test_module(s, "m005", m005)
622    test_module(s, "m006", m006)
623    test_module(s, "m007", m007)
624    test_module(s, "m008", m008)
625    test_module(s, "m009", m009)
626
627    test_module(s, "m010", m010)
628    test_module(s, "m011", m011)
629    test_module(s, "m012", m012)
630    test_module(s, "m013", m013)
631    test_module(s, "m014", m014)
632    test_module(s, "m015", m015)
633    test_module(s, "m016", m016)
634    test_module(s, "m017", m017)
635    test_module(s, "m018", m018)
636    test_module(s, "m019", m019)
637
638    test_module(s, "m020", m020)
639    test_module(s, "m021", m021)
640    test_module(s, "m022", m022)
641    test_module(s, "m023", m023)
642    test_module(s, "m024", m024)
643    test_module(s, "m025", m025)
644    test_module(s, "m026", m026)
645    test_module(s, "m027", m027)
646    test_module(s, "m028", m028)
647    test_module(s, "m029", m029)
648
649    test_module(s, "m030", m030)
650    test_module(s, "m031", m031)
651    test_module(s, "m032", m032)
652    test_module(s, "m033", m033)
653    test_module(s, "m034", m034)
654    test_module(s, "m035", m035)
655    test_module(s, "m036", m036)
656    test_module(s, "m037", m037)
657    test_module(s, "m038", m038)
658    test_module(s, "m039", m039)
659
660    test_module(s, "m040", m040)
661    test_module(s, "m041", m041)
662    test_module(s, "m042", m042)
663    test_module(s, "m043", m043)
664    test_module(s, "m044", m044)
665    test_module(s, "m045", m045)
666    test_module(s, "m046", m046)
667    test_module(s, "m047", m047)
668    test_module(s, "m048", m048)
669    test_module(s, "m049", m049)
670
671    test_module(s, "m050", m050)
672    test_module(s, "m051", m051)
673    test_module(s, "m052", m052)
674    test_module(s, "m053", m053)
675    test_module(s, "m054", m054)
676    test_module(s, "m055", m055)
677    test_module(s, "m056", m056)
678    test_module(s, "m057", m057)
679    test_module(s, "m058", m058)
680    test_module(s, "m059", m059)
681
682    test_module(s, "m060", m060)
683    test_module(s, "m061", m061)
684    test_module(s, "m062", m062)
685    test_module(s, "m063", m063)
686    test_module(s, "m064", m064)
687    test_module(s, "m065", m065)
688    test_module(s, "m066", m066)
689    test_module(s, "m067", m067)
690    test_module(s, "m068", m068)
691    test_module(s, "m069", m069)
692
693    test_module(s, "m070", m070)
694    test_module(s, "m071", m071)
695    test_module(s, "m072", m072)
696    test_module(s, "m073", m073)
697    test_module(s, "m074", m074)
698    test_module(s, "m075", m075)
699    test_module(s, "m076", m076)
700    test_module(s, "m077", m077)
701    test_module(s, "m078", m078)
702    test_module(s, "m079", m079)
703
704    test_module(s, "m080", m080)
705    test_module(s, "m081", m081)
706    test_module(s, "m082", m082)
707    test_module(s, "m083", m083)
708    test_module(s, "m084", m084)
709    test_module(s, "m085", m085)
710    test_module(s, "m086", m086)
711    test_module(s, "m087", m087)
712    test_module(s, "m088", m088)
713    test_module(s, "m089", m089)
def test_module(s, name, m):
607def test_module(s, name, m):
608    try:
609        s.add_module(m)
610    except Exception as e:
611        print(name)
612        print(e)