Skip to content

Commit

Permalink
chore(tests): Transactions usages
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Feb 11, 2024
1 parent 8eb2afc commit 7002f3a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
https://github.com/ethereum/execution-spec-tests/issues/381
"""

from itertools import count
from typing import Dict, Union

import pytest
Expand All @@ -20,6 +19,7 @@
StateTestFiller,
TestAddress,
Transaction,
Transactions,
compute_create2_address,
)
from ethereum_test_tools.vm.opcode import Opcodes as Op
Expand Down Expand Up @@ -430,38 +430,20 @@ def test_dynamic_create2_selfdestruct_collision_two_different_transactions(

post[sendall_destination] = Account(balance=sendall_destination_balance)

nonce = count()

blockchain_test(
genesis_environment=Environment(),
pre=pre,
post=post,
blocks=[
Block(
txs=[
Transaction(
ty=0x0,
chain_id=0x0,
nonce=next(nonce),
to=address_to,
gas_price=10,
protected=False,
data=initcode.bytecode if initcode.bytecode is not None else bytes(),
gas_limit=5000000,
value=0,
),
Transaction(
ty=0x0,
chain_id=0x0,
nonce=next(nonce),
to=address_to_second,
gas_price=10,
protected=False,
data=initcode.bytecode if initcode.bytecode is not None else bytes(),
gas_limit=5000000,
value=0,
),
]
txs=Transactions(
chain_id=0x0,
to=[address_to, address_to_second],
gas_price=10,
data=initcode.bytecode if initcode.bytecode is not None else bytes(),
gas_limit=5_000_000,
protected=False,
),
)
],
)
Expand Down Expand Up @@ -668,38 +650,21 @@ def test_dynamic_create2_selfdestruct_collision_multi_tx(

post[sendall_destination] = Account(balance=sendall_destination_balance)

nonce = count()

blockchain_test(
genesis_environment=Environment(),
pre=pre,
post=post,
blocks=[
Block(
txs=[
Transaction(
ty=0x0,
chain_id=0x0,
nonce=next(nonce),
to=address_to,
gas_price=10,
protected=False,
data=initcode.bytecode if initcode.bytecode is not None else bytes(),
gas_limit=5000000,
value=0,
),
Transaction(
ty=0x0,
chain_id=0x0,
nonce=next(nonce),
to=address_to,
gas_price=10,
protected=False,
data=initcode.bytecode if initcode.bytecode is not None else bytes(),
gas_limit=5000000,
value=0,
),
]
txs=Transactions(
chain_id=0x0,
to=address_to,
gas_price=10,
data=initcode.bytecode if initcode.bytecode is not None else bytes(),
gas_limit=5_000_000,
protected=False,
limit=2,
),
)
],
)
59 changes: 20 additions & 39 deletions tests/cancun/eip6780_selfdestruct/test_selfdestruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
Storage,
TestAddress,
Transaction,
Transactions,
YulCompiler,
compute_create2_address,
compute_create_address,
Expand Down Expand Up @@ -400,13 +401,11 @@ def test_create_selfdestruct_same_tx(

post[selfdestruct_contract_address] = Account.NONEXISTENT # type: ignore

nonce = count()
tx = Transaction(
ty=0x0,
value=100_000,
data=entry_code,
chain_id=0x0,
nonce=next(nonce),
to=None,
gas_limit=100_000_000,
gas_price=10,
Expand Down Expand Up @@ -528,13 +527,11 @@ def test_self_destructing_initcode(
sendall_recipient_addresses[0]: Account(balance=sendall_amount, storage={0: 1}),
}

nonce = count()
tx = Transaction(
ty=0x0,
value=100_000,
data=entry_code,
chain_id=0x0,
nonce=next(nonce),
to=None,
gas_limit=100_000_000,
gas_price=10,
Expand Down Expand Up @@ -583,13 +580,11 @@ def test_self_destructing_initcode_create_tx(
sendall_recipient_addresses[0]: Account(balance=sendall_amount, storage={0: 1}),
}

nonce = count()
tx = Transaction(
ty=0x0,
value=tx_value,
data=selfdestruct_contract_initcode,
chain_id=0x0,
nonce=next(nonce),
to=None,
gas_limit=100_000_000,
gas_price=10,
Expand Down Expand Up @@ -860,13 +855,11 @@ def test_selfdestruct_pre_existing(
else:
post[selfdestruct_contract_address] = Account.NONEXISTENT # type: ignore

nonce = count()
tx = Transaction(
ty=0x0,
value=100_000,
data=entry_code,
chain_id=0x0,
nonce=next(nonce),
to=None,
gas_limit=100_000_000,
gas_price=10,
Expand Down Expand Up @@ -960,33 +953,25 @@ def test_selfdestruct_created_same_block_different_tx(
else:
post[selfdestruct_contract_address] = Account.NONEXISTENT # type: ignore

nonce = count()
txs = [
Transaction(
ty=0x0,
value=0,
data=selfdestruct_contract_initcode,
chain_id=0x0,
nonce=next(nonce),
to=None,
gas_limit=100_000_000,
gas_price=10,
protected=False,
),
Transaction(
ty=0x0,
value=100_000,
data=entry_code,
chain_id=0x0,
nonce=next(nonce),
to=None,
gas_limit=100_000_000,
gas_price=10,
protected=False,
),
]

blockchain_test(genesis_environment=env, pre=pre, post=post, blocks=[Block(txs=txs)])
blockchain_test(
genesis_environment=env,
pre=pre,
post=post,
blocks=[
Block(
txs=Transactions(
ty=0x0,
value=[0, 100_000],
data=[selfdestruct_contract_initcode, entry_code],
chain_id=0x0,
to=None,
gas_limit=100_000_000,
gas_price=10,
protected=False,
)
),
],
)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -1136,13 +1121,11 @@ def test_delegatecall_from_new_contract_to_pre_existing_contract(
sendall_recipient_addresses[0]: Account(balance=sendall_amount, storage={0: 1}),
}

nonce = count()
tx = Transaction(
ty=0x0,
value=100_000,
data=entry_code,
chain_id=0x0,
nonce=next(nonce),
to=None,
gas_limit=100_000_000,
gas_price=10,
Expand Down Expand Up @@ -1293,13 +1276,11 @@ def test_delegatecall_from_pre_existing_contract_to_new_contract(
else:
post[delegate_caller_address] = Account.NONEXISTENT # type: ignore

nonce = count()
tx = Transaction(
ty=0x0,
value=100_000,
data=entry_code,
chain_id=0x0,
nonce=next(nonce),
to=None,
gas_limit=100_000_000,
gas_price=10,
Expand Down
5 changes: 0 additions & 5 deletions tests/cancun/eip6780_selfdestruct/test_selfdestruct_revert.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
tests for selfdestruct interaction with revert
"""

from itertools import count
from typing import Dict, SupportsBytes

import pytest
Expand Down Expand Up @@ -287,13 +286,11 @@ def test_selfdestruct_created_in_same_tx_with_revert( # noqa SC200
)
post[selfdestruct_recipient_address] = Account.NONEXISTENT # type: ignore

nonce = count()
tx = Transaction(
ty=0x0,
value=0,
data=entry_code,
chain_id=0x0,
nonce=next(nonce),
to=None,
gas_limit=100_000_000,
gas_price=10,
Expand Down Expand Up @@ -402,13 +399,11 @@ def test_selfdestruct_not_created_in_same_tx_with_revert(
)
post[selfdestruct_recipient_address] = Account.NONEXISTENT # type: ignore

nonce = count()
tx = Transaction(
ty=0x0,
value=0,
data=entry_code,
chain_id=0x0,
nonce=next(nonce),
to=None,
gas_limit=100_000_000,
gas_price=10,
Expand Down
1 change: 1 addition & 0 deletions tests/cancun/eip7516_blobgasfee/test_blobgasfee_opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Test BLOBGASFEE opcode [EIP-7516: BLOBBASEFEE opcode](https://eips.ethereum.org/EIPS/eip-7516)
""" # noqa: E501

from dataclasses import replace
from itertools import count
from typing import Dict
Expand Down

0 comments on commit 7002f3a

Please sign in to comment.