Skip to content

test_eofcreate_context()

Documentation for tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_eofcreate.py::test_eofcreate_context@49a16fac.

Generate fixtures for these test cases for Osaka with:

fill -v tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_eofcreate.py::test_eofcreate_context --fork Osaka

Test EOFCREATE's initcode context instructions.

Source code in tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_eofcreate.py
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
@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"),
    ],
)
def test_eofcreate_context(
    state_test: StateTestFiller,
    pre: Alloc,
    destination_code: Bytecode,
    expected_result: str,
):
    """Test EOFCREATE's initcode context instructions."""
    env = Environment()
    sender = pre.fund_eoa()
    value = 0x1123
    eofcreate_value = 0x13

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

    caller_contract = Container(
        sections=[
            Section.Code(
                Op.SSTORE(slot_code_worked, value_code_worked)
                + Op.EOFCREATE[0](eofcreate_value, 0, 0, 0)
                + Op.STOP
            ),
            Section.Container(initcode),
        ]
    )
    calling_contract_address = pre.deploy_contract(caller_contract)

    destination_contract_address = compute_eofcreate_address(calling_contract_address, 0, initcode)

    tx = Transaction(sender=sender, to=calling_contract_address, gas_limit=1000000, value=value)

    expected_bytes: Address | int
    if expected_result == "destination":
        expected_bytes = destination_contract_address
    elif expected_result == "caller":
        expected_bytes = calling_contract_address
    elif expected_result == "sender":
        expected_bytes = sender
    elif expected_result == "eofcreate_value":
        expected_bytes = eofcreate_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 = {
        calling_contract_address: Account(storage=calling_storage),
        destination_contract_address: Account(storage=destination_contract_storage),
    }

    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) destination_code expected_result
...fork_Osaka-blockchain_test-destination_code_ADDRESS-expected_result_destination ADDRESS destination
...fork_Osaka-blockchain_test-destination_code_CALLER-expected_result_caller CALLER caller
...fork_Osaka-blockchain_test-destination_code_CALLVALUE-expected_result_eofcreate_value CALLVALUE eofcreate_value
...fork_Osaka-blockchain_test-destination_code_ORIGIN-expected_result_sender ORIGIN sender
...fork_Osaka-state_test-destination_code_ADDRESS-expected_result_destination ADDRESS destination
...fork_Osaka-state_test-destination_code_CALLER-expected_result_caller CALLER caller
...fork_Osaka-state_test-destination_code_CALLVALUE-expected_result_eofcreate_value CALLVALUE eofcreate_value
...fork_Osaka-state_test-destination_code_ORIGIN-expected_result_sender ORIGIN sender