Skip to content

Showdown Function Test#200

Merged
Birdmannn merged 6 commits intoPrometheus-A:v1from
truthixify:fix-169
Sep 14, 2025
Merged

Showdown Function Test#200
Birdmannn merged 6 commits intoPrometheus-A:v1from
truthixify:fix-169

Conversation

@truthixify
Copy link
Contributor

@truthixify truthixify commented Jul 29, 2025

Description

This PR significantly enhances the test coverage for the showdown function within the actions.cairo contract. Previously, the showdown function, which is critical for verifying the fairness and integrity of poker rounds, lacked dedicated tests.

This update introduces a suite of tests that cover a valid end-to-end showdown scenario and various edge cases, including invalid parameters, incorrect nonces (to simulate replay attacks), and mismatched signature lengths. During the development of these tests, a minor bug related to the verify_game function's expected proof lengths was identified and fixed. Additionally, a helper function setup_valid_showdown was extracted to reduce code repetition across tests.

Related Issues

Closes #169

Changes Made - [ ]

  • Added test_showdown_valid_case to verify successful execution with correct parameters and signatures.
  • Implemented test_showdown_replay_attack_invalid_nonce to ensure the contract correctly rejects transactions with an incorrect nonce, preventing replay attacks.
  • Added test_showdown_invalid_salt_length to validate proper error handling when incorrect salt lengths are provided.
  • Included test_showdown_signature_length_mismatch to check for robust input validation on signature array lengths.
  • Introduced test_showdown_game_not_in_showdown_state to confirm the function fails if the game is not in the appropriate state.
  • Developed test_showdown_insufficient_community_cards to test scenarios where the community cards array is not fully populated.
  • Added test_showdown_player_not_in_round to ensure only active players can participate in showdown.
  • Implemented test_showdown_invalid_signature_recovery to test failure when signature components are malformed leading to failed public key recovery.
  • Created test_showdown_multiple_hands_valid to test the scenario with multiple players submitting valid hands.
  • Refactored common setup logic into a new helper function setup_valid_showdown to improve test readability and maintainability.
  • Debugged and fixed a bug in the verify_game utility that incorrectly assumed the total number of game proofs and dealt card proofs, instead of dynamically checking based on the number of hands. The fix ensures verify_game expects hands.len() * 2 proofs for both game_proofs and dealt_card_proofs.
  • Ensured all tests are strongly typed and adhere to project coding style.
  • Updated comments for clarity, focusing on complex logic and significant assertions.

How to Test

cd poker-texas-hold-em/contract
sozo test

Screenshots (if applicable)

image

Checklist

  • My code follows the project's coding style.
  • I have tested these changes locally.
  • Documentation has been updated where necessary.

@truthixify truthixify changed the title draft Showdown Function Test Sep 5, 2025
@truthixify truthixify marked this pull request as ready for review September 5, 2025 13:48
@Birdmannn Birdmannn merged commit d54067b into Prometheus-A:v1 Sep 14, 2025
1 check passed
@truthixify truthixify deleted the fix-169 branch September 17, 2025 11:12
@truthixify truthixify restored the fix-169 branch September 20, 2025 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat][Surgeon Needed] Test showdown

2 participants