diff options
| author | historia <[not public]> | 2026-09-18 05:31:09 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-09-18 05:31:09 -0400 |
| commit | 153acb7f644d755c45533b7c5311e3ffa47e8973 (patch) | |
| tree | 7645e6f7b65bc3830b078e3b9336d2e6b199d584 /internal/game/hardening_credit_cap_test.go | |
| parent | 87d08f0151e643951769e323995f1c5ed89ee200 (diff) | |
| download | thehouseoficarus-153acb7f644d755c45533b7c5311e3ffa47e8973.tar.gz | |
fix: harden engine across casino, economy, concurrency, security, and content
Diffstat (limited to 'internal/game/hardening_credit_cap_test.go')
| -rw-r--r-- | internal/game/hardening_credit_cap_test.go | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/internal/game/hardening_credit_cap_test.go b/internal/game/hardening_credit_cap_test.go new file mode 100644 index 0000000..872c746 --- /dev/null +++ b/internal/game/hardening_credit_cap_test.go @@ -0,0 +1,105 @@ +package game + +// Regression: credit pickups must never destroy value at the economy cap. +// Only the balance headroom below casino.MaxCredits may be removed from the +// ground; the remainder stays there. The previous code removed the whole +// ground stack and then let grantCredits clamp the excess away. + +import ( + "strings" + "testing" + + "thehouseoficarus/internal/casino" + "thehouseoficarus/internal/net" +) + +func TestPickupCreditsAtCapLeavesRemainderOnGround(t *testing.T) { + h := newHarness(t) + h.seedAccount("alice") + p := h.seedCharacter("alice", "alice") + h.g.RunOnOwner(func() { + p.Credits = casino.MaxCredits - 5 + h.g.World.AddGroundItem(p.RoomID, "credits", 20) + sess := &net.Session{Conn: newChanConn(), Player: p} + sess.SetState(net.StateGame) + + h.g.pickupCredits(sess, p, "credits") + + if p.Credits != casino.MaxCredits { + t.Errorf("balance = %d, want the cap %d", p.Credits, casino.MaxCredits) + } + if got := h.g.World.GroundItems(p.RoomID)["credits"]; got != 15 { + t.Errorf("ground credits = %d, want 15 left behind", got) + } + }) +} + +func TestPickupCreditsAtCapDestroysNothing(t *testing.T) { + h := newHarness(t) + h.seedAccount("alice") + p := h.seedCharacter("alice", "alice") + h.g.RunOnOwner(func() { + p.Credits = casino.MaxCredits + h.g.World.AddGroundItem(p.RoomID, "credits", 20) + sess := &net.Session{Conn: newChanConn(), Player: p} + sess.SetState(net.StateGame) + + h.g.pickupCredits(sess, p, "credits") + + if p.Credits != casino.MaxCredits { + t.Errorf("balance = %d, want the cap %d", p.Credits, casino.MaxCredits) + } + if got := h.g.World.GroundItems(p.RoomID)["credits"]; got != 20 { + t.Errorf("ground credits = %d, want the full stack to survive", got) + } + if out := string(sess.Conn.(*chanConn).Bytes()); !strings.Contains(out, "can't hold any more credits") { + t.Errorf("expected a cap message, got %q", out) + } + }) +} + +func TestGetAllCreditsAtCapLeavesRemainderOnGround(t *testing.T) { + h := newHarness(t) + h.seedAccount("alice") + p := h.seedCharacter("alice", "alice") + h.g.RunOnOwner(func() { + p.Credits = casino.MaxCredits - 5 + h.g.World.AddGroundItem(p.RoomID, "credits", 20) + sess := &net.Session{Conn: newChanConn(), Player: p} + sess.SetState(net.StateGame) + + h.g.doGetAll(sess) + + if p.Credits != casino.MaxCredits { + t.Errorf("balance = %d, want the cap %d", p.Credits, casino.MaxCredits) + } + if got := h.g.World.GroundItems(p.RoomID)["credits"]; got != 15 { + t.Errorf("ground credits = %d, want 15 left behind", got) + } + }) +} + +func TestGetAllCreditsAtCapReportsShortfall(t *testing.T) { + h := newHarness(t) + h.seedAccount("alice") + p := h.seedCharacter("alice", "alice") + h.g.RunOnOwner(func() { + p.Credits = casino.MaxCredits + h.g.World.AddGroundItem(p.RoomID, "credits", 20) + sess := &net.Session{Conn: newChanConn(), Player: p} + sess.SetState(net.StateGame) + + h.g.doGetAll(sess) + + if got := h.g.World.GroundItems(p.RoomID)["credits"]; got != 20 { + t.Errorf("ground credits = %d, want the full stack to survive", got) + } + out := string(sess.Conn.(*chanConn).Bytes()) + if !strings.Contains(out, "can't hold any more credits") { + t.Errorf("expected a cap message, got %q", out) + } + if strings.Contains(out, "inventory is full") { + t.Errorf("cap shortfall misreported as a full inventory: %q", out) + } + }) +} |
