File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -37,3 +37,30 @@ pub fn erc7201(id: &str) -> B256 {
37
37
let x = U256 :: from_be_bytes ( keccak256 ( id) . 0 ) - U256 :: from ( 1 ) ;
38
38
keccak256 ( x. to_be_bytes :: < 32 > ( ) ) & B256 :: from ( !U256 :: from ( 0xff ) )
39
39
}
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
+ }
You can’t perform that action at this time.
0 commit comments