mirror of https://github.com/waku-org/js-waku.git
Merge pull request #230 from status-im/karma
This commit is contained in:
commit
75fce5eed3
|
@ -0,0 +1,32 @@
|
||||||
|
process.env.CHROME_BIN = require('puppeteer').executablePath();
|
||||||
|
|
||||||
|
module.exports = function (config) {
|
||||||
|
config.set({
|
||||||
|
frameworks: ['mocha', 'karma-typescript'],
|
||||||
|
files: [
|
||||||
|
'src/lib/**/*.ts',
|
||||||
|
'src/proto/**/*.ts',
|
||||||
|
'src/tests/browser/*.spec.ts',
|
||||||
|
],
|
||||||
|
preprocessors: {
|
||||||
|
'**/*.ts': ['karma-typescript'],
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
require('karma-mocha'),
|
||||||
|
require('karma-typescript'),
|
||||||
|
require('karma-chrome-launcher'),
|
||||||
|
],
|
||||||
|
reporters: ['progress', 'karma-typescript'],
|
||||||
|
browsers: ['ChromeHeadless'],
|
||||||
|
singleRun: true,
|
||||||
|
karmaTypescriptConfig: {
|
||||||
|
bundlerOptions: {
|
||||||
|
entrypoints: /src\/tests\/browser\/.*\.spec\.ts$/,
|
||||||
|
},
|
||||||
|
tsconfig: './tsconfig.karma.json',
|
||||||
|
coverageOptions: {
|
||||||
|
instrumentation: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
|
@ -18,7 +18,7 @@
|
||||||
"build:module": "tsc -p tsconfig.module.json",
|
"build:module": "tsc -p tsconfig.module.json",
|
||||||
"build:dev": "tsc -p tsconfig.dev.json",
|
"build:dev": "tsc -p tsconfig.dev.json",
|
||||||
"fix": "run-s fix:*",
|
"fix": "run-s fix:*",
|
||||||
"fix:prettier": "prettier \"src/**/*.ts\" \"./*.json\" --write",
|
"fix:prettier": "prettier \"src/**/*.ts\" \"./*.json\" \"*.conf.js\" --write",
|
||||||
"fix:lint": "eslint src --ext .ts --fix",
|
"fix:lint": "eslint src --ext .ts --fix",
|
||||||
"pretest": "run-s pretest:*",
|
"pretest": "run-s pretest:*",
|
||||||
"pretest:1-init-git-submodules": "[ -f './nim-waku/build/wakunode2' ] || git submodule update --init --recursive",
|
"pretest:1-init-git-submodules": "[ -f './nim-waku/build/wakunode2' ] || git submodule update --init --recursive",
|
||||||
|
@ -27,9 +27,10 @@
|
||||||
"nim-waku:force-build": "(cd nim-waku && rm -rf ./build/ ./vendor && make -j$(nproc --all 2>/dev/null || echo 2) update) && run-s nim-waku:build",
|
"nim-waku:force-build": "(cd nim-waku && rm -rf ./build/ ./vendor && make -j$(nproc --all 2>/dev/null || echo 2) update) && run-s nim-waku:build",
|
||||||
"test": "run-s build test:*",
|
"test": "run-s build test:*",
|
||||||
"test:lint": "eslint src --ext .ts",
|
"test:lint": "eslint src --ext .ts",
|
||||||
"test:prettier": "prettier \"src/**/*.ts\" \"./*.json\" --list-different",
|
"test:prettier": "prettier \"src/**/*.ts\" \"./*.json\" \"*.conf.js\" --list-different",
|
||||||
"test:spelling": "cspell \"{README.md,.github/*.md,src/**/*.ts}\"",
|
"test:spelling": "cspell \"{README.md,.github/*.md,src/**/*.ts}\"",
|
||||||
"test:unit": "nyc --silent mocha",
|
"test:unit": "nyc --silent mocha",
|
||||||
|
"test:karma": "karma start",
|
||||||
"proto": "run-s proto:*",
|
"proto": "run-s proto:*",
|
||||||
"proto:lint": "buf lint",
|
"proto:lint": "buf lint",
|
||||||
"proto:build": "buf generate",
|
"proto:build": "buf generate",
|
||||||
|
@ -97,12 +98,17 @@
|
||||||
"eslint-plugin-import": "^2.22.0",
|
"eslint-plugin-import": "^2.22.0",
|
||||||
"fast-check": "^2.14.0",
|
"fast-check": "^2.14.0",
|
||||||
"gh-pages": "^3.1.0",
|
"gh-pages": "^3.1.0",
|
||||||
|
"karma": "^6.3.4",
|
||||||
|
"karma-chrome-launcher": "^3.1.0",
|
||||||
|
"karma-mocha": "^2.0.1",
|
||||||
|
"karma-typescript": "^5.5.1",
|
||||||
"mocha": "^8.3.2",
|
"mocha": "^8.3.2",
|
||||||
"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",
|
"p-timeout": "^4.1.0",
|
||||||
"prettier": "^2.1.1",
|
"prettier": "^2.1.1",
|
||||||
|
"puppeteer": "^10.1.0",
|
||||||
"standard-version": "^9.0.0",
|
"standard-version": "^9.0.0",
|
||||||
"tail": "^2.2.0",
|
"tail": "^2.2.0",
|
||||||
"ts-node": "^9.1.1",
|
"ts-node": "^9.1.1",
|
||||||
|
|
|
@ -1,39 +1,14 @@
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore: No types available
|
||||||
import TCP from 'libp2p-tcp';
|
import TCP from 'libp2p-tcp';
|
||||||
|
|
||||||
import {
|
import { makeLogFileName, NimWaku, NOISE_KEY_1 } from '../test_utils/';
|
||||||
makeLogFileName,
|
|
||||||
NimWaku,
|
|
||||||
NOISE_KEY_1,
|
|
||||||
NOISE_KEY_2,
|
|
||||||
} from '../test_utils/';
|
|
||||||
|
|
||||||
import { Waku } from './waku';
|
import { Waku } from './waku';
|
||||||
import { RelayCodec } from './waku_relay';
|
import { RelayCodec } from './waku_relay';
|
||||||
|
|
||||||
describe('Waku Dial', function () {
|
describe('Waku Dial', function () {
|
||||||
it('js connects to js', async function () {
|
|
||||||
this.timeout(10_000);
|
|
||||||
const [waku1, waku2] = await Promise.all([
|
|
||||||
Waku.create({
|
|
||||||
staticNoiseKey: NOISE_KEY_1,
|
|
||||||
libp2p: { addresses: { listen: ['/ip4/0.0.0.0/tcp/0/ws'] } },
|
|
||||||
}),
|
|
||||||
Waku.create({ staticNoiseKey: NOISE_KEY_2 }),
|
|
||||||
]);
|
|
||||||
const waku1MultiAddrWithId = waku1.getLocalMultiaddrWithID();
|
|
||||||
|
|
||||||
await waku2.dial(waku1MultiAddrWithId);
|
|
||||||
|
|
||||||
const waku2PeerId = waku2.libp2p.peerId;
|
|
||||||
|
|
||||||
const waku1Peers = waku1.libp2p.peerStore.peers;
|
|
||||||
|
|
||||||
expect(waku1Peers.has(waku2PeerId.toB58String())).to.be.true;
|
|
||||||
|
|
||||||
await Promise.all([waku1.stop(), waku2.stop()]);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Interop: Nim', function () {
|
describe('Interop: Nim', function () {
|
||||||
it('nim connects to js', async function () {
|
it('nim connects to js', async function () {
|
||||||
this.timeout(10_000);
|
this.timeout(10_000);
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
import Libp2p, { Connection, Libp2pModules, Libp2pOptions } from 'libp2p';
|
import Libp2p, { Connection, Libp2pModules, Libp2pOptions } from 'libp2p';
|
||||||
|
import { MuxedStream } from 'libp2p-interfaces/dist/src/stream-muxer/types';
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore: No types available
|
||||||
import Mplex from 'libp2p-mplex';
|
import Mplex from 'libp2p-mplex';
|
||||||
import { bytes } from 'libp2p-noise/dist/src/@types/basic';
|
import { bytes } from 'libp2p-noise/dist/src/@types/basic';
|
||||||
import { Noise } from 'libp2p-noise/dist/src/noise';
|
import { Noise } from 'libp2p-noise/dist/src/noise';
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore: No types available
|
||||||
import Websockets from 'libp2p-websockets';
|
import Websockets from 'libp2p-websockets';
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore: No types available
|
||||||
import filters from 'libp2p-websockets/src/filters';
|
import filters from 'libp2p-websockets/src/filters';
|
||||||
import Ping from 'libp2p/src/ping';
|
import Ping from 'libp2p/src/ping';
|
||||||
import { Multiaddr, multiaddr } from 'multiaddr';
|
import { Multiaddr, multiaddr } from 'multiaddr';
|
||||||
|
@ -160,7 +167,7 @@ export class Waku {
|
||||||
* @param peer The peer to dial
|
* @param peer The peer to dial
|
||||||
*/
|
*/
|
||||||
async dial(peer: PeerId | Multiaddr | string): Promise<{
|
async dial(peer: PeerId | Multiaddr | string): Promise<{
|
||||||
stream: import('libp2p-interfaces/src/stream-muxer/types').MuxedStream;
|
stream: MuxedStream;
|
||||||
protocol: string;
|
protocol: string;
|
||||||
}> {
|
}> {
|
||||||
return this.libp2p.dialProtocol(peer, [RelayCodec, StoreCodec]);
|
return this.libp2p.dialProtocol(peer, [RelayCodec, StoreCodec]);
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore: No types available
|
||||||
import TCP from 'libp2p-tcp';
|
import TCP from 'libp2p-tcp';
|
||||||
|
|
||||||
import { makeLogFileName, NimWaku, NOISE_KEY_1 } from '../../test_utils';
|
import { makeLogFileName, NimWaku, NOISE_KEY_1 } from '../../test_utils';
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import debug from 'debug';
|
import debug from 'debug';
|
||||||
import fc from 'fast-check';
|
import fc from 'fast-check';
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore: No types available
|
||||||
import TCP from 'libp2p-tcp';
|
import TCP from 'libp2p-tcp';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import debug from 'debug';
|
import debug from 'debug';
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore: No types available
|
||||||
import TCP from 'libp2p-tcp';
|
import TCP from 'libp2p-tcp';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import debug from 'debug';
|
import debug from 'debug';
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore: No types available
|
||||||
import TCP from 'libp2p-tcp';
|
import TCP from 'libp2p-tcp';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
|
|
@ -6,4 +6,4 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const NOISE_KEY_1 = Buffer.alloc(32, 1);
|
export const NOISE_KEY_1 = Buffer.alloc(32, 1);
|
||||||
export const NOISE_KEY_2 = Buffer.alloc(32, 1);
|
export const NOISE_KEY_2 = Buffer.alloc(32, 2);
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
import { expect } from 'chai';
|
||||||
|
import fc from 'fast-check';
|
||||||
|
|
||||||
|
import {
|
||||||
|
clearDecode,
|
||||||
|
clearEncode,
|
||||||
|
decryptAsymmetric,
|
||||||
|
encryptAsymmetric,
|
||||||
|
getPublicKey,
|
||||||
|
} from '../../lib/waku_message/version_1';
|
||||||
|
|
||||||
|
describe('Waku Message Version 1', function () {
|
||||||
|
it('Sign & Recover', function () {
|
||||||
|
fc.assert(
|
||||||
|
fc.property(
|
||||||
|
fc.uint8Array(),
|
||||||
|
fc.uint8Array({ minLength: 32, maxLength: 32 }),
|
||||||
|
(message, privKey) => {
|
||||||
|
const enc = clearEncode(message, privKey);
|
||||||
|
const res = clearDecode(enc.payload);
|
||||||
|
|
||||||
|
const pubKey = getPublicKey(privKey);
|
||||||
|
|
||||||
|
expect(res?.payload).deep.equal(
|
||||||
|
message,
|
||||||
|
'Payload was not encrypted then decrypted correctly'
|
||||||
|
);
|
||||||
|
expect(res?.sig?.publicKey).deep.equal(
|
||||||
|
pubKey,
|
||||||
|
'signature Public key was not recovered from encrypted then decrypted signature'
|
||||||
|
);
|
||||||
|
expect(enc?.sig?.publicKey).deep.equal(
|
||||||
|
pubKey,
|
||||||
|
'Incorrect signature public key was returned when signing the payload'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Asymmetric encrypt & Decrypt', async function () {
|
||||||
|
await fc.assert(
|
||||||
|
fc.asyncProperty(
|
||||||
|
fc.uint8Array({ minLength: 1 }),
|
||||||
|
fc.uint8Array({ minLength: 32, maxLength: 32 }),
|
||||||
|
async (message, privKey) => {
|
||||||
|
const publicKey = getPublicKey(privKey);
|
||||||
|
|
||||||
|
const enc = await encryptAsymmetric(message, publicKey);
|
||||||
|
const res = await decryptAsymmetric(enc, privKey);
|
||||||
|
|
||||||
|
expect(res).deep.equal(message);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,17 +0,0 @@
|
||||||
declare module 'libp2p-tcp' {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
const TCP: any;
|
|
||||||
export = TCP;
|
|
||||||
}
|
|
||||||
declare module 'libp2p-mplex' {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
const Mplex: any;
|
|
||||||
export = Mplex;
|
|
||||||
}
|
|
||||||
declare module 'libp2p-secio' {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
const Secio: any;
|
|
||||||
export = Secio;
|
|
||||||
}
|
|
||||||
declare module 'libp2p-websockets';
|
|
||||||
declare module 'libp2p-websockets/src/filters';
|
|
|
@ -7,7 +7,7 @@
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"inlineSourceMap": true,
|
"sourceMap": true,
|
||||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
||||||
"resolveJsonModule": true /* Include modules imported with .json extension. */,
|
"resolveJsonModule": true /* Include modules imported with .json extension. */,
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"extends": "./tsconfig",
|
||||||
|
"compilerOptions": {
|
||||||
|
"noEmit": false
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/lib/**/*.ts",
|
||||||
|
"src/proto/**/*.ts",
|
||||||
|
"src/tests/browser/**/*.ts"
|
||||||
|
],
|
||||||
|
"exclude": ["node_modules/**"]
|
||||||
|
}
|
Loading…
Reference in New Issue