-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathhelpers.nr
More file actions
82 lines (74 loc) · 2.45 KB
/
helpers.nr
File metadata and controls
82 lines (74 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use dep::aztec::{
protocol_types::address::AztecAddress, test::helpers::test_environment::TestEnvironment,
};
use crate::PodRacing;
// Test constants
pub global TEST_GAME_ID_1: Field = 1;
pub global TEST_GAME_ID_2: Field = 2;
pub global TEST_GAME_ID_3: Field = 3;
pub global TEST_GAME_ID_4: Field = 4;
pub global TEST_GAME_ID_5: Field = 5;
pub global TEST_GAME_ID_6: Field = 6;
pub global TEST_GAME_ID_7: Field = 7;
pub global TEST_GAME_ID_8: Field = 8;
pub global TEST_GAME_ID_9: Field = 9;
pub global TEST_GAME_ID_10: Field = 10;
pub global TEST_GAME_ID_11: Field = 11;
pub global TEST_GAME_ID_12: Field = 12;
pub global TEST_GAME_ID_13: Field = 13;
// Common point allocations for testing
// Balanced strategy: distribute points evenly
pub unconstrained fn balanced_allocation() -> (u8, u8, u8, u8, u8) {
(2, 2, 2, 2, 1)
}
// Aggressive strategy: focus on first 3 tracks
pub unconstrained fn aggressive_allocation() -> (u8, u8, u8, u8, u8) {
(3, 3, 3, 0, 0)
}
// Defensive strategy: focus on last 2 tracks
pub unconstrained fn defensive_allocation() -> (u8, u8, u8, u8, u8) {
(0, 0, 1, 4, 4)
}
// Maximum allowed points
pub unconstrained fn max_allocation() -> (u8, u8, u8, u8, u8) {
(5, 2, 1, 1, 0)
}
// Helper to setup a game with two players
pub unconstrained fn setup_two_player_game(
env: &mut TestEnvironment,
contract_address: AztecAddress,
player1: AztecAddress,
player2: AztecAddress,
game_id: Field
) {
env.call_public(player1, PodRacing::at(contract_address).create_game(game_id));
env.call_public(player2, PodRacing::at(contract_address).join_game(game_id));
}
// Helper to play a round with specific allocations
pub unconstrained fn play_round_with_allocation(
env: &mut TestEnvironment,
contract_address: AztecAddress,
player: AztecAddress,
game_id: Field,
round: u8,
allocation: (u8, u8, u8, u8, u8)
) {
let (t1, t2, t3, t4, t5) = allocation;
env.call_private(
player,
PodRacing::at(contract_address).play_round(game_id, round, t1, t2, t3, t4, t5)
);
}
// Helper to play all 3 rounds with the same strategy
pub unconstrained fn play_all_rounds_with_strategy(
env: &mut TestEnvironment,
contract_address: AztecAddress,
player: AztecAddress,
game_id: Field,
allocations: [(u8, u8, u8, u8, u8); 3]
) {
for i in 0..3 {
let round = (i + 1) as u8;
play_round_with_allocation(env, contract_address, player, game_id, round, allocations[i]);
}
}