Skip to content

test_field_as_list()

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

Generate fixtures for these test cases for Amsterdam with:

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

Encode one field as an RLP list instead of a byte string.

The gas price and v fields are equally rejected but have no field-specific decoding exception, so they are not covered.

Source code in tests/frontier/validation/test_transaction_rlp.py
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
@pytest.mark.ported_from(
    [
        f"{LEGACY_TX_TESTS}/ttWrongRLP/"
        "RLPElementIsListWhenItShouldntBeCopier.json",
        f"{LEGACY_TX_TESTS}/ttWrongRLP/"
        "RLPElementIsListWhenItShouldntBe2Copier.json",
        f"{LEGACY_TX_TESTS}/ttWrongRLP/TRANSCT_rvalue_GivenAsListCopier.json",
        f"{LEGACY_TX_TESTS}/ttWrongRLP/TRANSCT_svalue_GivenAsListCopier.json",
        f"{LEGACY_TX_TESTS}/ttWrongRLP/TRANSCT_data_GivenAsListCopier.json",
        f"{LEGACY_TX_TESTS}/ttWrongRLP/TRANSCT_gasLimit_GivenAsListCopier.json",
        f"{LEGACY_TX_TESTS}/ttWrongRLP/TRANSCT_to_GivenAsListCopier.json",
    ],
)
@pytest.mark.exception_test
@pytest.mark.parametrize(
    "field, error",
    [
        ("nonce", TransactionException.RLP_INVALID_NONCE),
        ("gas_limit", TransactionException.RLP_INVALID_GASLIMIT),
        ("to", TransactionException.RLP_INVALID_TO),
        ("value", TransactionException.RLP_INVALID_VALUE),
        ("data", TransactionException.RLP_INVALID_DATA),
        ("r", TransactionException.RLP_INVALID_SIGNATURE_R),
        ("s", TransactionException.RLP_INVALID_SIGNATURE_S),
    ],
)
def test_field_as_list(
    transaction_test: TransactionTestFiller,
    pre: Alloc,
    fork: Fork,
    field: str,
    error: TransactionException,
) -> None:
    """
    Encode one field as an RLP list instead of a byte string.

    The gas price and v fields are equally rejected but have no
    field-specific decoding exception, so they are not covered.
    """
    fields = signed_tx_fields(pre, fork)
    corrupted = rlp_list([rlp_bytes(fields[field])])
    rlp = encode_tx(fields, {field: corrupted})
    transaction_test(pre=pre, tx=invalid_tx(pre, rlp, error))

Parametrized Test Cases

This test generates 7 parametrized test cases across 16 forks.