Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tests for create_bot_player() Function with Successful and Existing Player Scenarios #190

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion onchain/src/systems/game_actions.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ pub mod GameActions {
player_address = contract_address_const::<'blue_bot'>();
},
PlayerColor::Red => {
username = 'red_bot ';
username = 'red_bot';
player_address = contract_address_const::<'red_bot'>();
}
};
Expand Down
61 changes: 60 additions & 1 deletion onchain/src/tests/test_game.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod tests {
};

// Models import
use starkludo::models::game::{Game, m_Game, GameCounter, m_GameCounter};
use starkludo::models::game::{Game, m_Game, GameCounter, m_GameCounter, PlayerColor};
use starkludo::models::player::{
Player, m_Player, AddressToUsername, UsernameToAddress, m_AddressToUsername,
m_UsernameToAddress
Expand Down Expand Up @@ -185,6 +185,65 @@ mod tests {
assert_eq!(address_to_username.username, username);
}

#[test]
fn test_create_bot_player_is_successful() {
let (_, game_action_system) = setup_world();

let blue_color = PlayerColor::Blue;
let green_color = PlayerColor::Green;
let red_color = PlayerColor::Red;
let yellow_color = PlayerColor::Yellow;

let created_blue_bot_player: Player = game_action_system.create_bot_player(blue_color);
let expected_blue_username = 'blue_bot';
let expected_blue_address = starknet::contract_address_const::<'blue_bot'>();
assert_eq!(created_blue_bot_player.username, expected_blue_username);
assert_eq!(created_blue_bot_player.owner, expected_blue_address);
assert_eq!(created_blue_bot_player.is_bot, true);

let created_green_bot_player: Player = game_action_system.create_bot_player(green_color);
let expected_green_username = 'green_bot';
let expected_green_address = starknet::contract_address_const::<'green_bot'>();
assert_eq!(created_green_bot_player.username, expected_green_username);
assert_eq!(created_green_bot_player.owner, expected_green_address);
assert_eq!(created_green_bot_player.is_bot, true);

let created_red_bot_player: Player = game_action_system.create_bot_player(red_color);
let expected_red_username = 'red_bot';
let expected_red_address = starknet::contract_address_const::<'red_bot'>();
assert_eq!(created_red_bot_player.username, expected_red_username);
assert_eq!(created_red_bot_player.owner, expected_red_address);
assert_eq!(created_red_bot_player.is_bot, true);

let created_yellow_bot_player: Player = game_action_system.create_bot_player(yellow_color);
let expected_yellow_username = 'yellow_bot';
let expected_yellow_address = starknet::contract_address_const::<'yellow_bot'>();
assert_eq!(created_yellow_bot_player.username, expected_yellow_username);
assert_eq!(created_yellow_bot_player.owner, expected_yellow_address);
assert_eq!(created_yellow_bot_player.is_bot, true);
}

#[test]
fn test_create_existing_bot_player() {
let (_, game_action_system) = setup_world();

let blue_color = PlayerColor::Blue;
let created_blue_bot_player: Player = game_action_system.create_bot_player(blue_color);

let expected_blue_username = 'blue_bot';
let expected_blue_address = starknet::contract_address_const::<'blue_bot'>();
assert_eq!(created_blue_bot_player.username, expected_blue_username);
assert_eq!(created_blue_bot_player.owner, expected_blue_address);
assert_eq!(created_blue_bot_player.is_bot, true);

let existing_blue_bot_player: Player = game_action_system.create_bot_player(blue_color);

assert_eq!(existing_blue_bot_player.username, expected_blue_username);
assert_eq!(existing_blue_bot_player.owner, expected_blue_address);
assert_eq!(existing_blue_bot_player.is_bot, true);
assert_eq!(created_blue_bot_player.owner, existing_blue_bot_player.owner);
}

#[test]
fn test_get_username_from_address() {
let ndef = namespace_def();
Expand Down
Loading