Skip to content

Commit 801c93c

Browse files
Merge pull request #13 from Chia-Network/20240820-fix-unsim-test-run
Dependency fix for cargo test without features=sim-tests
2 parents 5447edd + ba5ea8f commit 801c93c

File tree

7 files changed

+53
-37
lines changed

7 files changed

+53
-37
lines changed

.github/workflows/build-test.yml

+3
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ jobs:
9292
- name: cargo test
9393
run: |
9494
python -m pip install chia-blockchain
95+
# Try tests without sim-tests to ensure we're tracking build failures in that
96+
# configuration. Also it's a lot shorter.
97+
cargo test
9598
cargo test --features=sim-tests
9699
97100
coverage:

src/tests/calpoker.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use clvm_traits::{ClvmEncoder, ToClvm};
77

88
use crate::channel_handler::game::Game;
99
use crate::common::types::{AllocEncoder, Amount, Error, GameID, Hash, Sha256Input};
10-
use crate::tests::simenv::{GameAction, GameActionResult, SimulatorEnvironment};
10+
use crate::tests::game::{GameAction, GameActionResult};
11+
12+
#[cfg(feature = "sim-tests")]
13+
use crate::tests::simenv::SimulatorEnvironment;
1114

1215
pub fn load_calpoker(allocator: &mut AllocEncoder, game_id: GameID) -> Result<Game, Error> {
1316
Game::new(
@@ -17,6 +20,7 @@ pub fn load_calpoker(allocator: &mut AllocEncoder, game_id: GameID) -> Result<Ga
1720
)
1821
}
1922

23+
#[cfg(feature = "sim-tests")]
2024
#[test]
2125
fn test_load_calpoker() {
2226
let mut allocator = AllocEncoder::new();
@@ -31,6 +35,7 @@ fn test_load_calpoker() {
3135
.expect("should get a sim env");
3236
}
3337

38+
#[cfg(feature = "sim-tests")]
3439
fn run_calpoker_play_test(
3540
allocator: &mut AllocEncoder,
3641
moves: &[GameAction],
@@ -77,6 +82,7 @@ pub fn test_moves_1(allocator: &mut AllocEncoder) -> [GameAction; 5] {
7782
]
7883
}
7984

85+
#[cfg(feature = "sim-tests")]
8086
#[test]
8187
fn test_play_calpoker_happy_path() {
8288
let mut allocator = AllocEncoder::new();
@@ -86,6 +92,7 @@ fn test_play_calpoker_happy_path() {
8692
}
8793

8894
#[test]
95+
#[cfg(feature = "sim-tests")]
8996
fn test_play_calpoker_on_chain_after_1_move_p1() {
9097
let mut allocator = AllocEncoder::new();
9198

@@ -100,6 +107,7 @@ fn test_play_calpoker_on_chain_after_1_move_p1() {
100107
}
101108

102109
#[test]
110+
#[cfg(feature = "sim-tests")]
103111
fn test_play_calpoker_on_chain_after_1_move_p0_lost_message() {
104112
let mut allocator = AllocEncoder::new();
105113
let moves = test_moves_1(&mut allocator);
@@ -111,6 +119,7 @@ fn test_play_calpoker_on_chain_after_1_move_p0_lost_message() {
111119
}
112120

113121
#[test]
122+
#[cfg(feature = "sim-tests")]
114123
fn test_play_calpoker_on_chain_after_1_move_p0() {
115124
let mut allocator = AllocEncoder::new();
116125
let moves = test_moves_1(&mut allocator);
@@ -121,6 +130,7 @@ fn test_play_calpoker_on_chain_after_1_move_p0() {
121130
}
122131

123132
#[test]
133+
#[cfg(feature = "sim-tests")]
124134
fn test_play_calpoker_on_chain_after_2_moves_p0() {
125135
let mut allocator = AllocEncoder::new();
126136
let moves = test_moves_1(&mut allocator);
@@ -130,7 +140,9 @@ fn test_play_calpoker_on_chain_after_2_moves_p0() {
130140
let test4 = run_calpoker_play_test(&mut allocator, &on_chain_moves_3).expect("should work");
131141
debug!("play_result {test4:?}");
132142
}
143+
133144
#[test]
145+
#[cfg(feature = "sim-tests")]
134146
fn test_play_calpoker_on_chain_after_2_moves_p1() {
135147
let mut allocator = AllocEncoder::new();
136148
let moves = test_moves_1(&mut allocator);

src/tests/game.rs

+34
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use clvmr::NodePtr;
2+
13
#[cfg(feature = "sim-tests")]
24
use rand::prelude::*;
35

@@ -19,6 +21,38 @@ use crate::common::types::{Amount, CoinString, Error, IntoErr, Timeout};
1921
#[cfg(feature = "sim-tests")]
2022
use crate::simulator::Simulator;
2123

24+
#[derive(Debug, Clone)]
25+
pub enum GameAction {
26+
/// Do a timeout
27+
#[allow(dead_code)]
28+
Timeout(usize),
29+
/// Move (player, clvm readable move, was received)
30+
Move(usize, NodePtr, bool),
31+
/// Fake move, just calls receive on the indicated side.
32+
#[allow(dead_code)]
33+
FakeMove(usize, NodePtr, Vec<u8>),
34+
/// Go on chain
35+
GoOnChain(usize),
36+
}
37+
38+
impl GameAction {
39+
pub fn lose(&self) -> GameAction {
40+
if let GameAction::Move(p, m, _r) = self {
41+
return GameAction::Move(*p, *m, false);
42+
}
43+
44+
self.clone()
45+
}
46+
}
47+
48+
#[derive(Debug, Clone)]
49+
pub enum GameActionResult {
50+
#[allow(dead_code)]
51+
MoveResult(NodePtr, Vec<u8>),
52+
BrokenMove,
53+
MoveToOnChain,
54+
}
55+
2256
#[cfg(feature = "sim-tests")]
2357
pub fn new_channel_handler_game<R: Rng>(
2458
simulator: &Simulator,

src/tests/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#[cfg(feature = "sim-tests")]
21
pub mod calpoker;
32
pub mod channel_handler;
43
pub mod chialisp;

src/tests/peer/outside.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::common::standard_coin::standard_solution_partial;
2828
use crate::common::types::{CoinSpend, Program};
2929

3030
use crate::tests::calpoker::{load_calpoker, test_moves_1};
31-
use crate::tests::simenv::GameAction;
31+
use crate::tests::game::GameAction;
3232

3333
#[derive(Default)]
3434
struct Pipe {

src/tests/peer/outsim.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ use crate::peer_container::{
3030

3131
use crate::simulator::Simulator;
3232
use crate::tests::calpoker::test_moves_1;
33+
use crate::tests::game::GameAction;
3334
use crate::tests::peer::outside::{quiesce, run_move};
34-
use crate::tests::simenv::GameAction;
3535

3636
// potato handler tests with simulator.
3737
#[derive(Default)]

src/tests/simenv.rs

+1-33
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,9 @@ use crate::common::types::{
2323
PrivateKey, Program, PuzzleHash, Sha256tree, Spend, Timeout,
2424
};
2525
use crate::simulator::Simulator;
26-
use crate::tests::game::new_channel_handler_game;
26+
use crate::tests::game::{new_channel_handler_game, GameAction, GameActionResult};
2727
use crate::tests::referee::{make_debug_game_handler, RefereeTest};
2828

29-
#[derive(Debug, Clone)]
30-
pub enum GameAction {
31-
/// Do a timeout
32-
#[allow(dead_code)]
33-
Timeout(usize),
34-
/// Move (player, clvm readable move, was received)
35-
Move(usize, NodePtr, bool),
36-
/// Fake move, just calls receive on the indicated side.
37-
#[allow(dead_code)]
38-
FakeMove(usize, NodePtr, Vec<u8>),
39-
/// Go on chain
40-
GoOnChain(usize),
41-
}
42-
43-
impl GameAction {
44-
pub fn lose(&self) -> GameAction {
45-
if let GameAction::Move(p, m, _r) = self {
46-
return GameAction::Move(*p, *m, false);
47-
}
48-
49-
self.clone()
50-
}
51-
}
52-
53-
#[derive(Debug, Clone)]
54-
pub enum GameActionResult {
55-
#[allow(dead_code)]
56-
MoveResult(NodePtr, Vec<u8>),
57-
BrokenMove,
58-
MoveToOnChain,
59-
}
60-
6129
#[derive(Debug, Clone)]
6230
pub enum OnChainState {
6331
OffChain(CoinString),

0 commit comments

Comments
 (0)