import test from 'node:test'; import assert from 'node:assert/strict'; import { loadRecentDepositStatuses } from '../src/lib/postgres.mjs'; test('recent deposit status loader keeps old bridge deposits at original effective time', async () => { const txHash = '0xe8755a069e10a5963953c847f48f2db857c7a2dfdf8d21579c4057366126dd3f'; const rows = [ depositRow({ txHash, status: 'COMPLETED', ingestedAt: '2026-05-07T14:07:23.107Z', }), depositRow({ txHash, status: 'COMPLETED', ingestedAt: '2026-04-07T15:20:54.757Z', }), depositRow({ txHash, status: 'PENDING', ingestedAt: '2026-04-07T15:20:24.814Z', }), ]; const pool = { async query(sql, params) { assert.match(sql, /deposit_status_observed/); assert.equal(params[0], 500); return { rows }; }, }; const [deposit] = await loadRecentDepositStatuses(pool, { limit: 10 }); assert.equal(deposit.payload.status, 'COMPLETED'); assert.equal(deposit.ingested_at, '2026-05-07T14:07:23.107Z'); assert.equal(deposit.observed_at, '2026-04-07T15:20:24.814Z'); assert.equal(deposit.payload.details.created_at, '2026-04-07T15:20:24.814Z'); }); test('recent deposit status loader uses bridge created_at when present', async () => { const rows = [ depositRow({ txHash: 'eth-tx-new', status: 'COMPLETED', ingestedAt: '2026-05-07T14:07:23.107Z', createdAt: '2026-04-08T15:57:14.877Z', }), ]; const pool = { async query() { return { rows }; }, }; const [deposit] = await loadRecentDepositStatuses(pool, { limit: 10 }); assert.equal(deposit.observed_at, '2026-04-08T15:57:14.877Z'); assert.equal(deposit.payload.details.created_at, '2026-04-08T15:57:14.877Z'); }); function depositRow({ txHash, status, ingestedAt, createdAt = null, }) { return { observed_at: null, ingested_at: ingestedAt, payload: { action_type: 'deposit_status_observed', chain: 'eth:100', asset_id: 'nep141:eure.omft.near', status, details: { tx_hash: txHash, address: '0xdeposit', amount: '24999999800000000000', ...(createdAt ? { created_at: createdAt } : {}), }, }, }; }