mirror of
https://github.com/waku-org/js-waku.git
synced 2025-01-27 12:45:21 +00:00
test: check both custom and default agents
This commit is contained in:
parent
1cfba385c9
commit
c7920f09f3
@ -1,5 +1,6 @@
|
|||||||
import type { PeerId } from "@libp2p/interface-peer-id";
|
import type { PeerId } from "@libp2p/interface-peer-id";
|
||||||
import { bytesToUtf8, utf8ToBytes } from "@waku/byte-utils";
|
import { bytesToUtf8, utf8ToBytes } from "@waku/byte-utils";
|
||||||
|
import { DefaultUserAgent } from "@waku/core";
|
||||||
import { PeerDiscoveryStaticPeers } from "@waku/core/lib/peer_discovery_static_list";
|
import { PeerDiscoveryStaticPeers } from "@waku/core/lib/peer_discovery_static_list";
|
||||||
import { waitForRemotePeer } from "@waku/core/lib/wait_for_remote_peer";
|
import { waitForRemotePeer } from "@waku/core/lib/wait_for_remote_peer";
|
||||||
import { createLightNode, createPrivacyNode } from "@waku/create";
|
import { createLightNode, createPrivacyNode } from "@waku/create";
|
||||||
@ -187,35 +188,47 @@ describe("Decryption Keys", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("User Agent", () => {
|
describe("User Agent", () => {
|
||||||
let waku: Waku;
|
let waku1: Waku;
|
||||||
let nwaku: Nwaku;
|
let waku2: Waku;
|
||||||
|
|
||||||
afterEach(async function () {
|
afterEach(async function () {
|
||||||
!!nwaku && nwaku.stop();
|
!!waku1 && waku1.stop().catch((e) => console.log("Waku failed to stop", e));
|
||||||
!!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e));
|
!!waku2 && waku2.stop().catch((e) => console.log("Waku failed to stop", e));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Sets default value correctly", async function () {
|
it("Sets default value correctly", async function () {
|
||||||
this.timeout(20_000);
|
this.timeout(20_000);
|
||||||
nwaku = new Nwaku(makeLogFileName(this));
|
|
||||||
await nwaku.start({
|
|
||||||
filter: true,
|
|
||||||
store: true,
|
|
||||||
lightpush: true,
|
|
||||||
});
|
|
||||||
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
|
||||||
|
|
||||||
waku = await createLightNode({
|
const waku1UserAgent = "test-user-agent";
|
||||||
staticNoiseKey: NOISE_KEY_1,
|
|
||||||
userAgent: "test-user-agent",
|
|
||||||
});
|
|
||||||
await waku.start();
|
|
||||||
await waku.dial(multiAddrWithId);
|
|
||||||
await waitForRemotePeer(waku);
|
|
||||||
|
|
||||||
const peerInfo = await waku.libp2p.peerStore.metadataBook.get(
|
[waku1, waku2] = await Promise.all([
|
||||||
waku.libp2p.peerId
|
createPrivacyNode({
|
||||||
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
|
userAgent: waku1UserAgent,
|
||||||
|
}).then((waku) => waku.start().then(() => waku)),
|
||||||
|
createPrivacyNode({
|
||||||
|
staticNoiseKey: NOISE_KEY_2,
|
||||||
|
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } },
|
||||||
|
}).then((waku) => waku.start().then(() => waku)),
|
||||||
|
]);
|
||||||
|
|
||||||
|
waku1.addPeerToAddressBook(
|
||||||
|
waku2.libp2p.peerId,
|
||||||
|
waku2.libp2p.getMultiaddrs()
|
||||||
|
);
|
||||||
|
await waku1.dial(waku2.libp2p.peerId);
|
||||||
|
await waitForRemotePeer(waku1);
|
||||||
|
|
||||||
|
const [waku1PeerInfo, waku2PeerInfo] = await Promise.all([
|
||||||
|
waku2.libp2p.peerStore.metadataBook.get(waku1.libp2p.peerId),
|
||||||
|
waku1.libp2p.peerStore.metadataBook.get(waku2.libp2p.peerId),
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(bytesToUtf8(waku1PeerInfo.get("AgentVersion")!)).to.eq(
|
||||||
|
waku1UserAgent
|
||||||
|
);
|
||||||
|
expect(bytesToUtf8(waku2PeerInfo.get("AgentVersion")!)).to.eq(
|
||||||
|
DefaultUserAgent
|
||||||
);
|
);
|
||||||
console.log(bytesToUtf8(peerInfo.get("AgentVersion")!));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user