Skip to content

test_bal_7702_double_auth_reset()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7702.py::test_bal_7702_double_auth_reset@5c024cbb.

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_reset --fork Amsterdam

Ensure BAL captures the net code change when multiple authorizations occur in the same transaction (double auth).

This test verifies that when: 1. First auth sets delegation to CONTRACT_A 2. Second auth resets delegation to empty (address 0)

Scenario where the transaction is sponsored and self-funded are covered.

The BAL should show the NET change (empty -> empty), not intermediate states. This is a regression test for the bug where the BAL showed the first auth's code but the final state was empty.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7702.py
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
@pytest.mark.parametrize(
    "self_funded",
    [
        pytest.param(False, id="sponsored"),
        pytest.param(True, id="self_funded"),
    ],
)
def test_bal_7702_double_auth_reset(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    self_funded: bool,
) -> None:
    """
    Ensure BAL captures the net code change when multiple authorizations
    occur in the same transaction (double auth).

    This test verifies that when:
    1. First auth sets delegation to CONTRACT_A
    2. Second auth resets delegation to empty (address 0)

    Scenario where the transaction is sponsored and self-funded are covered.

    The BAL should show the NET change (empty -> empty), not intermediate
    states. This is a regression test for the bug where the BAL showed
    the first auth's code but the final state was empty.
    """
    alice = pre.fund_eoa()
    bob = pre.fund_eoa(amount=0)
    relayer = pre.fund_eoa()

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

    # Transaction with double auth:
    # 1. First sets delegation to contract_a
    # 2. Second resets to empty
    tx = Transaction(
        sender=alice if self_funded else relayer,
        to=bob,
        value=10,
        authorization_list=[
            AuthorizationTuple(
                address=contract_a,
                nonce=1 if self_funded else 0,
                signer=alice,
            ),
            AuthorizationTuple(
                address=0,  # Reset to empty
                nonce=2 if self_funded else 1,
                signer=alice,
            ),
        ],
    )

    alice_nonce = 3 if self_funded else 2
    relayer_nonce = 1 if not self_funded else 0
    relayer_bal_expectation = (
        BalAccountExpectation(
            nonce_changes=[BalNonceChange(block_access_index=1, post_nonce=1)]
        )
        if not self_funded
        else None
    )

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                expected_block_access_list=BlockAccessListExpectation(
                    account_expectations={
                        alice: BalAccountExpectation(
                            nonce_changes=[
                                BalNonceChange(
                                    block_access_index=1,
                                    post_nonce=alice_nonce,
                                )
                            ],
                            code_changes=[],
                        ),
                        bob: BalAccountExpectation(
                            balance_changes=[
                                BalBalanceChange(
                                    block_access_index=1, post_balance=10
                                )
                            ]
                        ),
                        relayer: relayer_bal_expectation,
                        contract_a: None,
                    }
                ),
            )
        ],
        post={
            alice: Account(nonce=alice_nonce, code=b""),  # Final code is empty
            bob: Account(balance=10),
            relayer: Account(nonce=relayer_nonce),
        },
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.