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

Fix cleanup method and test case formatting #12

Merged
merged 2 commits into from
Dec 20, 2023
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
3 changes: 2 additions & 1 deletion contracts/src/actions.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,14 @@ mod actions {

// reset player count
let mut game_data = get!(world, GAME_DATA_KEY, (GameData));
let total_players = game_data.number_of_players;
game_data.number_of_players = 0;
set!(world, (game_data));

// Kill off all players
let mut i = 1;
loop {
if i > 20 {
if i > total_players {
break;
}
player_dead(world, i);
Expand Down
7 changes: 3 additions & 4 deletions contracts/src/testing.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ mod tests {
let player_id = get!(world, caller, (PlayerID)).id;
assert(1 == player_id, 'incorrect id');

// Get player from id
let (position, rps_type, energy) = get!(world, player_id, (Position, RPSType, Energy));
assert(0 < position.x, 'incorrect position.x');
assert(0 < position.y, 'incorrect position.y');
Expand Down Expand Up @@ -108,13 +107,13 @@ mod tests {
let (caller, world, actions_) = spawn_world();

actions_.spawn('r');
// Get player ID
// Get player position
let pos_p1 = get!(world, get!(world, caller, (PlayerID)).id, (Position));

let caller = starknet::contract_address_const::<'jim'>();
starknet::testing::set_contract_address(caller);
actions_.spawn('r');
// Get player ID
// Get player position
let pos_p2 = get!(world, get!(world, caller, (PlayerID)).id, (Position));

assert(pos_p1.x != pos_p2.x, 'spawn pos.x same');
Expand All @@ -135,7 +134,7 @@ mod tests {
let (x_, y_) = actions::spawn_coords(world, caller.into(), id);

assert(x != x_, 'spawn pos.x same');
assert(y != y_, 'spawn pos.x same');
assert(y != y_, 'spawn pos.y same');
}

#[test]
Expand Down
Loading