Skip to content

Commit

Permalink
feat(fw): Add configurable starting contract addresses to fill
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Jun 4, 2024
1 parent 03323d7 commit 3b4e5b7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/ethereum_test_tools/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,6 @@ def __new__(
)
SENDERS = [next(SENDERS_ITER) for _ in range(MAX_SENDERS)]

# TODO: This should be modified to use a higher address range.
start_contract_address = 0x100


class AllocMode(IntEnum):
"""
Expand All @@ -549,6 +546,8 @@ class Alloc(RootModel[Dict[Address, Account | None]]):
root: Dict[Address, Account | None] = Field(default_factory=dict, validate_default=True)

alloc_mode: ClassVar[AllocMode] = AllocMode.PERMISSIVE
start_contract_address: ClassVar[int] = 0x1000
contract_address_increments: ClassVar[int] = 0x100

@dataclass(kw_only=True)
class UnexpectedAccount(Exception):
Expand Down Expand Up @@ -712,9 +711,9 @@ def deploy_contract(
assert address not in self, f"address {address} already in allocation"
contract_address = address
else:
current_address = start_contract_address
current_address = self.start_contract_address
while current_address in self:
current_address += 0x100
current_address += self.contract_address_increments
contract_address = Address(current_address)

if self.alloc_mode == AllocMode.STRICT:
Expand Down
26 changes: 25 additions & 1 deletion src/pytest_plugins/test_filler/test_filler.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,22 @@ def pytest_addoption(parser):
default=False,
help=("[DEBUG ONLY] Disallows deploying a contract in a predefined address."),
)
test_group.addoption(
"--test-contract-start-address",
action="store",
dest="test_contract_start_address",
default=None,
type=str,
help="The starting address from which tests will deploy contracts.",
)
test_group.addoption(
"--test-contract-address-increments",
action="store",
dest="test_contract_address_increments",
default=None,
type=str,
help="The address increment value to each deployed contract by a test.",
)

debug_group = parser.getgroup("debug", "Arguments defining debug behavior")
debug_group.addoption(
Expand Down Expand Up @@ -386,12 +402,20 @@ def t8n(request, evm_bin: Path) -> Generator[TransitionTool, None, None]:


@pytest.fixture(autouse=True, scope="session")
def pre_alloc_mode(request):
def configure_pre_alloc(request):
"""
Returns the configured solc binary path.
"""
if request.config.getoption("strict_alloc"):
Alloc.alloc_mode = AllocMode.STRICT
if request.config.getoption("test_contract_start_address"):
Alloc.start_contract_address = int(
request.config.getoption("test_contract_start_address"), 0
)
if request.config.getoption("test_contract_address_increments"):
Alloc.contract_address_increments = int(
request.config.getoption("test_contract_address_increments"), 0
)


@pytest.fixture(autouse=True)
Expand Down

0 comments on commit 3b4e5b7

Please sign in to comment.