Skip to content

Commit

Permalink
Passing test
Browse files Browse the repository at this point in the history
  • Loading branch information
prozacchiwawa committed Nov 16, 2024
1 parent d713df5 commit 328159f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 0 additions & 4 deletions src/potato_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,6 @@ impl PotatoHandler {
pub fn is_on_chain(&self) -> bool {
matches!(
self.handshake_state,
HandshakeState::OnChainTransition(_, _) |
HandshakeState::OnChainWaitingForUnrollTimeoutOrSpend(_, _) |
HandshakeState::OnChainWaitForConditions(_, _) |
HandshakeState::OnChainWaitingForUnrollSpend(_) |
HandshakeState::OnChain(_)
)
}
Expand Down
18 changes: 16 additions & 2 deletions src/tests/peer/potato_handler_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,8 @@ impl ToLocalUI for LocalTestUIReceiver {
}
}

fn run_calpoker_container_with_action_list(allocator: &mut AllocEncoder, moves: &[GameAction]) {
fn run_calpoker_container_with_action_list_with_success_predicate(allocator: &mut AllocEncoder, moves: &[GameAction], pred: Option<&dyn Fn(&[SynchronousGameCradle]) -> bool>)
{
// Coinset adapter for each side.
let mut rng = ChaCha8Rng::from_seed([0; 32]);
let game_type_map = poker_collection(allocator);
Expand Down Expand Up @@ -796,6 +797,13 @@ fn run_calpoker_container_with_action_list(allocator: &mut AllocEncoder, moves:
.make_report_from_coin_set_update(current_height as u64, &current_coins)
.expect("should work");

if let Some(p) = &pred {
if p(&cradles) {
// Success.
return;
}
}

for i in 0..=1 {
if local_uis[i].go_on_chain {
// Perform on chain move.
Expand Down Expand Up @@ -971,6 +979,10 @@ fn run_calpoker_container_with_action_list(allocator: &mut AllocEncoder, moves:
}
}

fn run_calpoker_container_with_action_list(allocator: &mut AllocEncoder, moves: &[GameAction]) {
run_calpoker_container_with_action_list_with_success_predicate(allocator, moves, None);
}

#[test]
fn sim_test_with_peer_container() {
let mut allocator = AllocEncoder::new();
Expand All @@ -990,5 +1002,7 @@ fn sim_test_with_peer_container_piss_off_peer() {
} else {
panic!("no move 1 to replace");
}
run_calpoker_container_with_action_list(&mut allocator, &moves);
run_calpoker_container_with_action_list_with_success_predicate(&mut allocator, &moves, Some(&mut |cradles| {
cradles[0].is_on_chain() && cradles[1].is_on_chain()
}));
}

0 comments on commit 328159f

Please sign in to comment.