Skip to content

Commit

Permalink
test NodeData encoding and decoding
Browse files Browse the repository at this point in the history
 * fixes #3
  • Loading branch information
Rjected committed Jun 25, 2022
1 parent 766f4f9 commit 57cd847
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct NodeData(pub Vec<bytes::Bytes>);
mod test {
use hex_literal::hex;

use crate::{message::RequestPair, GetNodeData};
use crate::{message::RequestPair, GetNodeData, NodeData};
use fastrlp::{Decodable, Encodable};

#[test]
Expand Down Expand Up @@ -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::<NodeData> {
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::<NodeData>::decode(&mut &data[..]).unwrap();
assert_eq!(
request,
RequestPair::<NodeData> {
request_id: 1111,
message: NodeData(vec![
hex!("deadc0de").as_slice().into(),
hex!("feedbeef").as_slice().into(),
])
}
);
}
}

0 comments on commit 57cd847

Please sign in to comment.