aboutsummaryrefslogtreecommitdiff
path: root/internal/game/wallet_refund_kind_test.go
blob: 370c2860dc612b405d1faa410712ba0fc5d33353 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package game

import "testing"

// RefundStakes must return chips as chips. PayCredits here used to convert the
// casino-only chip stake into spendable credits (an economy exploit via unbet).
func TestRefundStakesReturnsChipsInKind(t *testing.T) {
	h := newHarness(t)
	h.seedAccount("alice")
	p := h.seedCharacter("alice", "alice")
	h.g.RunOnOwner(func() {
		p.Credits = 100
		w := casinoWallet{g: h.g, p: p}
		if !h.g.giveChips(p, 30) {
			t.Error("could not seed chips")
			return
		}
		wager, err := w.Wager(30) // spends chips first, 0 credits
		if err != nil {
			t.Error(err)
			return
		}
		if wager.Chips != 30 || wager.Credits != 0 {
			t.Errorf("wager = %+v, want 30 chips / 0 credits", wager)
		}
		if err := w.RefundStakes(wager.ID); err != nil {
			t.Error(err)
		}
	})
	h.barrier()
	if p.Credits != 100 {
		t.Fatalf("credits changed to %d, want 100 (chips must return in kind)", p.Credits)
	}
	if got := countChips(p); got != 30 {
		t.Fatalf("chips after refund = %d, want 30", got)
	}
	if len(p.PendingWagers) != 0 {
		t.Fatalf("pending stake not cleared: %+v", p.PendingWagers)
	}
}