Skip to content

fix(tests): EIP-7702: send tx of eoa after setcode tx is mined #1411

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

Merged
Merged
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
25 changes: 12 additions & 13 deletions src/ethereum_test_execution/transaction_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class TransactionPost(BaseExecute):
"""Represents a simple transaction-send then post-check execution format."""

transactions: List[Transaction]
blocks: List[List[Transaction]]
post: Alloc

format_name: ClassVar[str] = "transaction_post"
Expand All @@ -24,20 +24,19 @@ class TransactionPost(BaseExecute):

def execute(self, eth_rpc: EthRPC):
"""Execute the format."""
assert not any(tx.ty == 3 for tx in self.transactions), (
assert not any(tx.ty == 3 for block in self.blocks for tx in block), (
"Transaction type 3 is not supported in execute mode."
)
if any(tx.error is not None for tx in self.transactions):
for transaction in self.transactions:
if transaction.error is None:
eth_rpc.send_wait_transaction(transaction.with_signature_and_sender())
else:
with pytest.raises(SendTransactionExceptionError):
eth_rpc.send_transaction(transaction.with_signature_and_sender())
else:
eth_rpc.send_wait_transactions(
[tx.with_signature_and_sender() for tx in self.transactions]
)
for block in self.blocks:
if any(tx.error is not None for tx in block):
for transaction in block:
if transaction.error is None:
eth_rpc.send_wait_transaction(transaction.with_signature_and_sender())
else:
with pytest.raises(SendTransactionExceptionError):
eth_rpc.send_transaction(transaction.with_signature_and_sender())
else:
eth_rpc.send_wait_transactions([tx.with_signature_and_sender() for tx in block])

for address, account in self.post.root.items():
balance = eth_rpc.get_balance(address)
Expand Down
6 changes: 3 additions & 3 deletions src/ethereum_test_specs/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,11 +750,11 @@ def execute(
) -> BaseExecute:
"""Generate the list of test fixtures."""
if execute_format == TransactionPost:
txs: List[Transaction] = []
blocks: List[List[Transaction]] = []
for block in self.blocks:
txs += block.txs
blocks += [block.txs]
return TransactionPost(
transactions=txs,
blocks=blocks,
post=self.post,
)
raise Exception(f"Unsupported execute format: {execute_format}")
Expand Down
2 changes: 1 addition & 1 deletion src/ethereum_test_specs/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def execute(
"""Generate the list of test fixtures."""
if execute_format == TransactionPost:
return TransactionPost(
transactions=[self.tx],
blocks=[[self.tx]],
post=self.post,
)
raise Exception(f"Unsupported execute format: {execute_format}")
Expand Down
2 changes: 1 addition & 1 deletion src/ethereum_test_specs/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def execute(
"""Execute the transaction test by sending it to the live network."""
if execute_format == TransactionPost:
return TransactionPost(
transactions=[self.tx],
blocks=[[self.tx]],
post={},
)
raise Exception(f"Unsupported execute format: {execute_format}")
Expand Down
101 changes: 60 additions & 41 deletions tests/prague/eip7702_set_code_tx/test_set_code_txs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from hashlib import sha256
from itertools import count
from typing import List

import pytest

Expand Down Expand Up @@ -2719,60 +2720,71 @@ def test_set_code_to_system_contract(
if tx_type in [0, 3]
else None,
)
@pytest.mark.parametrize(
"same_block",
[
pytest.param(
True,
marks=[pytest.mark.execute(pytest.mark.skip("duplicate scenario for execute"))],
id="same_block",
),
pytest.param(False, id="different_block"),
],
)
def test_eoa_tx_after_set_code(
blockchain_test: BlockchainTestFiller,
pre: Alloc,
tx_type: int,
fork: Fork,
evm_code_type: EVMCodeType,
same_block: bool,
):
"""Test sending a transaction from an EOA after code has been set to the account."""
auth_signer = pre.fund_eoa()

set_code = Op.SSTORE(1, Op.ADD(Op.SLOAD(1), 1)) + Op.STOP
set_code_to_address = pre.deploy_contract(set_code)

txs = [
Transaction(
sender=pre.fund_eoa(),
gas_limit=500_000,
to=auth_signer,
value=0,
authorization_list=[
AuthorizationTuple(
address=set_code_to_address,
nonce=0,
signer=auth_signer,
),
],
)
]
first_eoa_tx = Transaction(
sender=pre.fund_eoa(),
gas_limit=500_000,
to=auth_signer,
value=0,
authorization_list=[
AuthorizationTuple(
address=set_code_to_address,
nonce=0,
signer=auth_signer,
),
],
)
auth_signer.nonce += 1 # type: ignore

follow_up_eoa_txs: List[Transaction] = []
match tx_type:
case 0:
txs.append(
Transaction(
type=tx_type,
sender=auth_signer,
gas_limit=500_000,
to=auth_signer,
value=0,
protected=True,
),
)
txs.append(
Transaction(
type=tx_type,
sender=auth_signer,
gas_limit=500_000,
to=auth_signer,
value=0,
protected=False,
),
follow_up_eoa_txs.extend(
[
Transaction(
type=tx_type,
sender=auth_signer,
gas_limit=500_000,
to=auth_signer,
value=0,
protected=True,
),
Transaction(
type=tx_type,
sender=auth_signer,
gas_limit=500_000,
to=auth_signer,
value=0,
protected=False,
),
]
)
case 1:
txs.append(
follow_up_eoa_txs.append(
Transaction(
type=tx_type,
sender=auth_signer,
Expand All @@ -2785,10 +2797,10 @@ def test_eoa_tx_after_set_code(
storage_keys=[1],
)
],
),
)
)
case 2:
txs.append(
follow_up_eoa_txs.append(
Transaction(
type=tx_type,
sender=auth_signer,
Expand All @@ -2797,10 +2809,10 @@ def test_eoa_tx_after_set_code(
value=0,
max_fee_per_gas=1_000,
max_priority_fee_per_gas=1_000,
),
)
)
case 3:
txs.append(
follow_up_eoa_txs.append(
Transaction(
type=tx_type,
sender=auth_signer,
Expand All @@ -2814,14 +2826,21 @@ def test_eoa_tx_after_set_code(
[Hash(1)],
Spec4844.BLOB_COMMITMENT_VERSION_KZG,
),
),
)
)
case _:
raise ValueError(f"Unsupported tx type: {tx_type}, test needs update")

if same_block:
blocks = [Block(txs=[first_eoa_tx] + follow_up_eoa_txs)]
else:
blocks = [
Block(txs=[first_eoa_tx]),
Block(txs=follow_up_eoa_txs),
]
blockchain_test(
pre=pre,
blocks=[Block(txs=txs)],
blocks=blocks,
post={
auth_signer: Account(
nonce=3 if tx_type == 0 else 2,
Expand Down