Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

Commit

Permalink
fix: add naming rules to panic message
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed Oct 11, 2024
1 parent 5008a0f commit 61ffcae
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions crates/contracts/src/tests/world/resources.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ fn test_register_model_for_namespace_writer() {

#[test]
#[should_panic(
expected: ("Name `foo-bis` is invalid according to Dojo naming rules", 'ENTRYPOINT_FAILED',)
expected: (
"Name `foo-bis` is invalid according to Dojo naming rules: ^[a-zA-Z0-9_]+$",
'ENTRYPOINT_FAILED',
)
)]
fn test_register_model_with_invalid_name() {
let world = deploy_world();
Expand All @@ -185,7 +188,7 @@ fn test_register_model_with_invalid_name() {
#[test]
#[should_panic(
expected: (
"Namespace `inv@lid n@mesp@ce` is invalid according to Dojo naming rules",
"Namespace `inv@lid n@mesp@ce` is invalid according to Dojo naming rules: ^[a-zA-Z0-9_]+$",
'ENTRYPOINT_FAILED',
)
)]
Expand Down
2 changes: 1 addition & 1 deletion crates/contracts/src/world/errors.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ pub fn no_world_owner(caller: ContractAddress, target: @ByteArray) -> ByteArray
}

pub fn invalid_naming(kind: ByteArray, what: @ByteArray) -> ByteArray {
format!("{kind} `{what}` is invalid according to Dojo naming rules")
format!("{kind} `{what}` is invalid according to Dojo naming rules: ^[a-zA-Z0-9_]+$")
}
4 changes: 2 additions & 2 deletions crates/contracts/src/world/world_contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -937,14 +937,14 @@ pub mod world {
self.panic_with_details(caller, resource_selector, permission)
}

///
/// Asserts the name is valid according to the naming convention.
fn assert_name(self: @ContractState, name: @ByteArray) {
if !dojo::utils::is_name_valid(name) {
panic_with_byte_array(@errors::invalid_naming("Name", name))
}
}

///
/// Asserts the namespace is valid according to the naming convention.
fn assert_namespace(self: @ContractState, namespace: @ByteArray) {
if !dojo::utils::is_name_valid(namespace) {
panic_with_byte_array(@errors::invalid_naming("Namespace", namespace))
Expand Down

0 comments on commit 61ffcae

Please sign in to comment.