unrip/test/postgres-funding.test.mjs
philipp 4adc705a2b
Some checks failed
deploy / deploy (push) Failing after 34s
Use bridge deposit time for funding activity
Proof: npm test (147 passing); npm run operator-dashboard:build; git diff --cached --check.

Assumptions: Bridge recent_deposits created_at is the authoritative source time for deposit activity; rows without created_at must be deduped to their earliest observed status instead of the latest replay ingestion.

Still fake: No fund movement or bridge migration was performed; ntfy messages already sent before this fix cannot be unsent.
2026-05-07 16:47:52 +02:00

84 lines
2.2 KiB
JavaScript

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 } : {}),
},
},
};
}