Skip to content

Commit

Permalink
fix: add latest edition and bump to 1.1.1 (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm authored Jan 29, 2025
1 parent 9c36faf commit 001093e
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 35 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 6 additions & 4 deletions Scarb.toml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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" }
8 changes: 4 additions & 4 deletions src/lib.cairo
Original file line number Diff line number Diff line change
@@ -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;
}
4 changes: 2 additions & 2 deletions src/models.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}


Expand Down Expand Up @@ -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() {
Expand Down
18 changes: 10 additions & 8 deletions src/systems/actions.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use dojo_starter::models::{Direction, Position};

// define the interface
#[starknet::interface]
trait IActions<T> {
pub trait IActions<T> {
fn spawn(ref self: T);
fn move(ref self: T, direction: Direction);
}
Expand All @@ -12,9 +12,9 @@ trait IActions<T> {
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)]
Expand All @@ -40,15 +40,15 @@ 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.
world.write_model(@new_position);

// 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.
Expand All @@ -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;
}
Expand Down Expand Up @@ -111,7 +113,7 @@ fn next_position(mut position: Position, direction: Option<Direction>) -> Positi
Direction::Right => { position.vec.x += 1; },
Direction::Up => { position.vec.y -= 1; },
Direction::Down => { position.vec.y += 1; },
}
},
};
position
}
19 changes: 12 additions & 7 deletions src/tests/test_world.cairo
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 001093e

Please sign in to comment.