Skip to content

test_blake2b_gas()

Documentation for tests/istanbul/eip152_blake2/test_blake2.py::test_blake2b_gas@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/istanbul/eip152_blake2/test_blake2.py::test_blake2b_gas --fork Bogota

Test BLAKE2b precompile with different gas limits.

Source code in tests/istanbul/eip152_blake2/test_blake2.py
@pytest.mark.valid_from("Istanbul")
@pytest.mark.parametrize("call_opcode", [Op.CALL, Op.CALLCODE])
@pytest.mark.parametrize(
    ["data", "output"],
    [
        pytest.param(
            Blake2bInput(
                rounds=0,
            ),
            ExpectedOutput(
                data_1="0x08c9bcf367e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5",
                data_2="0xd282e6ad7f520e511f6c3e2b8c68059b9442be0454267ce079217e1319cde05b",
            ),
            id="EIP-152-case3-data4-gas-limit",
        ),
        pytest.param(
            Blake2bInput(),
            ExpectedOutput(
                data_1="0xba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d1",
                data_2="0x7d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923",
            ),
            id="EIP-152-case4-data5-gas-limit",
        ),
        pytest.param(
            Blake2bInput(
                f=False,
            ),
            ExpectedOutput(
                data_1="0x75ab69d3190a562c51aef8d88f1c2775876944407270c42c9844252c26d28752",
                data_2="0x98743e7f6d5ea2f2d3e8d226039cd31b4e426ac4f2d3d666a610c2116fde4735",
            ),
            id="EIP-152-case5-data6-gas-limit",
        ),
        pytest.param(
            Blake2bInput(
                rounds=1,
            ),
            ExpectedOutput(
                data_1="0xb63a380cb2897d521994a85234ee2c181b5f844d2c624c002677e9703449d2fb",
                data_2="0xa551b3a8333bcdf5f2f7e08993d53923de3d64fcc68c034e717b9293fed7a421",
            ),
            id="EIP-152-case6-data7-gas-limit",
        ),
        pytest.param(
            Blake2bInput(
                rounds=0,
                h="00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
                m="0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
                t_0=0,
                t_1=SpecTestVectors.BLAKE2_OFFSET_COUNTER_1,
                f=0,
            ),
            ExpectedOutput(
                data_1="0x08c9bcf367e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5",
                data_2="0xd182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b",
            ),
            id="EIP-152-case7-data8-gas-limit",
        ),
    ],
)
@pytest.mark.parametrize(
    "precompile_gas_modifier",
    [
        pytest.param(0, id="sufficient_gas"),
        pytest.param(-1, id="insufficient_gas"),
    ],
)
@pytest.mark.eels_base_coverage
def test_blake2b_gas(
    state_test: StateTestFiller,
    pre: Alloc,
    call_opcode: Op,
    blake2b_contract_bytecode: Bytecode,
    data: Blake2bInput | bytes,
    precompile_gas: int,
    output: ExpectedOutput,
    precompile_gas_modifier: int,
) -> None:
    """Test BLAKE2b precompile with different gas limits."""
    sufficient_gas = precompile_gas_modifier == 0
    if not sufficient_gas and precompile_gas == 0:
        pytest.skip("Precompile cost is zero, cannot run oog")

    account = pre.deploy_contract(
        blake2b_contract_bytecode, storage={0: 0xDEADBEEF}
    )
    sender = pre.fund_eoa()

    tx = Transaction(to=account, data=data, sender=sender)

    post = {
        account: Account(
            storage={0: 0x1, 1: output.data_1, 2: output.data_2}
            if sufficient_gas
            else {0: 0x0, 1: 0x0, 2: 0x0}
        )
    }
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 20 parametrized test cases across 10 forks.