Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it easier to swap nwaku for go-waku in tests #763

Merged
merged 9 commits into from
Aug 25, 2022
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,52 @@ jobs:
name: nwaku-logs
path: log/

node_with_go_waku:
runs-on: ubuntu-latest
env:
GO_WAKU_VERSION: "0.2.1"
WAKU_SERVICE_NODE_DIR: ./go-waku
WAKU_SERVICE_NODE_BIN: ./waku
WAKU_SERVICE_NODE_PARAMS: "--min-relay-peers-to-publish=0" # Can be removed once https://github.com/status-im/nwaku/issues/1004 is done
DEBUG: "waku*"
steps:
- uses: actions/checkout@v3

- name: Get go-waku
shell: bash
run: |
pwd
mkdir -p go-waku/
cd go-waku
wget "https://github.com/status-im/go-waku/releases/download/v${GO_WAKU_VERSION}/gowaku-${GO_WAKU_VERSION}-x86_64.deb"
sudo apt install ./gowaku-${GO_WAKU_VERSION}-x86_64.deb
cp $(which waku) ./

- name: Ensure go-waku is ready
shell: bash
run: |
uname -a
cd "${WAKU_SERVICE_NODE_DIR}"
"${WAKU_SERVICE_NODE_BIN}" --version

- name: Install NodeJS
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}

- uses: bahmutov/npm-install@v1

- run: npm run test:node
env:
DEBUG: "waku:nwaku*,waku:test*"

- name: Upload logs on failure
uses: actions/upload-artifact@v2
if: failure()
with:
name: go-waku-logs
path: log/

release_next:
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
Expand Down
10 changes: 9 additions & 1 deletion src/lib/peer_discovery_dns/dns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,15 @@ export class DnsNodeDiscovery {
this._errorTolerance,
() => this._search(domain, context)
);
dbg("retrieved peers: ", peers);
dbg(
"retrieved peers: ",
peers.map((peer) => {
return {
id: peer.peerId?.toString(),
multiaddrs: peer.multiaddrs?.map((ma) => ma.toString()),
};
})
);
return peers;
}

Expand Down
2 changes: 2 additions & 0 deletions src/lib/wait_for_remote_peer.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ describe("Wait for remote peer", function () {
relay: false,
lightpush: false,
filter: false,
persistMessages: true,
});
const multiAddrWithId = await nwaku.getMultiaddrWithId();

Expand All @@ -125,6 +126,7 @@ describe("Wait for remote peer", function () {
relay: false,
lightpush: false,
filter: false,
persistMessages: true,
});
const multiAddrWithId = await nwaku.getMultiaddrWithId();

Expand Down
9 changes: 8 additions & 1 deletion src/lib/waku_filter/index.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe("Waku Filter", () => {
});

beforeEach(async function () {
this.timeout(10000);
this.timeout(15000);
nwaku = new Nwaku(makeLogFileName(this));
await nwaku.start({ filter: true, lightpush: true });
waku = await createWaku({
Expand All @@ -46,6 +46,10 @@ describe("Waku Filter", () => {
expect(msg.payloadAsUtf8).to.eq(messageText);
};
await waku.filter.subscribe(callback, [TestContentTopic]);
// As the filter protocol does not cater for a ack of subscription
// we cannot know whether the subscription happened. Something we want to
// correct in future versions of the protocol.
await delay(200);
const message = await WakuMessage.fromUtf8String(
messageText,
TestContentTopic
Expand All @@ -66,6 +70,7 @@ describe("Waku Filter", () => {
expect(msg.contentTopic).to.eq(TestContentTopic);
};
await waku.filter.subscribe(callback, [TestContentTopic]);
await delay(200);
await waku.lightPush.push(
await WakuMessage.fromUtf8String("Filtering works!", TestContentTopic)
);
Expand All @@ -89,6 +94,7 @@ describe("Waku Filter", () => {
const unsubscribe = await waku.filter.subscribe(callback, [
TestContentTopic,
]);
await delay(200);
await waku.lightPush.push(
await WakuMessage.fromUtf8String(
"This should be received",
Expand All @@ -97,6 +103,7 @@ describe("Waku Filter", () => {
);
await delay(100);
await unsubscribe();
await delay(200);
await waku.lightPush.push(
await WakuMessage.fromUtf8String(
"This should not be received",
Expand Down
13 changes: 11 additions & 2 deletions src/test_utils/nwaku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { WakuMessage } from "../lib/waku_message";
import * as proto from "../proto/message";

import { existsAsync, mkdirAsync, openAsync } from "./async_fs";
import { delay } from "./delay";
import waitForLine from "./log_file";

const dbg = debug("waku:nwaku");
Expand Down Expand Up @@ -181,6 +182,7 @@ export class Nwaku {

dbg(`Waiting to see '${NODE_READY_LOG_LINE}' in nwaku logs`);
await this.waitForLog(NODE_READY_LOG_LINE, 15000);
if (process.env.CI) await delay(100);
dbg("nwaku node has been started");
}

Expand Down Expand Up @@ -249,12 +251,19 @@ export class Nwaku {
async getAsymmetricKeyPair(): Promise<KeyPair> {
this.checkProcess();

const { seckey, pubkey } = await this.rpcCall<{
const { privateKey, publicKey, seckey, pubkey } = await this.rpcCall<{
seckey: string;
pubkey: string;
privateKey: string;
publicKey: string;
}>("get_waku_v2_private_v1_asymmetric_keypair", []);

return { privateKey: seckey, publicKey: pubkey };
// To be removed once https://github.com/vacp2p/rfc/issues/507 is fixed
if (seckey) {
return { privateKey: seckey, publicKey: pubkey };
} else {
return { privateKey, publicKey };
}
}

async postAsymmetricMessage(
Expand Down