Skip to content

test_non_canonical_single_byte()

Documentation for tests/frontier/validation/test_transaction_rlp.py::test_non_canonical_single_byte@49633827.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/frontier/validation/test_transaction_rlp.py::test_non_canonical_single_byte --fork Amsterdam

Encode the single-byte nonce payload behind a one-byte string header (0x8101) instead of as the byte itself; the non-canonical encoding must be rejected.

Source code in tests/frontier/validation/test_transaction_rlp.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
@pytest.mark.ported_from(
    [
        f"{LEGACY_TX_TESTS}/ttWrongRLP/RLPIncorrectByteEncoding00Copier.json",
        f"{LEGACY_TX_TESTS}/ttWrongRLP/RLPIncorrectByteEncoding01Copier.json",
        f"{LEGACY_TX_TESTS}/ttWrongRLP/RLPIncorrectByteEncoding127Copier.json",
    ],
)
@pytest.mark.exception_test
def test_non_canonical_single_byte(
    transaction_test: TransactionTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Encode the single-byte nonce payload behind a one-byte string
    header (0x8101) instead of as the byte itself; the non-canonical
    encoding must be rejected.
    """
    fields = signed_tx_fields(pre, fork, nonce=1)
    payload = fields["nonce"]
    assert len(payload) == 1 and payload[0] < 0x80
    rlp = encode_tx(fields, {"nonce": b"\x81" + payload})
    transaction_test(
        pre=pre,
        tx=invalid_tx(
            pre, rlp, TransactionException.RLP_LEADING_ZEROS_NONCE_SIZE
        ),
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 16 forks.