diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4c9612ad08..4fca0988f8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,9 +19,10 @@ To help ensure your PR passes, just run before committing: To build and test this repository, you need: - - [Node.js & npm](https://nodejs.org/en/) - - [bufbuild](https://github.com/bufbuild/buf) (only if changing protobuf files) - - [protoc](https://grpc.io/docs/protoc-installation/) (only if changing protobuf files) + - [Node.js & npm](https://nodejs.org/en/). + - [bufbuild](https://github.com/bufbuild/buf) (only if changing protobuf files). + - [protoc](https://grpc.io/docs/protoc-installation/) (only if changing protobuf files). + - Firefox & Chrome (for browser testing). To ensure interoperability with [nim-waku](https://github.com/status-im/nim-waku/), some tests are run against a nim-waku node. This is why `nim-waku` is present as a [git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules), which itself contain several submodules. @@ -29,10 +30,14 @@ At this stage, it is not possible to exclude nim-waku tests, hence `git submodul To build nim-waku, you also need [Rust](https://www.rust-lang.org/tools/install). +Note that we run tests in both NodeJS and browser environments (both Chrome and Firefox, using [karma](https://karma-runner.github.io/)). +Files named `*.spec.ts` are only run in NodeJS environment; +Files named `*.browser.spec.ts` are run in both NodeJS and browser environment. + ## Guidelines -- Please follow [Chris Beam's commit message guide](https://chris.beams.io/posts/git-commit/), -- Usually best to test new code, +- Please follow [Chris Beam's commit message guide](https://chris.beams.io/posts/git-commit/) for commit patches, +- Please test new code, we use [mocha](https://mochajs.org/), [chai](https://www.chaijs.com/) and [karma](https://karma-runner.github.io/). ### Committing Patches diff --git a/karma.conf.js b/karma.conf.js index 35a9e1ff2b..f0b71c49a1 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -3,11 +3,7 @@ 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', - ], + files: ['src/lib/**/*.ts', 'src/proto/**/*.ts'], preprocessors: { '**/*.ts': ['karma-typescript'], }, @@ -21,7 +17,7 @@ module.exports = function (config) { singleRun: true, karmaTypescriptConfig: { bundlerOptions: { - entrypoints: /src\/tests\/browser\/.*\.spec\.ts$/, + entrypoints: /.*\.browser\.spec\.ts$/, }, tsconfig: './tsconfig.karma.json', coverageOptions: { diff --git a/src/tests/browser/waku_message.spec.ts b/src/lib/waku_message/index.browser.spec.ts similarity index 95% rename from src/tests/browser/waku_message.spec.ts rename to src/lib/waku_message/index.browser.spec.ts index 8657354b3e..d167e539c9 100644 --- a/src/tests/browser/waku_message.spec.ts +++ b/src/lib/waku_message/index.browser.spec.ts @@ -1,12 +1,6 @@ import { expect } from 'chai'; import fc from 'fast-check'; -fc.configureGlobal({ - interruptAfterTimeLimit: 1500, - markInterruptAsFailure: true, - numRuns: 10, // Firefox is too slow for 100 (fc default) runs in 2s (mocha default) -}); - import { WakuMessage } from '../../lib/waku_message'; import { getPublicKey } from '../../lib/waku_message/version_1'; diff --git a/src/lib/waku_message/version_1.spec.ts b/src/lib/waku_message/version_1.browser.spec.ts similarity index 100% rename from src/lib/waku_message/version_1.spec.ts rename to src/lib/waku_message/version_1.browser.spec.ts diff --git a/src/tests/browser/version_1.spec.ts b/src/tests/browser/version_1.spec.ts deleted file mode 100644 index 8721e40d74..0000000000 --- a/src/tests/browser/version_1.spec.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { expect } from 'chai'; -import fc from 'fast-check'; - -import { - clearDecode, - clearEncode, - decryptAsymmetric, - decryptSymmetric, - encryptAsymmetric, - encryptSymmetric, - 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); - } - ) - ); - }); - - it('Symmetric encrypt & Decrypt', async function () { - await fc.assert( - fc.asyncProperty( - fc.uint8Array(), - fc.uint8Array({ minLength: 32, maxLength: 32 }), - async (message, key) => { - const enc = await encryptSymmetric(message, key); - const res = await decryptSymmetric(enc, key); - - expect(res).deep.equal(message); - } - ) - ); - }); -});