Skip to content

Commit f983086

Browse files
feat(pre_alloc): integrate fork dependency for dynamic bytecode size limit
1 parent c76fcd9 commit f983086

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/pytest_plugins/filler/pre_alloc.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
CONTRACT_START_ADDRESS_DEFAULT = 0x1000000000000000000000000000000000001000
3737
CONTRACT_ADDRESS_INCREMENTS_DEFAULT = 0x100
3838

39-
MAX_BYTECODE_SIZE = 24576
40-
4139

4240
def pytest_addoption(parser: pytest.Parser):
4341
"""Add command-line options to pytest."""
@@ -98,13 +96,15 @@ class Alloc(BaseAlloc):
9896
_contract_address_iterator: Iterator[Address] = PrivateAttr()
9997
_eoa_iterator: Iterator[EOA] = PrivateAttr()
10098
_evm_code_type: EVMCodeType | None = PrivateAttr(None)
99+
_fork: Fork = PrivateAttr()
101100

102101
def __init__(
103102
self,
104103
*args,
105104
alloc_mode: AllocMode,
106105
contract_address_iterator: Iterator[Address],
107106
eoa_iterator: Iterator[EOA],
107+
fork: Fork,
108108
evm_code_type: EVMCodeType | None = None,
109109
**kwargs,
110110
):
@@ -114,6 +114,7 @@ def __init__(
114114
self._contract_address_iterator = contract_address_iterator
115115
self._eoa_iterator = eoa_iterator
116116
self._evm_code_type = evm_code_type
117+
self._fork = fork
117118

118119
def __setitem__(self, address: Address | FixedSizeBytesConvertible, account: Account | None):
119120
"""Set account associated with an address."""
@@ -166,8 +167,9 @@ def deploy_contract(
166167

167168
code = self.code_pre_processor(code, evm_code_type=evm_code_type)
168169
code_bytes = bytes(code) if not isinstance(code, (bytes, str)) else code
169-
assert len(code_bytes) <= MAX_BYTECODE_SIZE, (
170-
f"code too large: {len(code_bytes)} > {MAX_BYTECODE_SIZE}"
170+
max_code_size = self._fork.max_code_size()
171+
assert len(code_bytes) <= max_code_size, (
172+
f"code too large: {len(code_bytes)} > {max_code_size}"
171173
)
172174

173175
super().__setitem__(
@@ -424,11 +426,13 @@ def pre(
424426
contract_address_iterator: Iterator[Address],
425427
eoa_iterator: Iterator[EOA],
426428
evm_code_type: EVMCodeType,
429+
fork: Fork,
427430
) -> Alloc:
428431
"""Return default pre allocation for all tests (Empty alloc)."""
429432
return Alloc(
430433
alloc_mode=alloc_mode,
431434
contract_address_iterator=contract_address_iterator,
432435
eoa_iterator=eoa_iterator,
436+
fork=fork,
433437
evm_code_type=evm_code_type,
434438
)

src/pytest_plugins/filler/tests/test_pre_alloc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66

77
from ethereum_test_base_types import Address, TestPrivateKey, TestPrivateKey2
8+
from ethereum_test_forks import Prague
89
from ethereum_test_types import EOA
910
from ethereum_test_vm import EVMCodeType
1011
from ethereum_test_vm import Opcodes as Op
@@ -33,6 +34,7 @@ def create_test_alloc(
3334
alloc_mode=alloc_mode,
3435
contract_address_iterator=contract_iter,
3536
eoa_iterator=eoa_iter,
37+
fork=Prague,
3638
evm_code_type=evm_code_type,
3739
)
3840

0 commit comments

Comments
 (0)