Skip to content

Commit

Permalink
fix: failing build and test
Browse files Browse the repository at this point in the history
  • Loading branch information
0xibs committed Jan 31, 2025
1 parent 4b65185 commit 4868ffb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 31 deletions.
2 changes: 2 additions & 0 deletions onchain/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ origami_random = { git = "https://github.com/dojoengine/origami" }
build-external-contracts = ["dojo::world::world_contract::world"]

[dev-dependencies]
assert_macros = "=2.9.2"
cairo_test = "=2.9.2"
dojo_cairo_test = { git = "https://github.com/dojoengine/dojo", tag = "v1.1.2" }
67 changes: 36 additions & 31 deletions onchain/src/tests/test_game.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,9 @@ mod tests {
#[test]
fn test_pos_to_board() {
let positions = array![0, 13, 26, 52, 39, 27, 52, 53, 54, 8, 28, 38, 55];
let expected_board_positions = array![0, 13, 26, 1001, 52, 40, 2001, 2002, 3003, 34, 2, 12, 4004];
let expected_board_positions = array![
0, 13, 26, 1001, 52, 40, 2001, 2002, 3003, 34, 2, 12, 4004,
];
let board_positions = pos_to_board(positions);
assert(board_positions == expected_board_positions, 'Pos to board failed');
}
Expand Down Expand Up @@ -468,8 +470,8 @@ mod tests {

#[test]
fn test_move_initial_position_with_six() {

// This test case verifies that a piece can move from its initial position when the dice roll is 6.
// This test case verifies that a piece can move from its initial position when the dice
// roll is 6.

let (mut world, game_action_system) = setup_world();

Expand All @@ -480,7 +482,8 @@ mod tests {
game_action_system.create_new_player(username, false);

// Setup initial game state
let game_id = game_action_system.create_new_game(GameMode::MultiPlayer, PlayerColor::Red, 2);
let game_id = game_action_system
.create_new_game(GameMode::MultiPlayer, PlayerColor::Red, 2);
game_action_system.start_game(game_id);

let mut game: Game = world.read_model(game_id);
Expand All @@ -503,8 +506,8 @@ mod tests {

#[test]
fn test_move_initial_position_without_six() {

// This test case verifies that a piece cannot move from its initial position if the dice roll is not 6.
// This test case verifies that a piece cannot move from its initial position if the dice
// roll is not 6.

let (mut world, game_action_system) = setup_world();

Expand All @@ -515,7 +518,8 @@ mod tests {
game_action_system.create_new_player(username, false);

// Setup initial game state
let game_id = game_action_system.create_new_game(GameMode::MultiPlayer, PlayerColor::Red, 2);
let game_id = game_action_system
.create_new_game(GameMode::MultiPlayer, PlayerColor::Red, 2);
game_action_system.start_game(game_id);

let mut game: Game = world.read_model(game_id);
Expand All @@ -537,8 +541,8 @@ mod tests {

#[test]
fn test_move_normal_position() {

// This test case verifies that a piece can move from a normal position based on the dice roll.
// This test case verifies that a piece can move from a normal position based on the dice
// roll.

let (mut world, game_action_system) = setup_world();
let caller = contract_address_const::<'test_alice'>();
Expand All @@ -548,20 +552,21 @@ mod tests {
game_action_system.create_new_player(username, false);

// Setup initial game state
let game_id = game_action_system.create_new_game(GameMode::MultiPlayer, PlayerColor::Red, 2);
let game_id = game_action_system
.create_new_game(GameMode::MultiPlayer, PlayerColor::Red, 2);
game_action_system.start_game(game_id);

let mut game: Game = world.read_model(game_id);
game.dice_face = 6;
testing::set_contract_address(game_action_system.contract_address);
world.write_model(@game);
game_action_system.move('r1', 0); // move from its initial position to 1.
game_action_system.move('r1', 0); // move from its initial position to 1.

let mut game: Game = world.read_model(game_id);
game.dice_face = 5;
testing::set_contract_address(game_action_system.contract_address);
world.write_model(@game);
game_action_system.move('r1', 0); // move from 1 to 6.
game_action_system.move('r1', 0); // move from 1 to 6.

// Verify the new position
let game: Game = world.read_model(game_id);
Expand All @@ -574,7 +579,6 @@ mod tests {

#[test]
fn test_move_to_safe_position() {

// This test case verifies that a piece can move to a safe position on the board.

let (mut world, game_action_system) = setup_world();
Expand All @@ -585,26 +589,27 @@ mod tests {
game_action_system.create_new_player(username, false);

// Setup initial game state
let game_id = game_action_system.create_new_game(GameMode::MultiPlayer, PlayerColor::Green, 2);
let game_id = game_action_system
.create_new_game(GameMode::MultiPlayer, PlayerColor::Green, 2);
game_action_system.start_game(game_id);

let mut game: Game = world.read_model(game_id);
game.dice_face = 6;
testing::set_contract_address(game_action_system.contract_address);
world.write_model(@game);
game_action_system.move('g1', 1); // move from its initial position to 14.
game_action_system.move('g1', 1); // move from its initial position to 14.

let mut game: Game = world.read_model(game_id);
game.dice_face = 5;
testing::set_contract_address(game_action_system.contract_address);
world.write_model(@game);
game_action_system.move('g1', 1); // move from 14 to 19.
game_action_system.move('g1', 1); // move from 14 to 19.

let mut game: Game = world.read_model(game_id);
game.dice_face = 3;
testing::set_contract_address(game_action_system.contract_address);
world.write_model(@game);
game_action_system.move('g1', 1); // move from 19 to 22.
game_action_system.move('g1', 1); // move from 19 to 22.

// Verify the new position
let game: Game = world.read_model(game_id);
Expand All @@ -616,7 +621,6 @@ mod tests {

#[test]
fn test_move_to_occupied_position() {

// This test case verifies that a piece can move to an occupied position on the board.

let (mut world, game_action_system) = setup_world();
Expand All @@ -627,32 +631,33 @@ mod tests {
game_action_system.create_new_player(username, false);

// Setup initial game state
let game_id = game_action_system.create_new_game(GameMode::MultiPlayer, PlayerColor::Green, 2);
let game_id = game_action_system
.create_new_game(GameMode::MultiPlayer, PlayerColor::Green, 2);
game_action_system.start_game(game_id);

let mut game: Game = world.read_model(game_id);
game.dice_face = 6;
testing::set_contract_address(game_action_system.contract_address);
world.write_model(@game);
game_action_system.move('g1', 1); // move g1 from its initial position to 14.
game_action_system.move('g1', 1); // move g1 from its initial position to 14.

let mut game: Game = world.read_model(game_id);
game.dice_face = 6;
testing::set_contract_address(game_action_system.contract_address);
world.write_model(@game);
game_action_system.move('g2', 1); // move g2 from its initial position to 14.
game_action_system.move('g2', 1); // move g2 from its initial position to 14.

let mut game: Game = world.read_model(game_id);
game.dice_face = 5;
testing::set_contract_address(game_action_system.contract_address);
world.write_model(@game);
game_action_system.move('g1', 1); // move from 14 to 19.
game_action_system.move('g1', 1); // move from 14 to 19.

let mut game: Game = world.read_model(game_id);
game.dice_face = 5;
testing::set_contract_address(game_action_system.contract_address);
world.write_model(@game);
game_action_system.move('g2', 1); // move from 14 to 19.
game_action_system.move('g2', 1); // move from 14 to 19.

// Verify the new position
let game: Game = world.read_model(game_id);
Expand All @@ -664,7 +669,6 @@ mod tests {

#[test]
fn test_capture_opponent_piece() {

// This test case verifies the capturing mechanism in the game

let (mut world, game_action_system) = setup_world();
Expand All @@ -676,7 +680,8 @@ mod tests {
game_action_system.create_new_player(username_red, false);

// Setup initial game state
let game_id = game_action_system.create_new_game(GameMode::MultiPlayer, PlayerColor::Red, 2);
let game_id = game_action_system
.create_new_game(GameMode::MultiPlayer, PlayerColor::Red, 2);
game_action_system.start_game(game_id);

let mut game: Game = world.read_model(game_id);
Expand Down Expand Up @@ -712,8 +717,7 @@ mod tests {

#[test]
fn test_capture_opponent_piece_in_safe_zone() {

// This test case verifies that a player cannot capture an opponent's piece in the safe zone
// This test case verifies that a player cannot capture an opponent's piece in the safe zone

let (mut world, game_action_system) = setup_world();

Expand All @@ -724,7 +728,8 @@ mod tests {
game_action_system.create_new_player(username_red, false);

// Setup initial game state
let game_id = game_action_system.create_new_game(GameMode::MultiPlayer, PlayerColor::Red, 2);
let game_id = game_action_system
.create_new_game(GameMode::MultiPlayer, PlayerColor::Red, 2);
game_action_system.start_game(game_id);

let mut game: Game = world.read_model(game_id);
Expand Down Expand Up @@ -759,7 +764,6 @@ mod tests {

#[test]
fn test_red_player_wins() {

// This test case verifies the winning condition in the game.

let (mut world, game_action_system) = setup_world();
Expand All @@ -771,7 +775,8 @@ mod tests {
game_action_system.create_new_player(username_red, false);

// Setup initial game state
let game_id = game_action_system.create_new_game(GameMode::MultiPlayer, PlayerColor::Red, 2);
let game_id = game_action_system
.create_new_game(GameMode::MultiPlayer, PlayerColor::Red, 2);
game_action_system.start_game(game_id);

// Move red piece to position 56 (one step away from winning)
Expand All @@ -792,4 +797,4 @@ mod tests {
let game_condition = array![1006, 1006, 1006, 1006, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
assert(game.game_condition == game_condition, 'Game Condition should match');
}
}
}

0 comments on commit 4868ffb

Please sign in to comment.