diff --git a/src/state.rs b/src/state.rs index 2f8a630..a77205c 100644 --- a/src/state.rs +++ b/src/state.rs @@ -15,7 +15,7 @@ pub struct NodeData(pub Vec); mod test { use hex_literal::hex; - use crate::{message::RequestPair, GetNodeData}; + use crate::{message::RequestPair, GetNodeData, NodeData}; use fastrlp::{Decodable, Encodable}; #[test] @@ -50,4 +50,37 @@ mod test { } ); } + + #[test] + // Test vector from: https://eips.ethereum.org/EIPS/eip-2481 + fn encode_node_data() { + let expected = hex!("ce820457ca84deadc0de84feedbeef"); + let mut data = vec![]; + let request = RequestPair:: { + request_id: 1111, + message: NodeData(vec![ + hex!("deadc0de").as_slice().into(), + hex!("feedbeef").as_slice().into(), + ]), + }; + request.encode(&mut data); + assert_eq!(data, expected); + } + + #[test] + // Test vector from: https://eips.ethereum.org/EIPS/eip-2481 + fn decode_node_data() { + let data = hex!("ce820457ca84deadc0de84feedbeef"); + let request = RequestPair::::decode(&mut &data[..]).unwrap(); + assert_eq!( + request, + RequestPair:: { + request_id: 1111, + message: NodeData(vec![ + hex!("deadc0de").as_slice().into(), + hex!("feedbeef").as_slice().into(), + ]) + } + ); + } }