package game import "testing" // TestStakeCoveredRespectsCreationOrder: an open payout created BEFORE a stake // must not be treated as that stake's settlement, or RefundOutstanding would // resolve the later stake without returning its money. func TestStakeCoveredRespectsCreationOrder(t *testing.T) { j := newEconomyJournal(t.TempDir()) stake := &economyRecord{ID: "stake", Player: "alice", Kind: "wager", Status: "open", Seq: 2} j.registerStake(stake) older := &economyRecord{ID: "older", Player: "alice", Kind: "payout", Status: "open", Seq: 1, Tracked: true} j.openPayoutRecs[stake.key()] = []*economyRecord{older} if j.stakeCovered(stake) { t.Fatal("a payout created before the stake must not cover it") } newer := &economyRecord{ID: "newer", Player: "alice", Kind: "payout", Status: "open", Seq: 3, Tracked: true} j.openPayoutRecs[stake.key()] = []*economyRecord{newer} if !j.stakeCovered(stake) { t.Fatal("a payout created after the stake should cover it") } }