aboutsummaryrefslogtreecommitdiff
path: root/internal/game/wallet_refund_kind_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/wallet_refund_kind_test.go')
-rw-r--r--internal/game/wallet_refund_kind_test.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/internal/game/wallet_refund_kind_test.go b/internal/game/wallet_refund_kind_test.go
new file mode 100644
index 0000000..370c286
--- /dev/null
+++ b/internal/game/wallet_refund_kind_test.go
@@ -0,0 +1,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)
+ }
+}