Skip to content

test_field_as_list()

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

Generate fixtures for these test cases for Bogota with:

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

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
@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 17 forks.