@@ -24,6 +24,8 @@ struct Game {
24
24
player_count : u8 ,
25
25
nonce : u32 ,
26
26
price : u256 ,
27
+ clock : u64 ,
28
+ penality : u64 ,
27
29
}
28
30
29
31
#[derive(Drop , PartialEq )]
@@ -55,12 +57,14 @@ mod errors {
55
57
#[generate_trait]
56
58
impl GameImpl of GameTrait {
57
59
#[inline(always)]
58
- fn new (id : u32 , host : felt252 , price : u256 ) -> Game {
60
+ fn new (id : u32 , host : felt252 , price : u256 , penality : u64 ) -> Game {
59
61
// [Check] Host is valid
60
62
assert (host != 0 , errors :: GAME_INVALID_HOST );
61
63
62
64
// [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
+ }
64
68
}
65
69
66
70
#[inline(always)]
@@ -296,7 +300,17 @@ impl GameAssert of AssertTrait {
296
300
impl ZeroableGame of Zeroable <Game > {
297
301
#[inline(always)]
298
302
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
+ }
300
314
}
301
315
302
316
#[inline(always)]
@@ -324,6 +338,7 @@ mod tests {
324
338
325
339
const ID : u32 = 0 ;
326
340
const PRICE : u256 = 1_000_000_000_000_000_000 ;
341
+ const PENALITY : u64 = 60 ;
327
342
const SEED : felt252 = ' SEED' ;
328
343
const PLAYER_COUNT : u8 = 4 ;
329
344
const HOST : felt252 = ' HOST' ;
@@ -332,7 +347,7 @@ mod tests {
332
347
#[test]
333
348
#[available_gas(100_000)]
334
349
fn test_game_new () {
335
- let game = GameTrait :: new (ID , HOST , PRICE );
350
+ let game = GameTrait :: new (ID , HOST , PRICE , PENALITY );
336
351
assert (game . host == HOST , ' Game: wrong account' );
337
352
assert (game . id == ID , ' Game: wrong id' );
338
353
assert (game . over == false , ' Game: wrong over' );
@@ -344,7 +359,7 @@ mod tests {
344
359
#[test]
345
360
#[available_gas(100_000)]
346
361
fn test_game_join () {
347
- let mut game = GameTrait :: new (ID , HOST , PRICE );
362
+ let mut game = GameTrait :: new (ID , HOST , PRICE , PENALITY );
348
363
game . join ();
349
364
let index = game . join ();
350
365
assert (game . player_count == 2 , ' Game: wrong count' );
@@ -363,7 +378,7 @@ mod tests {
363
378
#[available_gas(100_000)]
364
379
#[should_panic(expected: (' Game: is over' ,))]
365
380
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 );
367
382
game . over = true ;
368
383
game . join ();
369
384
}
@@ -372,7 +387,7 @@ mod tests {
372
387
#[available_gas(100_000)]
373
388
#[should_panic(expected: (' Game: has started' ,))]
374
389
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 );
376
391
game . seed = 1 ;
377
392
game . join ();
378
393
}
@@ -381,7 +396,7 @@ mod tests {
381
396
#[available_gas(150_000)]
382
397
#[should_panic(expected: (' Game: is full' ,))]
383
398
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 );
385
400
let mut index = MAXIMUM_PLAYER_COUNT + 1 ;
386
401
loop {
387
402
if index == 0 {
@@ -395,7 +410,7 @@ mod tests {
395
410
#[test]
396
411
#[available_gas(100_000)]
397
412
fn test_game_leave () {
398
- let mut game = GameTrait :: new (ID , HOST , PRICE );
413
+ let mut game = GameTrait :: new (ID , HOST , PRICE , PENALITY );
399
414
game . join ();
400
415
let index = game . leave (PLAYER );
401
416
assert (game . player_count == 0 , ' Game: wrong count' );
@@ -406,7 +421,7 @@ mod tests {
406
421
#[available_gas(100_000)]
407
422
#[should_panic(expected: (' Game: user is the host' ,))]
408
423
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 );
410
425
game . join ();
411
426
game . leave (HOST );
412
427
assert (game . over, ' Game: wrong status' );
@@ -416,7 +431,7 @@ mod tests {
416
431
#[available_gas(100_000)]
417
432
#[should_panic(expected: (' Game: is empty' ,))]
418
433
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 );
420
435
game . join ();
421
436
game . player_count = 0 ;
422
437
game . leave (PLAYER );
@@ -426,7 +441,7 @@ mod tests {
426
441
#[available_gas(100_000)]
427
442
#[should_panic(expected: (' Game: is over' ,))]
428
443
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 );
430
445
game . join ();
431
446
game . over = true ;
432
447
game . leave (PLAYER );
@@ -436,7 +451,7 @@ mod tests {
436
451
#[available_gas(100_000)]
437
452
#[should_panic(expected: (' Game: has started' ,))]
438
453
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 );
440
455
game . seed = 1 ;
441
456
game . join ();
442
457
game . leave (PLAYER );
@@ -446,7 +461,7 @@ mod tests {
446
461
#[available_gas(100_000)]
447
462
#[should_panic(expected: (' Game: is empty' ,))]
448
463
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 );
450
465
game . join ();
451
466
game . leave (PLAYER );
452
467
game . leave (PLAYER );
@@ -455,7 +470,7 @@ mod tests {
455
470
#[test]
456
471
#[available_gas(200_000)]
457
472
fn test_game_delete_host () {
458
- let mut game = GameTrait :: new (ID , HOST , PRICE );
473
+ let mut game = GameTrait :: new (ID , HOST , PRICE , PENALITY );
459
474
game . join ();
460
475
game . delete (HOST );
461
476
assert (game . is_zero (), ' Game: not zero' );
@@ -464,7 +479,7 @@ mod tests {
464
479
#[test]
465
480
#[available_gas(200_000)]
466
481
fn test_game_start () {
467
- let mut game = GameTrait :: new (ID , HOST , PRICE );
482
+ let mut game = GameTrait :: new (ID , HOST , PRICE , PENALITY );
468
483
let mut index = PLAYER_COUNT ;
469
484
loop {
470
485
if index == 0 {
@@ -482,7 +497,7 @@ mod tests {
482
497
#[available_gas(200_000)]
483
498
#[should_panic(expected: (' Game: too few players' ,))]
484
499
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 );
486
501
game . player_count = 0 ;
487
502
let players = array! [HOST , PLAYER ];
488
503
game . start (players );
@@ -492,7 +507,7 @@ mod tests {
492
507
#[available_gas(200_000)]
493
508
#[should_panic(expected: (' Game: is over' ,))]
494
509
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 );
496
511
game . over = true ;
497
512
let players = array! [HOST , PLAYER ];
498
513
game . start (players );
@@ -502,7 +517,7 @@ mod tests {
502
517
#[available_gas(200_000)]
503
518
#[should_panic(expected: (' Game: has started' ,))]
504
519
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 );
506
521
game . seed = 1 ;
507
522
let players = array! [HOST , PLAYER ];
508
523
game . start (players );
@@ -511,7 +526,7 @@ mod tests {
511
526
#[test]
512
527
#[available_gas(1_000_000)]
513
528
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 );
515
530
game . player_count = 6 ;
516
531
assert (game . player () == 0 , ' Game: wrong player index 0+0' );
517
532
game . nonce += 1 ;
@@ -534,7 +549,7 @@ mod tests {
534
549
#[test]
535
550
#[available_gas(100_000)]
536
551
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 );
538
553
game . player_count = 6 ;
539
554
assert (game . player () == 0 , ' Game: wrong player index 0+0' );
540
555
assert (game . next_player () == 1 , ' Game: wrong next player 0+0' );
@@ -546,7 +561,7 @@ mod tests {
546
561
#[test]
547
562
#[available_gas(100_000)]
548
563
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 );
550
565
assert (game . turn (). into () == 0_u32 , ' Game: wrong turn index 0' );
551
566
game . nonce += 1 ;
552
567
assert (game . turn (). into () == 1_u32 , ' Game: wrong turn index 1' );
@@ -560,7 +575,7 @@ mod tests {
560
575
#[test]
561
576
#[available_gas(100_000)]
562
577
fn test_game_pass () {
563
- let mut game = GameTrait :: new (ID , HOST , PRICE );
578
+ let mut game = GameTrait :: new (ID , HOST , PRICE , PENALITY );
564
579
game . player_count = 6 ;
565
580
game . pass ();
566
581
assert (game . player () == 1 , ' Game: wrong player' );
0 commit comments