Skip to content

test_sender_balance_insufficient_state_test()

Documentation for tests/frontier/validation/test_transaction.py::test_sender_balance_insufficient_state_test@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/frontier/validation/test_transaction.py::test_sender_balance_insufficient_state_test --fork Bogota

A legacy transaction from a sender that cannot afford gas * gasPrice must be rejected, exercised through the state-test code path.

Source code in tests/frontier/validation/test_transaction.py
@pytest.mark.inclusion_test
@pytest.mark.valid_from("Frontier")
@pytest.mark.state_test_only
@pytest.mark.exception_test
@pytest.mark.eels_base_coverage
def test_sender_balance_insufficient_state_test(
    state_test: StateTestFiller,
    pre: Alloc,
) -> None:
    """
    A legacy transaction from a sender that cannot afford `gas * gasPrice`
    must be rejected, exercised through the state-test code path.
    """
    storage = Storage()
    # If the transaction were (incorrectly) executed, this SSTORE would land a
    # non-default value in slot 0, diverging the post-state root from the
    # rejected (pre == post) outcome.
    contract = pre.deploy_contract(
        code=Op.SSTORE(storage.store_next(0, "must_stay_unset"), 0x1)
        + Op.STOP,
    )
    # Zero balance, unable to cover any gas cost.
    sender = pre.fund_eoa(amount=0)

    tx = Transaction(
        sender=sender,
        to=contract,
        gas_limit=100_000,
        gas_price=10,
        protected=False,  # legacy tx
        error=TransactionException.INSUFFICIENT_ACCOUNT_FUNDS,
    )

    state_test(
        env=Environment(),
        pre=pre,
        # Transaction rejected: contract storage stays empty.
        post={contract: Account(storage=storage)},
        tx=tx,
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 17 forks.