unrip/test/config-assets.test.mjs
philipp 2ffa4b17f1
Some checks failed
deploy / deploy (push) Failing after 34s
Move trading config into Postgres
Proof: npm test passed 159/159; npm run operator-dashboard:build passed; repo-local Postgres importer smoke test imported 163 live 1Click tokens with only 3 inventory-enabled seed assets and nBTC/EURe pairs at 49 bps.

Assumptions: Forgejo main push is the repo deployment path; production has existing repo-managed POSTGRES_URL/POSTGRES_PASSWORD/NEAR_INTENTS_API_KEY secrets; startup seed may create initial current nBTC/EURe config but must preserve DB runtime pair flags after creation.

Still fake: no live funds movement was attempted; imported supported assets remain catalog-only unless explicitly enabled in DB; production rollout evidence still depends on the Forgejo deploy job completing after this push.
2026-05-12 21:34:58 +02:00

51 lines
1.9 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { loadConfig } from '../src/lib/config.mjs';
const ENV_KEYS = [
'NEAR_RPC_URL',
'TRADING_BTC_ASSET_ID',
'TRADING_BTC_TRACKED_ASSET_IDS',
'TRADING_BTC_LABEL',
'TRADING_EURE_ASSET_ID',
];
const NBTC = 'nep141:nbtc.bridge.near';
const LEGACY_BTC = 'nep141:btc.omft.near';
const EURE = 'nep141:gnosis-0x420ca0f9b9b604ce0fd9c18ef134c705e5fa3430.omft.near';
function withCleanEnv(fn) {
const previous = Object.fromEntries(ENV_KEYS.map((key) => [key, process.env[key]]));
for (const key of ENV_KEYS) delete process.env[key];
try {
return fn();
} finally {
for (const [key, value] of Object.entries(previous)) {
if (value == null) delete process.env[key];
else process.env[key] = value;
}
}
}
test('default config trades nBTC while still tracking legacy BTC', () => withCleanEnv(() => {
const config = loadConfig({ envPath: '/tmp/unrip-no-such-env-file' });
assert.equal(config.nearRpcUrl, 'https://near.lava.build');
assert.equal(config.tradingBtc.assetId, NBTC);
assert.deepEqual(config.activeAssetIds, [NBTC, EURE]);
assert.deepEqual(config.trackedAssetIds, [NBTC, LEGACY_BTC, EURE]);
assert.equal(config.assetRegistry.get(NBTC).label, 'BTC / nBTC reserve');
assert.equal(config.assetRegistry.get(LEGACY_BTC).label, 'BTC / legacy OMFT');
assert.equal(config.assetRegistry.get(LEGACY_BTC).role, 'legacy');
}));
test('legacy trading asset env overrides are ignored by runtime config', () => withCleanEnv(() => {
process.env.TRADING_BTC_ASSET_ID = 'nep141:wrong-btc.near';
process.env.TRADING_BTC_TRACKED_ASSET_IDS = LEGACY_BTC;
const config = loadConfig({ envPath: '/tmp/unrip-no-such-env-file' });
assert.deepEqual(config.tradingBtcAssets.map((asset) => asset.assetId), [NBTC, LEGACY_BTC]);
assert.deepEqual(config.activeAssetIds, [NBTC, EURE]);
}));