-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53e690c
commit 69e2503
Showing
1 changed file
with
57 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,57 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use starknet::class_hash::Felt252TryIntoClassHash; | ||
// import world dispatcher | ||
use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; | ||
// import test utils | ||
use dojo::test_utils::{spawn_test_world, deploy_contract}; | ||
// import test utils | ||
use dojo_starter::{ | ||
systems::{actions::{actions, IActionsDispatcher, IActionsDispatcherTrait}}, | ||
models::{position::{Position, Vec2, position}, moves::{Moves, Direction, moves}} | ||
}; | ||
|
||
#[test] | ||
fn test_move() { | ||
// caller | ||
let caller = starknet::contract_address_const::<0x0>(); | ||
|
||
// models | ||
let mut models = array![position::TEST_CLASS_HASH, moves::TEST_CLASS_HASH]; | ||
|
||
// deploy world with models | ||
let world = spawn_test_world(models); | ||
|
||
// deploy systems contract | ||
let contract_address = world | ||
.deploy_contract('salt', actions::TEST_CLASS_HASH.try_into().unwrap(), array![].span()); | ||
let actions_system = IActionsDispatcher { contract_address }; | ||
|
||
// call spawn() | ||
actions_system.spawn(); | ||
|
||
// call move with direction right | ||
actions_system.move(Direction::Right); | ||
|
||
// Check world state | ||
let moves = get!(world, caller, Moves); | ||
|
||
// casting right direction | ||
let right_dir_felt: felt252 = Direction::Right.into(); | ||
|
||
// check moves | ||
assert(moves.remaining == 99, 'moves is wrong'); | ||
|
||
// check last direction | ||
assert(moves.last_direction.into() == right_dir_felt, 'last direction is wrong'); | ||
|
||
// get new_position | ||
let new_position = get!(world, caller, Position); | ||
|
||
// check new position x | ||
assert(new_position.vec.x == 11, 'position x is wrong'); | ||
|
||
// check new position y | ||
assert(new_position.vec.y == 10, 'position y is wrong'); | ||
} | ||
} | ||
// #[cfg(test)] | ||
// mod tests { | ||
// use starknet::class_hash::Felt252TryIntoClassHash; | ||
// // import world dispatcher | ||
// use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; | ||
// // import test utils | ||
// use dojo::test_utils::{spawn_test_world, deploy_contract}; | ||
// // import test utils | ||
// use dojo_starter::{ | ||
// systems::{actions::{actions, IActionsDispatcher, IActionsDispatcherTrait}}, | ||
// models::{position::{Position, Vec2, position}, moves::{Moves, Direction, moves}} | ||
// }; | ||
|
||
// #[test] | ||
// fn test_move() { | ||
// // caller | ||
// let caller = starknet::contract_address_const::<0x0>(); | ||
|
||
// // models | ||
// let mut models = array![position::TEST_CLASS_HASH, moves::TEST_CLASS_HASH]; | ||
|
||
// // deploy world with models | ||
// let world = spawn_test_world(models); | ||
|
||
// // deploy systems contract | ||
// let contract_address = world | ||
// .deploy_contract('salt', actions::TEST_CLASS_HASH.try_into().unwrap(), array![].span()); | ||
// let actions_system = IActionsDispatcher { contract_address }; | ||
|
||
// // call spawn() | ||
// actions_system.spawn(); | ||
|
||
// // call move with direction right | ||
// actions_system.move(Direction::Right); | ||
|
||
// // Check world state | ||
// let moves = get!(world, caller, Moves); | ||
|
||
// // casting right direction | ||
// let right_dir_felt: felt252 = Direction::Right.into(); | ||
|
||
// // check moves | ||
// assert(moves.remaining == 99, 'moves is wrong'); | ||
|
||
// // check last direction | ||
// assert(moves.last_direction.into() == right_dir_felt, 'last direction is wrong'); | ||
|
||
// // get new_position | ||
// let new_position = get!(world, caller, Position); | ||
|
||
// // check new position x | ||
// assert(new_position.vec.x == 11, 'position x is wrong'); | ||
|
||
// // check new position y | ||
// assert(new_position.vec.y == 10, 'position y is wrong'); | ||
// } | ||
// } |