Skip to content

test_tx_nonce()

Documentation for tests/frontier/validation/test_transaction.py::test_tx_nonce@5f132e7c.

Generate fixtures for these test cases for Amsterdam with:

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

Tests that the tx nonce matches the account nonce.

Source code in tests/frontier/validation/test_transaction.py
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
@pytest.mark.parametrize(
    "nonce_diff, expected_exception",
    [
        pytest.param(
            -1,
            TransactionException.NONCE_MISMATCH_TOO_LOW,
            marks=pytest.mark.exception_test,
        ),
        (0, None),  # Valid case - no exception
        pytest.param(
            1,
            TransactionException.NONCE_MISMATCH_TOO_HIGH,
            marks=pytest.mark.exception_test,
        ),
    ],
)
@pytest.mark.pre_alloc_mutable
@pytest.mark.eels_base_coverage
def test_tx_nonce(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    env: Environment,
    nonce_diff: int,
    expected_exception: TransactionException | None,
) -> None:
    """
    Tests that the tx nonce matches the account nonce.
    """
    sender = pre.fund_eoa(nonce=5)
    to = pre.fund_eoa()

    tx = Transaction(
        to=to,
        nonce=sender.nonce + nonce_diff,
        sender=sender,
        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 14 forks.