// Run in the image's njs (see deploy/README.md): // podman run --rm -v ./njs:/t:ro --entrypoint njs -p /t /t/fips.test.js import fips from 'fips.js'; const cases = [ // Known npub -> FIPS address pairs, read off real nodes' fips0 interfaces. ['npub1ttuu24hncq0l4gvyl26pc6aa94k442mnm5z2yrfmu55es5nd0ztsgkc96k.fips', 'fd86:64e0:74b1:5940:ade8:ad00:f722:e770'], ['npub10yffd020a4ag8zcy75f9pruq3rnghvvhd5hphl9s62zgp35s560qrksp9u.fips', 'fd68:9863:d40b:c5ec:4756:339f:39c0:aa1c'], ['npub1s6ktsdp2hptm55v49lpek07wp9ryqxxhhwaq2wl789h5rkzd5ycst3t5nu.fips', 'fd15:3972:ecdb:5b72:c039:855a:7fd6:781e'], // Bad checksum (last char changed), non-npub alias, empty. ['npub1ttuu24hncq0l4gvyl26pc6aa94k442mnm5z2yrfmu55es5nd0ztsgkc96q.fips', ''], ['podcasts.fips', ''], ['', ''], ]; const norm = (a) => (a ? a.split(':').map((g) => g.padStart(4, '0')).join(':') : ''); let failed = 0; for (let i = 0; i < cases.length; i++) { const got = fips.address({ variables: { fips_host: cases[i][0] } }); if (norm(got) !== norm(cases[i][1])) { failed++; console.log(`FAIL ${cases[i][0] || '(empty)'}: got ${JSON.stringify(got)}, want ${JSON.stringify(cases[i][1])}`); } } console.log(failed ? `${failed} of ${cases.length} failed` : `all ${cases.length} passed`); if (failed) throw new Error('fips.js tests failed');