diff options
Diffstat (limited to 'internal/game/economy_reanchor_test.go')
| -rw-r--r-- | internal/game/economy_reanchor_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/internal/game/economy_reanchor_test.go b/internal/game/economy_reanchor_test.go new file mode 100644 index 0000000..86d7bf1 --- /dev/null +++ b/internal/game/economy_reanchor_test.go @@ -0,0 +1,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) + } +} |
