Skip to content

test_sender_balance_insufficient_state_test()

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

Generate fixtures for these test cases for Amsterdam with:

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

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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
@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 16 forks.