unrip/test/near-intents-status.test.mjs
philipp 5425152ed9
Some checks failed
deploy / deploy (push) Failing after 45s
Ignore scoped HOT bridge quoting incidents
Proof: npm test; npm run operator-dashboard:build; live NEAR Intents status-page payload normalizes to operational for tracked BTC/Gnosis assets while 1Click still returns a EURe-to-nBTC dry quote.

Assumptions: Generic partial quoting or bridge-maintenance wording is not enough to pause our BTC/Gnosis path unless the incident names a core Intents component, protocol-wide swap outage, or our tracked chains/assets.

Still fake: Status-page relevance is still text/service scoped because the upstream status API does not expose a per-asset machine-readable impact matrix.
2026-05-11 21:02:26 +02:00

255 lines
9.1 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' },
{ id: 'PNEJBRE', name: 'Other Blockchains', display_name: 'Other Blockchains' },
],
};
const trackedAssets = [
{
assetId: 'nep141:nbtc.bridge.near',
chain: 'btc:mainnet',
},
{
assetId: 'nep141:gnosis-0x420ca0f9b9b604ce0fd9c18ef134c705e5fa3430.omft.near',
chain: 'eth:100',
},
];
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('scoped NEAR Intents status ignores unrelated paused destination chains', () => {
const normalized = normalizeNearIntentsStatus({
observedAt: '2026-05-07T15:55:00.000Z',
servicesResponse,
postEnumsResponse,
trackedAssets,
postsResponse: {
posts: [{
id: 'PO2LXSS',
title: 'BSC, TON, XML destinations are temporarily paused',
post_type: 'incident',
latest_update: {
status_id: 'PSCS3IV',
severity_id: 'P187122',
reported_at: 1778165160000,
impacts: [{ service_id: 'PNEJBRE', severity_id: 'PCIGMKW' }],
message: '<p>HOT bridge is having a reliability incident. Full list of chains: BSC, MONAD, XLAYER, PLASMA, POL, TON, OP, AVAX, STELLAR, ADI</p>',
},
}],
},
});
assert.equal(normalized.status, 'operational');
assert.equal(normalized.label, 'operational');
assert.equal(normalized.current_incident_count, 0);
assert.equal(normalized.observed_incident_count, 1);
assert.equal(normalized.unrelated_incident_count, 1);
assert.equal(normalized.quoting_stopped, false);
assert.deepEqual(normalized.affected_services, []);
assert.deepEqual(normalized.observed_affected_services, ['Other Blockchains']);
assert.match(normalized.decisive_reason, /none match this deployment scope/);
assert.match(normalized.decisive_reason, /BSC, TON, XML/);
});
test('scoped NEAR Intents status ignores HOT-chain quoting and partial bridge maintenance incidents', () => {
const normalized = normalizeNearIntentsStatus({
observedAt: '2026-05-11T18:58:30.605Z',
servicesResponse,
postEnumsResponse,
trackedAssets,
postsResponse: {
posts: [
{
id: 'PIX3ZX5',
title: 'Quoting is temporarily paused for the HOT bridge chains',
post_type: 'incident',
latest_update: {
status_id: 'PSCS3IV',
severity_id: 'P187122',
reported_at: 1778510700000,
impacts: [{ service_id: 'PNEJBRE', severity_id: 'PCIGMKW' }],
message: '<p>This is the list of chains we rely on the Hot Bridge: BSC, MONAD, XLAYER, PLASMA, POL, TON, OP, AVAX, STELLAR, ADI</p>',
},
},
{
id: 'PJ0GZ74',
title: 'Bridge maintenance',
post_type: 'maintenance',
latest_update: {
status_id: 'PSCS3IV',
severity_id: 'P187122',
reported_at: 1778497153000,
impacts: [{ service_id: 'PXQFSY1', severity_id: 'PCIGMKW' }],
message: '<p>We will perform a bridge maintenance, some of the quoting will be temporarily disabled.</p>',
},
},
],
},
});
assert.equal(normalized.status, 'operational');
assert.equal(normalized.label, 'operational');
assert.equal(normalized.current_incident_count, 0);
assert.equal(normalized.observed_incident_count, 2);
assert.equal(normalized.unrelated_incident_count, 2);
assert.equal(normalized.quoting_stopped, false);
assert.deepEqual(normalized.affected_services, []);
assert.deepEqual(
normalized.observed_affected_services,
['Other Blockchains', 'Cross-Chain Bridging'],
);
assert.match(normalized.decisive_reason, /none match this deployment scope/);
assert.match(normalized.decisive_reason, /HOT bridge chains/);
});
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-/);
});