Skip to content

Commit

Permalink
test: add test for rlp data (#9200)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Oct 26, 2024
1 parent ce74f6b commit 6913a3d
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion crates/cast/src/rlp_converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ impl fmt::Display for Item {
#[cfg(test)]
mod test {
use crate::rlp_converter::Item;
use alloy_rlp::Decodable;
use alloy_primitives::hex;
use alloy_rlp::{Bytes, Decodable};
use serde_json::Result as JsonResult;

// https://en.wikipedia.org/wiki/Set-theoretic_definition_of_natural_numbers
Expand Down Expand Up @@ -179,4 +180,24 @@ mod test {

Ok(())
}

#[test]
fn rlp_data() {
// <https://github.com/foundry-rs/foundry/issues/9197>
let hex_val_rlp = hex!("820002");
let item = Item::decode(&mut &hex_val_rlp[..]).unwrap();

let data = hex!("0002");
let encoded = alloy_rlp::encode(&data[..]);
let decoded: Bytes = alloy_rlp::decode_exact(&encoded[..]).unwrap();
assert_eq!(Item::Data(decoded.to_vec()), item);

let hex_val_rlp = hex!("00");
let item = Item::decode(&mut &hex_val_rlp[..]).unwrap();

let data = hex!("00");
let encoded = alloy_rlp::encode(&data[..]);
let decoded: Bytes = alloy_rlp::decode_exact(&encoded[..]).unwrap();
assert_eq!(Item::Data(decoded.to_vec()), item);
}
}

0 comments on commit 6913a3d

Please sign in to comment.