Skip to content

test_newly_created_contract()

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

Generate fixtures for these test cases for Prague with:

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

Test Withdrawing to a newly created contract.

Source code in tests/shanghai/eip4895_withdrawals/test_withdrawals.py
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
@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,
    request,
):
    """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

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) include_value_in_tx
...fork_Shanghai-blockchain_test-without_tx_value False
...fork_Shanghai-blockchain_test-with_tx_value True
...fork_Cancun-blockchain_test-without_tx_value False
...fork_Cancun-blockchain_test-with_tx_value True
...fork_Prague-blockchain_test-without_tx_value False
...fork_Prague-blockchain_test-with_tx_value True
...fork_Osaka-blockchain_test-without_tx_value False
...fork_Osaka-blockchain_test-with_tx_value True