Skip to content

fix(tests): EIP-7702: use penultimate block number instead of fixing block 0 #1390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ethereum_test_rpc/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ def __init__(
super().__init__(url, extra_headers)
self.transaction_wait_timeout = transaction_wait_timeout

def get_block_number(self) -> int:
"""`eth_blockNumber`: Returns the number of the most recent block."""
return int(self.post_request("blockNumber"), 16)

def get_block_by_number(self, block_number: BlockNumberType = "latest", full_txs: bool = True):
"""`eth_getBlockByNumber`: Returns information about a block by block number."""
block = hex(block_number) if isinstance(block_number, int) else block_number
Expand Down
4 changes: 4 additions & 0 deletions src/ethereum_test_types/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ def fund_address(self, address: Address, amount: NumberConvertible):
"""
raise NotImplementedError("fund_address is not implemented in the base class")

def get_block_number(self):
"""Return the last block number."""
raise NotImplementedError("get_block_number is not implemented in the base class")


class WithdrawalGeneric(CamelModel, Generic[NumberBoundTypeVar]):
"""Withdrawal generic type, used as a parent class for `Withdrawal` and `FixtureWithdrawal`."""
Expand Down
4 changes: 4 additions & 0 deletions src/pytest_plugins/execute/pre_alloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ def fund_address(self, address: Address, amount: NumberConvertible):

super().__setitem__(address, Account(balance=amount))

def get_block_number(self):
"""Return the last block number."""
return self._eth_rpc.get_block_number()

def wait_for_transactions(self) -> List[TransactionByHashResponse]:
"""Wait for all transactions to be included in blocks."""
return self._eth_rpc.wait_for_transactions(self._txs)
Expand Down
4 changes: 4 additions & 0 deletions src/pytest_plugins/filler/pre_alloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ def fund_address(self, address: Address, amount: NumberConvertible):
return
super().__setitem__(address, Account(balance=amount))

def get_block_number(self):
"""Return the last block number."""
return 0


@pytest.fixture(scope="session")
def alloc_mode(request: pytest.FixtureRequest) -> AllocMode:
Expand Down
3 changes: 2 additions & 1 deletion tests/prague/eip7702_set_code_tx/test_set_code_txs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2656,7 +2656,8 @@ def test_set_code_to_system_contract(
caller_payload = consolidation_request.calldata
call_value = consolidation_request.value
case Address(0x0000F90827F1C53A10CB7A02335B175320002935): # EIP-2935
caller_payload = Hash(0)
# Use the penultimate block to ensure it is saved in the history contract
caller_payload = Hash(max(pre.get_block_number() - 1, 0))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't it be in env?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be in env too, but I can't find how to get block number from node without using _eth_rpc of Alloc, can you suggest a better solution?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this should be in the env, and I think this requires a bit more complex solution.

We probably need to take the same approach as pre where it's a global fixture generated by the filler/execute plugin:

In the filler plugin, the fixture result would always be an instance of Environment with the default values.

In the execute plugin, the fixture is also an instance of Environment but the values are populated using the return self._eth_rpc... methods.

caller_code_storage[call_return_data_size_slot] = 32
case _:
raise ValueError(f"Not implemented system contract: {system_contract}")
Expand Down