Skip to content

test_beacon_root_selfdestruct()

Documentation for tests/cancun/eip4788_beacon_root/test_beacon_root_contract.py::test_beacon_root_selfdestruct@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/cancun/eip4788_beacon_root/test_beacon_root_contract.py::test_beacon_root_selfdestruct --fork Amsterdam

Tests that self destructing the beacon root address transfers actors balance correctly.

Source code in tests/cancun/eip4788_beacon_root/test_beacon_root_contract.py
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
@pytest.mark.parametrize("timestamp", [12])
@pytest.mark.valid_from("Cancun")
def test_beacon_root_selfdestruct(
    blockchain_test: BlockchainTestFiller,
    beacon_root: bytes,
    timestamp: int,
    pre: Alloc,
    tx: Transaction,
    post: Dict,
) -> None:
    """
    Tests that self destructing the beacon root address transfers actors
    balance correctly.
    """
    # self destruct actor
    self_destruct_actor_address = pre.deploy_contract(
        Op.SELFDESTRUCT(Spec.BEACON_ROOTS_ADDRESS),
        balance=0xBA1,
    )
    # self destruct caller
    self_destruct_caller_address = pre.deploy_contract(
        Op.CALL(gas=100_000, address=self_destruct_actor_address)
        + Op.SSTORE(0, Op.BALANCE(Spec.BEACON_ROOTS_ADDRESS))
    )
    post = {
        self_destruct_caller_address: Account(
            storage=Storage({0: 0xBA1}),  # type: ignore
        )
    }
    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[
                    Transaction(
                        sender=pre.fund_eoa(),
                        to=self_destruct_caller_address,
                        gas_limit=100_000,
                    )
                ]
            )
        ],
        post=post,
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 4 forks.