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@636b5f17.

Generate fixtures for these test cases for Bogota with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7702.py::test_bal_7702_double_auth_reset --fork Bogota

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
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
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
@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 2 forks.