Skip to content

test_txcreate_context()

Documentation for tests/osaka/eip7692_eof_v1/eip7873_tx_create/test_txcreate.py::test_txcreate_context@v4.4.0.

Generate fixtures for these test cases for Osaka with:

fill -v tests/osaka/eip7692_eof_v1/eip7873_tx_create/test_txcreate.py::test_txcreate_context --fork Osaka

Test TXCREATE's initcode context instructions.

Source code in tests/osaka/eip7692_eof_v1/eip7873_tx_create/test_txcreate.py
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
@pytest.mark.with_all_evm_code_types
@pytest.mark.parametrize(
    ["destination_code", "expected_result"],
    [
        pytest.param(Op.ADDRESS, "destination"),
        pytest.param(Op.CALLER, "caller"),
        pytest.param(Op.CALLVALUE, "eofcreate_value"),
        pytest.param(Op.ORIGIN, "sender"),
        pytest.param(Op.SELFBALANCE, "selfbalance"),
        pytest.param(Op.BALANCE(Op.CALLER), "factorybalance"),
    ],
)
def test_txcreate_context(
    state_test: StateTestFiller,
    pre: Alloc,
    destination_code: Bytecode,
    expected_result: str,
):
    """Test TXCREATE's initcode context instructions."""
    env = Environment()
    sender = pre.fund_eoa()
    value = 0x1123
    txcreate_value = 0x13

    initcode = Container(
        sections=[
            Section.Code(Op.SSTORE(slot_call_result, destination_code) + Op.RETURNCODE[0](0, 0)),
            Section.Container(smallest_runtime_subcontainer),
        ]
    )
    initcode_hash = initcode.hash

    factory_address = pre.deploy_contract(
        code=Op.SSTORE(slot_code_worked, value_code_worked)
        + Op.TXCREATE(tx_initcode_hash=initcode_hash, value=txcreate_value)
        + Op.STOP
    )

    destination_contract_address = compute_eofcreate_address(factory_address, 0)

    tx = Transaction(
        sender=sender,
        to=factory_address,
        gas_limit=200_000,
        value=value,
        initcodes=[initcode],
    )

    expected_bytes: Address | int
    if expected_result == "destination":
        expected_bytes = destination_contract_address
    elif expected_result == "caller":
        expected_bytes = factory_address
    elif expected_result == "sender":
        expected_bytes = sender
    elif expected_result == "eofcreate_value":
        expected_bytes = txcreate_value
    elif expected_result == "selfbalance":
        expected_bytes = txcreate_value
    elif expected_result == "factorybalance":
        # Factory receives value from sender and passes on eofcreate_value as endowment.
        expected_bytes = value - txcreate_value
    else:
        raise TypeError("Unexpected expected_result", expected_result)

    calling_storage = {
        slot_code_worked: value_code_worked,
    }
    destination_contract_storage = {
        slot_call_result: expected_bytes,
    }

    post = {
        factory_address: Account(storage=calling_storage, balance=value - txcreate_value),
        destination_contract_address: Account(
            storage=destination_contract_storage, balance=txcreate_value
        ),
    }

    state_test(
        env=env,
        pre=pre,
        post=post,
        tx=tx,
    )

Parametrized Test Cases

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

Test ID (Abbreviated) evm_code_type destination_code expected_result
...fork_Osaka-evm_code_type_LEGACY-state_test-destination_code_ADDRESS-expected_result_destination LEGACY ADDRESS destination
...fork_Osaka-evm_code_type_LEGACY-state_test-destination_code_CALLER-expected_result_caller LEGACY CALLER caller
...fork_Osaka-evm_code_type_LEGACY-state_test-destination_code_CALLVALUE-expected_result_eofcreate_value LEGACY CALLVALUE eofcreate_value
...fork_Osaka-evm_code_type_LEGACY-state_test-destination_code_ORIGIN-expected_result_sender LEGACY ORIGIN sender
...fork_Osaka-evm_code_type_LEGACY-state_test-destination_code_SELFBALANCE-expected_result_selfbalance LEGACY SELFBALANCE selfbalance
...fork_Osaka-evm_code_type_LEGACY-state_test-destination_code_-expected_result_factorybalance LEGACY factorybalance
...fork_Osaka-evm_code_type_LEGACY-blockchain_test_from_state_test-destination_code_ADDRESS-expected_result_destination LEGACY ADDRESS destination
...fork_Osaka-evm_code_type_LEGACY-blockchain_test_from_state_test-destination_code_CALLER-expected_result_caller LEGACY CALLER caller
...fork_Osaka-evm_code_type_LEGACY-blockchain_test_from_state_test-destination_code_CALLVALUE-expected_result_eofcreate_value LEGACY CALLVALUE eofcreate_value
...fork_Osaka-evm_code_type_LEGACY-blockchain_test_from_state_test-destination_code_ORIGIN-expected_result_sender LEGACY ORIGIN sender
...fork_Osaka-evm_code_type_LEGACY-blockchain_test_from_state_test-destination_code_SELFBALANCE-expected_result_selfbalance LEGACY SELFBALANCE selfbalance
...fork_Osaka-evm_code_type_LEGACY-blockchain_test_from_state_test-destination_code_-expected_result_factorybalance LEGACY factorybalance
...fork_Osaka-evm_code_type_EOF_V1-state_test-destination_code_ADDRESS-expected_result_destination EOF_V1 ADDRESS destination
...fork_Osaka-evm_code_type_EOF_V1-state_test-destination_code_CALLER-expected_result_caller EOF_V1 CALLER caller
...fork_Osaka-evm_code_type_EOF_V1-state_test-destination_code_CALLVALUE-expected_result_eofcreate_value EOF_V1 CALLVALUE eofcreate_value
...fork_Osaka-evm_code_type_EOF_V1-state_test-destination_code_ORIGIN-expected_result_sender EOF_V1 ORIGIN sender
...fork_Osaka-evm_code_type_EOF_V1-state_test-destination_code_SELFBALANCE-expected_result_selfbalance EOF_V1 SELFBALANCE selfbalance
...fork_Osaka-evm_code_type_EOF_V1-state_test-destination_code_-expected_result_factorybalance EOF_V1 factorybalance
...fork_Osaka-evm_code_type_EOF_V1-blockchain_test_from_state_test-destination_code_ADDRESS-expected_result_destination EOF_V1 ADDRESS destination
...fork_Osaka-evm_code_type_EOF_V1-blockchain_test_from_state_test-destination_code_CALLER-expected_result_caller EOF_V1 CALLER caller
...fork_Osaka-evm_code_type_EOF_V1-blockchain_test_from_state_test-destination_code_CALLVALUE-expected_result_eofcreate_value EOF_V1 CALLVALUE eofcreate_value
...fork_Osaka-evm_code_type_EOF_V1-blockchain_test_from_state_test-destination_code_ORIGIN-expected_result_sender EOF_V1 ORIGIN sender
...fork_Osaka-evm_code_type_EOF_V1-blockchain_test_from_state_test-destination_code_SELFBALANCE-expected_result_selfbalance EOF_V1 SELFBALANCE selfbalance
...fork_Osaka-evm_code_type_EOF_V1-blockchain_test_from_state_test-destination_code_-expected_result_factorybalance EOF_V1 factorybalance