From f65adf779171ffd8a5f0c2d0c9bc92a3b8dff5d6 Mon Sep 17 00:00:00 2001 From: Jagadeeshftw Date: Fri, 10 Jan 2025 17:14:21 +0530 Subject: [PATCH 1/2] Updated game_actions.cairo --- onchain/src/systems/game_actions.cairo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onchain/src/systems/game_actions.cairo b/onchain/src/systems/game_actions.cairo index dd8be9e..a271764 100644 --- a/onchain/src/systems/game_actions.cairo +++ b/onchain/src/systems/game_actions.cairo @@ -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'>(); } }; From 29938bf621d2ca11f6b6c58f14cf848036101938 Mon Sep 17 00:00:00 2001 From: Jagadeeshftw Date: Fri, 10 Jan 2025 17:14:34 +0530 Subject: [PATCH 2/2] Updated test_game.cairo --- onchain/src/tests/test_game.cairo | 61 ++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/onchain/src/tests/test_game.cairo b/onchain/src/tests/test_game.cairo index 6be1721..3877a35 100644 --- a/onchain/src/tests/test_game.cairo +++ b/onchain/src/tests/test_game.cairo @@ -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 @@ -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();