Skip to content

Commit 1b5fcbb

Browse files
committed
test(utils): add test for erc7201 utility function
1 parent a914bb5 commit 1b5fcbb

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

crates/common/src/utils.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,30 @@ pub fn erc7201(id: &str) -> B256 {
3737
let x = U256::from_be_bytes(keccak256(id).0) - U256::from(1);
3838
keccak256(x.to_be_bytes::<32>()) & B256::from(!U256::from(0xff))
3939
}
40+
41+
#[cfg(test)]
42+
mod tests {
43+
use super::*;
44+
use alloy_primitives::b256;
45+
46+
#[test]
47+
fn test_erc7201_known_value() {
48+
let id = "example.main";
49+
let expected = b256!("0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500");
50+
assert_eq!(erc7201(id), expected);
51+
}
52+
53+
#[test]
54+
fn test_erc7201_different_inputs() {
55+
let a = erc7201("foo.bar");
56+
let b = erc7201("baz.bat");
57+
assert_ne!(a, b);
58+
}
59+
60+
#[test]
61+
fn test_erc7201_format() {
62+
let id = "my.storage.slot";
63+
let slot = erc7201(id);
64+
assert_eq!(slot.len(), 32);
65+
}
66+
}

0 commit comments

Comments
 (0)