aboutsummaryrefslogtreecommitdiff
path: root/internal/casino/paycredits_atomic_test.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-09-18 21:50:17 -0400
committerhistoria <[not public]>2026-09-18 21:50:17 -0400
commit2c38386484cdb507c4687caceb37e0b963e33594 (patch)
treeb25ecf9f509a48d8126f5a4b3a0482de42676239 /internal/casino/paycredits_atomic_test.go
parente7848ea79a9a57fdf391d30c48ce649f3d2f6180 (diff)
downloadthehouseoficarus-2c38386484cdb507c4687caceb37e0b963e33594.tar.gz
fix: make slot payout and stake resolution one durable save
Diffstat (limited to 'internal/casino/paycredits_atomic_test.go')
-rw-r--r--internal/casino/paycredits_atomic_test.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/internal/casino/paycredits_atomic_test.go b/internal/casino/paycredits_atomic_test.go
new file mode 100644
index 0000000..b08415e
--- /dev/null
+++ b/internal/casino/paycredits_atomic_test.go
@@ -0,0 +1,38 @@
+package casino
+
+import "testing"
+
+// recordingWallet records the stake IDs passed to PayCredits so a winning
+// spin's atomicity can be asserted directly.
+type recordingWallet struct {
+ testWallet
+ payStakes []string
+}
+
+func (w *recordingWallet) PayCredits(amount int, stakeIDs ...string) error {
+ w.payStakes = append(w.payStakes, stakeIDs...)
+ return w.testWallet.PayCredits(amount, stakeIDs...)
+}
+
+// TestWinningSpinConsumesStakeInPayoutSave: a winning paid spin must pass its
+// triggering stake to the SAME PayCredits call, so the credit and the stake
+// consumption are one durable save. Resolving the stake in a separate later
+// call leaves a crash window in which the payout is durable but the stake is
+// still pending — startup would then refund it on top of the win.
+func TestWinningSpinConsumesStakeInPayoutSave(t *testing.T) {
+ m := newMachine(1, MachineConfig{ID: "slots", Game: GameSlots}, newTestRand())
+ w := &recordingWallet{testWallet: testWallet{credits: 100}}
+ m.join("alice")
+ m.beginSpinLocked(10, w, "", "")
+ wagerID := m.stakeID
+
+ m.spin = &SlotSpin{Payout: 25}
+ m.finishSpin()
+
+ if len(w.payStakes) != 1 || w.payStakes[0] != wagerID {
+ t.Fatalf("winning spin passed stakes %v to PayCredits; want [%q] (one atomic payout+resolve)", w.payStakes, wagerID)
+ }
+ if len(w.open) != 0 {
+ t.Fatalf("winning spin left %d stake(s) pending: %+v", len(w.open), w.open)
+ }
+}