Skip to content

Commit

Permalink
fix: add world as valid keyword for grant/revoke
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed Nov 9, 2024
1 parent a39ab05 commit a00f2dc
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion bin/sozo/src/commands/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,14 @@ impl PermissionPair {
&self,
contracts: &HashMap<String, ContractInfo>,
) -> Result<(Felt, Felt)> {
let selector = dojo_types::naming::compute_selector_from_tag_or_name(&self.resource_tag);
let selector = if self.resource_tag == "world" {
Felt::ZERO
} else if self.resource_tag.starts_with("0x") {
Felt::from_str(&self.resource_tag)
.map_err(|_| anyhow!("Invalid resource selector: {}", self.resource_tag))?
} else {
dojo_types::naming::compute_selector_from_tag_or_name(&self.resource_tag)
};

let contract_address = if self.grantee_tag_or_address.starts_with("0x") {
Felt::from_str(&self.grantee_tag_or_address)
Expand Down Expand Up @@ -775,5 +782,21 @@ mod tests {
grantee_tag_or_address: "0xinvalid".to_string(),
};
assert!(pair.to_selector_and_address(&contracts).is_err());

let pair = PermissionPair {
resource_tag: "world".to_string(),
grantee_tag_or_address: "0x123".to_string(),
};
let (selector, address) = pair.to_selector_and_address(&contracts).unwrap();
assert_eq!(selector, Felt::ZERO);
assert_eq!(address, Felt::from_str("0x123").unwrap());

let pair = PermissionPair {
resource_tag: "0x123".to_string(),
grantee_tag_or_address: "0x456".to_string(),
};
let (selector, address) = pair.to_selector_and_address(&contracts).unwrap();
assert_eq!(selector, Felt::from_str("0x123").unwrap());
assert_eq!(address, Felt::from_str("0x456").unwrap());
}
}

0 comments on commit a00f2dc

Please sign in to comment.