262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380 | @pytest.mark.parametrize(
"self_funded",
[
pytest.param(False, id="sponsored"),
pytest.param(True, id="self_funded"),
],
)
def test_bal_7702_delegation_clear(
pre: Alloc,
blockchain_test: BlockchainTestFiller,
self_funded: bool,
) -> None:
"""Ensure BAL captures clearing of EOA delegation."""
alice = pre.fund_eoa()
bob = pre.fund_eoa(amount=0)
if not self_funded:
relayer = pre.fund_eoa()
sender = relayer
else:
sender = alice
oracle = pre.deploy_contract(code=Op.STOP)
abyss = Spec7702.RESET_DELEGATION_ADDRESS
## Perhaps create a pre-existing delegation,
## see `test_bal_7702_delegated_storage_access` since
## `test_bal_7702_delegation_create` already tests creation
tx_create = Transaction(
sender=sender,
to=bob,
value=10,
gas_limit=1_000_000,
authorization_list=[
AuthorizationTuple(
address=oracle,
nonce=1 if self_funded else 0,
signer=alice,
)
],
)
tx_clear = Transaction(
nonce=2 if self_funded else 1,
sender=sender,
to=bob,
value=10,
gas_limit=1_000_000,
authorization_list=[
AuthorizationTuple(
address=abyss,
nonce=3 if self_funded else 1,
signer=alice,
)
],
)
account_expectations = {
alice: BalAccountExpectation(
nonce_changes=[
BalNonceChange(
block_access_index=1, post_nonce=2 if self_funded else 1
),
BalNonceChange(
block_access_index=2, post_nonce=4 if self_funded else 2
),
],
code_changes=[
BalCodeChange(
block_access_index=1,
new_code=Spec7702.delegation_designation(oracle),
),
BalCodeChange(block_access_index=2, new_code=""),
],
),
bob: BalAccountExpectation(
balance_changes=[
BalBalanceChange(block_access_index=1, post_balance=10),
BalBalanceChange(block_access_index=2, post_balance=20),
]
),
# Both delegation targets must not be present in BAL
# the account is never accessed
oracle: None,
abyss: None,
}
# For sponsored variant, relayer must also be included in BAL
if not self_funded:
account_expectations[relayer] = BalAccountExpectation(
nonce_changes=[
BalNonceChange(block_access_index=1, post_nonce=1),
BalNonceChange(block_access_index=2, post_nonce=2),
],
)
block = Block(
txs=[tx_create, tx_clear],
expected_block_access_list=BlockAccessListExpectation(
account_expectations=account_expectations
),
)
post = {
# Finally Alice's account should NOT have any code
alice: Account(nonce=4 if self_funded else 2, code=""),
# Bob receives 20 wei in total
bob: Account(balance=20),
}
# For sponsored variant, include relayer in post state
if not self_funded:
post.update({relayer: Account(nonce=2)})
blockchain_test(
pre=pre,
blocks=[block],
post=post,
)
|