unrip/test/near-intents-status.test.mjs
philipp 601450c664
Some checks failed
deploy / deploy (push) Failing after 29s
Persist NEAR status changes only
Proof: npm test; npm run operator-dashboard:build; node --test test/near-intents-status.test.mjs test/environment-status-history.test.mjs test/operator-dashboard.test.mjs test/operator-dashboard-ui-static.test.mjs test/ops-sentinel-static.test.mjs; PYTHONPATH=. python3 test/repo_deployments_test.py; kubectl kustomize deploy/k8s/base.

Assumptions: NEAR Intents public status page API remains the official upstream environmental-status source; status fingerprint changes are the durable boundary for saving environmental history.

Still fake: This stores and displays official upstream status changes, but it does not create an alternate quote source or make NEAR quoting operational during an upstream pause.
2026-04-17 14:34:10 +02:00

158 lines
5.5 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {
buildNearIntentsStatusEventPayload,
normalizeNearIntentsStatus,
} from '../src/core/near-intents-status.mjs';
const postEnumsResponse = {
post_enums: [
{ id: 'PSCS3IV', post_enum_type: 'status', name: 'investigating' },
{ id: 'PP34365', post_enum_type: 'status', name: 'detected' },
{ id: 'P8TG2TF', post_enum_type: 'status', name: 'resolved' },
{ id: 'P187122', post_enum_type: 'severity', name: 'minor' },
{ id: 'PCIGMKW', post_enum_type: 'severity', name: 'degraded' },
],
};
const servicesResponse = {
services: [
{ id: 'PXQFSY1', name: 'Cross-Chain Bridging', display_name: 'Cross-Chain Bridging' },
{ id: 'PLT88AT', name: 'Solvers Network', display_name: 'Solvers Network' },
],
};
test('NEAR Intents status normalizer exposes current quoting disruption as upstream paused evidence', () => {
const normalized = normalizeNearIntentsStatus({
observedAt: '2026-04-16T12:40:00.000Z',
servicesResponse,
postEnumsResponse,
postsResponse: {
posts: [{
id: 'PM7LK6N',
title: '1Click Quoting is temporarily stopped',
post_type: 'incident',
latest_update: {
status_id: 'PSCS3IV',
severity_id: 'P187122',
reported_at: 1776342420000,
impacts: [{ service_id: 'PXQFSY1', severity_id: 'PCIGMKW' }],
message: '<p>The protocol is paused due to a security incident. Swaps are paused.</p>',
},
}],
},
});
assert.equal(normalized.source, 'near_intents_status_page');
assert.equal(normalized.status, 'disrupted');
assert.equal(normalized.label, 'upstream paused');
assert.equal(normalized.quoting_stopped, true);
assert.deepEqual(normalized.affected_services, ['Cross-Chain Bridging']);
assert.equal(normalized.current_incident_count, 1);
assert.equal(normalized.current_incidents[0].status, 'investigating');
assert.equal(normalized.current_incidents[0].severity, 'minor');
assert.equal(normalized.current_incidents[0].impacts[0].severity, 'degraded');
assert.match(normalized.decisive_reason, /1Click Quoting is temporarily stopped/);
assert.match(normalized.decisive_reason, /Swaps are paused/);
});
test('resolved NEAR Intents status posts do not make the relay look disrupted', () => {
const normalized = normalizeNearIntentsStatus({
observedAt: '2026-04-16T13:00:00.000Z',
servicesResponse,
postEnumsResponse,
postsResponse: {
posts: [{
id: 'PM7LK6N',
title: '1Click Quoting is temporarily stopped',
post_type: 'incident',
latest_update: {
status_id: 'P8TG2TF',
severity_id: 'P187122',
reported_at: 1776346020000,
impacts: [{ service_id: 'PXQFSY1', severity_id: 'PCIGMKW' }],
message: '<p>Resolved.</p>',
},
}],
},
});
assert.equal(normalized.status, 'operational');
assert.equal(normalized.label, 'operational');
assert.equal(normalized.quoting_stopped, false);
assert.equal(normalized.current_incident_count, 0);
assert.match(normalized.decisive_reason, /no active incident/i);
});
test('NEAR Intents status fingerprint is stable across polls and changes on official updates', () => {
const first = normalizeNearIntentsStatus({
observedAt: '2026-04-16T12:40:00.000Z',
servicesResponse,
postEnumsResponse,
postsResponse: {
posts: [{
id: 'PM7LK6N',
title: '1Click Quoting is temporarily stopped',
post_type: 'incident',
latest_update: {
status_id: 'PSCS3IV',
severity_id: 'P187122',
reported_at: 1776342420000,
impacts: [{ service_id: 'PXQFSY1', severity_id: 'PCIGMKW' }],
message: '<p>The protocol is paused.</p>',
},
}],
},
});
const samePollLater = normalizeNearIntentsStatus({
observedAt: '2026-04-16T12:41:00.000Z',
servicesResponse,
postEnumsResponse,
postsResponse: {
posts: [{
id: 'PM7LK6N',
title: '1Click Quoting is temporarily stopped',
post_type: 'incident',
latest_update: {
status_id: 'PSCS3IV',
severity_id: 'P187122',
reported_at: 1776342420000,
impacts: [{ service_id: 'PXQFSY1', severity_id: 'PCIGMKW' }],
message: '<p>The protocol is paused.</p>',
},
}],
},
});
const updatedOfficialMessage = normalizeNearIntentsStatus({
observedAt: '2026-04-16T12:42:00.000Z',
servicesResponse,
postEnumsResponse,
postsResponse: {
posts: [{
id: 'PM7LK6N',
title: '1Click Quoting is temporarily stopped',
post_type: 'incident',
latest_update: {
status_id: 'PSCS3IV',
severity_id: 'P187122',
reported_at: 1776346020000,
impacts: [{ service_id: 'PXQFSY1', severity_id: 'PCIGMKW' }],
message: '<p>The protocol remains paused for 12 hours.</p>',
},
}],
},
});
assert.equal(first.status_fingerprint, samePollLater.status_fingerprint);
assert.notEqual(first.status_fingerprint, updatedOfficialMessage.status_fingerprint);
const payload = buildNearIntentsStatusEventPayload(updatedOfficialMessage, {
changedAt: '2026-04-16T12:42:00.000Z',
previousFingerprint: first.status_fingerprint,
});
assert.equal(payload.status_fingerprint, updatedOfficialMessage.status_fingerprint);
assert.equal(payload.previous_status_fingerprint, first.status_fingerprint);
assert.match(payload.environment_status_id, /^near-intents-status-/);
});