aboutsummaryrefslogtreecommitdiff
path: root/internal/game/economy_reanchor_test.go
blob: 86d7bf153e021f213db1fe03890f48fe86bdd111 (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
package game

import (
	"testing"

	"thehouseoficarus/internal/casino"
)

// TestReanchorOwedPayoutReadsAsOwed: when recovery cannot pay every sibling in
// an identical-signature payout group, the unpaid remainder must be re-anchored
// to the current durable balance. Otherwise a later run (after compaction drops
// the settled sibling evidence) reads the balance as the record's own
// durability and settles the liability without paying it.
func TestReanchorOwedPayoutReadsAsOwed(t *testing.T) {
	rec := &economyRecord{Credit: 20, CreditsBefore: 90, CreditsAfter: 110}
	// One sibling was paid: the durable balance now sits at 110.
	reanchorOwedPayout(rec, 110, rec.Credit)
	if rec.CreditsBefore != 110 || rec.CreditsAfter != 130 {
		t.Fatalf("re-anchored checkpoints = before %d after %d, want before 110 after 130", rec.CreditsBefore, rec.CreditsAfter)
	}

	// At the economy cap the post-checkpoint must stay reachable: before ==
	// after so the record keeps reading as owed instead of claiming an
	// impossible balance that a coincidental balance could be mistaken for.
	capped := &economyRecord{Credit: 20}
	reanchorOwedPayout(capped, casino.MaxCredits, capped.Credit)
	if capped.CreditsBefore != casino.MaxCredits || capped.CreditsAfter != casino.MaxCredits {
		t.Fatalf("cap re-anchor = before %d after %d, want both %d",
			capped.CreditsBefore, capped.CreditsAfter, casino.MaxCredits)
	}
}