mirror of https://github.com/waku-org/js-waku.git
Merge pull request #1025 from waku-org/nwaku-v0.13.0
This commit is contained in:
commit
07e3a1ad69
|
@ -9,7 +9,7 @@ on:
|
|||
pull_request:
|
||||
|
||||
env:
|
||||
NWAKU_VERSION: "v0.11"
|
||||
NWAKU_VERSION: "v0.13.0"
|
||||
NODE_JS: "16"
|
||||
|
||||
jobs:
|
||||
|
|
2
nwaku
2
nwaku
|
@ -1 +1 @@
|
|||
Subproject commit fec13974836149c2b81cab8d4178dee7bfc56db1
|
||||
Subproject commit 9debd44e2aebf07eaf96b4525a4497c69aaf4445
|
|
@ -13,8 +13,8 @@ import { FilterCodec, WakuFilter } from "./waku_filter";
|
|||
import { LightPushCodec, WakuLightPush } from "./waku_light_push";
|
||||
import { EncoderV0 } from "./waku_message/version_0";
|
||||
import { WakuRelay } from "./waku_relay";
|
||||
import { RelayCodecs, RelayPingContentTopic } from "./waku_relay/constants";
|
||||
import * as relayConstants from "./waku_relay/constants";
|
||||
import { RelayCodecs, RelayPingContentTopic } from "./waku_relay/constants";
|
||||
import { StoreCodec, WakuStore } from "./waku_store";
|
||||
|
||||
export const DefaultPingKeepAliveValueSecs = 0;
|
||||
|
@ -109,13 +109,20 @@ export class WakuNode implements Waku {
|
|||
* Dials to the provided peer.
|
||||
*
|
||||
* @param peer The peer to dial
|
||||
* @param protocols Waku protocols we expect from the peer; Default to Relay
|
||||
* @param protocols Waku protocols we expect from the peer; Defaults to mounted protocols
|
||||
*/
|
||||
async dial(
|
||||
peer: PeerId | Multiaddr,
|
||||
protocols?: Protocols[]
|
||||
): Promise<Stream> {
|
||||
const _protocols = protocols ?? [Protocols.Relay];
|
||||
const _protocols = protocols ?? [];
|
||||
|
||||
if (typeof protocols === "undefined") {
|
||||
this.relay && _protocols.push(Protocols.Relay);
|
||||
this.store && _protocols.push(Protocols.Store);
|
||||
this.filter && _protocols.push(Protocols.Filter);
|
||||
this.lightPush && _protocols.push(Protocols.LightPush);
|
||||
}
|
||||
|
||||
const codecs: string[] = [];
|
||||
if (_protocols.includes(Protocols.Relay)) {
|
||||
|
@ -131,8 +138,6 @@ export class WakuNode implements Waku {
|
|||
codecs.push(FilterCodec);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: new Multiaddr is not backward compatible
|
||||
return this.libp2p.dialProtocol(peer, codecs);
|
||||
}
|
||||
|
||||
|
|
|
@ -227,8 +227,8 @@ export class WakuStore {
|
|||
);
|
||||
|
||||
log("Querying history with the following options", {
|
||||
peerId: options?.peerId?.toString(),
|
||||
...options,
|
||||
peerId: options?.peerId?.toString(),
|
||||
});
|
||||
|
||||
const res = await selectPeerForProtocol(
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
"check:spelling": "cspell \"{README.md,{tests,src}/**/*.ts}\"",
|
||||
"check:tsc": "tsc -p tsconfig.dev.json",
|
||||
"test": "run-s test:*",
|
||||
"test:node": "TS_NODE_PROJECT=./tsconfig.json mocha",
|
||||
"test:node": "TS_NODE_PROJECT=./tsconfig.dev.json mocha",
|
||||
"reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build"
|
||||
},
|
||||
"engines": {
|
||||
|
|
|
@ -44,10 +44,10 @@ export interface Args {
|
|||
nodekey?: string;
|
||||
portsShift?: number;
|
||||
logLevel?: LogLevel;
|
||||
persistMessages?: boolean;
|
||||
lightpush?: boolean;
|
||||
filter?: boolean;
|
||||
store?: boolean;
|
||||
storeMessageDbUrl?: string;
|
||||
topics?: string;
|
||||
rpcPrivate?: boolean;
|
||||
websocketSupport?: boolean;
|
||||
|
@ -407,7 +407,7 @@ export class Nwaku {
|
|||
headers: new Headers({ "Content-Type": "application/json" }),
|
||||
});
|
||||
const json = await res.json();
|
||||
log(`RPC Response: `, res, JSON.stringify(json));
|
||||
log(`RPC Response: `, JSON.stringify(json));
|
||||
return json.result;
|
||||
}
|
||||
|
||||
|
@ -423,7 +423,7 @@ export function argsToArray(args: Args): Array<string> {
|
|||
|
||||
for (const [key, value] of Object.entries(args)) {
|
||||
// Change the key from camelCase to kebab-case
|
||||
const kebabKey = key.replace(/([A-Z])/, (_, capital) => {
|
||||
const kebabKey = key.replace(/([A-Z])/g, (_, capital) => {
|
||||
return "-" + capital.toLowerCase();
|
||||
});
|
||||
|
||||
|
@ -442,6 +442,7 @@ export function defaultArgs(): Args {
|
|||
rpc: true,
|
||||
rpcAdmin: true,
|
||||
websocketSupport: true,
|
||||
storeMessageDbUrl: "sqlite://:memory:",
|
||||
logLevel: LogLevel.Debug,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ describe("nwaku", () => {
|
|||
"--rpc=true",
|
||||
"--rpc-admin=true",
|
||||
"--websocket-support=true",
|
||||
"--store-message-db-url=sqlite://:memory:",
|
||||
"--log-level=DEBUG",
|
||||
"--ports-shift=42",
|
||||
];
|
||||
|
|
|
@ -32,7 +32,7 @@ describe("Waku Store", () => {
|
|||
beforeEach(async function () {
|
||||
this.timeout(15_000);
|
||||
nwaku = new Nwaku(makeLogFileName(this));
|
||||
await nwaku.start({ persistMessages: true, store: true, lightpush: true });
|
||||
await nwaku.start({ store: true, lightpush: true });
|
||||
});
|
||||
|
||||
afterEach(async function () {
|
||||
|
@ -48,7 +48,7 @@ describe("Waku Store", () => {
|
|||
expect(
|
||||
await nwaku.sendMessage(
|
||||
Nwaku.toMessageRpcQuery({
|
||||
payload: utf8ToBytes(`Message ${i}`),
|
||||
payload: new Uint8Array([i]),
|
||||
contentTopic: TestContentTopic,
|
||||
})
|
||||
)
|
||||
|
@ -78,7 +78,7 @@ describe("Waku Store", () => {
|
|||
|
||||
expect(messages?.length).eq(totalMsgs);
|
||||
const result = messages?.findIndex((msg) => {
|
||||
return bytesToUtf8(msg.payload!) === "Message 0";
|
||||
return msg.payload![0]! === 0;
|
||||
});
|
||||
expect(result).to.not.eq(-1);
|
||||
});
|
||||
|
@ -119,7 +119,7 @@ describe("Waku Store", () => {
|
|||
expect(
|
||||
await nwaku.sendMessage(
|
||||
Nwaku.toMessageRpcQuery({
|
||||
payload: utf8ToBytes(`Message ${i}`),
|
||||
payload: new Uint8Array([i]),
|
||||
contentTopic: TestContentTopic,
|
||||
})
|
||||
)
|
||||
|
@ -146,7 +146,7 @@ describe("Waku Store", () => {
|
|||
|
||||
expect(messages?.length).eq(totalMsgs);
|
||||
const result = messages?.findIndex((msg) => {
|
||||
return bytesToUtf8(msg.payload!) === "Message 0";
|
||||
return msg.payload![0]! === 0;
|
||||
});
|
||||
expect(result).to.not.eq(-1);
|
||||
});
|
||||
|
@ -160,7 +160,7 @@ describe("Waku Store", () => {
|
|||
expect(
|
||||
await nwaku.sendMessage(
|
||||
Nwaku.toMessageRpcQuery({
|
||||
payload: utf8ToBytes(`Message ${i}`),
|
||||
payload: new Uint8Array([i]),
|
||||
contentTopic: TestContentTopic,
|
||||
})
|
||||
)
|
||||
|
@ -199,7 +199,7 @@ describe("Waku Store", () => {
|
|||
expect(
|
||||
await nwaku.sendMessage(
|
||||
Nwaku.toMessageRpcQuery({
|
||||
payload: utf8ToBytes(`Message ${i}`),
|
||||
payload: new Uint8Array([i]),
|
||||
contentTopic: TestContentTopic,
|
||||
})
|
||||
)
|
||||
|
@ -225,13 +225,8 @@ describe("Waku Store", () => {
|
|||
);
|
||||
|
||||
expect(messages?.length).eq(totalMsgs);
|
||||
for (let index = 0; index < totalMsgs; index++) {
|
||||
expect(
|
||||
messages?.findIndex((msg) => {
|
||||
return bytesToUtf8(msg.payload!) === `Message ${index}`;
|
||||
})
|
||||
).to.eq(index);
|
||||
}
|
||||
const payloads = messages.map((msg) => msg.payload![0]!);
|
||||
expect(payloads).to.deep.eq(Array.from(Array(totalMsgs).keys()));
|
||||
});
|
||||
|
||||
it("Ordered Callback - Backward", async function () {
|
||||
|
@ -242,7 +237,7 @@ describe("Waku Store", () => {
|
|||
expect(
|
||||
await nwaku.sendMessage(
|
||||
Nwaku.toMessageRpcQuery({
|
||||
payload: utf8ToBytes(`Message ${i}`),
|
||||
payload: new Uint8Array([i]),
|
||||
contentTopic: TestContentTopic,
|
||||
})
|
||||
)
|
||||
|
@ -270,13 +265,8 @@ describe("Waku Store", () => {
|
|||
messages = messages.reverse();
|
||||
|
||||
expect(messages?.length).eq(totalMsgs);
|
||||
for (let index = 0; index < totalMsgs; index++) {
|
||||
expect(
|
||||
messages?.findIndex((msg) => {
|
||||
return bytesToUtf8(msg.payload!) === `Message ${index}`;
|
||||
})
|
||||
).to.eq(index);
|
||||
}
|
||||
const payloads = messages.map((msg) => msg.payload![0]!);
|
||||
expect(payloads).to.deep.eq(Array.from(Array(totalMsgs).keys()));
|
||||
});
|
||||
|
||||
it("Generator, with asymmetric & symmetric encrypted messages", async function () {
|
||||
|
@ -385,27 +375,27 @@ describe("Waku Store", () => {
|
|||
const now = new Date();
|
||||
|
||||
const startTime = new Date();
|
||||
// Set start time 5 minutes in the past
|
||||
startTime.setTime(now.getTime() - 5 * 60 * 1000);
|
||||
// Set start time 15 seconds in the past
|
||||
startTime.setTime(now.getTime() - 15 * 1000);
|
||||
|
||||
const message1Timestamp = new Date();
|
||||
// Set first message was 4 minutes in the past
|
||||
message1Timestamp.setTime(now.getTime() - 4 * 60 * 1000);
|
||||
// Set first message was 10 seconds in the past
|
||||
message1Timestamp.setTime(now.getTime() - 10 * 1000);
|
||||
|
||||
const message2Timestamp = new Date();
|
||||
// Set second message 2 minutes in the past
|
||||
message2Timestamp.setTime(now.getTime() - 2 * 60 * 1000);
|
||||
// Set second message 2 seconds in the past
|
||||
message2Timestamp.setTime(now.getTime() - 2 * 1000);
|
||||
const messageTimestamps = [message1Timestamp, message2Timestamp];
|
||||
|
||||
const endTime = new Date();
|
||||
// Set end time 1 minute in the past
|
||||
endTime.setTime(now.getTime() - 60 * 1000);
|
||||
// Set end time 1 second in the past
|
||||
endTime.setTime(now.getTime() - 1000);
|
||||
|
||||
for (let i = 0; i < 2; i++) {
|
||||
expect(
|
||||
await nwaku.sendMessage(
|
||||
Nwaku.toMessageRpcQuery({
|
||||
payload: utf8ToBytes(`Message ${i}`),
|
||||
payload: new Uint8Array([i]),
|
||||
contentTopic: TestContentTopic,
|
||||
timestamp: messageTimestamps[i],
|
||||
})
|
||||
|
@ -453,7 +443,7 @@ describe("Waku Store", () => {
|
|||
|
||||
expect(firstMessages?.length).eq(1);
|
||||
|
||||
expect(bytesToUtf8(firstMessages[0].payload!)).eq("Message 0");
|
||||
expect(firstMessages[0].payload![0]!).eq(0);
|
||||
|
||||
expect(bothMessages?.length).eq(2);
|
||||
});
|
||||
|
@ -467,7 +457,7 @@ describe("Waku Store", () => {
|
|||
expect(
|
||||
await nwaku.sendMessage(
|
||||
Nwaku.toMessageRpcQuery({
|
||||
payload: utf8ToBytes(`Message ${i}`),
|
||||
payload: new Uint8Array([i]),
|
||||
contentTopic: TestContentTopic,
|
||||
})
|
||||
)
|
||||
|
@ -505,7 +495,6 @@ describe("Waku Store, custom pubsub topic", () => {
|
|||
this.timeout(15_000);
|
||||
nwaku = new Nwaku(makeLogFileName(this));
|
||||
await nwaku.start({
|
||||
persistMessages: true,
|
||||
store: true,
|
||||
topics: customPubSubTopic,
|
||||
});
|
||||
|
@ -524,7 +513,7 @@ describe("Waku Store, custom pubsub topic", () => {
|
|||
expect(
|
||||
await nwaku.sendMessage(
|
||||
Nwaku.toMessageRpcQuery({
|
||||
payload: utf8ToBytes(`Message ${i}`),
|
||||
payload: new Uint8Array([i]),
|
||||
contentTopic: TestContentTopic,
|
||||
}),
|
||||
customPubSubTopic
|
||||
|
@ -556,7 +545,7 @@ describe("Waku Store, custom pubsub topic", () => {
|
|||
|
||||
expect(messages?.length).eq(totalMsgs);
|
||||
const result = messages?.findIndex((msg) => {
|
||||
return bytesToUtf8(msg.payload!) === "Message 0";
|
||||
return msg.payload![0]! === 0;
|
||||
});
|
||||
expect(result).to.not.eq(-1);
|
||||
});
|
||||
|
|
|
@ -101,7 +101,6 @@ describe("Wait for remote peer", function () {
|
|||
relay: false,
|
||||
lightpush: false,
|
||||
filter: false,
|
||||
persistMessages: true,
|
||||
});
|
||||
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
||||
|
||||
|
@ -128,7 +127,6 @@ describe("Wait for remote peer", function () {
|
|||
relay: false,
|
||||
lightpush: false,
|
||||
filter: false,
|
||||
persistMessages: true,
|
||||
});
|
||||
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
||||
|
||||
|
@ -213,7 +211,6 @@ describe("Wait for remote peer", function () {
|
|||
lightpush: true,
|
||||
relay: false,
|
||||
store: true,
|
||||
persistMessages: true,
|
||||
});
|
||||
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@ describe("Waku Dial [node only]", function () {
|
|||
filter: true,
|
||||
store: true,
|
||||
lightpush: true,
|
||||
persistMessages: true,
|
||||
});
|
||||
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
||||
|
||||
|
|
Loading…
Reference in New Issue