@@ -545,3 +545,77 @@ def test_createConstantBlocks_tmpl_all():
545545
546546 actual = createConstantBlocks (ops )
547547 assert actual == expected
548+
549+
550+ def test_createConstantBlocks_intc ():
551+ """Test scenario where there are more than 4 constants in the intcblock.
552+ If the 4th constant can't fit in one varuint byte (more than 2**7) it
553+ should be referenced with the Op.intc 4 command.
554+ """
555+
556+ ops = [
557+ TealOp (None , Op .int , 0 ),
558+ TealOp (None , Op .int , 0 ),
559+ TealOp (None , Op .int , 1 ),
560+ TealOp (None , Op .int , 1 ),
561+ TealOp (None , Op .int , 2 ),
562+ TealOp (None , Op .int , 2 ),
563+ TealOp (None , Op .int , 3 ),
564+ TealOp (None , Op .int , 3 ),
565+ TealOp (None , Op .int , 2 ** 7 ),
566+ TealOp (None , Op .int , 2 ** 7 ),
567+ ]
568+
569+ expected = [
570+ TealOp (None , Op .intcblock , 0 , 1 , 2 , 3 , 2 ** 7 ),
571+ TealOp (None , Op .intc_0 , "//" , 0 ),
572+ TealOp (None , Op .intc_0 , "//" , 0 ),
573+ TealOp (None , Op .intc_1 , "//" , 1 ),
574+ TealOp (None , Op .intc_1 , "//" , 1 ),
575+ TealOp (None , Op .intc_2 , "//" , 2 ),
576+ TealOp (None , Op .intc_2 , "//" , 2 ),
577+ TealOp (None , Op .intc_3 , "//" , 3 ),
578+ TealOp (None , Op .intc_3 , "//" , 3 ),
579+ TealOp (None , Op .intc , 4 , "//" , 2 ** 7 ),
580+ TealOp (None , Op .intc , 4 , "//" , 2 ** 7 ),
581+ ]
582+
583+ actual = createConstantBlocks (ops )
584+ assert actual == expected
585+
586+
587+ def test_createConstantBlocks_small_constant ():
588+ """If a constant cannot be referenced using the intc_[0..3] commands
589+ and it can be stored in one varuint it byte then Op.pushint is used.
590+ """
591+
592+ for cur in range (4 , 2 ** 7 ):
593+ ops = [
594+ TealOp (None , Op .int , 0 ),
595+ TealOp (None , Op .int , 0 ),
596+ TealOp (None , Op .int , 1 ),
597+ TealOp (None , Op .int , 1 ),
598+ TealOp (None , Op .int , 2 ),
599+ TealOp (None , Op .int , 2 ),
600+ TealOp (None , Op .int , 3 ),
601+ TealOp (None , Op .int , 3 ),
602+ TealOp (None , Op .int , cur ),
603+ TealOp (None , Op .int , cur ),
604+ ]
605+
606+ expected = [
607+ TealOp (None , Op .intcblock , 0 , 1 , 2 , 3 ),
608+ TealOp (None , Op .intc_0 , "//" , 0 ),
609+ TealOp (None , Op .intc_0 , "//" , 0 ),
610+ TealOp (None , Op .intc_1 , "//" , 1 ),
611+ TealOp (None , Op .intc_1 , "//" , 1 ),
612+ TealOp (None , Op .intc_2 , "//" , 2 ),
613+ TealOp (None , Op .intc_2 , "//" , 2 ),
614+ TealOp (None , Op .intc_3 , "//" , 3 ),
615+ TealOp (None , Op .intc_3 , "//" , 3 ),
616+ TealOp (None , Op .pushint , cur , "//" , cur ),
617+ TealOp (None , Op .pushint , cur , "//" , cur ),
618+ ]
619+
620+ actual = createConstantBlocks (ops )
621+ assert actual == expected
0 commit comments