test_call_opcodes_transfer_log_behavior()
Documentation for tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py::test_call_opcodes_transfer_log_behavior@c74f1a67.
Generate fixtures for these test cases for Amsterdam with:
fill -v tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py::test_call_opcodes_transfer_log_behavior --fork Amsterdam
Test ETH transfer log behavior across all call opcode contexts.
- CALL with value: emits log (caller -> callee)
- CALLCODE with value: emits log (caller -> caller) as self-transfer
- DELEGATECALL: no value parameter, no transfer log
- STATICCALL: no value parameter, no transfer log
Source code in tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261 | @pytest.mark.with_all_call_opcodes
def test_call_opcodes_transfer_log_behavior(
state_test: StateTestFiller,
env: Environment,
pre: Alloc,
sender: EOA,
call_opcode: Op,
) -> None:
"""
Test ETH transfer log behavior across all call opcode contexts.
- CALL with value: emits log (caller -> callee)
- CALLCODE with value: emits log (caller -> caller) as self-transfer
- DELEGATECALL: no value parameter, no transfer log
- STATICCALL: no value parameter, no transfer log
"""
callee = pre.deploy_contract(Op.STOP)
# Build the call based on opcode type
if call_opcode in [Op.CALL, Op.CALLCODE]:
# These opcodes have a value parameter
call_code = call_opcode(address=callee, value=1)
else:
# DELEGATECALL and STATICCALL don't have value parameter
call_code = call_opcode(address=callee)
contract = pre.deploy_contract(call_code, balance=1)
# Determine expected logs based on opcode behavior
expected_logs = [transfer_log(sender, contract, 1)]
if call_opcode == Op.CALL:
# CALL transfers value from contract to callee
expected_logs.append(transfer_log(contract, callee, 1))
post = {callee: Account(balance=1)}
elif call_opcode == Op.CALLCODE:
# CALLCODE transfers value but stays in caller's context.
# This is a self-transfer (contract -> contract), so no transfer
# log per EIP-7708 ("CALL to a different account").
post = {}
else:
# DELEGATECALL and STATICCALL: no value transfer, no additional log
post = {}
tx = Transaction(
sender=sender,
to=contract,
value=1,
expected_receipt=TransactionReceipt(logs=expected_logs),
)
state_test(env=env, pre=pre, post=post, tx=tx)
|
Parametrized Test Cases
This test generates 4 parametrized test cases across 1 fork.