Skip to content

test_sender_balance()

Documentation for tests/frontier/validation/test_transaction.py::test_sender_balance@02aafd78.

Generate fixtures for these test cases for Bogota with:

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

Tests that the sender has sufficient balance.

Source code in tests/frontier/validation/test_transaction.py
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
@pytest.mark.inclusion_test
@pytest.mark.parametrize(
    "balance_diff, expected_exception",
    [
        pytest.param(
            -1,
            TransactionException.INSUFFICIENT_ACCOUNT_FUNDS,
            marks=pytest.mark.exception_test,
        ),
        (0, None),  # Valid case - no exception
        (1, None),
    ],
)
@pytest.mark.eels_base_coverage
def test_sender_balance(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    env: Environment,
    fork: BaseFork,
    balance_diff: int,
    expected_exception: TransactionException | None,
) -> None:
    """
    Tests that the sender has sufficient balance.
    """
    to = pre.fund_eoa()

    intrinsic_cost = fork.transaction_intrinsic_cost_calculator()
    tx_gas_limit = intrinsic_cost()
    tx_gas_price = TransactionDefaults.gas_price
    tx_value = 0

    # Calculate required balance from tx fields and fund sender
    required_balance = tx_gas_limit * tx_gas_price + tx_value
    sender = pre.fund_eoa(amount=required_balance + balance_diff)

    # Create transaction first with defaults
    tx = Transaction(
        sender=sender,
        gas_limit=tx_gas_limit,
        gas_price=tx_gas_price,
        value=tx_value,
        to=to,
        protected=False,
        error=expected_exception,
    )

    block = Block(
        txs=[tx],
        exception=expected_exception,
    )

    blockchain_test(pre=pre, post={}, blocks=[block], genesis_environment=env)

Parametrized Test Cases

This test generates 3 parametrized test cases across 17 forks.