aboutsummaryrefslogtreecommitdiffstats
path: root/tools/connect-relays-test.js
blob: f54407d0855d3a6f01f5afff5e2a27cb4d7dadbf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// The relays a nostrconnect:// link names: relay.coinos.io first, then the
// next live ones, three in all, leaving out any this device found dead.
// Run: bun tools/connect-relays-test.js
import { connectRelays } from '../src/nostr-login.js';
import { markRelaySick } from '../src/nostr.js';
let ok = true;
const check = (n, c, d = '') => { console.log(` ${c ? '✓' : '✗'} ${n}${d ? ' — ' + d : ''}`); if (!c) ok = false; };
const fresh = connectRelays();
check('three relays, ours first, primal second', fresh.length === 3 && fresh[0] === 'wss://relay.coinos.io' && fresh[1] === 'wss://relay.primal.net', fresh.join(' '));
check('nos.lol is no longer second', fresh[1] !== 'wss://nos.lol');
markRelaySick('wss://nos.lol', 'test');
const after = connectRelays();
check('a relay found dead is left out, the next one takes its place', !after.includes('wss://nos.lol') && after.includes('wss://offchain.pub') && after.length === 3, after.join(' '));
markRelaySick('wss://relay.primal.net', 'test'); markRelaySick('wss://offchain.pub', 'test');
const one = connectRelays();
check('relay.coinos.io stays whatever else is down', one[0] === 'wss://relay.coinos.io', one.join(' '));
console.log(ok ? '\n✅ connect links name live relays' : '\n❌ failed');
process.exit(ok ? 0 : 1);