From 001093e82209418070ef09c38776ae0db80b9368 Mon Sep 17 00:00:00 2001 From: glihm Date: Tue, 28 Jan 2025 22:38:48 -0600 Subject: [PATCH] fix: add latest edition and bump to `1.1.1` (#101) --- .github/workflows/test.yaml | 10 +++++++--- Scarb.lock | 14 +++++++------- Scarb.toml | 10 ++++++---- src/lib.cairo | 8 ++++---- src/models.cairo | 4 ++-- src/systems/actions.cairo | 18 ++++++++++-------- src/tests/test_world.cairo | 19 ++++++++++++------- 7 files changed, 48 insertions(+), 35 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5683242..a947ae2 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,11 +10,15 @@ jobs: sozo-test: runs-on: ubuntu-latest env: - DOJO_VERSION: v1.0.11 + DOJO_VERSION: v1.1.1 steps: - uses: actions/checkout@v3 - - run: curl -L https://install.dojoengine.org | bash - - run: /home/runner/.config/.dojo/bin/dojoup -v ${{ env.DOJO_VERSION }} + - uses: software-mansion/setup-scarb@v1 + with: + scarb-version: "2.9.2" + - run: | + curl -L https://install.dojoengine.org | bash + /home/runner/.config/.dojo/bin/dojoup -v ${{ env.DOJO_VERSION }} - run: | /home/runner/.config/.dojo/bin/sozo build /home/runner/.config/.dojo/bin/sozo test diff --git a/Scarb.lock b/Scarb.lock index 35da30b..4cec9a6 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -3,28 +3,28 @@ version = 1 [[package]] name = "dojo" -version = "1.0.11" -source = "git+https://github.com/dojoengine/dojo?tag=v1.0.11#2c77db4a334a312ce53a005c560b3398fcb7bf99" +version = "1.1.1" +source = "git+https://github.com/dojoengine/dojo?tag=v1.1.1#dba10f26191bce47bb442ddc626ba7c6e2d8c160" dependencies = [ "dojo_plugin", ] [[package]] name = "dojo_cairo_test" -version = "1.0.0-rc.0" -source = "git+https://github.com/dojoengine/dojo?tag=v1.0.11#2c77db4a334a312ce53a005c560b3398fcb7bf99" +version = "1.0.12" +source = "git+https://github.com/dojoengine/dojo?tag=v1.1.1#dba10f26191bce47bb442ddc626ba7c6e2d8c160" dependencies = [ "dojo", ] [[package]] name = "dojo_plugin" -version = "2.8.4" -source = "git+https://github.com/dojoengine/dojo?tag=v1.0.11#2c77db4a334a312ce53a005c560b3398fcb7bf99" +version = "2.9.2" +source = "git+https://github.com/dojoengine/dojo?tag=v1.1.1#dba10f26191bce47bb442ddc626ba7c6e2d8c160" [[package]] name = "dojo_starter" -version = "1.0.11" +version = "1.1.0" dependencies = [ "dojo", "dojo_cairo_test", diff --git a/Scarb.toml b/Scarb.toml index f91b62a..90d0863 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -1,7 +1,8 @@ [package] -cairo-version = "=2.8.4" +cairo-version = "=2.9.2" name = "dojo_starter" -version = "1.0.11" +version = "1.1.0" +edition = "2024_07" [cairo] sierra-replace-ids = true @@ -12,10 +13,11 @@ spawn = "sozo execute dojo_starter-actions spawn --wait" # scarb run spawn move = "sozo execute dojo_starter-actions move -c 1 --wait" # scarb run move [dependencies] -dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.11" } +dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.1.1" } [[target.starknet-contract]] build-external-contracts = ["dojo::world::world_contract::world"] [dev-dependencies] -dojo_cairo_test = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.11" } +cairo_test = "=2.9.2" +dojo_cairo_test = { git = "https://github.com/dojoengine/dojo", tag = "v1.1.1" } diff --git a/src/lib.cairo b/src/lib.cairo index 786bb77..3f415a2 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -1,9 +1,9 @@ -mod systems { - mod actions; +pub mod systems { + pub mod actions; } -mod models; +pub mod models; -mod tests { +pub mod tests { mod test_world; } diff --git a/src/models.cairo b/src/models.cairo index 06b0ebb..42180d9 100644 --- a/src/models.cairo +++ b/src/models.cairo @@ -39,7 +39,7 @@ pub enum Direction { #[derive(Copy, Drop, Serde, IntrospectPacked, Debug)] pub struct Vec2 { pub x: u32, - pub y: u32 + pub y: u32, } @@ -79,7 +79,7 @@ impl Vec2Impl of Vec2Trait { #[cfg(test)] mod tests { - use super::{Position, Vec2, Vec2Trait}; + use super::{Vec2, Vec2Trait}; #[test] fn test_vec_is_zero() { diff --git a/src/systems/actions.cairo b/src/systems/actions.cairo index 859fb43..cc24870 100644 --- a/src/systems/actions.cairo +++ b/src/systems/actions.cairo @@ -2,7 +2,7 @@ use dojo_starter::models::{Direction, Position}; // define the interface #[starknet::interface] -trait IActions { +pub trait IActions { fn spawn(ref self: T); fn move(ref self: T, direction: Direction); } @@ -12,9 +12,9 @@ trait IActions { pub mod actions { use super::{IActions, Direction, Position, next_position}; use starknet::{ContractAddress, get_caller_address}; - use dojo_starter::models::{Vec2, Moves, DirectionsAvailable}; + use dojo_starter::models::{Vec2, Moves}; - use dojo::model::{ModelStorage, ModelValueStorage}; + use dojo::model::{ModelStorage}; use dojo::event::EventStorage; #[derive(Copy, Drop, Serde)] @@ -40,7 +40,7 @@ pub mod actions { // 1. Move the player's position 10 units in both the x and y direction. let new_position = Position { - player, vec: Vec2 { x: position.vec.x + 10, y: position.vec.y + 10 } + player, vec: Vec2 { x: position.vec.x + 10, y: position.vec.y + 10 }, }; // Write the new position to the world. @@ -48,7 +48,7 @@ pub mod actions { // 2. Set the player's remaining moves to 100. let moves = Moves { - player, remaining: 100, last_direction: Option::None, can_move: true + player, remaining: 100, last_direction: Option::None, can_move: true, }; // Write the new moves to the world. @@ -66,8 +66,10 @@ pub mod actions { // Retrieve the player's current position and moves data from the world. let position: Position = world.read_model(player); let mut moves: Moves = world.read_model(player); - // if player hasn't spawn, read returns model default values. This leads to sub overflow afterwards. - // Plus it's generally considered as a good pratice to fast-return on matching conditions. + // if player hasn't spawn, read returns model default values. This leads to sub overflow + // afterwards. + // Plus it's generally considered as a good pratice to fast-return on matching + // conditions. if !moves.can_move { return; } @@ -111,7 +113,7 @@ fn next_position(mut position: Position, direction: Option) -> Positi Direction::Right => { position.vec.x += 1; }, Direction::Up => { position.vec.y -= 1; }, Direction::Down => { position.vec.y += 1; }, - } + }, }; position } diff --git a/src/tests/test_world.cairo b/src/tests/test_world.cairo index 0282fa7..61a8a2c 100644 --- a/src/tests/test_world.cairo +++ b/src/tests/test_world.cairo @@ -1,21 +1,25 @@ #[cfg(test)] mod tests { use dojo_cairo_test::WorldStorageTestTrait; -use dojo::model::{ModelStorage, ModelValueStorage, ModelStorageTest}; + use dojo::model::{ModelStorage, ModelStorageTest}; use dojo::world::WorldStorageTrait; - use dojo_cairo_test::{spawn_test_world, NamespaceDef, TestResource, ContractDefTrait, ContractDef}; + use dojo_cairo_test::{ + spawn_test_world, NamespaceDef, TestResource, ContractDefTrait, ContractDef, + }; use dojo_starter::systems::actions::{actions, IActionsDispatcher, IActionsDispatcherTrait}; use dojo_starter::models::{Position, m_Position, Moves, m_Moves, Direction}; fn namespace_def() -> NamespaceDef { let ndef = NamespaceDef { - namespace: "dojo_starter", resources: [ + namespace: "dojo_starter", + resources: [ TestResource::Model(m_Position::TEST_CLASS_HASH), TestResource::Model(m_Moves::TEST_CLASS_HASH), TestResource::Event(actions::e_Moved::TEST_CLASS_HASH), - TestResource::Contract(actions::TEST_CLASS_HASH) - ].span() + TestResource::Contract(actions::TEST_CLASS_HASH), + ] + .span(), }; ndef @@ -25,7 +29,8 @@ use dojo::model::{ModelStorage, ModelValueStorage, ModelStorageTest}; [ ContractDefTrait::new(@"dojo_starter", @"actions") .with_writer_of([dojo::utils::bytearray_hash(@"dojo_starter")].span()) - ].span() + ] + .span() } #[test] @@ -76,7 +81,7 @@ use dojo::model::{ModelStorage, ModelValueStorage, ModelStorageTest}; let initial_position: Position = world.read_model(caller); assert( - initial_position.vec.x == 10 && initial_position.vec.y == 10, 'wrong initial position' + initial_position.vec.x == 10 && initial_position.vec.y == 10, 'wrong initial position', ); actions_system.move(Direction::Right(()).into());