diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a41bf51bbf..40a33f9322 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -137,7 +137,7 @@ jobs: /tmp/bins/sozo --manifest-path crates/dojo/core/Scarb.toml test /tmp/bins/sozo --manifest-path crates/dojo/core-cairo-test/Scarb.toml test - dojo-spawn-and-move-example-test: + dojo-examples-test: needs: build runs-on: ubuntu-latest container: @@ -150,6 +150,9 @@ jobs: - uses: actions/checkout@v3 - run: | chmod +x /tmp/bins/sozo + /tmp/bins/sozo --manifest-path examples/spawn-and-move/Scarb.toml build + /tmp/bins/sozo --manifest-path examples/spawn-and-move/Scarb.toml inspect ns-Flatbow + /tmp/bins/sozo --manifest-path examples/spawn-and-move/Scarb.toml inspect ns-RiverSkale /tmp/bins/sozo --manifest-path examples/spawn-and-move/Scarb.toml test /tmp/bins/sozo --manifest-path examples/simple/Scarb.toml test diff --git a/bin/sozo/src/commands/inspect.rs b/bin/sozo/src/commands/inspect.rs index b811bdadcc..d24a21c049 100644 --- a/bin/sozo/src/commands/inspect.rs +++ b/bin/sozo/src/commands/inspect.rs @@ -40,7 +40,7 @@ impl InspectArgs { utils::get_world_diff_and_provider(starknet.clone(), world, &ws).await?; if let Some(resource) = resource { - inspect_resource(&resource, &world_diff); + inspect_resource(&resource, &world_diff)?; } else { inspect_world(&world_diff); } @@ -166,7 +166,7 @@ struct GranteeDisplay { } /// Inspects a resource. -fn inspect_resource(resource_name_or_tag: &str, world_diff: &WorldDiff) { +fn inspect_resource(resource_name_or_tag: &str, world_diff: &WorldDiff) -> Result<()> { let selector = if naming::is_valid_tag(resource_name_or_tag) { naming::compute_selector_from_tag(resource_name_or_tag) } else { @@ -175,8 +175,7 @@ fn inspect_resource(resource_name_or_tag: &str, world_diff: &WorldDiff) { let resource_diff = world_diff.resources.get(&selector); if resource_diff.is_none() { - println!("Resource not found locally."); - return; + return Err(anyhow::anyhow!("Resource not found locally.")); } let resource_diff = resource_diff.unwrap(); @@ -243,6 +242,7 @@ fn inspect_resource(resource_name_or_tag: &str, world_diff: &WorldDiff) { print_table(&writers_disp, Some(Color::FG_BRIGHT_CYAN), Some("\n> Writers")); print_table(&owners_disp, Some(Color::FG_BRIGHT_MAGENTA), Some("\n> Owners")); + Ok(()) } /// Inspects the whole world. diff --git a/bin/sozo/src/utils.rs b/bin/sozo/src/utils.rs index 818b5ad7ec..b056c0f99f 100644 --- a/bin/sozo/src/utils.rs +++ b/bin/sozo/src/utils.rs @@ -21,7 +21,7 @@ use starknet::core::types::Felt; use starknet::core::utils as snutils; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::{JsonRpcClient, Provider}; -use tracing::{error, trace}; +use tracing::{trace, warn}; use crate::commands::options::account::{AccountOptions, SozoAccount}; use crate::commands::options::starknet::StarknetOptions; @@ -117,10 +117,15 @@ pub async fn get_world_diff_and_provider( let (provider, rpc_url) = starknet.provider(env)?; let provider = Arc::new(provider); - if let Err(e) = provider_utils::health_check_provider(provider.clone()).await { - error!(target: LOG_TARGET,"Provider health check failed during sozo inspect."); - return Err(e); + if (provider_utils::health_check_provider(provider.clone()).await).is_err() { + 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."); + return Ok(( + WorldDiff::from_local(world_local)?, + Arc::try_unwrap(provider).map_err(|_| anyhow!("Failed to unwrap Arc"))?, + rpc_url, + )); } + let provider = Arc::try_unwrap(provider).map_err(|_| anyhow!("Failed to unwrap Arc"))?; trace!(?provider, "Provider initialized."); diff --git a/bin/sozo/tests/test_data/invalid_cairo_version/Scarb.lock b/bin/sozo/tests/test_data/invalid_cairo_version/Scarb.lock new file mode 100644 index 0000000000..b430fc3d8d --- /dev/null +++ b/bin/sozo/tests/test_data/invalid_cairo_version/Scarb.lock @@ -0,0 +1,6 @@ +# Code generated by scarb DO NOT EDIT. +version = 1 + +[[package]] +name = "sozo_test" +version = "0.3.1-rc7" diff --git a/crates/dojo/core-cairo-test/Scarb.lock b/crates/dojo/core-cairo-test/Scarb.lock index 6d9a3fcab9..b696256903 100644 --- a/crates/dojo/core-cairo-test/Scarb.lock +++ b/crates/dojo/core-cairo-test/Scarb.lock @@ -3,7 +3,7 @@ version = 1 [[package]] name = "dojo" -version = "1.0.11" +version = "1.0.12" dependencies = [ "dojo_plugin", ] diff --git a/examples/spawn-and-move/Scarb.lock b/examples/spawn-and-move/Scarb.lock index 019c180bc8..ac0f63fee5 100644 --- a/examples/spawn-and-move/Scarb.lock +++ b/examples/spawn-and-move/Scarb.lock @@ -31,7 +31,7 @@ dependencies = [ [[package]] name = "dojo_examples" -version = "1.0.11" +version = "1.0.12" dependencies = [ "armory", "bestiary", diff --git a/examples/spawn-and-move/Scarb.toml b/examples/spawn-and-move/Scarb.toml index 32672d248f..8982b684e4 100644 --- a/examples/spawn-and-move/Scarb.toml +++ b/examples/spawn-and-move/Scarb.toml @@ -10,7 +10,7 @@ edition = "2024_07" sierra-replace-ids = true [[target.starknet-contract]] -build-external-contracts = [ "dojo::world::world_contract::world" ] +build-external-contracts = [ "dojo::world::world_contract::world", "armory::m_Flatbow", "bestiary::m_RiverSkale" ] [dependencies] armory = { path = "../game-lib/armory" } diff --git a/examples/spawn-and-move/src/actions.cairo b/examples/spawn-and-move/src/actions.cairo index cd116a2255..fc2ace0903 100644 --- a/examples/spawn-and-move/src/actions.cairo +++ b/examples/spawn-and-move/src/actions.cairo @@ -228,6 +228,7 @@ mod tests { }; use super::{actions, IActionsDispatcher, IActionsDispatcherTrait}; + use crate::dungeon::dungeon; use dojo_examples::models::{Position, PositionValue, m_Position, Moves, m_Moves, Direction,}; fn namespace_def() -> NamespaceDef { @@ -318,4 +319,38 @@ mod tests { assert(new_position.vec.x == initial_position.vec.x + 1, 'position x is wrong'); assert(new_position.vec.y == initial_position.vec.y, 'position y is wrong'); } + + #[test] + #[available_gas(30000000)] + #[cfg(feature: 'dungeon')] + fn test_feature_dungeon() { + let ndef = NamespaceDef { + namespace: "ns", resources: [ + TestResource::Model(armory::m_Flatbow::TEST_CLASS_HASH), + TestResource::Model(bestiary::m_RiverSkale::TEST_CLASS_HASH), + TestResource::Contract(actions::TEST_CLASS_HASH), + TestResource::Contract(dungeon::TEST_CLASS_HASH), + ].span() + }; + + let contract_defs = [ + ContractDefTrait::new(@"ns", @"actions") + .with_writer_of([dojo::utils::bytearray_hash(@"ns")].span()), + ContractDefTrait::new(@"ns", @"dungeon") + .with_writer_of([dojo::utils::bytearray_hash(@"ns")].span()), + ].span(); + + let mut world = spawn_test_world([ndef].span()); + world.sync_perms_and_inits(contract_defs); + + let other = starknet::contract_address_const::<0x1234>(); + starknet::testing::set_contract_address(other); + + let (dungeon_addr, _) = world.dns(@"dungeon").unwrap(); + + let (actions_system_addr, _) = world.dns(@"actions").unwrap(); + let actions_system = IActionsDispatcher { contract_address: actions_system_addr }; + + actions_system.enter_dungeon(dungeon_addr); + } }