diff options
Diffstat (limited to 'internal/casino/money_regression_test.go')
| -rw-r--r-- | internal/casino/money_regression_test.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/internal/casino/money_regression_test.go b/internal/casino/money_regression_test.go index 79f9b46..31cd0e6 100644 --- a/internal/casino/money_regression_test.go +++ b/internal/casino/money_regression_test.go @@ -249,3 +249,40 @@ func TestSlotsStakeResolvesOnlyAfterFullRound(t *testing.T) { t.Errorf("refundAll double-paid a completed round: paid %d -> %d", paidBefore, wallet.paid) } } + +// TestSlotsSecondSpinDoesNotResolveFailedPayoutStake: a spin whose payout +// could not be persisted leaves its stake OPEN as recovery evidence. The +// next round must resolve only its own stake — a player-wide ResolveStakes +// would silently erase the failed round's evidence and drop the refund. +func TestSlotsSecondSpinDoesNotResolveFailedPayoutStake(t *testing.T) { + machine := newMachine(1, MachineConfig{ID: "slots", Game: GameSlots, SpinTicks: 1}, newTestRand()) + wallet := &failingPayoutWallet{testWallet{credits: 100}} + machine.join("alice") + machine.setBet("alice", 10, wallet) + machine.spin = &SlotSpin{Payout: 20} // winning spin the wallet refuses to pay + for i := 0; i < 20 && machine.phase != machineReady; i++ { + machine.tick() + } + if len(wallet.open) != 1 { + t.Fatal("setup: a failed payout must leave the stake open") + } + + // A second, losing round must not resolve the first (still-open) stake. + machine.setBet("alice", 10, wallet) + machine.spin = &SlotSpin{} + for i := 0; i < 20 && machine.phase != machineReady; i++ { + machine.tick() + } + if len(wallet.open) != 1 { + t.Fatalf("the second spin resolved the failed-payout stake; open=%d, want 1", len(wallet.open)) + } + + // The preserved stake is still refundable at shutdown. + machine.refundAll() + if len(wallet.open) != 0 { + t.Fatalf("failed-payout stake was not refunded: open=%+v", wallet.open) + } + if got := wallet.credits + wallet.paid; got != 90 { + t.Fatalf("balance %d, want 90 (first stake refunded, second leg lost)", got) + } +} |
