def test_preserving_api(rlp_data, expected, expected_per_item_rlp): decoded, per_item_rlp = rusty_rlp.decode_raw(rlp_data, strict=True, preserve_cache_info=True) assert decoded == expected assert per_item_rlp == expected_per_item_rlp decoded, per_item_rlp = rusty_rlp.decode_raw(rlp_data, strict=True, preserve_cache_info=False) assert decoded == expected assert per_item_rlp == []
def test_decode_tuple_as_list(input, expected): pyrlp_encoded = encode_raw(input) rustyrlp_encoded = rusty_rlp.encode_raw(input) assert pyrlp_encoded == rustyrlp_encoded pyrlp_decoded = decode(pyrlp_encoded) rustyrlp_decoded, _ = rusty_rlp.decode_raw(rustyrlp_encoded, True, False) assert pyrlp_decoded == rustyrlp_decoded == expected
def test_decode_raw(input): pyrlp_encoded = encode_raw(input) rustyrlp_encoded = rusty_rlp.encode_raw(input) assert pyrlp_encoded == rustyrlp_encoded pyrlp_decoded = decode(pyrlp_encoded) rustyrlp_decoded, _ = rusty_rlp.decode_raw(rustyrlp_encoded, True, False) assert pyrlp_decoded == rustyrlp_decoded == input
def decode_raw(item, strict, preserve_per_item_rlp): try: return rusty_rlp.decode_raw(item, strict, preserve_per_item_rlp) except (TypeError, rusty_rlp.DecodingError) as e: raise DecodingError(e, item)
def test_invalid_deserializations(rlp_data, expected_error): with pytest.raises(expected_error): rusty_rlp.decode_raw(rlp_data, True, False)
def test_nonstrict_deserializations(rlp_data, expected): decoded, _ = rusty_rlp.decode_raw(rlp_data, False, False) assert decoded == expected
def test_decode_special_cases(rlp_data, expected): decoded, _ = rusty_rlp.decode_raw(rlp_data, True, False) assert decoded == expected