Skip to content
Merged
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
65 changes: 0 additions & 65 deletions tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,71 +311,6 @@ def test_create_opcode_emits_log(
state_test(env=env, pre=pre, post=post, tx=tx)


@pytest.mark.with_all_create_opcodes
def test_selfdestruct_during_initcode(
state_test: StateTestFiller,
env: Environment,
pre: Alloc,
sender: EOA,
create_opcode: Op,
) -> None:
"""
Test that SELFDESTRUCT during initcode emits transfer log.

Contract is created with value, then immediately self-destructs to a
beneficiary during initcode execution (before deployment completes).
Expected logs:
- CREATE transfer: factory -> created_address
- SELFDESTRUCT transfer: created_address -> beneficiary
"""
beneficiary = pre.deploy_contract(Op.STOP)

# Initcode that self-destructs to beneficiary (contract never deploys code)
initcode = Op.SELFDESTRUCT(beneficiary)
initcode_bytes = bytes(initcode)
initcode_len = len(initcode_bytes)

if create_opcode == Op.CREATE:
factory_code = Op.MSTORE(
0, Op.PUSH32(initcode_bytes.rjust(32, b"\x00"))
) + Op.CREATE(value=1, offset=32 - initcode_len, size=initcode_len)
else:
factory_code = Op.MSTORE(
0, Op.PUSH32(initcode_bytes.rjust(32, b"\x00"))
) + Op.CREATE2(
value=1, offset=32 - initcode_len, size=initcode_len, salt=0
)

factory = pre.deploy_contract(factory_code, balance=1)

# Compute created address
if create_opcode == Op.CREATE:
created_address = compute_create_address(address=factory, nonce=1)
else:
created_address = compute_create2_address(
address=factory, salt=0, initcode=initcode_bytes
)

tx = Transaction(
sender=sender,
to=factory,
value=0,
gas_limit=200_000,
expected_receipt=TransactionReceipt(
logs=[
# CREATE transfers value to new contract
transfer_log(factory, created_address, 1),
# SELFDESTRUCT transfers balance to beneficiary
transfer_log(created_address, beneficiary, 1),
]
),
)

# Beneficiary receives the balance, created contract is destroyed
post = {beneficiary: Account(balance=1)}
state_test(env=env, pre=pre, post=post, tx=tx)


@pytest.mark.with_all_create_opcodes
def test_initcode_calls_with_value(
state_test: StateTestFiller,
Expand Down
Loading