Skip to content

Commit a1027b7

Browse files
committed
test: add snip-12 simple enum test case
The expected hash is based on a patched version of starknet.js at: starknet-io/starknet.js#1292
1 parent cfc3765 commit a1027b7

File tree

1 file changed

+46
-1
lines changed
  • starknet-core/src/types/typed_data

1 file changed

+46
-1
lines changed

starknet-core/src/types/typed_data/mod.rs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,52 @@ mod tests {
878878

879879
#[test]
880880
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
881-
fn test_message_hash_v1_with_enum() {
881+
fn test_message_hash_v1_with_simple_enum() {
882+
let raw = r###"{
883+
"types": {
884+
"StarknetDomain": [
885+
{ "name": "name", "type": "shortstring" },
886+
{ "name": "version", "type": "shortstring" },
887+
{ "name": "chainId", "type": "shortstring" },
888+
{ "name": "revision", "type": "shortstring" }
889+
],
890+
"Example Message": [
891+
{ "name": "Value", "type": "enum", "contains": "My Enum" }
892+
],
893+
"My Enum": [
894+
{ "name": "Variant 1", "type": "()" },
895+
{ "name": "Variant 2", "type": "(string)" },
896+
{ "name": "Variant 3", "type": "(u128)" }
897+
]
898+
},
899+
"primaryType": "Example Message",
900+
"domain": {
901+
"name": "Starknet Example",
902+
"version": "1",
903+
"chainId": "SN_MAIN",
904+
"revision": "1"
905+
},
906+
"message": {
907+
"Value": {
908+
"Variant 2": ["tuple element"]
909+
}
910+
}
911+
}"###;
912+
913+
let data = serde_json::from_str::<TypedData>(raw).unwrap();
914+
915+
assert_eq!(
916+
data.message_hash(Felt::from_hex_unchecked("0x1234"))
917+
.unwrap(),
918+
Felt::from_hex_unchecked(
919+
"0x06143075810eaff76810682ad4db8c97ba0fd2c80d5f12d3e7e3a9c127e6f0f3"
920+
)
921+
);
922+
}
923+
924+
#[test]
925+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
926+
fn test_message_hash_v1_with_enum_nested() {
882927
let raw = r###"{
883928
"types": {
884929
"StarknetDomain": [

0 commit comments

Comments
 (0)