diff options
Diffstat (limited to 'internal/casino/manager_test.go')
| -rw-r--r-- | internal/casino/manager_test.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/internal/casino/manager_test.go b/internal/casino/manager_test.go index 889618c..1e77b0b 100644 --- a/internal/casino/manager_test.go +++ b/internal/casino/manager_test.go @@ -74,6 +74,29 @@ func (w *testWallet) RefundOutstanding() (chips, credits int, err error) { return chips, credits, nil } +// RefundStakes returns the named outstanding stakes to the balances in kind, +// mirroring the production wallet's take-back path. +func (w *testWallet) RefundStakes(stakeIDs ...string) error { + wanted := make(map[string]bool, len(stakeIDs)) + for _, id := range stakeIDs { + wanted[id] = true + } + var chips, credits int + kept := w.open[:0] + for _, wager := range w.open { + if wanted[wager.ID] { + chips += wager.Chips + credits += wager.Credits + continue + } + kept = append(kept, wager) + } + w.open = kept + w.chips += chips + w.paid += credits + return nil +} + func TestMixedWagerUsesChipsFirst(t *testing.T) { w := &testWallet{chips: 7, credits: 50} wager, err := w.Wager(12) |
