Skip to content

Commit

Permalink
add test for summoning on new game and fix bug where HOTCOLD and FAMI…
Browse files Browse the repository at this point in the history
…LIARS_HELD IDs collide
  • Loading branch information
willemolding committed Nov 19, 2023
1 parent ce254fb commit ad8bcbe
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion contracts/src/cards/actions.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/constants.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
31 changes: 31 additions & 0 deletions contracts/src/systems.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
4 changes: 3 additions & 1 deletion contracts/src/utils/testing.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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);
Expand Down

0 comments on commit ad8bcbe

Please sign in to comment.