Skip to content

test_bal_7702_double_auth_swap()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7702.py::test_bal_7702_double_auth_swap@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7702.py::test_bal_7702_double_auth_swap --fork Amsterdam

Ensure BAL captures the net code change when double auth swaps delegation targets.

This test verifies that when: 1. First auth sets delegation to CONTRACT_A 2. Second auth changes delegation to CONTRACT_B

The BAL should show the final code change (empty -> CONTRACT_B), not the intermediate CONTRACT_A.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7702.py
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
def test_bal_7702_double_auth_swap(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
) -> None:
    """
    Ensure BAL captures the net code change when double auth swaps
    delegation targets.

    This test verifies that when:
    1. First auth sets delegation to CONTRACT_A
    2. Second auth changes delegation to CONTRACT_B

    The BAL should show the final code change (empty -> CONTRACT_B),
    not the intermediate CONTRACT_A.
    """
    alice = pre.fund_eoa()
    bob = pre.fund_eoa(amount=0)
    relayer = pre.fund_eoa()

    contract_a = pre.deploy_contract(code=Op.STOP)
    contract_b = pre.deploy_contract(code=Op.STOP)

    tx = Transaction(
        sender=relayer,
        to=bob,
        value=10,
        gas_limit=1_000_000,
        authorization_list=[
            AuthorizationTuple(
                address=contract_a,
                nonce=0,
                signer=alice,
            ),
            AuthorizationTuple(
                address=contract_b,  # Override to contract_b
                nonce=1,
                signer=alice,
            ),
        ],
    )

    account_expectations = {
        alice: BalAccountExpectation(
            nonce_changes=[BalNonceChange(block_access_index=1, post_nonce=2)],
            code_changes=[
                # Should show final code (CONTRACT_B), not CONTRACT_A
                BalCodeChange(
                    block_access_index=1,
                    new_code=Spec7702.delegation_designation(contract_b),
                )
            ],
        ),
        bob: BalAccountExpectation(
            balance_changes=[
                BalBalanceChange(block_access_index=1, post_balance=10)
            ]
        ),
        relayer: BalAccountExpectation(
            nonce_changes=[BalNonceChange(block_access_index=1, post_nonce=1)],
        ),
        # Neither contract appears in BAL during delegation setup
        contract_a: None,
        contract_b: None,
    }

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                expected_block_access_list=BlockAccessListExpectation(
                    account_expectations=account_expectations
                ),
            )
        ],
        post={
            alice: Account(
                nonce=2, code=Spec7702.delegation_designation(contract_b)
            ),
            bob: Account(balance=10),
            relayer: Account(nonce=1),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.