diff --git a/scripts/deploy/financial-audit.sql b/scripts/deploy/financial-audit.sql index 6f9eb05..f0de4a4 100644 --- a/scripts/deploy/financial-audit.sql +++ b/scripts/deploy/financial-audit.sql @@ -11,7 +11,7 @@ FROM schema_migrations; WITH audit(category, row_count, atomic_amount) AS ( SELECT 'payout_nonterminal', COUNT(*), COALESCE(SUM(amount), 0)::numeric FROM payouts - WHERE status IS NULL OR status NOT IN ('recorded', 'completed') + WHERE status IS DISTINCT FROM 'completed' UNION ALL SELECT 'payout_completed_missing_tx', COUNT(*), COALESCE(SUM(amount), 0)::numeric FROM payouts @@ -71,7 +71,7 @@ WITH ledger AS ( WHERE status = 'completed' AND NULLIF(BTRIM(COALESCE(tx_hash, '')), '') IS NULL UNION ALL SELECT COUNT(*) FROM payment_refunds - WHERE status IS DISTINCT FROM 'completed' + WHERE status IS NULL OR status NOT IN ('recorded', 'completed') UNION ALL SELECT COUNT(*) FROM games WHERE status IS NULL OR status NOT IN ('won', 'lost', 'expired') UNION ALL diff --git a/test/financialAuditContract.test.js b/test/financialAuditContract.test.js index 6ce3a70..24b932a 100644 --- a/test/financialAuditContract.test.js +++ b/test/financialAuditContract.test.js @@ -15,6 +15,10 @@ describe('deployment financial-audit contract', () => { test('nullable or unknown money/game states and a stale schema ledger fail closed', () => { expect(audit).toContain("payouts WHERE status IS DISTINCT FROM 'completed'"); + expect(audit).toMatch(/FROM payouts\s+WHERE status IS DISTINCT FROM 'completed'/); + expect(audit).not.toMatch( + /FROM payouts\s+WHERE status IS NULL OR status NOT IN \('recorded', 'completed'\)/ + ); expect(audit).toContain("games WHERE status IS NULL OR status NOT IN ('won', 'lost', 'expired')"); expect(audit).toContain("MAX(filename) = '042_immutable_financial_event_snapshots.sql'"); expect(audit.match(/status IS NULL OR status NOT IN \('recorded', 'completed'\)/g))