Skip to content

test_invalid_tx_invalid_rlp_encoding()

Documentation for tests/prague/eip7702_set_code_tx/test_invalid_tx.py::test_invalid_tx_invalid_rlp_encoding@21507778.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/prague/eip7702_set_code_tx/test_invalid_tx.py::test_invalid_tx_invalid_rlp_encoding --fork Amsterdam

Test sending a transaction type-4 where the RLP encoding of the transaction is invalid.

Source code in tests/prague/eip7702_set_code_tx/test_invalid_tx.py
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
@pytest.mark.parametrize(
    "invalid_rlp_mode",
    [
        pytest.param(InvalidRLPMode.TRUNCATED_RLP, id="truncated_rlp"),
        pytest.param(InvalidRLPMode.EXTRA_BYTES, id="extra_bytes"),
    ],
)
@pytest.mark.parametrize(
    "delegate_address",
    [
        pytest.param(
            Spec.RESET_DELEGATION_ADDRESS, id="reset_delegation_address"
        ),
        pytest.param(Address(1), id="non_zero_address"),
    ],
)
def test_invalid_tx_invalid_rlp_encoding(
    transaction_test: TransactionTestFiller,
    pre: Alloc,
    delegate_address: Address,
    invalid_rlp_mode: InvalidRLPMode,
) -> None:
    """
    Test sending a transaction type-4 where the RLP encoding of the transaction
    is invalid.
    """
    auth_signer = pre.fund_eoa()

    tx = Transaction(
        gas_limit=100_000,
        to=0,
        value=0,
        authorization_list=[
            AuthorizationTuple(
                address=delegate_address,
                nonce=0,
                signer=auth_signer,
            )
        ],
        error=TransactionException.TYPE_4_INVALID_AUTHORIZATION_FORMAT,
        sender=pre.fund_eoa(),
    )

    if invalid_rlp_mode == InvalidRLPMode.TRUNCATED_RLP:
        # Truncate the last byte of the RLP encoding
        tx.rlp_override = Bytes(tx.rlp()[:-1])
    elif invalid_rlp_mode == InvalidRLPMode.EXTRA_BYTES:
        # Add an extra byte to the end of the RLP encoding
        tx.rlp_override = Bytes(tx.rlp() + b"\x00")

    transaction_test(
        pre=pre,
        tx=tx,
    )

Parametrized Test Cases

This test generates 4 parametrized test cases across 3 forks.