Skip to content

Commit 12c0087

Browse files
authored
fix(fw): EOF - Accept initcode_prefix on EOF Container.Init (#819)
* fix(fw): Accept `initcode_prefix` on EOF `Container.Init` * fix(fw): Remove kwargs * add(fw): unit tests
1 parent b48db3c commit 12c0087

File tree

2 files changed

+74
-6
lines changed

2 files changed

+74
-6
lines changed

src/ethereum_test_types/eof/v1/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,14 +481,18 @@ def Code(cls, code: BytesConvertible = Bytecode(), **kwargs) -> "Container": #
481481
return cls(sections=[Section.Code(code=code, **kwargs)])
482482

483483
@classmethod
484-
def Init(cls, deploy_container: "Container", **kwargs) -> "Container": # noqa: N802
484+
def Init( # noqa: N802
485+
cls,
486+
deploy_container: "Container",
487+
initcode_prefix: Bytecode = Bytecode(),
488+
) -> "Container":
485489
"""
486490
Creates simple init container that deploys the specified container.
487491
"""
488492
return cls(
489493
sections=[
490494
Section.Code(
491-
code=Op.RETURNCONTRACT[0](0, 0),
495+
code=initcode_prefix + Op.RETURNCONTRACT[0](0, 0),
492496
),
493497
Section.Container(
494498
container=deploy_container,

src/ethereum_test_types/tests/test_eof_v1.py

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from ethereum_test_base_types import to_json
1010
from ethereum_test_base_types.pydantic import CopyValidateModel
11+
from ethereum_test_vm import Opcodes as Op
1112

1213
from ..eof.v1 import AutoSection, Container, Section, SectionKind
1314

@@ -651,7 +652,7 @@
651652
),
652653
"""
653654
# EOF deployed code
654-
ef0001 # Magic followed by bad version
655+
ef0001 # Magic followed by version
655656
020001 # One code segment
656657
0003 # code seg 0: 3 bytes
657658
010004 # One code segment
@@ -690,7 +691,7 @@
690691
),
691692
"""
692693
# EOF deployed code
693-
ef0001 # Magic followed by bad version
694+
ef0001 # Magic followed by version
694695
010004 # One code segment
695696
020001 # One code segment
696697
0003 # code seg 0: 3 bytes
@@ -725,7 +726,7 @@
725726
),
726727
"""
727728
# EOF deployed code
728-
ef0001 # Magic followed by bad version
729+
ef0001 # Magic followed by version
729730
020001 # One code segment
730731
0003 # code seg 0: 3 bytes
731732
040001 # One byte data segment
@@ -759,7 +760,7 @@
759760
),
760761
"""
761762
# EOF deployed code
762-
ef0001 # Magic followed by bad version
763+
ef0001 # Magic followed by version
763764
010004 # Types section
764765
020001 # One code segment
765766
0003 # code seg 0: 3 bytes
@@ -774,6 +775,69 @@
774775
ef
775776
""",
776777
),
778+
(
779+
"Container.Init simple test",
780+
Container.Init(deploy_container=Container.Code(b"\0")),
781+
"""
782+
# EOF deployed code
783+
ef0001 # Magic followed by version
784+
010004 # Types section
785+
020001 # One code segment
786+
0006 # code seg 0: 6 bytes
787+
030001 # One container segment
788+
0014 # container seg 0: 20 bytes
789+
040000 # Zero byte data segment
790+
00 # End of header
791+
0080 0002 # Types section
792+
# Code segment 0 code
793+
6000 # 1 PUSH1 0
794+
6000 # 2 PUSH1 0
795+
ee00 # 3 RETURNCONTRACT[0]
796+
# Subcontainer 0
797+
ef0001 # Magic followed by version
798+
010004 # Types section
799+
020001 # One code segment
800+
0001 # code seg 0: 1 byte
801+
040000 # Zero byte data segment
802+
00 # End of header
803+
0080 0000 # Types section
804+
# Code segment 0 code
805+
00 # 1 STOP
806+
""",
807+
),
808+
(
809+
"Container.Init initcode prefix",
810+
Container.Init(deploy_container=Container.Code(b"\0"), initcode_prefix=Op.SSTORE(0, 0)),
811+
"""
812+
# EOF deployed code
813+
ef0001 # Magic followed by version
814+
010004 # Types section
815+
020001 # One code segment
816+
000b # code seg 0: 11 bytes
817+
030001 # One container segment
818+
0014 # container seg 0: 20 bytes
819+
040000 # Zero byte data segment
820+
00 # End of header
821+
0080 0002 # Types section
822+
# Code segment 0 code
823+
6000 # 1 PUSH1 0
824+
6000 # 2 PUSH1 0
825+
55 # 3 SSTORE
826+
6000 # 4 PUSH1 0
827+
6000 # 5 PUSH1 0
828+
ee00 # 6 RETURNCONTRACT[0]
829+
# Subcontainer 0
830+
ef0001 # Magic followed by version
831+
010004 # Types section
832+
020001 # One code segment
833+
0001 # code seg 0: 1 byte
834+
040000 # Zero byte data segment
835+
00 # End of header
836+
0080 0000 # Types section
837+
# Code segment 0 code
838+
00 # 1 STOP
839+
""",
840+
),
777841
]
778842

779843

0 commit comments

Comments
 (0)