unrip/test/config-assets.test.mjs
philipp ab078d976a
Some checks failed
deploy / deploy (push) Failing after 37s
Track nBTC reserve and legacy BTC asset
Proof: npm test (138 passing); npm run operator-dashboard:build; git diff --cached --check.

Assumptions: Bridge deposits expose near_token_id/intents_token_id for credited asset attribution; nBTC is the solver trading reserve while btc.omft.near remains a tracked legacy BTC wrapper.

Still fake: No live asset migration was submitted; existing btc.omft.near balance is only tracked and withdrawable until a separately approved conversion or withdrawal is executed.
2026-05-07 16:06:26 +02:00

56 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',
'NEAR_INTENTS_PAIR_FILTER',
'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.nearIntentsPairFilter,
`${NBTC}->${EURE}`,
);
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('tracked BTC ids always include the configured trading BTC reserve', () => withCleanEnv(() => {
process.env.TRADING_BTC_ASSET_ID = NBTC;
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]);
}));