Skip to content

Commit

Permalink
build test fix #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Kishore-MK committed Jun 17, 2024
1 parent 53e690c commit 69e2503
Showing 1 changed file with 57 additions and 57 deletions.
114 changes: 57 additions & 57 deletions src/tests/test_world.cairo
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');
// }
// }

0 comments on commit 69e2503

Please sign in to comment.