def test_rlp_decode_successfully() -> None: test_cases = [ (bytearray([0x80]), bytearray()), (bytearray([0xB7]) + bytearray(b"\x83" * 55), bytearray(b"\x83") * 55), (bytearray([0xC0]), []), ( b"\xdb\x85hello\xd4\x83how\xcf\x83are\x83you\xc6\x85doing", [b"hello", [b"how", [b"are", b"you", [b"doing"]]]], ), ] for (encoding, expected_raw_data) in test_cases: assert rlp.decode(encoding) == expected_raw_data
def test_roundtrip_encoding_and_decoding() -> None: test_cases = [ b"", b"h", b"hello how are you doing today?", Uint(35).to_be_bytes(), Uint(255).to_be_bytes(), [], [ b"hello", [b"how", [b"are", b"you", [b"doing", [Uint(255).to_be_bytes()]]]], ], ] for raw_data in test_cases: assert rlp.decode(rlp.encode(cast(RLP, raw_data))) == raw_data
def test_ethtest_fixtures_for_fails_in_rlp_decoding( raw_data: Bytes, encoded_data: Bytes) -> None: with pytest.raises(Exception): rlp.decode(encoded_data)
def test_ethtest_fixtures_for_successfull_rlp_decoding( raw_data: Bytes, encoded_data: Bytes) -> None: decoded_data = rlp.decode(encoded_data) assert rlp.encode(decoded_data) == encoded_data
def test_rlp_decode_failure_empty_bytes() -> None: with pytest.raises(Exception): rlp.decode(b"")
def test_rlp_decode_multi_char_str() -> None: assert rlp.decode(b"\x85hello") == "hello".encode()
def test_rlp_decode_one_char_str() -> None: assert rlp.decode(b"h") == "h".encode()
def test_rlp_decode_empty_str() -> None: assert rlp.decode(b"\x80") == "".encode()
def test_rlp_decode_to_255_uint() -> None: assert rlp.decode(b"\x81\xff") == Uint(255).to_be_bytes()
def test_rlp_decode_to_zero_uint() -> None: assert rlp.decode(b"\x80") == Uint(0).to_be_bytes()