From ad8bcbe033543a07945582588b653e421986a9fb Mon Sep 17 00:00:00 2001 From: Willem Olding Date: Sun, 19 Nov 2023 12:01:29 +0300 Subject: [PATCH] add test for summoning on new game and fix bug where HOTCOLD and FAMILIARS_HELD IDs collide --- contracts/src/cards/actions.cairo | 2 +- contracts/src/constants.cairo | 4 ++-- contracts/src/systems.cairo | 31 +++++++++++++++++++++++++++++++ contracts/src/utils/testing.cairo | 4 +++- 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/contracts/src/cards/actions.cairo b/contracts/src/cards/actions.cairo index dfe86b2..ac823a0 100644 --- a/contracts/src/cards/actions.cairo +++ b/contracts/src/cards/actions.cairo @@ -136,7 +136,7 @@ fn decrease_stat(world: IWorldDispatcher, game_id: u128, stat_id: u128, delta: u ); } -// increase the value of the stat given by stat_id by delta +// Return if a given stat meets or exceeds the threhshold fn stat_meets_threshold( world: IWorldDispatcher, game_id: u128, stat_id: u128, threshold: Option<(u32, bool)> ) -> bool { diff --git a/contracts/src/constants.cairo b/contracts/src/constants.cairo index f5f4c63..0783bb7 100644 --- a/contracts/src/constants.cairo +++ b/contracts/src/constants.cairo @@ -25,8 +25,8 @@ const TICKS: u128 = 10005; const POLAR_STAT_MIDPOINT: u32 = 2_147_483_647; // polar stats -const HOTCOLD_STAT: u128 = 10004; -const LIGHTDARK_STAT: u128 = 10005; +const HOTCOLD_STAT: u128 = 20004; +const LIGHTDARK_STAT: u128 = 20005; // familiars const RAVENS: u128 = 30001; diff --git a/contracts/src/systems.cairo b/contracts/src/systems.cairo index 4ee4e81..6718433 100644 --- a/contracts/src/systems.cairo +++ b/contracts/src/systems.cairo @@ -225,3 +225,34 @@ mod interact_tests { system.interact(game_id, CARD_ID); } } + +#[cfg(test)] +mod summon_tests { + use traits::{Into, TryInto}; + use result::ResultTrait; + use array::ArrayTrait; + use option::OptionTrait; + use serde::Serde; + + use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; + use dojo::test_utils::deploy_contract; + + use spellcrafter::utils::testing::{deploy_game, SpellcraftDeployment}; + use spellcrafter::components::{Owner, ValueInGame}; + use spellcrafter::types::FamiliarType; + use spellcrafter::constants::{FAMILIARS_HELD}; + + use super::{spellcrafter_system, ISpellCrafterDispatcher, ISpellCrafterDispatcherTrait}; + + #[test] + #[available_gas(300000000000)] + fn can_summon_on_new_game() { + let SpellcraftDeployment{world, system } = deploy_game(); + let game_id = system.new_game(); + let familiar_entity_id = system.summon(game_id, FamiliarType::Cat); + + // post conditions + let familiars = get!(world, (FAMILIARS_HELD, game_id), ValueInGame).value; + assert(familiars == 1, 'familiars_held not incremented'); + } +} diff --git a/contracts/src/utils/testing.cairo b/contracts/src/utils/testing.cairo index 0701370..c2aa804 100644 --- a/contracts/src/utils/testing.cairo +++ b/contracts/src/utils/testing.cairo @@ -6,7 +6,8 @@ use dojo::test_utils::spawn_test_world; use spellcrafter::components::{ owner::owner, value_in_game::value_in_game, - occupied::occupied + occupied::occupied, + familiar::familiar, }; use spellcrafter::systems::{spellcrafter_system, ISpellCrafterDispatcher}; @@ -22,6 +23,7 @@ fn deploy_game() -> SpellcraftDeployment { owner::TEST_CLASS_HASH, value_in_game::TEST_CLASS_HASH, occupied::TEST_CLASS_HASH, + familiar::TEST_CLASS_HASH, ]; let world = spawn_test_world(models);