Skip to content

test_newly_created_contract()

Documentation for tests/shanghai/eip4895_withdrawals/test_withdrawals.py::test_newly_created_contract@02aafd78.

Generate fixtures for these test cases for Bogota with:

fill -v tests/shanghai/eip4895_withdrawals/test_withdrawals.py::test_newly_created_contract --fork Bogota

Test withdrawing to a newly created contract.

Source code in tests/shanghai/eip4895_withdrawals/test_withdrawals.py
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
@pytest.mark.parametrize(
    "include_value_in_tx",
    [False, True],
    ids=["without_tx_value", "with_tx_value"],
)
def test_newly_created_contract(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    include_value_in_tx: bool,
) -> None:
    """Test withdrawing to a newly created contract."""
    sender = pre.fund_eoa()
    initcode = Op.RETURN(0, 1)
    tx = Transaction(
        # Transaction sent from the `sender`, that creates a
        # new contract.
        sender=sender,
        gas_limit=1000000,
        to=None,
        value=ONE_GWEI if include_value_in_tx else 0,
        data=initcode,
    )
    created_contract = tx.created_contract

    withdrawal = Withdrawal(
        index=0,
        validator_index=0,
        address=created_contract,
        amount=1,
    )

    created_contract_balance = ONE_GWEI
    if include_value_in_tx:
        created_contract_balance = 2 * ONE_GWEI

    post = {
        created_contract: Account(
            code=Op.STOP,
            balance=created_contract_balance,
        ),
    }

    block = Block(
        txs=[tx],
        withdrawals=[withdrawal],
    )

    blockchain_test(pre=pre, post=post, blocks=[block])

Parametrized Test Cases

This test generates 2 parametrized test cases across 6 forks.