Skip to content

test_nested_calls_log_order()

Documentation for tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py::test_nested_calls_log_order@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py::test_nested_calls_log_order --fork Amsterdam

Test that nested CALLs emit transfer logs in chronological order.

Source code in tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
@pytest.mark.parametrize(
    "call_depth",
    [
        pytest.param(2, id="depth_2"),
        pytest.param(3, id="depth_3"),
        pytest.param(10, id="depth_10"),
    ],
)
def test_nested_calls_log_order(
    state_test: StateTestFiller,
    env: Environment,
    pre: Alloc,
    sender: EOA,
    call_depth: int,
) -> None:
    """Test that nested CALLs emit transfer logs in chronological order."""
    transfer_value = 100
    tx_value = 1000

    # Build the chain from innermost outward by prepending each new caller.
    # Once finished, accounts[0] is the entry contract (the tx target) and
    # accounts[-1] is the final recipient.
    # Forward all gas (`Op.GAS`) rather than a fixed amount: under EIP-8037
    # each frame's per-frame `SSTORE` and the deepest `NEW_ACCOUNT` charge
    # make a fixed forward too small to reach the chain depth.
    accounts: list[Address] = [pre.nonexistent_account()]
    for _ in range(call_depth):
        contract_code = Op.SSTORE(
            0,
            Op.CALL(gas=Op.GAS, address=accounts[0], value=transfer_value),
        )
        accounts.insert(
            0, pre.deploy_contract(contract_code, balance=transfer_value)
        )

    entry_contract = accounts[0]
    final_recipient = accounts[-1]

    expected_logs: list[TransactionLog] = [
        transfer_log(sender, entry_contract, tx_value)
    ]
    for i in range(call_depth):
        expected_logs.append(
            transfer_log(accounts[i], accounts[i + 1], transfer_value)
        )

    tx = Transaction(
        sender=sender,
        to=entry_contract,
        value=tx_value,
        expected_receipt=TransactionReceipt(logs=expected_logs),
    )

    post: dict[Address, Account] = {
        final_recipient: Account(balance=transfer_value)
    }
    for chain_contract in accounts[:-1]:
        post[chain_contract] = Account(storage={0: 1})
    state_test(env=env, pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 3 parametrized test cases across 1 fork.