doc: build first to avoid not found deps issues (#2307)

* doc: build first to avoid not found deps issues

* fix: Remove XMLHttpRequest usage

XMLHttpRequest API is deprecated and not available in browser extensions.

Replace the culprit dependency with a more modern one.

Some options are removed. The assumption is that nobody uses them. It can always be added if a developer wants the flexibility.

* test: simplify test

The test focus on testing DNS Discovery, there is no need to also have a nwaku local node for bootstrap.

Bootstrap on nwaku local node is used in many other tests.
This commit is contained in:
fryorcraken 2025-03-19 19:43:41 +11:00 committed by GitHub
parent c315b363c5
commit edfb56243d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 36 additions and 142 deletions

View File

@ -22,6 +22,8 @@ To build and test this repository, you need:
- [Node.js & npm](https://nodejs.org/en/). - [Node.js & npm](https://nodejs.org/en/).
- Chrome (for browser testing). - Chrome (for browser testing).
Run `npm run build` at least once so that intra-dependencies are resolved.
To ensure interoperability with [nim-waku](https://github.com/status-im/nim-waku/), some tests are run against a nim-waku node. To ensure interoperability with [nim-waku](https://github.com/status-im/nim-waku/), some tests are run against a nim-waku node.
This is why the relevant docker images for the node is pulled as part of the `pretest` script that runs before `npm run test`. This is why the relevant docker images for the node is pulled as part of the `pretest` script that runs before `npm run test`.

105
package-lock.json generated
View File

@ -6344,41 +6344,6 @@
"node": ">=v12.0.0" "node": ">=v12.0.0"
} }
}, },
"node_modules/@leichtgewicht/base64-codec": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@leichtgewicht/base64-codec/-/base64-codec-1.0.0.tgz",
"integrity": "sha512-0cgP4lRBzh3F4tlpTfs7F+PJyBN8j5yUC9KrQFWp/bREswgzZVHE8T1rNyRDWgvALwwpPtnJDQfqWUmxI33Epg==",
"license": "MIT"
},
"node_modules/@leichtgewicht/dns-packet": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/@leichtgewicht/dns-packet/-/dns-packet-6.0.3.tgz",
"integrity": "sha512-qmVHhFBFiBvPsk/wJ/EdoWHb+tGkzY4haybmDPukhF6w0+8wpEbrHTIRE9LzeUu2P0bAbmrK8WOXt5V5QN6jQg==",
"license": "MIT",
"dependencies": {
"@leichtgewicht/ip-codec": "^2.0.4",
"bytes.js": "^0.0.2",
"utf8-bytes": "^0.0.1",
"utf8-codec": "^1.0.0",
"utf8-length": "^0.0.1",
"utf8-string-bytes": "^1.0.3"
},
"engines": {
"node": ">=6"
}
},
"node_modules/@leichtgewicht/dns-socket": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/@leichtgewicht/dns-socket/-/dns-socket-5.0.0.tgz",
"integrity": "sha512-Sbrn/OG0HTTPGSkwIDCHy8/tUI6UglIzFsMNjzZn/Na1/i5owSm6rVi9CfKNNjRcUlYEzICELYW6EoZdjwVY2A==",
"license": "MIT",
"dependencies": {
"@leichtgewicht/dns-packet": "^6.0.0"
},
"engines": {
"node": ">=6"
}
},
"node_modules/@leichtgewicht/ip-codec": { "node_modules/@leichtgewicht/ip-codec": {
"version": "2.0.5", "version": "2.0.5",
"resolved": "https://registry.npmjs.org/@leichtgewicht/ip-codec/-/ip-codec-2.0.5.tgz", "resolved": "https://registry.npmjs.org/@leichtgewicht/ip-codec/-/ip-codec-2.0.5.tgz",
@ -14168,12 +14133,6 @@
"node": ">= 0.8" "node": ">= 0.8"
} }
}, },
"node_modules/bytes.js": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/bytes.js/-/bytes.js-0.0.2.tgz",
"integrity": "sha512-KrLm4hv5Qs9w6b0U7h1bCdqxrsf+e9QMsfHeyQFzAz94x/5Aqa+FTEUSNBtt5d2VuV3Hfiea3c4ti74RZDDYkg==",
"license": "MIT"
},
"node_modules/c8": { "node_modules/c8": {
"version": "10.1.3", "version": "10.1.3",
"resolved": "https://registry.npmjs.org/c8/-/c8-10.1.3.tgz", "resolved": "https://registry.npmjs.org/c8/-/c8-10.1.3.tgz",
@ -17094,6 +17053,28 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/dns-over-http-resolver": {
"version": "3.0.8",
"resolved": "https://registry.npmjs.org/dns-over-http-resolver/-/dns-over-http-resolver-3.0.8.tgz",
"integrity": "sha512-ng8JaOf34kdLE9Ni8U8rxHrrHtNKKBzW4oC1Zv68EmNnmt6SIYOahI3ZWYvD+N/9dQfCHlMivHQrCxhjAKWlnA==",
"license": "Apache-2.0 OR MIT",
"dependencies": {
"quick-lru": "^7.0.0",
"weald": "^1.0.2"
}
},
"node_modules/dns-over-http-resolver/node_modules/quick-lru": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-7.0.0.tgz",
"integrity": "sha512-MX8gB7cVYTrYcFfAnfLlhRd0+Toyl8yX8uBx1MrX7K0jegiz9TumwOK27ldXrgDlHRdVi+MqU9Ssw6dr4BNreg==",
"license": "MIT",
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/dns-packet": { "node_modules/dns-packet": {
"version": "5.6.1", "version": "5.6.1",
"resolved": "https://registry.npmjs.org/dns-packet/-/dns-packet-5.6.1.tgz", "resolved": "https://registry.npmjs.org/dns-packet/-/dns-packet-5.6.1.tgz",
@ -17106,22 +17087,6 @@
"node": ">=6" "node": ">=6"
} }
}, },
"node_modules/dns-query": {
"version": "0.11.2",
"resolved": "https://registry.npmjs.org/dns-query/-/dns-query-0.11.2.tgz",
"integrity": "sha512-zF8qxQpqCB467o4A63DLpQClo77H642JEKMx0Ra9GFww7Rx0234Fo8NoG0LBoSBZxamWkXfLxhzDG19bTBHvXQ==",
"license": "MIT",
"dependencies": {
"@leichtgewicht/base64-codec": "^1.0.0",
"@leichtgewicht/dns-packet": "^6.0.2",
"@leichtgewicht/dns-socket": "^5.0.0",
"@leichtgewicht/ip-codec": "^2.0.4",
"utf8-codec": "^1.0.0"
},
"bin": {
"dns-query": "bin/dns-query"
}
},
"node_modules/docker-modem": { "node_modules/docker-modem": {
"version": "5.0.6", "version": "5.0.6",
"resolved": "https://registry.npmjs.org/docker-modem/-/docker-modem-5.0.6.tgz", "resolved": "https://registry.npmjs.org/docker-modem/-/docker-modem-5.0.6.tgz",
@ -40957,30 +40922,6 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/utf8-bytes": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/utf8-bytes/-/utf8-bytes-0.0.1.tgz",
"integrity": "sha512-GifWmJAx2qAXT+lZLhbkWhBsy7pr6xWHiPWlVToDiELdWgZwt4Ogjf9tlgvKuALzTFR/d+EPQQI9ogJV3957Jg==",
"license": "MIT"
},
"node_modules/utf8-codec": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/utf8-codec/-/utf8-codec-1.0.0.tgz",
"integrity": "sha512-S/QSLezp3qvG4ld5PUfXiH7mCFxLKjSVZRFkB3DOjgwHuJPFDkInAXc/anf7BAbHt/D38ozDzL+QMZ6/7gsI6w==",
"license": "MIT"
},
"node_modules/utf8-length": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/utf8-length/-/utf8-length-0.0.1.tgz",
"integrity": "sha512-j/XH2ftofBiobnyApxlN/J6j/ixwT89WEjDcjT66d2i0+GIn9RZfzt8lpEXXE4jUe4NsjBSUq70kS2euQ4nnMw==",
"license": "MIT"
},
"node_modules/utf8-string-bytes": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/utf8-string-bytes/-/utf8-string-bytes-1.0.3.tgz",
"integrity": "sha512-i/I1Omf6lADjVBlwJpQifZOePV15snHny9w04+lc71+3t8PyWuLC/7clyoOSHOBNGXFe2PAGxmTiZ+Z4HWsPyw==",
"license": "Apache-2.0"
},
"node_modules/util": { "node_modules/util": {
"version": "0.10.4", "version": "0.10.4",
"resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz", "resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz",
@ -42119,7 +42060,7 @@
"@waku/proto": "^0.0.8", "@waku/proto": "^0.0.8",
"@waku/utils": "0.0.21", "@waku/utils": "0.0.21",
"debug": "^4.3.4", "debug": "^4.3.4",
"dns-query": "^0.11.2", "dns-over-http-resolver": "^3.0.8",
"hi-base32": "^0.5.1", "hi-base32": "^0.5.1",
"uint8arrays": "^5.0.1" "uint8arrays": "^5.0.1"
}, },

View File

@ -51,13 +51,13 @@
"node": ">=20" "node": ">=20"
}, },
"dependencies": { "dependencies": {
"@waku/core": "0.0.33",
"@waku/enr": "0.0.27",
"@waku/interfaces": "0.0.28", "@waku/interfaces": "0.0.28",
"@waku/proto": "^0.0.8", "@waku/proto": "^0.0.8",
"@waku/enr": "0.0.27",
"@waku/core": "0.0.33",
"@waku/utils": "0.0.21", "@waku/utils": "0.0.21",
"debug": "^4.3.4", "debug": "^4.3.4",
"dns-query": "^0.11.2", "dns-over-http-resolver": "^3.0.8",
"hi-base32": "^0.5.1", "hi-base32": "^0.5.1",
"uint8arrays": "^5.0.1" "uint8arrays": "^5.0.1"
}, },

View File

@ -1,7 +1,7 @@
import type { DnsClient } from "@waku/interfaces"; import type { DnsClient } from "@waku/interfaces";
import { Logger } from "@waku/utils"; import { Logger } from "@waku/utils";
import { bytesToUtf8 } from "@waku/utils/bytes"; import { bytesToUtf8 } from "@waku/utils/bytes";
import { Endpoint, query, wellknown } from "dns-query"; import DnsOverHttpResolver from "dns-over-http-resolver";
const log = new Logger("dns-over-https"); const log = new Logger("dns-over-https");
@ -9,25 +9,13 @@ export class DnsOverHttps implements DnsClient {
/** /**
* Create new Dns-Over-Http DNS client. * Create new Dns-Over-Http DNS client.
* *
* @param endpoints The endpoints for Dns-Over-Https queries;
* Defaults to using dns-query's API..
* @param retries Retries if a given endpoint fails.
*
* @throws {code: string} If DNS query fails. * @throws {code: string} If DNS query fails.
*/ */
public static async create( public static async create(): Promise<DnsOverHttps> {
endpoints?: Endpoint[], return new DnsOverHttps();
retries?: number
): Promise<DnsOverHttps> {
const _endpoints = endpoints ?? (await wellknown.endpoints("doh"));
return new DnsOverHttps(_endpoints, retries);
} }
private constructor( private constructor(private resolver = new DnsOverHttpResolver()) {}
private endpoints: Endpoint[],
private retries: number = 3
) {}
/** /**
* Resolves a TXT record * Resolves a TXT record
@ -39,16 +27,7 @@ export class DnsOverHttps implements DnsClient {
public async resolveTXT(domain: string): Promise<string[]> { public async resolveTXT(domain: string): Promise<string[]> {
let answers; let answers;
try { try {
const res = await query( answers = await this.resolver.resolveTxt(domain);
{
question: { type: "TXT", name: domain }
},
{
endpoints: this.endpoints,
retries: this.retries
}
);
answers = res.answers;
} catch (error) { } catch (error) {
log.error("query failed: ", error); log.error("query failed: ", error);
throw new Error("DNS query failed"); throw new Error("DNS query failed");
@ -56,13 +35,9 @@ export class DnsOverHttps implements DnsClient {
if (!answers) throw new Error(`Could not resolve ${domain}`); if (!answers) throw new Error(`Could not resolve ${domain}`);
const data = answers.map((a) => a.data) as
| Array<string | Uint8Array>
| Array<Array<string | Uint8Array>>;
const result: string[] = []; const result: string[] = [];
data.forEach((d) => { answers.forEach((d) => {
if (typeof d === "string") { if (typeof d === "string") {
result.push(d); result.push(d);
} else if (Array.isArray(d)) { } else if (Array.isArray(d)) {

View File

@ -1,31 +1,14 @@
import { bootstrap } from "@libp2p/bootstrap";
import { enrTree, wakuDnsDiscovery } from "@waku/discovery"; import { enrTree, wakuDnsDiscovery } from "@waku/discovery";
import { LightNode } from "@waku/interfaces"; import { LightNode } from "@waku/interfaces";
import { createLightNode } from "@waku/sdk"; import { createLightNode } from "@waku/sdk";
import { expect } from "chai"; import { expect } from "chai";
import {
afterEachCustom,
makeLogFileName,
ServiceNode,
tearDownNodes
} from "../src/index.js";
describe("Use static and several ENR trees for bootstrap", function () { describe("Use static and several ENR trees for bootstrap", function () {
let waku: LightNode; let waku: LightNode;
let nwaku: ServiceNode;
afterEachCustom(this, async () => {
await tearDownNodes(nwaku, waku);
});
it("", async function () { it("", async function () {
this.timeout(10_000); this.timeout(10_000);
nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start();
const multiAddrWithId = await nwaku.getMultiaddrWithId();
const NODE_REQUIREMENTS = { const NODE_REQUIREMENTS = {
store: 3, store: 3,
lightPush: 3, lightPush: 3,
@ -35,7 +18,6 @@ describe("Use static and several ENR trees for bootstrap", function () {
waku = await createLightNode({ waku = await createLightNode({
libp2p: { libp2p: {
peerDiscovery: [ peerDiscovery: [
bootstrap({ list: [multiAddrWithId.toString()] }),
wakuDnsDiscovery( wakuDnsDiscovery(
[enrTree["SANDBOX"], enrTree["TEST"]], [enrTree["SANDBOX"], enrTree["TEST"]],
NODE_REQUIREMENTS NODE_REQUIREMENTS
@ -47,13 +29,7 @@ describe("Use static and several ENR trees for bootstrap", function () {
const peersDiscovered = await waku.libp2p.peerStore.all(); const peersDiscovered = await waku.libp2p.peerStore.all();
// 3 from DNS Disc, 1 from bootstrap // 3 from DNS Disc
expect(peersDiscovered.length).to.eq(3 + 1); expect(peersDiscovered.length).to.eq(3);
// should also have the bootstrap peer
expect(
peersDiscovered.find(
(p) => p.id.toString() === multiAddrWithId.getPeerId()?.toString()
)
).to.not.be.undefined;
}); });
}); });