Skip to content

Test: betting flow#198

Open
guha-rahul wants to merge 8 commits intoPrometheus-A:v1from
guha-rahul:pr_187
Open

Test: betting flow#198
guha-rahul wants to merge 8 commits intoPrometheus-A:v1from
guha-rahul:pr_187

Conversation

@guha-rahul
Copy link

Description

This work addresses the need for comprehensive testing of the betting flow, particularly:

  • Small blind deduction from player next to dealer
  • Player turn restrictions
  • Betting validation for different amounts
  • Raise validation
  • All-in scenarios with pot adjustments
  • Betting round continuation
  • Next player logic with all-in players

Related Issues

fixes #187

Changes Made - [ ]

How to Test

Screenshots (if applicable)

Checklist

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

Copy link
Collaborator

@Birdmannn Birdmannn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said, for each should_panic function, please remove the ENTRYPOINT_FAILED from the expected panic message's tuple. Graçias. @guha-rahul

Know that this review is not abnormal... though I have no idea how your previous PRs were reviewed. I usually try to reduce review overhead, so please pay attention to the details in this one. If there's anything that you couldn't understand after you have googled it, then you can ask. I just hope I'd see more good on the next review, and corrections very close to none

Congrats to us 🌾


// Simulate small blind deduction (Player 1 is next to dealer)
let small_blind = game.params.small_blind;
player_1.chips -= small_blind.into();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it you doing the deduction? please we are testing the contract itself, so what you should do is call the contract's abi. Please don't just mock the storage because dojo allows you to do so. You're free to mock the initial player and game states when the game begins (actually I'd prefer you even call the abi for this... the initialize_game, join_game, etc)

let small_blind = initial_game.params.small_blind;

// Simulate round start (this would normally be called by _start_round)
simulate_round_start(ref world);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can observe what I said earlier right? You are "testing" the automatic deduction, yet you're the one doing the deducting. It's not sounding right sir 👀

let contracts = array![CoreContract::Actions];
let (mut world, systems) = deploy_contracts(contracts);
setup_four_player_betting_game(ref world);
simulate_round_start(ref world);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this too. I suggest just calling the start_round. It's a complex task, don't worry... that's why its difficulty is hard. You're free to comment out the verification of signature in the contracts function just for the sake of this test. But you must call the start_round, and any issues found, it's only natural that you fix them... 🌚


// Try to make small blind player (Player 1) play when it's Player 2's turn
set_contract_address(PLAYER_1());
systems.actions.check();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// Player 2 (big blind player) tries to raise with invalid amount
set_contract_address(PLAYER_2());
systems.actions.raise(invalid_raise);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert!(!game_state.showdown, "Game should not be in showdown when bets are unmatched");
}

/// Test 9: Next player should skip all-in player
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You must note that you haven't simulated any bit of the gameplay stated in the second section of the issue description sir @guha-rahul

I usually try my best to give you how and what is happening, and steps to follow in a long issue description, and yet some of you don't understand. If only you know how long it takes me to cook a single issue 😪

Comment on lines +532 to +534
// Manually simulate after_play logic to find next active player
// In a real game, this would happen after Player 2 makes a move

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??
I need the code, not the comments. You should implement what you commented.

Comment on lines +539 to +542
assert!(
expected_next_player != Option::Some(PLAYER_3()),
"Next player should not be the all-in player",
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously... because why not?
this test basically does nothing, by the way... I don't know if you know that sir 👀

Comment on lines +549 to +567
fn test_all_in_player_cannot_play_but_remains_in_round() {
// Setup
let contracts = array![CoreContract::Actions];
let (mut world, systems) = deploy_contracts(contracts);
setup_four_player_betting_game(ref world);

// Set Player 3 as all-in
let mut player_3: Player = world.read_model(PLAYER_3());
player_3.chips = 0; // All-in
player_3.in_round = true; // Still in round
world.write_model(@player_3);

let mut game: Game = world.read_model(1);
game.next_player = Option::Some(PLAYER_3()); // Force Player 3 to be next
world.write_model(@game);

// Try to make Player 3 play - should panic due to no chips
set_contract_address(PLAYER_3());
systems.actions.check();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalid ❌😪.
First off, it shouldn't panic... that's what we are trying to make sure.
Second, as usual, the gameplay wasn't simulated. You just changed one or two variables and you thought we were good to go.

Comment on lines +572 to +591
#[test]
fn test_all_in_player_state_verification() {
// Setup
let contracts = array![CoreContract::Actions];
let (mut world, _systems) = deploy_contracts(contracts);
setup_four_player_betting_game(ref world);

// Manually set player to all-in state
let mut player_3: Player = world.read_model(PLAYER_3());
player_3.chips = 0;
player_3.in_round = true;
world.write_model(@player_3);

// Verify Player 3's state after all-in
let player_3_after: Player = world.read_model(PLAYER_3());

assert!(player_3_after.chips == 0, "Player should have 0 chips after all-in");
assert!(player_3_after.in_round, "Player should still be in round after all-in");
assert!(player_3_after.is_in_game(1), "Player should still be in game after all-in");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test tests absolutely nothing... in my opinion sir. I don't know of yours.

Anyway, it just basically means you first have to understand what a game simulation is. You can check out some tests in Azura's repo, and see how things were cooked there. It resembles how you test your normal regular smart contract. Ohayo. ⛅️

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.

[Test][Doctor Needed] Test betting flow, PART 1

2 participants