31
31
stop_sub_container = Section .Container (stop_container )
32
32
return_sub_container = Section .Container (Container .Code (Op .RETURN (0 , 0 )))
33
33
revert_sub_container = Section .Container (Container .Code (Op .REVERT (0 , 0 )))
34
+ abort_sub_container = Section .Container (Container .Code (Op .INVALID ))
34
35
returncontract_sub_container = Section .Container (
35
36
Container (
36
37
sections = [
@@ -447,6 +448,41 @@ def test_container_both_kinds_same_sub(eof_test: EOFTestFiller):
447
448
)
448
449
449
450
451
+ @pytest .mark .parametrize ("container_idx" , [0 , 1 , 255 ])
452
+ @pytest .mark .parametrize (
453
+ "sub_container" ,
454
+ [
455
+ pytest .param (abort_sub_container , id = "abort" ),
456
+ pytest .param (revert_sub_container , id = "revert" ),
457
+ ],
458
+ )
459
+ def test_container_ambiguous_kind (
460
+ eof_test : EOFTestFiller , container_idx : int , sub_container : Section
461
+ ):
462
+ """
463
+ Test ambiguous container kind:
464
+ a single subcontainer reference by both EOFCREATE and RETURNCONTRACT.
465
+ """
466
+ sections = [
467
+ Section .Code (
468
+ code = (
469
+ sum (Op .EOFCREATE [i ](0 , 0 , 0 , 0 ) for i in range (container_idx ))
470
+ + Op .EOFCREATE [container_idx ](0 , 0 , 0 , 0 )
471
+ + Op .RETURNCONTRACT [container_idx ](0 , 0 )
472
+ ),
473
+ ),
474
+ ]
475
+ sections += (container_idx + 1 ) * [sub_container ]
476
+
477
+ eof_test (
478
+ container = Container (
479
+ sections = sections ,
480
+ kind = ContainerKind .INITCODE ,
481
+ ),
482
+ expect_exception = EOFException .AMBIGUOUS_CONTAINER_KIND ,
483
+ )
484
+
485
+
450
486
def test_container_both_kinds_different_sub (eof_test : EOFTestFiller ):
451
487
"""Test multiple kinds of subcontainer at the same level."""
452
488
eof_test (
@@ -715,7 +751,7 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
715
751
+ Op .POP
716
752
+ Op .STOP
717
753
),
718
- Section . Container ( Container . Code ( Op . INVALID )) ,
754
+ abort_sub_container ,
719
755
],
720
756
expected_bytecode = """
721
757
ef0001010004020001000b0300010014040000000080000436600060ff6000ec005000ef000101000402
@@ -727,7 +763,7 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
727
763
Container (
728
764
sections = [
729
765
Section .Code (Op .PUSH1 [0 ] + Op .RJUMP [0 ] + Op .STOP ),
730
- Section . Container ( Container . Code ( Op . INVALID )) ,
766
+ abort_sub_container ,
731
767
],
732
768
expected_bytecode = """
733
769
ef00010100040200010006030001001404000000008000016000e0000000ef0001010004020001000104
@@ -742,7 +778,7 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
742
778
Container (
743
779
sections = [
744
780
Section .Code (Op .PUSH1 [0 ] + Op .RJUMP [0 ] + Op .STOP ),
745
- Section . Container ( Container . Code ( Op . INVALID )) ,
781
+ abort_sub_container ,
746
782
Section .Data (custom_size = 2 ),
747
783
],
748
784
expected_bytecode = """
@@ -758,7 +794,7 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
758
794
Container (
759
795
sections = [
760
796
Section .Code (Op .PUSH1 [0 ] + Op .RJUMP [0 ] + Op .STOP ),
761
- Section . Container ( Container . Code ( Op . INVALID )) ,
797
+ abort_sub_container ,
762
798
Section .Data ("aabb" ),
763
799
],
764
800
expected_bytecode = """
@@ -794,7 +830,7 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
794
830
+ Op .STOP
795
831
)
796
832
]
797
- + 2 * [Section . Container ( Container . Code ( Op . INVALID )) ],
833
+ + 2 * [abort_sub_container ],
798
834
expected_bytecode = """
799
835
ef0001010004020001000b03000200140014040000000080000436600060ff6000ec015000ef00010100
800
836
0402000100010400000000800000feef000101000402000100010400000000800000fe""" ,
@@ -808,7 +844,7 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
808
844
Container (
809
845
sections = [
810
846
Section .Code (Op .PUSH1 [0 ] + Op .RJUMP [0 ] + Op .STOP ),
811
- Section . Container ( Container . Code ( Op . INVALID )) ,
847
+ abort_sub_container ,
812
848
Section .Container (Container .Code (Op .PUSH0 + Op .PUSH0 + Op .RETURN )),
813
849
],
814
850
expected_bytecode = """
@@ -833,7 +869,7 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
833
869
+ Op .STOP
834
870
)
835
871
]
836
- + 256 * [Section . Container ( Container . Code ( Op . INVALID )) ],
872
+ + 256 * [abort_sub_container ],
837
873
# Originally this test was "valid" because it was created
838
874
# before "orphan subcontainer" rule was introduced.
839
875
validity_error = EOFException .ORPHAN_SUBCONTAINER ,
@@ -843,7 +879,7 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
843
879
pytest .param (
844
880
Container (
845
881
sections = [Section .Code (Op .PUSH1 [0 ] + Op .RJUMP [0 ] + Op .STOP )]
846
- + 256 * [Section . Container ( Container . Code ( Op . INVALID )) ],
882
+ + 256 * [abort_sub_container ],
847
883
# Originally this test was "valid" because it was created
848
884
# before "orphan subcontainer" rule was introduced.
849
885
validity_error = EOFException .ORPHAN_SUBCONTAINER ,
0 commit comments