mirror of
https://github.com/waku-org/js-waku.git
synced 2025-02-20 16:18:21 +00:00
test: Nim-waku connects to JS (success)
This commit is contained in:
parent
a6c1fae5a6
commit
057f5f80ab
43
package-lock.json
generated
43
package-lock.json
generated
@ -917,6 +917,12 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.12.0.tgz",
|
"resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.12.0.tgz",
|
||||||
"integrity": "sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA=="
|
"integrity": "sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA=="
|
||||||
},
|
},
|
||||||
|
"@types/tail": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/tail/-/tail-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-TYTfnILhrZUAZKGNgot5+sBDap7oPIzV3818p7g4VhKGc81+/eoEZ93wKBTGnSg/tpDjzWSb8Wx5E737FCH/Sw==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"@typescript-eslint/eslint-plugin": {
|
"@typescript-eslint/eslint-plugin": {
|
||||||
"version": "4.16.1",
|
"version": "4.16.1",
|
||||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.16.1.tgz",
|
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.16.1.tgz",
|
||||||
@ -9900,6 +9906,17 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"p-timeout": "^3.1.0"
|
"p-timeout": "^3.1.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"p-timeout": {
|
||||||
|
"version": "3.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-3.2.0.tgz",
|
||||||
|
"integrity": "sha512-rhIwUycgwwKcP9yTOOFK/AKsAopjjCakVqLHePO3CC6Mir1Z99xT+R63jZxAT5lFZLa2inS5h+ZS2GvR99/FBg==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"p-finally": "^1.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"p-fifo": {
|
"p-fifo": {
|
||||||
@ -9994,12 +10011,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"p-timeout": {
|
"p-timeout": {
|
||||||
"version": "3.2.0",
|
"version": "4.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-3.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-4.1.0.tgz",
|
||||||
"integrity": "sha512-rhIwUycgwwKcP9yTOOFK/AKsAopjjCakVqLHePO3CC6Mir1Z99xT+R63jZxAT5lFZLa2inS5h+ZS2GvR99/FBg==",
|
"integrity": "sha512-+/wmHtzJuWii1sXn3HCuH/FTwGhrp4tmJTxSKJbfS+vkipci6osxXM5mY0jUiRzWKMTgUT8l7HFbeSwZAynqHw==",
|
||||||
"requires": {
|
"dev": true
|
||||||
"p-finally": "^1.0.0"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"p-try": {
|
"p-try": {
|
||||||
"version": "2.2.0",
|
"version": "2.2.0",
|
||||||
@ -10012,6 +10027,16 @@
|
|||||||
"integrity": "sha512-wpgERjNkLrBiFmkMEjuZJEWKKDrNfHCKA1OhyN1wg1FrLkULbviEy6py1AyJUgZ72YWFbZ38FIpnqvVqAlDUwA==",
|
"integrity": "sha512-wpgERjNkLrBiFmkMEjuZJEWKKDrNfHCKA1OhyN1wg1FrLkULbviEy6py1AyJUgZ72YWFbZ38FIpnqvVqAlDUwA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"p-timeout": "^3.0.0"
|
"p-timeout": "^3.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"p-timeout": {
|
||||||
|
"version": "3.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-3.2.0.tgz",
|
||||||
|
"integrity": "sha512-rhIwUycgwwKcP9yTOOFK/AKsAopjjCakVqLHePO3CC6Mir1Z99xT+R63jZxAT5lFZLa2inS5h+ZS2GvR99/FBg==",
|
||||||
|
"requires": {
|
||||||
|
"p-finally": "^1.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"package-hash": {
|
"package-hash": {
|
||||||
@ -11919,6 +11944,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"tail": {
|
||||||
|
"version": "2.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/tail/-/tail-2.2.0.tgz",
|
||||||
|
"integrity": "sha512-QqUMtWlnzArTvGyjVnAE5fAiXEm2Psvk/BlE7vWx2/dIEWMsAhcNPz7iW6WTiSM8h1fjtCkRMsaWBS1j6rpGBg==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"teeny-request": {
|
"teeny-request": {
|
||||||
"version": "6.0.1",
|
"version": "6.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/teeny-request/-/teeny-request-6.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/teeny-request/-/teeny-request-6.0.1.tgz",
|
||||||
|
@ -61,6 +61,7 @@
|
|||||||
"@istanbuljs/nyc-config-typescript": "^1.0.1",
|
"@istanbuljs/nyc-config-typescript": "^1.0.1",
|
||||||
"@types/axios": "^0.14.0",
|
"@types/axios": "^0.14.0",
|
||||||
"@types/node": "^14.14.31",
|
"@types/node": "^14.14.31",
|
||||||
|
"@types/tail": "^2.0.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^4.0.1",
|
"@typescript-eslint/eslint-plugin": "^4.0.1",
|
||||||
"@typescript-eslint/parser": "^4.0.1",
|
"@typescript-eslint/parser": "^4.0.1",
|
||||||
"ava": "^3.15.0",
|
"ava": "^3.15.0",
|
||||||
@ -80,8 +81,10 @@
|
|||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
"nyc": "^15.1.0",
|
"nyc": "^15.1.0",
|
||||||
"open-cli": "^6.0.1",
|
"open-cli": "^6.0.1",
|
||||||
|
"p-timeout": "^4.1.0",
|
||||||
"prettier": "^2.1.1",
|
"prettier": "^2.1.1",
|
||||||
"standard-version": "^9.0.0",
|
"standard-version": "^9.0.0",
|
||||||
|
"tail": "^2.2.0",
|
||||||
"ts-node": "^9.0.0",
|
"ts-node": "^9.0.0",
|
||||||
"typedoc": "^0.20.29",
|
"typedoc": "^0.20.29",
|
||||||
"typescript": "^4.0.2"
|
"typescript": "^4.0.2"
|
||||||
|
53
src/test_utils/log_file.ts
Normal file
53
src/test_utils/log_file.ts
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import fs, { promises as asyncFs } from 'fs';
|
||||||
|
|
||||||
|
import pTimeout from 'p-timeout';
|
||||||
|
import { Tail } from 'tail';
|
||||||
|
|
||||||
|
import { delay } from './delay';
|
||||||
|
|
||||||
|
const existsAsync = (filepath: string) =>
|
||||||
|
asyncFs.access(filepath, fs.constants.F_OK);
|
||||||
|
|
||||||
|
async function waitForFile(path: string) {
|
||||||
|
let found = false;
|
||||||
|
do {
|
||||||
|
try {
|
||||||
|
await existsAsync(path);
|
||||||
|
found = true;
|
||||||
|
} catch (e) {
|
||||||
|
await delay(500);
|
||||||
|
}
|
||||||
|
} while (!found);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function waitForLine(filepath: string, logLine: string) {
|
||||||
|
await pTimeout(waitForFile(filepath), 2000);
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
fromBeginning: true,
|
||||||
|
follow: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
const tail = new Tail(filepath, options);
|
||||||
|
|
||||||
|
await pTimeout(
|
||||||
|
find(tail, logLine),
|
||||||
|
60000,
|
||||||
|
`could not to find '${logLine}' in file '${filepath}'`
|
||||||
|
);
|
||||||
|
tail.unwatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function find(tail: Tail, line: string) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
tail.on('line', (data: string) => {
|
||||||
|
if (data.includes(line)) {
|
||||||
|
resolve(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
tail.on('error', (err) => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -7,7 +7,7 @@ import Multiaddr from 'multiaddr';
|
|||||||
import multiaddr from 'multiaddr';
|
import multiaddr from 'multiaddr';
|
||||||
import PeerId from 'peer-id';
|
import PeerId from 'peer-id';
|
||||||
|
|
||||||
import { delay } from './delay';
|
import waitForLine from './log_file';
|
||||||
|
|
||||||
const openAsync = promisify(fs.open);
|
const openAsync = promisify(fs.open);
|
||||||
|
|
||||||
@ -35,7 +35,9 @@ export class NimWaku {
|
|||||||
// Start a local only node with the right RPC commands
|
// Start a local only node with the right RPC commands
|
||||||
// The fixed nodekey ensures the node has a fixed Peerid: 16Uiu2HAkyzsXzENw5XBDYEQQAeQTCYjBJpMLgBmEXuwbtcrgxBJ4
|
// The fixed nodekey ensures the node has a fixed Peerid: 16Uiu2HAkyzsXzENw5XBDYEQQAeQTCYjBJpMLgBmEXuwbtcrgxBJ4
|
||||||
|
|
||||||
const logFile = await openAsync('./nim-waku.log', 'w');
|
const logPath = './nim-waku.log';
|
||||||
|
|
||||||
|
const logFile = await openAsync(logPath, 'w');
|
||||||
|
|
||||||
const mergedArgs = argsToArray(mergeArguments(args));
|
const mergedArgs = argsToArray(mergeArguments(args));
|
||||||
console.log(mergedArgs);
|
console.log(mergedArgs);
|
||||||
@ -52,10 +54,9 @@ export class NimWaku {
|
|||||||
console.log(`ERROR: nim-waku node stopped: ${signal}`);
|
console.log(`ERROR: nim-waku node stopped: ${signal}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: Wait for line "RPC Server started "
|
await waitForLine(logPath, 'RPC Server started');
|
||||||
await delay(5000);
|
console.log('Nim waku RPC is started');
|
||||||
console.log(await this.info());
|
console.log(await this.info());
|
||||||
console.log('Nim waku is hopefully started');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Calls nim-waku2 JSON-RPC API `get_waku_v2_admin_v1_peers` to check
|
/** Calls nim-waku2 JSON-RPC API `get_waku_v2_admin_v1_peers` to check
|
||||||
|
Loading…
x
Reference in New Issue
Block a user