Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f9c909d

Browse files
committedMar 6, 2024
✨ Ability to kick an inactive player, banish play action
1 parent 73f5f45 commit f9c909d

10 files changed

+132
-58
lines changed
 

‎src/models/game.cairo

+38-23
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ struct Game {
2424
player_count: u8,
2525
nonce: u32,
2626
price: u256,
27+
clock: u64,
28+
penality: u64,
2729
}
2830

2931
#[derive(Drop, PartialEq)]
@@ -55,12 +57,14 @@ mod errors {
5557
#[generate_trait]
5658
impl GameImpl of GameTrait {
5759
#[inline(always)]
58-
fn new(id: u32, host: felt252, price: u256) -> Game {
60+
fn new(id: u32, host: felt252, price: u256, penality: u64) -> Game {
5961
// [Check] Host is valid
6062
assert(host != 0, errors::GAME_INVALID_HOST);
6163

6264
// [Return] Default game
63-
Game { id, host, over: false, seed: 0, player_count: 0, nonce: 0, price }
65+
Game {
66+
id, host, over: false, seed: 0, player_count: 0, nonce: 0, price, clock: 0, penality
67+
}
6468
}
6569

6670
#[inline(always)]
@@ -296,7 +300,17 @@ impl GameAssert of AssertTrait {
296300
impl ZeroableGame of Zeroable<Game> {
297301
#[inline(always)]
298302
fn zero() -> Game {
299-
Game { id: 0, host: 0, over: false, seed: 0, player_count: 0, nonce: 0, price: 0, }
303+
Game {
304+
id: 0,
305+
host: 0,
306+
over: false,
307+
seed: 0,
308+
player_count: 0,
309+
nonce: 0,
310+
price: 0,
311+
clock: 0,
312+
penality: 0
313+
}
300314
}
301315

302316
#[inline(always)]
@@ -324,6 +338,7 @@ mod tests {
324338

325339
const ID: u32 = 0;
326340
const PRICE: u256 = 1_000_000_000_000_000_000;
341+
const PENALITY: u64 = 60;
327342
const SEED: felt252 = 'SEED';
328343
const PLAYER_COUNT: u8 = 4;
329344
const HOST: felt252 = 'HOST';
@@ -332,7 +347,7 @@ mod tests {
332347
#[test]
333348
#[available_gas(100_000)]
334349
fn test_game_new() {
335-
let game = GameTrait::new(ID, HOST, PRICE);
350+
let game = GameTrait::new(ID, HOST, PRICE, PENALITY);
336351
assert(game.host == HOST, 'Game: wrong account');
337352
assert(game.id == ID, 'Game: wrong id');
338353
assert(game.over == false, 'Game: wrong over');
@@ -344,7 +359,7 @@ mod tests {
344359
#[test]
345360
#[available_gas(100_000)]
346361
fn test_game_join() {
347-
let mut game = GameTrait::new(ID, HOST, PRICE);
362+
let mut game = GameTrait::new(ID, HOST, PRICE, PENALITY);
348363
game.join();
349364
let index = game.join();
350365
assert(game.player_count == 2, 'Game: wrong count');
@@ -363,7 +378,7 @@ mod tests {
363378
#[available_gas(100_000)]
364379
#[should_panic(expected: ('Game: is over',))]
365380
fn test_game_join_revert_is_over() {
366-
let mut game = GameTrait::new(ID, HOST, PRICE);
381+
let mut game = GameTrait::new(ID, HOST, PRICE, PENALITY);
367382
game.over = true;
368383
game.join();
369384
}
@@ -372,7 +387,7 @@ mod tests {
372387
#[available_gas(100_000)]
373388
#[should_panic(expected: ('Game: has started',))]
374389
fn test_game_join_revert_has_started() {
375-
let mut game = GameTrait::new(ID, HOST, PRICE);
390+
let mut game = GameTrait::new(ID, HOST, PRICE, PENALITY);
376391
game.seed = 1;
377392
game.join();
378393
}
@@ -381,7 +396,7 @@ mod tests {
381396
#[available_gas(150_000)]
382397
#[should_panic(expected: ('Game: is full',))]
383398
fn test_game_join_revert_no_remaining_slots() {
384-
let mut game = GameTrait::new(ID, HOST, PRICE);
399+
let mut game = GameTrait::new(ID, HOST, PRICE, PENALITY);
385400
let mut index = MAXIMUM_PLAYER_COUNT + 1;
386401
loop {
387402
if index == 0 {
@@ -395,7 +410,7 @@ mod tests {
395410
#[test]
396411
#[available_gas(100_000)]
397412
fn test_game_leave() {
398-
let mut game = GameTrait::new(ID, HOST, PRICE);
413+
let mut game = GameTrait::new(ID, HOST, PRICE, PENALITY);
399414
game.join();
400415
let index = game.leave(PLAYER);
401416
assert(game.player_count == 0, 'Game: wrong count');
@@ -406,7 +421,7 @@ mod tests {
406421
#[available_gas(100_000)]
407422
#[should_panic(expected: ('Game: user is the host',))]
408423
fn test_game_leave_host_revert_host() {
409-
let mut game = GameTrait::new(ID, HOST, PRICE);
424+
let mut game = GameTrait::new(ID, HOST, PRICE, PENALITY);
410425
game.join();
411426
game.leave(HOST);
412427
assert(game.over, 'Game: wrong status');
@@ -416,7 +431,7 @@ mod tests {
416431
#[available_gas(100_000)]
417432
#[should_panic(expected: ('Game: is empty',))]
418433
fn test_game_leave_revert_does_not_exist() {
419-
let mut game = GameTrait::new(ID, HOST, PRICE);
434+
let mut game = GameTrait::new(ID, HOST, PRICE, PENALITY);
420435
game.join();
421436
game.player_count = 0;
422437
game.leave(PLAYER);
@@ -426,7 +441,7 @@ mod tests {
426441
#[available_gas(100_000)]
427442
#[should_panic(expected: ('Game: is over',))]
428443
fn test_game_leave_revert_over() {
429-
let mut game = GameTrait::new(ID, HOST, PRICE);
444+
let mut game = GameTrait::new(ID, HOST, PRICE, PENALITY);
430445
game.join();
431446
game.over = true;
432447
game.leave(PLAYER);
@@ -436,7 +451,7 @@ mod tests {
436451
#[available_gas(100_000)]
437452
#[should_panic(expected: ('Game: has started',))]
438453
fn test_game_leave_revert_has_started() {
439-
let mut game = GameTrait::new(ID, HOST, PRICE);
454+
let mut game = GameTrait::new(ID, HOST, PRICE, PENALITY);
440455
game.seed = 1;
441456
game.join();
442457
game.leave(PLAYER);
@@ -446,7 +461,7 @@ mod tests {
446461
#[available_gas(100_000)]
447462
#[should_panic(expected: ('Game: is empty',))]
448463
fn test_game_leave_revert_is_empty() {
449-
let mut game = GameTrait::new(ID, HOST, PRICE);
464+
let mut game = GameTrait::new(ID, HOST, PRICE, PENALITY);
450465
game.join();
451466
game.leave(PLAYER);
452467
game.leave(PLAYER);
@@ -455,7 +470,7 @@ mod tests {
455470
#[test]
456471
#[available_gas(200_000)]
457472
fn test_game_delete_host() {
458-
let mut game = GameTrait::new(ID, HOST, PRICE);
473+
let mut game = GameTrait::new(ID, HOST, PRICE, PENALITY);
459474
game.join();
460475
game.delete(HOST);
461476
assert(game.is_zero(), 'Game: not zero');
@@ -464,7 +479,7 @@ mod tests {
464479
#[test]
465480
#[available_gas(200_000)]
466481
fn test_game_start() {
467-
let mut game = GameTrait::new(ID, HOST, PRICE);
482+
let mut game = GameTrait::new(ID, HOST, PRICE, PENALITY);
468483
let mut index = PLAYER_COUNT;
469484
loop {
470485
if index == 0 {
@@ -482,7 +497,7 @@ mod tests {
482497
#[available_gas(200_000)]
483498
#[should_panic(expected: ('Game: too few players',))]
484499
fn test_game_start_revert_too_few_players() {
485-
let mut game = GameTrait::new(ID, HOST, PRICE);
500+
let mut game = GameTrait::new(ID, HOST, PRICE, PENALITY);
486501
game.player_count = 0;
487502
let players = array![HOST, PLAYER];
488503
game.start(players);
@@ -492,7 +507,7 @@ mod tests {
492507
#[available_gas(200_000)]
493508
#[should_panic(expected: ('Game: is over',))]
494509
fn test_game_start_revert_is_over() {
495-
let mut game = GameTrait::new(ID, HOST, PRICE);
510+
let mut game = GameTrait::new(ID, HOST, PRICE, PENALITY);
496511
game.over = true;
497512
let players = array![HOST, PLAYER];
498513
game.start(players);
@@ -502,7 +517,7 @@ mod tests {
502517
#[available_gas(200_000)]
503518
#[should_panic(expected: ('Game: has started',))]
504519
fn test_game_start_revert_has_started() {
505-
let mut game = GameTrait::new(ID, HOST, PRICE);
520+
let mut game = GameTrait::new(ID, HOST, PRICE, PENALITY);
506521
game.seed = 1;
507522
let players = array![HOST, PLAYER];
508523
game.start(players);
@@ -511,7 +526,7 @@ mod tests {
511526
#[test]
512527
#[available_gas(1_000_000)]
513528
fn test_game_get_player_index() {
514-
let mut game = GameTrait::new(ID, HOST, PRICE);
529+
let mut game = GameTrait::new(ID, HOST, PRICE, PENALITY);
515530
game.player_count = 6;
516531
assert(game.player() == 0, 'Game: wrong player index 0+0');
517532
game.nonce += 1;
@@ -534,7 +549,7 @@ mod tests {
534549
#[test]
535550
#[available_gas(100_000)]
536551
fn test_game_get_next_player_index() {
537-
let mut game = GameTrait::new(ID, HOST, PRICE);
552+
let mut game = GameTrait::new(ID, HOST, PRICE, PENALITY);
538553
game.player_count = 6;
539554
assert(game.player() == 0, 'Game: wrong player index 0+0');
540555
assert(game.next_player() == 1, 'Game: wrong next player 0+0');
@@ -546,7 +561,7 @@ mod tests {
546561
#[test]
547562
#[available_gas(100_000)]
548563
fn test_game_get_turn_index() {
549-
let mut game = GameTrait::new(ID, HOST, PRICE);
564+
let mut game = GameTrait::new(ID, HOST, PRICE, PENALITY);
550565
assert(game.turn().into() == 0_u32, 'Game: wrong turn index 0');
551566
game.nonce += 1;
552567
assert(game.turn().into() == 1_u32, 'Game: wrong turn index 1');
@@ -560,7 +575,7 @@ mod tests {
560575
#[test]
561576
#[available_gas(100_000)]
562577
fn test_game_pass() {
563-
let mut game = GameTrait::new(ID, HOST, PRICE);
578+
let mut game = GameTrait::new(ID, HOST, PRICE, PENALITY);
564579
game.player_count = 6;
565580
game.pass();
566581
assert(game.player() == 1, 'Game: wrong player');

‎src/models/player.cairo

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ impl PlayerImpl of PlayerTrait {
4949
self.conqueror = false;
5050
self.rank = 0;
5151
}
52+
53+
#[inline(always)]
54+
fn is_dead(ref self: Player) -> bool {
55+
self.rank > 0
56+
}
5257
}
5358

5459
#[generate_trait]

‎src/systems/host.cairo

+13-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ use dojo::world::IWorldDispatcher;
1111
#[starknet::interface]
1212
trait IHost<TContractState> {
1313
fn create(
14-
self: @TContractState, world: IWorldDispatcher, player_name: felt252, price: u256
14+
self: @TContractState,
15+
world: IWorldDispatcher,
16+
player_name: felt252,
17+
price: u256,
18+
penality: u64
1519
) -> u32;
1620
fn join(self: @TContractState, world: IWorldDispatcher, game_id: u32, player_name: felt252);
1721
fn leave(self: @TContractState, world: IWorldDispatcher, game_id: u32);
@@ -82,7 +86,11 @@ mod host {
8286
#[abi(embed_v0)]
8387
impl Host of IHost<ContractState> {
8488
fn create(
85-
self: @ContractState, world: IWorldDispatcher, player_name: felt252, price: u256
89+
self: @ContractState,
90+
world: IWorldDispatcher,
91+
player_name: felt252,
92+
price: u256,
93+
penality: u64
8694
) -> u32 {
8795
// [Setup] Datastore
8896
let mut store: Store = StoreTrait::new(world);
@@ -93,7 +101,9 @@ mod host {
93101

94102
// [Effect] Game
95103
let game_id = world.uuid();
96-
let mut game = GameTrait::new(id: game_id, host: caller.into(), price: price);
104+
let mut game = GameTrait::new(
105+
id: game_id, host: caller.into(), price: price, penality: penality
106+
);
97107
let player_index: u32 = game.join().into();
98108
store.set_game(game);
99109

‎src/systems/play.cairo

+46-8
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ trait IPlay<TContractState> {
4545
to_index: u8,
4646
army: u32
4747
);
48+
fn banish(ref self: TContractState, world: IWorldDispatcher, game_id: u32, player_index: u8);
4849
}
4950

5051
#[starknet::interface]
@@ -58,7 +59,7 @@ trait IERC20<TContractState> {
5859
mod play {
5960
// Starknet imports
6061

61-
use starknet::{get_tx_info, get_caller_address};
62+
use starknet::{get_tx_info, get_caller_address, get_block_timestamp};
6263

6364
// Dojo imports
6465

@@ -104,6 +105,9 @@ mod play {
104105
const TRANSFER_INVALID_TURN: felt252 = 'Transfer: invalid turn';
105106
const TRANSFER_INVALID_PLAYER: felt252 = 'Transfer: invalid player';
106107
const TRANSFER_INVALID_OWNER: felt252 = 'Transfer: invalid owner';
108+
const BANISH_NO_PENALITY_SET: felt252 = 'Banish: no penality set';
109+
const BANISH_INVALID_PLAYER: felt252 = 'Banish: invalid player';
110+
const BANISH_INVALID_CONDITION: felt252 = 'Banish: invalid condition';
107111
}
108112

109113
#[storage]
@@ -252,18 +256,25 @@ mod play {
252256
// [Setup] Datastore
253257
let mut store: Store = StoreTrait::new(world);
254258

255-
// [Check] Caller is player
259+
// [Check] Caller is player or player is dead
256260
let caller = get_caller_address();
257261
let mut game: Game = store.game(game_id);
258262
let mut player = store.current_player(game);
259-
assert(player.address == caller.into(), errors::FINISH_INVALID_PLAYER);
263+
assert(
264+
player.address == caller.into() || player.is_dead(), errors::FINISH_INVALID_PLAYER
265+
);
260266

261267
// [Check] Player supply is empty
262-
let mut player = store.current_player(game);
263-
assert(player.supply == 0, errors::FINISH_INVALID_SUPPLY);
268+
assert(player.supply == 0 || player.is_dead(), errors::FINISH_INVALID_SUPPLY);
269+
270+
// [Command] Update game turn according to the player status
271+
if player.is_dead() {
272+
game.pass();
273+
} else {
274+
game.increment();
275+
}
264276

265-
// [Command] Update next player supply if next turn is supply
266-
game.increment();
277+
// [Effect] Update next player supply if next turn is supply
267278
if game.turn() == Turn::Supply {
268279
// [Compute] Draw card if conqueror
269280
if player.conqueror {
@@ -291,7 +302,7 @@ mod play {
291302
};
292303

293304
// [Check] Player rank is not 0 means the player is dead, move to next player
294-
if next_player.rank > 0 {
305+
if next_player.is_dead() {
295306
// [Effect] Move to next player
296307
game.pass();
297308
continue;
@@ -321,9 +332,36 @@ mod play {
321332
};
322333

323334
// [Effect] Update game
335+
let time = get_block_timestamp();
336+
game.clock = time;
324337
store.set_game(game);
325338
}
326339

340+
fn banish(
341+
ref self: ContractState, world: IWorldDispatcher, game_id: u32, player_index: u8
342+
) {
343+
// [Setup] Datastore
344+
let mut store: Store = StoreTrait::new(world);
345+
346+
// [Check] Game penamity is valid
347+
let game: Game = store.game(game_id);
348+
assert(game.penality > 0, errors::BANISH_NO_PENALITY_SET);
349+
350+
// [Check] Targeted player is the current player
351+
let mut current_player = store.current_player(game);
352+
let mut player = store.player(game, player_index.into());
353+
assert(current_player.address == player.address, errors::BANISH_INVALID_PLAYER);
354+
355+
// [Check] Player is banishable
356+
let mut game: Game = store.game(game_id);
357+
let time = get_block_timestamp();
358+
assert(time > game.clock + game.penality, errors::BANISH_INVALID_CONDITION);
359+
360+
// [Effect] Update player
361+
player.rank(store.get_next_rank(game));
362+
store.set_player(player);
363+
}
364+
327365
fn supply(
328366
ref self: ContractState,
329367
world: IWorldDispatcher,

‎src/tests/attack.cairo

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use zconqueror::tests::setup::{setup, setup::{Systems, Context, HOST, PLAYER}};
2626
const HOST_NAME: felt252 = 'HOST';
2727
const PLAYER_NAME: felt252 = 'PLAYER';
2828
const PRICE: u256 = 1_000_000_000_000_000_000;
29+
const PENALITY: u64 = 60;
2930
const PLAYER_COUNT: u8 = 2;
3031
const PLAYER_INDEX: u32 = 0;
3132

@@ -37,7 +38,7 @@ fn test_attack() {
3738
let mut store = StoreTrait::new(world);
3839

3940
// [Create]
40-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
41+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
4142
set_contract_address(PLAYER());
4243
systems.host.join(world, game_id, PLAYER_NAME);
4344
set_contract_address(HOST());
@@ -93,7 +94,7 @@ fn test_attack_revert_invalid_player() {
9394
let mut store = StoreTrait::new(world);
9495

9596
// [Create]
96-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
97+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
9798
set_contract_address(PLAYER());
9899
systems.host.join(world, game_id, PLAYER_NAME);
99100
set_contract_address(HOST());
@@ -135,7 +136,7 @@ fn test_attack_revert_invalid_owner() {
135136
let mut store = StoreTrait::new(world);
136137

137138
// [Create]
138-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
139+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
139140
set_contract_address(PLAYER());
140141
systems.host.join(world, game_id, PLAYER_NAME);
141142
set_contract_address(HOST());

‎src/tests/defend.cairo

+6-5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use zconqueror::tests::setup::{setup, setup::{Systems, Context, HOST, PLAYER}};
2626
const HOST_NAME: felt252 = 'HOST';
2727
const PLAYER_NAME: felt252 = 'PLAYER';
2828
const PRICE: u256 = 1_000_000_000_000_000_000;
29+
const PENALITY: u64 = 60;
2930
const PLAYER_COUNT: u8 = 2;
3031
const PLAYER_INDEX: u32 = 0;
3132

@@ -37,7 +38,7 @@ fn test_defend_win() {
3738
let mut store = StoreTrait::new(world);
3839

3940
// [Create]
40-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
41+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
4142
set_contract_address(PLAYER());
4243
systems.host.join(world, game_id, PLAYER_NAME);
4344
set_contract_address(HOST());
@@ -117,7 +118,7 @@ fn test_defend_lose() {
117118
let mut store = StoreTrait::new(world);
118119

119120
// [Create]
120-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
121+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
121122
set_contract_address(PLAYER());
122123
systems.host.join(world, game_id, PLAYER_NAME);
123124
set_contract_address(HOST());
@@ -199,7 +200,7 @@ fn test_defend_revert_invalid_order() {
199200
let mut store = StoreTrait::new(world);
200201

201202
// [Create]
202-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
203+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
203204
set_contract_address(PLAYER());
204205
systems.host.join(world, game_id, PLAYER_NAME);
205206
set_contract_address(HOST());
@@ -260,7 +261,7 @@ fn test_defend_revert_invalid_player() {
260261
let mut store = StoreTrait::new(world);
261262

262263
// [Create]
263-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
264+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
264265
set_contract_address(PLAYER());
265266
systems.host.join(world, game_id, PLAYER_NAME);
266267
set_contract_address(HOST());
@@ -302,7 +303,7 @@ fn test_defend_revert_invalid_owner() {
302303
let mut store = StoreTrait::new(world);
303304

304305
// [Create]
305-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
306+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
306307
set_contract_address(PLAYER());
307308
systems.host.join(world, game_id, PLAYER_NAME);
308309
set_contract_address(HOST());

‎src/tests/finish.cairo

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use zconqueror::tests::setup::{setup, setup::{Systems, Context, HOST, PLAYER}};
2626
const HOST_NAME: felt252 = 'HOST';
2727
const PLAYER_NAME: felt252 = 'PLAYER';
2828
const PRICE: u256 = 1_000_000_000_000_000_000;
29+
const PENALITY: u64 = 60;
2930
const PLAYER_COUNT: u8 = 2;
3031
const PLAYER_INDEX: u32 = 0;
3132

@@ -37,7 +38,7 @@ fn test_finish_next_player() {
3738
let mut store = StoreTrait::new(world);
3839

3940
// [Create]
40-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
41+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
4142
set_contract_address(PLAYER());
4243
systems.host.join(world, game_id, PLAYER_NAME);
4344
set_contract_address(HOST());
@@ -104,7 +105,7 @@ fn test_finish_revert_invalid_supply() {
104105
let mut store = StoreTrait::new(world);
105106

106107
// [Create]
107-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
108+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
108109
set_contract_address(PLAYER());
109110
systems.host.join(world, game_id, PLAYER_NAME);
110111
set_contract_address(HOST());
@@ -127,7 +128,7 @@ fn test_finish_revert_invalid_player() {
127128
let mut store = StoreTrait::new(world);
128129

129130
// [Create]
130-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
131+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
131132
set_contract_address(PLAYER());
132133
systems.host.join(world, game_id, PLAYER_NAME);
133134
set_contract_address(HOST());

‎src/tests/host.cairo

+8-7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const HOST_NAME: felt252 = 'HOST';
2727
const PLAYER_NAME: felt252 = 'PLAYER';
2828
const ANYONE_NAME: felt252 = 'ANYONE';
2929
const PRICE: u256 = 1_000_000_000_000_000_000;
30+
const PENALITY: u64 = 60;
3031
const PLAYER_COUNT: u8 = 2;
3132

3233
#[test]
@@ -37,7 +38,7 @@ fn test_host_create_and_join() {
3738
let mut store = StoreTrait::new(world);
3839

3940
// [Create]
40-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
41+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
4142
set_contract_address(PLAYER());
4243
systems.host.join(world, game_id, PLAYER_NAME);
4344
set_contract_address(HOST());
@@ -100,7 +101,7 @@ fn test_host_create_and_host_deletes() {
100101
let mut store = StoreTrait::new(world);
101102

102103
// [Create]
103-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
104+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
104105
systems.host.delete(world, game_id);
105106

106107
// [Assert] Game
@@ -116,7 +117,7 @@ fn test_host_create_and_player_leaves() {
116117
let mut store = StoreTrait::new(world);
117118

118119
// [Create]
119-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
120+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
120121
set_contract_address(PLAYER());
121122
systems.host.join(world, game_id, PLAYER_NAME);
122123
systems.host.leave(world, game_id);
@@ -134,7 +135,7 @@ fn test_host_create_and_tranfer_and_host_leaves() {
134135
let mut store = StoreTrait::new(world);
135136

136137
// [Create]
137-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
138+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
138139
set_contract_address(PLAYER());
139140
systems.host.join(world, game_id, PLAYER_NAME);
140141
set_contract_address(HOST());
@@ -156,7 +157,7 @@ fn test_host_create_and_tranfer_and_kick_host() {
156157
let mut store = StoreTrait::new(world);
157158

158159
// [Create]
159-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
160+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
160161
set_contract_address(PLAYER());
161162
systems.host.join(world, game_id, PLAYER_NAME);
162163
set_contract_address(HOST());
@@ -180,7 +181,7 @@ fn test_host_start_then_join_revert_started() {
180181
let (world, systems, _) = setup::spawn_game();
181182

182183
// [Create]
183-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
184+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
184185
set_contract_address(PLAYER());
185186
systems.host.join(world, game_id, PLAYER_NAME);
186187
set_contract_address(HOST());
@@ -199,7 +200,7 @@ fn test_host_start_then_leave_revert_started() {
199200
let (world, systems, _) = setup::spawn_game();
200201

201202
// [Create]
202-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
203+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
203204
set_contract_address(PLAYER());
204205
systems.host.join(world, game_id, PLAYER_NAME);
205206
set_contract_address(HOST());

‎src/tests/supply.cairo

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use zconqueror::tests::setup::{setup, setup::{Systems, Context, HOST, PLAYER}};
2626
const HOST_NAME: felt252 = 'HOST';
2727
const PLAYER_NAME: felt252 = 'PLAYER';
2828
const PRICE: u256 = 1_000_000_000_000_000_000;
29+
const PENALITY: u64 = 60;
2930
const PLAYER_COUNT: u8 = 2;
3031
const PLAYER_INDEX: u32 = 0;
3132

@@ -36,7 +37,7 @@ fn test_supply() {
3637
let mut store = StoreTrait::new(world);
3738

3839
// [Create]
39-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
40+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
4041
set_contract_address(PLAYER());
4142
systems.host.join(world, game_id, PLAYER_NAME);
4243
set_contract_address(HOST());
@@ -79,7 +80,7 @@ fn test_supply_revert_invalid_player() {
7980
let mut store = StoreTrait::new(world);
8081

8182
// [Create]
82-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
83+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
8384
set_contract_address(PLAYER());
8485
systems.host.join(world, game_id, PLAYER_NAME);
8586
set_contract_address(HOST());
@@ -104,7 +105,7 @@ fn test_supply_revert_invalid_owner() {
104105
let mut store = StoreTrait::new(world);
105106

106107
// [Create]
107-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
108+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
108109
set_contract_address(PLAYER());
109110
systems.host.join(world, game_id, PLAYER_NAME);
110111
set_contract_address(HOST());

‎src/tests/transfer.cairo

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use zconqueror::tests::setup::{setup, setup::{Systems, Context, HOST, PLAYER}};
2626
const HOST_NAME: felt252 = 'HOST';
2727
const PLAYER_NAME: felt252 = 'PLAYER';
2828
const PRICE: u256 = 1_000_000_000_000_000_000;
29+
const PENALITY: u64 = 60;
2930
const PLAYER_COUNT: u8 = 2;
3031
const PLAYER_INDEX: u32 = 0;
3132

@@ -37,7 +38,7 @@ fn test_transfer_valid() {
3738
let mut store = StoreTrait::new(world);
3839

3940
// [Create]
40-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
41+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
4142
set_contract_address(PLAYER());
4243
systems.host.join(world, game_id, PLAYER_NAME);
4344
set_contract_address(HOST());
@@ -106,7 +107,7 @@ fn test_transfer_revert_invalid_player() {
106107
let mut store = StoreTrait::new(world);
107108

108109
// [Create]
109-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
110+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
110111
set_contract_address(PLAYER());
111112
systems.host.join(world, game_id, PLAYER_NAME);
112113
set_contract_address(HOST());
@@ -151,7 +152,7 @@ fn test_transfer_revert_invalid_owner() {
151152
let mut store = StoreTrait::new(world);
152153

153154
// [Create]
154-
let game_id = systems.host.create(world, HOST_NAME, PRICE);
155+
let game_id = systems.host.create(world, HOST_NAME, PRICE, PENALITY);
155156
set_contract_address(PLAYER());
156157
systems.host.join(world, game_id, PLAYER_NAME);
157158
set_contract_address(HOST());

0 commit comments

Comments
 (0)