Skip to content

Commit

Permalink
fix: ensure namespaces are correctly mapped for default, and add traces
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed Oct 30, 2024
1 parent 33f4efc commit 077a252
Show file tree
Hide file tree
Showing 5 changed files with 288 additions and 13 deletions.
3 changes: 3 additions & 0 deletions bin/sozo/src/commands/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ fn inspect_resource(resource_name_or_tag: &str, world_diff: &WorldDiff) {
});
}

writers_disp.sort_by_key(|m| m.tag.to_string());
owners_disp.sort_by_key(|m| m.tag.to_string());

print_table(&writers_disp, "\n> Writers");
print_table(&owners_disp, "\n> Owners");
}
Expand Down
25 changes: 24 additions & 1 deletion crates/dojo/world/src/local/artifact_to_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use cairo_lang_starknet_classes::contract_class::ContractClass;
use serde_json;
use starknet::core::types::contract::{AbiEntry, AbiImpl, SierraClass};
use starknet::core::types::Felt;
use tracing::trace;

use super::*;
use crate::config::ProfileConfig;
Expand Down Expand Up @@ -57,6 +58,12 @@ impl WorldLocal {
let namespaces = profile_config.namespace.get_namespaces(&name);

for ns in namespaces {
trace!(
name,
namespace = ns,
"Adding local contract from artifact."
);

let resource = ResourceLocal::Contract(ContractLocal {
common: CommonLocalInfo {
namespace: ns,
Expand All @@ -76,6 +83,12 @@ impl WorldLocal {
let namespaces = profile_config.namespace.get_namespaces(&name);

for ns in namespaces {
trace!(
name,
namespace = ns,
"Adding local model from artifact."
);

let resource = ResourceLocal::Model(ModelLocal {
common: CommonLocalInfo {
namespace: ns,
Expand All @@ -95,6 +108,12 @@ impl WorldLocal {
let namespaces = profile_config.namespace.get_namespaces(&name);

for ns in namespaces {
trace!(
name,
namespace = ns,
"Adding local event from artifact."
);

let resource = ResourceLocal::Event(EventLocal {
common: CommonLocalInfo {
namespace: ns,
Expand All @@ -121,9 +140,13 @@ impl WorldLocal {
name: profile_config.namespace.default.clone(),
}));

// Ensures all namespaces used as mapping key are registered as resources,
// if it's not the default namespace.
if let Some(mappings) = &profile_config.namespace.mappings {
for ns in mappings.keys() {
resources.push(ResourceLocal::Namespace(NamespaceLocal { name: ns.clone() }));
if ns != &profile_config.namespace.default {
resources.push(ResourceLocal::Namespace(NamespaceLocal { name: ns.clone() }));
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions crates/sozo/ops/src/migrate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,12 @@ where
// The issue is that `e` is bound to concrete type `SingleOwnerAccount`.
// Thus, we can't return `e` directly.
// Might have a better solution by addind a new variant?
if e.to_string().contains("Class already declared") {
// If the class is already declared, it might be because it was already
// declared in a previous run or an other declarer.
continue;
}

return Err(MigrationError::DeclareClassError(e.to_string()));
}
}
Expand Down
10 changes: 6 additions & 4 deletions examples/simple/dojo_dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@ description = "Simple world."
name = "simple"
seed = "simple"

[namespace]
default = "ns"

[env]
rpc_url = "http://localhost:5050/"
# Default account for katana with seed = 0
account_address = "0x127fd5f1fe78a71f8bcd1fec63e3fe2f0486b6ecd5c86a0466c3a21fa5cfcec"
private_key = "0xc5b2fcab997346f3ea1c00b002ecf6f382c5f9c9659a3894eb783c5320f912"
#world_address = "0x077c0dc7c1aba7f8842aff393ce6aa71fa675b4ced1bc927f7fc971b6acd92fc"

[namespace]
default = "ns"
mappings = { "ns" = ["c1", "M"], "ns2" = ["c1", "M"] }

[init_call_args]
"ns-c1" = ["0xfffe"]
"ns2-c1" = ["0xfffe"]

[writers]
"ns" = ["ns-c1", "ns-c2"]
"ns-M" = ["ns-c2", "ns-c1"]
"ns-M" = ["ns-c2", "ns-c1", "ns2-c1"]

[owners]
"ns" = ["ns-c1"]
Expand Down
Loading

0 comments on commit 077a252

Please sign in to comment.