Skip to content

Commit 74ccf13

Browse files
authored
fix(sozo): return error if inspect doesn't find resource (#2920)
1 parent 30e574c commit 74ccf13

File tree

10 files changed

+60
-14
lines changed

10 files changed

+60
-14
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ jobs:
140140
/tmp/bins/sozo --manifest-path crates/dojo/core/Scarb.toml test
141141
/tmp/bins/sozo --manifest-path crates/dojo/core-cairo-test/Scarb.toml test
142142
143-
dojo-spawn-and-move-example-test:
143+
dojo-examples-test:
144144
needs: build
145145
runs-on: ubuntu-latest
146146
steps:
@@ -154,6 +154,9 @@ jobs:
154154
- uses: actions/checkout@v3
155155
- run: |
156156
chmod +x /tmp/bins/sozo
157+
/tmp/bins/sozo --manifest-path examples/spawn-and-move/Scarb.toml build
158+
/tmp/bins/sozo --manifest-path examples/spawn-and-move/Scarb.toml inspect ns-Flatbow
159+
/tmp/bins/sozo --manifest-path examples/spawn-and-move/Scarb.toml inspect ns-RiverSkale
157160
/tmp/bins/sozo --manifest-path examples/spawn-and-move/Scarb.toml test
158161
/tmp/bins/sozo --manifest-path examples/simple/Scarb.toml test
159162

bin/sozo/src/commands/inspect.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl InspectArgs {
4040
utils::get_world_diff_and_provider(starknet.clone(), world, &ws).await?;
4141

4242
if let Some(resource) = resource {
43-
inspect_resource(&resource, &world_diff);
43+
inspect_resource(&resource, &world_diff)?;
4444
} else {
4545
inspect_world(&world_diff);
4646
}
@@ -166,7 +166,7 @@ struct GranteeDisplay {
166166
}
167167

168168
/// Inspects a resource.
169-
fn inspect_resource(resource_name_or_tag: &str, world_diff: &WorldDiff) {
169+
fn inspect_resource(resource_name_or_tag: &str, world_diff: &WorldDiff) -> Result<()> {
170170
let selector = if naming::is_valid_tag(resource_name_or_tag) {
171171
naming::compute_selector_from_tag(resource_name_or_tag)
172172
} else {
@@ -175,8 +175,7 @@ fn inspect_resource(resource_name_or_tag: &str, world_diff: &WorldDiff) {
175175
let resource_diff = world_diff.resources.get(&selector);
176176

177177
if resource_diff.is_none() {
178-
println!("Resource not found locally.");
179-
return;
178+
return Err(anyhow::anyhow!("Resource not found locally."));
180179
}
181180

182181
let resource_diff = resource_diff.unwrap();
@@ -243,6 +242,7 @@ fn inspect_resource(resource_name_or_tag: &str, world_diff: &WorldDiff) {
243242

244243
print_table(&writers_disp, Some(Color::FG_BRIGHT_CYAN), Some("\n> Writers"));
245244
print_table(&owners_disp, Some(Color::FG_BRIGHT_MAGENTA), Some("\n> Owners"));
245+
Ok(())
246246
}
247247

248248
/// Inspects the whole world.

bin/sozo/src/utils.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use starknet::core::types::Felt;
2121
use starknet::core::utils as snutils;
2222
use starknet::providers::jsonrpc::HttpTransport;
2323
use starknet::providers::{JsonRpcClient, Provider};
24-
use tracing::{error, trace};
24+
use tracing::{trace, warn};
2525

2626
use crate::commands::options::account::{AccountOptions, SozoAccount};
2727
use crate::commands::options::starknet::StarknetOptions;
@@ -133,10 +133,15 @@ pub async fn get_world_diff_and_provider(
133133

134134
let (provider, rpc_url) = starknet.provider(env)?;
135135
let provider = Arc::new(provider);
136-
if let Err(e) = provider_utils::health_check_provider(provider.clone()).await {
137-
error!(target: LOG_TARGET,"Provider health check failed during sozo inspect.");
138-
return Err(e);
136+
if (provider_utils::health_check_provider(provider.clone()).await).is_err() {
137+
warn!(target: LOG_TARGET, "Provider health check failed during sozo inspect, inspecting locally and all resources will appeared as `Created`. Remote resources will not be fetched.");
138+
return Ok((
139+
WorldDiff::from_local(world_local)?,
140+
Arc::try_unwrap(provider).map_err(|_| anyhow!("Failed to unwrap Arc"))?,
141+
rpc_url,
142+
));
139143
}
144+
140145
let provider = Arc::try_unwrap(provider).map_err(|_| anyhow!("Failed to unwrap Arc"))?;
141146
trace!(?provider, "Provider initialized.");
142147

crates/dojo/bindgen/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ mod tests {
262262
gather_dojo_data(&config.manifest_path().to_path_buf(), "ns", "dev", skip_migrations)
263263
.expect("Failed to gather dojo data");
264264

265-
assert_eq!(data.models.len(), 6);
265+
assert_eq!(data.models.len(), 8);
266266

267267
assert_eq!(data.world.name, "ns");
268268

crates/torii/indexer/src/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ async fn test_load_from_remote(sequencer: &RunnerCtx) {
140140

141141
let _block_timestamp = 1710754478_u64;
142142
let models = sqlx::query("SELECT * FROM models").fetch_all(&pool).await.unwrap();
143-
assert_eq!(models.len(), 8);
143+
assert_eq!(models.len(), 10);
144144

145145
let (id, name, namespace, packed_size, unpacked_size): (String, String, String, u8, u8) =
146146
sqlx::query_as(

examples/game-lib/Scarb.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ dependencies = [
1717

1818
[[package]]
1919
name = "dojo"
20-
version = "1.0.0-rc.0"
20+
version = "1.0.12"
2121
dependencies = [
2222
"dojo_plugin",
2323
]
2424

2525
[[package]]
2626
name = "dojo_plugin"
27-
version = "2.9.1"
27+
version = "2.9.2"

examples/spawn-and-move/Scarb.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ edition = "2024_07"
1010
sierra-replace-ids = true
1111

1212
[[target.starknet-contract]]
13-
build-external-contracts = [ "dojo::world::world_contract::world" ]
13+
build-external-contracts = [ "dojo::world::world_contract::world", "armory::m_Flatbow", "bestiary::m_RiverSkale" ]
1414

1515
[dependencies]
1616
armory = { path = "../game-lib/armory" }

examples/spawn-and-move/src/actions.cairo

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ mod tests {
228228
};
229229

230230
use super::{actions, IActionsDispatcher, IActionsDispatcherTrait};
231+
use crate::dungeon::dungeon;
231232
use dojo_examples::models::{Position, PositionValue, m_Position, Moves, m_Moves, Direction};
232233

233234
fn namespace_def() -> NamespaceDef {
@@ -321,4 +322,41 @@ mod tests {
321322
assert(new_position.vec.x == initial_position.vec.x + 1, 'position x is wrong');
322323
assert(new_position.vec.y == initial_position.vec.y, 'position y is wrong');
323324
}
325+
326+
#[test]
327+
#[available_gas(30000000)]
328+
#[cfg(feature: 'dungeon')]
329+
fn test_feature_dungeon() {
330+
let ndef = NamespaceDef {
331+
namespace: "ns",
332+
resources: [
333+
TestResource::Model(armory::m_Flatbow::TEST_CLASS_HASH),
334+
TestResource::Model(bestiary::m_RiverSkale::TEST_CLASS_HASH),
335+
TestResource::Contract(actions::TEST_CLASS_HASH),
336+
TestResource::Contract(dungeon::TEST_CLASS_HASH),
337+
]
338+
.span(),
339+
};
340+
341+
let contract_defs = [
342+
ContractDefTrait::new(@"ns", @"actions")
343+
.with_writer_of([dojo::utils::bytearray_hash(@"ns")].span()),
344+
ContractDefTrait::new(@"ns", @"dungeon")
345+
.with_writer_of([dojo::utils::bytearray_hash(@"ns")].span()),
346+
]
347+
.span();
348+
349+
let mut world = spawn_test_world([ndef].span());
350+
world.sync_perms_and_inits(contract_defs);
351+
352+
let other = starknet::contract_address_const::<0x1234>();
353+
starknet::testing::set_contract_address(other);
354+
355+
let (dungeon_addr, _) = world.dns(@"dungeon").unwrap();
356+
357+
let (actions_system_addr, _) = world.dns(@"actions").unwrap();
358+
let actions_system = IActionsDispatcher { contract_address: actions_system_addr };
359+
360+
actions_system.enter_dungeon(dungeon_addr);
361+
}
324362
}

spawn-and-move-db.tar.gz

71.8 KB
Binary file not shown.

types-test-db.tar.gz

37 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)