Skip to content

Commit efc39d5

Browse files
sonhv0212marioevz
andauthored
fix(execute,tests): EIP-7702: send tx of eoa after setcode tx is mined (#1411)
* fix(tests): EIP-7702: send transaction of an EOA after setcode tx is mined * refactor(execute): send batch of txs by block * fix(tests): Parametrize instead of change * refactor(execution): Change error check to per-block basis --------- Co-authored-by: Mario Vega <[email protected]>
1 parent 7c9de1d commit efc39d5

File tree

5 files changed

+77
-59
lines changed

5 files changed

+77
-59
lines changed

src/ethereum_test_execution/transaction_post.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class TransactionPost(BaseExecute):
1515
"""Represents a simple transaction-send then post-check execution format."""
1616

17-
transactions: List[Transaction]
17+
blocks: List[List[Transaction]]
1818
post: Alloc
1919

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

2525
def execute(self, eth_rpc: EthRPC):
2626
"""Execute the format."""
27-
assert not any(tx.ty == 3 for tx in self.transactions), (
27+
assert not any(tx.ty == 3 for block in self.blocks for tx in block), (
2828
"Transaction type 3 is not supported in execute mode."
2929
)
30-
if any(tx.error is not None for tx in self.transactions):
31-
for transaction in self.transactions:
32-
if transaction.error is None:
33-
eth_rpc.send_wait_transaction(transaction.with_signature_and_sender())
34-
else:
35-
with pytest.raises(SendTransactionExceptionError):
36-
eth_rpc.send_transaction(transaction.with_signature_and_sender())
37-
else:
38-
eth_rpc.send_wait_transactions(
39-
[tx.with_signature_and_sender() for tx in self.transactions]
40-
)
30+
for block in self.blocks:
31+
if any(tx.error is not None for tx in block):
32+
for transaction in block:
33+
if transaction.error is None:
34+
eth_rpc.send_wait_transaction(transaction.with_signature_and_sender())
35+
else:
36+
with pytest.raises(SendTransactionExceptionError):
37+
eth_rpc.send_transaction(transaction.with_signature_and_sender())
38+
else:
39+
eth_rpc.send_wait_transactions([tx.with_signature_and_sender() for tx in block])
4140

4241
for address, account in self.post.root.items():
4342
balance = eth_rpc.get_balance(address)

src/ethereum_test_specs/blockchain.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,11 +750,11 @@ def execute(
750750
) -> BaseExecute:
751751
"""Generate the list of test fixtures."""
752752
if execute_format == TransactionPost:
753-
txs: List[Transaction] = []
753+
blocks: List[List[Transaction]] = []
754754
for block in self.blocks:
755-
txs += block.txs
755+
blocks += [block.txs]
756756
return TransactionPost(
757-
transactions=txs,
757+
blocks=blocks,
758758
post=self.post,
759759
)
760760
raise Exception(f"Unsupported execute format: {execute_format}")

src/ethereum_test_specs/state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def execute(
239239
"""Generate the list of test fixtures."""
240240
if execute_format == TransactionPost:
241241
return TransactionPost(
242-
transactions=[self.tx],
242+
blocks=[[self.tx]],
243243
post=self.post,
244244
)
245245
raise Exception(f"Unsupported execute format: {execute_format}")

src/ethereum_test_specs/transaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def execute(
100100
"""Execute the transaction test by sending it to the live network."""
101101
if execute_format == TransactionPost:
102102
return TransactionPost(
103-
transactions=[self.tx],
103+
blocks=[[self.tx]],
104104
post={},
105105
)
106106
raise Exception(f"Unsupported execute format: {execute_format}")

tests/prague/eip7702_set_code_tx/test_set_code_txs.py

Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from hashlib import sha256
77
from itertools import count
8+
from typing import List
89

910
import pytest
1011

@@ -2719,60 +2720,71 @@ def test_set_code_to_system_contract(
27192720
if tx_type in [0, 3]
27202721
else None,
27212722
)
2723+
@pytest.mark.parametrize(
2724+
"same_block",
2725+
[
2726+
pytest.param(
2727+
True,
2728+
marks=[pytest.mark.execute(pytest.mark.skip("duplicate scenario for execute"))],
2729+
id="same_block",
2730+
),
2731+
pytest.param(False, id="different_block"),
2732+
],
2733+
)
27222734
def test_eoa_tx_after_set_code(
27232735
blockchain_test: BlockchainTestFiller,
27242736
pre: Alloc,
27252737
tx_type: int,
27262738
fork: Fork,
27272739
evm_code_type: EVMCodeType,
2740+
same_block: bool,
27282741
):
27292742
"""Test sending a transaction from an EOA after code has been set to the account."""
27302743
auth_signer = pre.fund_eoa()
27312744

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

2735-
txs = [
2736-
Transaction(
2737-
sender=pre.fund_eoa(),
2738-
gas_limit=500_000,
2739-
to=auth_signer,
2740-
value=0,
2741-
authorization_list=[
2742-
AuthorizationTuple(
2743-
address=set_code_to_address,
2744-
nonce=0,
2745-
signer=auth_signer,
2746-
),
2747-
],
2748-
)
2749-
]
2748+
first_eoa_tx = Transaction(
2749+
sender=pre.fund_eoa(),
2750+
gas_limit=500_000,
2751+
to=auth_signer,
2752+
value=0,
2753+
authorization_list=[
2754+
AuthorizationTuple(
2755+
address=set_code_to_address,
2756+
nonce=0,
2757+
signer=auth_signer,
2758+
),
2759+
],
2760+
)
27502761
auth_signer.nonce += 1 # type: ignore
27512762

2763+
follow_up_eoa_txs: List[Transaction] = []
27522764
match tx_type:
27532765
case 0:
2754-
txs.append(
2755-
Transaction(
2756-
type=tx_type,
2757-
sender=auth_signer,
2758-
gas_limit=500_000,
2759-
to=auth_signer,
2760-
value=0,
2761-
protected=True,
2762-
),
2763-
)
2764-
txs.append(
2765-
Transaction(
2766-
type=tx_type,
2767-
sender=auth_signer,
2768-
gas_limit=500_000,
2769-
to=auth_signer,
2770-
value=0,
2771-
protected=False,
2772-
),
2766+
follow_up_eoa_txs.extend(
2767+
[
2768+
Transaction(
2769+
type=tx_type,
2770+
sender=auth_signer,
2771+
gas_limit=500_000,
2772+
to=auth_signer,
2773+
value=0,
2774+
protected=True,
2775+
),
2776+
Transaction(
2777+
type=tx_type,
2778+
sender=auth_signer,
2779+
gas_limit=500_000,
2780+
to=auth_signer,
2781+
value=0,
2782+
protected=False,
2783+
),
2784+
]
27732785
)
27742786
case 1:
2775-
txs.append(
2787+
follow_up_eoa_txs.append(
27762788
Transaction(
27772789
type=tx_type,
27782790
sender=auth_signer,
@@ -2785,10 +2797,10 @@ def test_eoa_tx_after_set_code(
27852797
storage_keys=[1],
27862798
)
27872799
],
2788-
),
2800+
)
27892801
)
27902802
case 2:
2791-
txs.append(
2803+
follow_up_eoa_txs.append(
27922804
Transaction(
27932805
type=tx_type,
27942806
sender=auth_signer,
@@ -2797,10 +2809,10 @@ def test_eoa_tx_after_set_code(
27972809
value=0,
27982810
max_fee_per_gas=1_000,
27992811
max_priority_fee_per_gas=1_000,
2800-
),
2812+
)
28012813
)
28022814
case 3:
2803-
txs.append(
2815+
follow_up_eoa_txs.append(
28042816
Transaction(
28052817
type=tx_type,
28062818
sender=auth_signer,
@@ -2814,14 +2826,21 @@ def test_eoa_tx_after_set_code(
28142826
[Hash(1)],
28152827
Spec4844.BLOB_COMMITMENT_VERSION_KZG,
28162828
),
2817-
),
2829+
)
28182830
)
28192831
case _:
28202832
raise ValueError(f"Unsupported tx type: {tx_type}, test needs update")
28212833

2834+
if same_block:
2835+
blocks = [Block(txs=[first_eoa_tx] + follow_up_eoa_txs)]
2836+
else:
2837+
blocks = [
2838+
Block(txs=[first_eoa_tx]),
2839+
Block(txs=follow_up_eoa_txs),
2840+
]
28222841
blockchain_test(
28232842
pre=pre,
2824-
blocks=[Block(txs=txs)],
2843+
blocks=blocks,
28252844
post={
28262845
auth_signer: Account(
28272846
nonce=3 if tx_type == 0 else 2,

0 commit comments

Comments
 (0)