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) } }