mirror of
https://github.com/logos-messaging/js-rln.git
synced 2026-01-08 00:23:12 +00:00
use jest
This commit is contained in:
parent
fa70837558
commit
0add061024
@ -1,11 +0,0 @@
|
||||
{
|
||||
"extension": ["ts"],
|
||||
"spec": "src/**/*.spec.ts",
|
||||
"require": ["ts-node/register", "isomorphic-fetch", "jsdom-global/register"],
|
||||
"loader": "ts-node/esm",
|
||||
"node-option": [
|
||||
"experimental-specifier-resolution=node",
|
||||
"loader=ts-node/esm"
|
||||
],
|
||||
"exit": true
|
||||
}
|
||||
6
babel.config.cjs
Normal file
6
babel.config.cjs
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
presets: [
|
||||
["@babel/preset-env", { targets: { node: "current" } }],
|
||||
"@babel/preset-typescript",
|
||||
],
|
||||
};
|
||||
194
jest.config.cjs
Normal file
194
jest.config.cjs
Normal file
@ -0,0 +1,194 @@
|
||||
/*
|
||||
* For a detailed explanation regarding each configuration property and type check, visit:
|
||||
* https://jestjs.io/docs/configuration
|
||||
*/
|
||||
|
||||
export default {
|
||||
// All imported modules in your tests should be mocked automatically
|
||||
// automock: false,
|
||||
|
||||
// Stop running tests after `n` failures
|
||||
// bail: 0,
|
||||
|
||||
// The directory where Jest should store its cached dependency information
|
||||
// cacheDirectory: "/private/var/folders/bg/vg98n32s74vcd5v1pkpylnh00000gn/T/jest_dx",
|
||||
|
||||
// Automatically clear mock calls, instances, contexts and results before every test
|
||||
clearMocks: true,
|
||||
|
||||
// Indicates whether the coverage information should be collected while executing the test
|
||||
// collectCoverage: false,
|
||||
|
||||
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
||||
// collectCoverageFrom: undefined,
|
||||
|
||||
// The directory where Jest should output its coverage files
|
||||
// coverageDirectory: undefined,
|
||||
|
||||
// An array of regexp pattern strings used to skip coverage collection
|
||||
// coveragePathIgnorePatterns: [
|
||||
// "/node_modules/"
|
||||
// ],
|
||||
|
||||
// Indicates which provider should be used to instrument code for coverage
|
||||
// coverageProvider: "babel",
|
||||
|
||||
// A list of reporter names that Jest uses when writing coverage reports
|
||||
// coverageReporters: [
|
||||
// "json",
|
||||
// "text",
|
||||
// "lcov",
|
||||
// "clover"
|
||||
// ],
|
||||
|
||||
// An object that configures minimum threshold enforcement for coverage results
|
||||
// coverageThreshold: undefined,
|
||||
|
||||
// A path to a custom dependency extractor
|
||||
// dependencyExtractor: undefined,
|
||||
|
||||
// Make calling deprecated APIs throw helpful error messages
|
||||
// errorOnDeprecated: false,
|
||||
|
||||
// The default configuration for fake timers
|
||||
// fakeTimers: {
|
||||
// "enableGlobally": false
|
||||
// },
|
||||
|
||||
// Force coverage collection from ignored files using an array of glob patterns
|
||||
// forceCoverageMatch: [],
|
||||
|
||||
// A path to a module which exports an async function that is triggered once before all test suites
|
||||
// globalSetup: undefined,
|
||||
|
||||
// A path to a module which exports an async function that is triggered once after all test suites
|
||||
// globalTeardown: undefined,
|
||||
|
||||
// A set of global variables that need to be available in all test environments
|
||||
// globals: {},
|
||||
|
||||
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
|
||||
// maxWorkers: "50%",
|
||||
|
||||
// An array of directory names to be searched recursively up from the requiring module's location
|
||||
moduleDirectories: ["node_modules", "<rootDir>/src"],
|
||||
|
||||
// An array of file extensions your modules use
|
||||
// moduleFileExtensions: [
|
||||
// "js",
|
||||
// "mjs",
|
||||
// "cjs",
|
||||
// "jsx",
|
||||
// "ts",
|
||||
// "tsx",
|
||||
// "json",
|
||||
// "node"
|
||||
// ],
|
||||
|
||||
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
||||
// moduleNameMapper: {},
|
||||
|
||||
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
||||
// modulePathIgnorePatterns: [],
|
||||
|
||||
// Activates notifications for test results
|
||||
// notify: false,
|
||||
|
||||
// An enum that specifies notification mode. Requires { notify: true }
|
||||
// notifyMode: "failure-change",
|
||||
|
||||
// A preset that is used as a base for Jest's configuration
|
||||
// preset: undefined,
|
||||
|
||||
// Run tests from one or more projects
|
||||
// projects: undefined,
|
||||
|
||||
// Use this configuration option to add custom reporters to Jest
|
||||
// reporters: undefined,
|
||||
|
||||
// Automatically reset mock state before every test
|
||||
// resetMocks: false,
|
||||
|
||||
// Reset the module registry before running each individual test
|
||||
// resetModules: false,
|
||||
|
||||
// A path to a custom resolver
|
||||
// resolver: undefined,
|
||||
|
||||
// Automatically restore mock state and implementation before every test
|
||||
// restoreMocks: false,
|
||||
|
||||
// The root directory that Jest should scan for tests and modules within
|
||||
rootDir: "./",
|
||||
|
||||
// A list of paths to directories that Jest should use to search for files in
|
||||
roots: ["<rootDir>"],
|
||||
|
||||
// Allows you to use a custom runner instead of Jest's default test runner
|
||||
// runner: "jest-runner",
|
||||
|
||||
// The paths to modules that run some code to configure or set up the testing environment before each test
|
||||
// setupFiles: [],
|
||||
|
||||
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
||||
// setupFilesAfterEnv: [],
|
||||
|
||||
// The number of seconds after which a test is considered as slow and reported as such in the results.
|
||||
// slowTestThreshold: 5,
|
||||
|
||||
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
||||
// snapshotSerializers: [],
|
||||
|
||||
// The test environment that will be used for testing
|
||||
testEnvironment: "jsdom",
|
||||
|
||||
// Options that will be passed to the testEnvironment
|
||||
// testEnvironmentOptions: {},
|
||||
|
||||
// Adds a location field to test results
|
||||
// testLocationInResults: false,
|
||||
|
||||
// The glob patterns Jest uses to detect test files
|
||||
// testMatch: [
|
||||
// "**/__tests__/**/*.[jt]s?(x)",
|
||||
// "**/?(*.)+(spec|test).[tj]s?(x)"
|
||||
// ],
|
||||
|
||||
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
||||
// testPathIgnorePatterns: [
|
||||
// "/node_modules/"
|
||||
// ],
|
||||
|
||||
// The regexp pattern or array of patterns that Jest uses to detect test files
|
||||
// testRegex: [],
|
||||
|
||||
// This option allows the use of a custom results processor
|
||||
// testResultsProcessor: undefined,
|
||||
|
||||
// This option allows use of a custom test runner
|
||||
// testRunner: "jest-circus/runner",
|
||||
|
||||
// A map from regular expressions to paths to transformers
|
||||
transform: {
|
||||
"\\.(js)$": "babel-jest",
|
||||
"\\.(ts)$": "ts-jest",
|
||||
},
|
||||
|
||||
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
||||
// transformIgnorePatterns: [
|
||||
// "/node_modules/",
|
||||
// '^.+\\.js$'
|
||||
// ],
|
||||
|
||||
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
|
||||
// unmockedModulePathPatterns: undefined,
|
||||
|
||||
// Indicates whether each individual test should be reported during the run
|
||||
// verbose: undefined,
|
||||
|
||||
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
||||
// watchPathIgnorePatterns: [],
|
||||
|
||||
// Whether to use watchman for file crawling
|
||||
// watchman: true,
|
||||
};
|
||||
@ -1,67 +0,0 @@
|
||||
process.env.CHROME_BIN = require("puppeteer").executablePath();
|
||||
|
||||
const os = require("os");
|
||||
const path = require("path");
|
||||
const ResolveTypeScriptPlugin = require("resolve-typescript-plugin");
|
||||
|
||||
const output = {
|
||||
path:
|
||||
path.join(os.tmpdir(), "_karma_webpack_") +
|
||||
Math.floor(Math.random() * 1000000),
|
||||
};
|
||||
|
||||
module.exports = function (config) {
|
||||
config.set({
|
||||
frameworks: ["webpack", "mocha"],
|
||||
preprocessors: {
|
||||
"**/*.ts": ["webpack"],
|
||||
},
|
||||
|
||||
files: [
|
||||
"src/**/*.spec.ts",
|
||||
"src/**/*.ts",
|
||||
{
|
||||
pattern: `${output.path}/**/*`,
|
||||
watched: false,
|
||||
included: false,
|
||||
served: true,
|
||||
},
|
||||
],
|
||||
envPreprocessor: ["CI"],
|
||||
reporters: ["progress"],
|
||||
browsers: ["ChromeHeadless"],
|
||||
singleRun: true,
|
||||
client: {
|
||||
mocha: {
|
||||
timeout: 6000, // Default is 2s
|
||||
},
|
||||
},
|
||||
webpack: {
|
||||
mode: "production",
|
||||
resolve: {
|
||||
// Add `.ts` and `.tsx` as a resolvable extension.
|
||||
extensions: [".ts", ".tsx", ".js"],
|
||||
plugins: [new ResolveTypeScriptPlugin()],
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.wasm$/,
|
||||
type: "asset/resource",
|
||||
},
|
||||
{
|
||||
test: /\.(js|tsx?)$/,
|
||||
loader: "ts-loader",
|
||||
exclude: /node_modules|\.d\.ts$/,
|
||||
options: { configFile: "tsconfig.karma.json" },
|
||||
},
|
||||
{
|
||||
test: /\.d\.ts$/,
|
||||
loader: "ignore-loader",
|
||||
},
|
||||
],
|
||||
},
|
||||
output,
|
||||
},
|
||||
});
|
||||
};
|
||||
20617
package-lock.json
generated
20617
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
28
package.json
28
package.json
@ -35,10 +35,9 @@
|
||||
"test:prettier": "prettier \"src/**/*.ts\" \"./*.json\" \"*.*js\" \".github/**/*.yml\" --list-different",
|
||||
"test:spelling": "cspell \"{*.md,.github/*.md,src/**/*.ts}\"",
|
||||
"test:tsc": "tsc -p tsconfig.dev.json",
|
||||
"test:browser": "karma start karma.conf.cjs",
|
||||
"test:unit": "jest",
|
||||
"watch:build": "tsc -p tsconfig.json -w",
|
||||
"watch:test": "mocha --watch",
|
||||
"prepublish": "npm run build",
|
||||
"watch:test": "jest --watch",
|
||||
"reset-hard": "git clean -dfx && git reset --hard && npm i && npm run build"
|
||||
},
|
||||
"browser": {
|
||||
@ -52,15 +51,17 @@
|
||||
"registry": "https://registry.npmjs.org/"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.20.12",
|
||||
"@babel/preset-env": "^7.20.2",
|
||||
"@babel/preset-typescript": "^7.18.6",
|
||||
"@rollup/plugin-commonjs": "^22.0.2",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
"@rollup/plugin-node-resolve": "^13.3.0",
|
||||
"@rollup/plugin-wasm": "^5.2.0",
|
||||
"@size-limit/preset-big-lib": "^8.0.0",
|
||||
"@types/app-root-path": "^1.2.4",
|
||||
"@types/chai": "^4.2.15",
|
||||
"@types/debug": "^4.1.7",
|
||||
"@types/mocha": "^9.1.0",
|
||||
"@types/jest": "^29.2.6",
|
||||
"@types/node": "^17.0.6",
|
||||
"@types/tail": "^2.0.0",
|
||||
"@types/uuid": "^8.3.0",
|
||||
@ -68,7 +69,7 @@
|
||||
"@typescript-eslint/parser": "^5.8.1",
|
||||
"@web/rollup-plugin-import-meta-assets": "^1.0.7",
|
||||
"app-root-path": "^3.0.0",
|
||||
"chai": "^4.3.4",
|
||||
"babel-jest": "^29.3.1",
|
||||
"cspell": "^5.14.0",
|
||||
"eslint": "^8.6.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
@ -81,25 +82,19 @@
|
||||
"husky": "^7.0.4",
|
||||
"ignore-loader": "^0.1.2",
|
||||
"isomorphic-fetch": "^3.0.0",
|
||||
"js-waku": "^0.29.0-29436ea",
|
||||
"jsdom": "^19.0.0",
|
||||
"jsdom-global": "^3.0.2",
|
||||
"karma": "^6.3.12",
|
||||
"karma-chrome-launcher": "^3.1.0",
|
||||
"karma-mocha": "^2.0.1",
|
||||
"karma-webpack": "^5.0.0",
|
||||
"jest": "^29.3.1",
|
||||
"jest-environment-jsdom": "^29.3.1",
|
||||
"lint-staged": "^13.0.3",
|
||||
"mocha": "^9.1.3",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"p-timeout": "^4.1.0",
|
||||
"prettier": "^2.1.1",
|
||||
"process": "^0.11.10",
|
||||
"puppeteer": "^13.0.1",
|
||||
"resolve-typescript-plugin": "^1.2.0",
|
||||
"rollup": "^2.75.0",
|
||||
"rollup-plugin-copy": "^3.4.0",
|
||||
"size-limit": "^8.0.0",
|
||||
"tail": "^2.2.0",
|
||||
"ts-jest": "^29.0.5",
|
||||
"ts-loader": "^9.3.1",
|
||||
"ts-node": "^10.9.1",
|
||||
"typedoc": "^0.23.10",
|
||||
@ -125,6 +120,7 @@
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@waku/zerokit-rln-wasm": "^0.0.5"
|
||||
"@waku/zerokit-rln-wasm": "^0.0.5",
|
||||
"js-waku": "^0.30.0"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import { expect } from "chai";
|
||||
import {
|
||||
generatePrivateKey,
|
||||
generateSymmetricKey,
|
||||
@ -16,11 +15,11 @@ import {
|
||||
SymEncoder,
|
||||
} from "js-waku/lib/waku_message/version_1";
|
||||
|
||||
import { RLNDecoder, RLNEncoder } from "./codec.js";
|
||||
import { epochBytesToInt } from "./epoch.js";
|
||||
import { RlnMessage } from "./message.js";
|
||||
import { RLNDecoder, RLNEncoder } from "./codec";
|
||||
import { epochBytesToInt } from "./epoch";
|
||||
import { RlnMessage } from "./message";
|
||||
|
||||
import * as rln from "./index.js";
|
||||
import * as rln from "./index";
|
||||
|
||||
const TestContentTopic = "/test/1/waku-message/utf8";
|
||||
|
||||
@ -46,21 +45,21 @@ describe("RLN codec with version 0", () => {
|
||||
|
||||
const bytes = await rlnEncoder.toWire({ payload });
|
||||
|
||||
expect(bytes).to.not.be.undefined;
|
||||
expect(bytes).toBeDefined();
|
||||
const protoResult = await rlnDecoder.fromWireToProtoObj(bytes!);
|
||||
expect(protoResult).to.not.be.undefined;
|
||||
expect(protoResult).toBeDefined();
|
||||
const msg = (await rlnDecoder.fromProtoObj(protoResult!))!;
|
||||
|
||||
expect(msg.rateLimitProof).to.not.be.undefined;
|
||||
expect(msg.verify()).to.be.true;
|
||||
expect(msg.verifyNoRoot()).to.be.true;
|
||||
expect(msg.epoch).to.not.be.undefined;
|
||||
expect(msg.epoch).to.be.gt(0);
|
||||
expect(msg.rateLimitProof).toBeDefined();
|
||||
expect(msg.verify()).toBe(true);
|
||||
expect(msg.verifyNoRoot()).toBe(true);
|
||||
expect(msg.epoch).toBeDefined();
|
||||
expect(msg.epoch).toBeGreaterThan(0);
|
||||
|
||||
expect(msg.contentTopic).to.eq(TestContentTopic);
|
||||
expect(msg.msg.version).to.eq(0);
|
||||
expect(msg.payload).to.deep.eq(payload);
|
||||
expect(msg.timestamp).to.not.be.undefined;
|
||||
expect(msg.contentTopic).toBe(TestContentTopic);
|
||||
expect(msg.msg.version).toBe(0);
|
||||
expect(msg.payload).toEqual(payload);
|
||||
expect(msg.timestamp).toBeDefined();
|
||||
});
|
||||
|
||||
it("toProtoObj", async function () {
|
||||
@ -84,23 +83,23 @@ describe("RLN codec with version 0", () => {
|
||||
|
||||
const proto = await rlnEncoder.toProtoObj({ payload });
|
||||
|
||||
expect(proto).to.not.be.undefined;
|
||||
expect(proto).toBeDefined();
|
||||
const msg = (await rlnDecoder.fromProtoObj(
|
||||
proto!
|
||||
)) as RlnMessage<MessageV0>;
|
||||
|
||||
expect(msg).to.not.be.undefined;
|
||||
expect(msg.rateLimitProof).to.not.be.undefined;
|
||||
expect(msg).toBeDefined();
|
||||
expect(msg.rateLimitProof).toBeDefined();
|
||||
|
||||
expect(msg.verify()).to.be.true;
|
||||
expect(msg.verifyNoRoot()).to.be.true;
|
||||
expect(msg.epoch).to.not.be.undefined;
|
||||
expect(msg.epoch).to.be.gt(0);
|
||||
expect(msg.verify()).toBe(true);
|
||||
expect(msg.verifyNoRoot()).toBe(true);
|
||||
expect(msg.epoch).toBeDefined();
|
||||
expect(msg.epoch).toBeGreaterThan(0);
|
||||
|
||||
expect(msg.contentTopic).to.eq(TestContentTopic);
|
||||
expect(msg.msg.version).to.eq(0);
|
||||
expect(msg.payload).to.deep.eq(payload);
|
||||
expect(msg.timestamp).to.not.be.undefined;
|
||||
expect(msg.contentTopic).toBe(TestContentTopic);
|
||||
expect(msg.msg.version).toBe(0);
|
||||
expect(msg.payload).toEqual(payload);
|
||||
expect(msg.timestamp).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
@ -128,22 +127,22 @@ describe("RLN codec with version 1", () => {
|
||||
|
||||
const bytes = await rlnEncoder.toWire({ payload });
|
||||
|
||||
expect(bytes).to.not.be.undefined;
|
||||
expect(bytes).toBeDefined();
|
||||
const protoResult = await rlnDecoder.fromWireToProtoObj(bytes!);
|
||||
|
||||
expect(protoResult).to.not.be.undefined;
|
||||
expect(protoResult).toBeDefined();
|
||||
const msg = (await rlnDecoder.fromProtoObj(protoResult!))!;
|
||||
|
||||
expect(msg.rateLimitProof).to.not.be.undefined;
|
||||
expect(msg.verify()).to.be.true;
|
||||
expect(msg.verifyNoRoot()).to.be.true;
|
||||
expect(msg.epoch).to.not.be.undefined;
|
||||
expect(msg.epoch).to.be.gt(0);
|
||||
expect(msg.rateLimitProof).toBeDefined();
|
||||
expect(msg.verify()).toBe(true);
|
||||
expect(msg.verifyNoRoot()).toBe(true);
|
||||
expect(msg.epoch).toBeDefined();
|
||||
expect(msg.epoch).toBeGreaterThan(0);
|
||||
|
||||
expect(msg.contentTopic).to.eq(TestContentTopic);
|
||||
expect(msg.msg.version).to.eq(1);
|
||||
expect(msg.payload).to.deep.eq(payload);
|
||||
expect(msg.timestamp).to.not.be.undefined;
|
||||
expect(msg.contentTopic).toBe(TestContentTopic);
|
||||
expect(msg.msg.version).toBe(1);
|
||||
expect(msg.payload).toEqual(payload);
|
||||
expect(msg.timestamp).toBeDefined();
|
||||
});
|
||||
|
||||
it("Symmetric, toProtoObj", async function () {
|
||||
@ -169,23 +168,23 @@ describe("RLN codec with version 1", () => {
|
||||
|
||||
const proto = await rlnEncoder.toProtoObj({ payload });
|
||||
|
||||
expect(proto).to.not.be.undefined;
|
||||
expect(proto).toBeDefined();
|
||||
const msg = (await rlnDecoder.fromProtoObj(
|
||||
proto!
|
||||
)) as RlnMessage<MessageV0>;
|
||||
|
||||
expect(msg).to.not.be.undefined;
|
||||
expect(msg.rateLimitProof).to.not.be.undefined;
|
||||
expect(msg).toBeDefined();
|
||||
expect(msg.rateLimitProof).toBeDefined();
|
||||
|
||||
expect(msg.verify()).to.be.true;
|
||||
expect(msg.verifyNoRoot()).to.be.true;
|
||||
expect(msg.epoch).to.not.be.undefined;
|
||||
expect(msg.epoch).to.be.gt(0);
|
||||
expect(msg.verify()).toBe(true);
|
||||
expect(msg.verifyNoRoot()).toBe(true);
|
||||
expect(msg.epoch).toBeDefined();
|
||||
expect(msg.epoch).toBeGreaterThan(0);
|
||||
|
||||
expect(msg.contentTopic).to.eq(TestContentTopic);
|
||||
expect(msg.msg.version).to.eq(1);
|
||||
expect(msg.payload).to.deep.eq(payload);
|
||||
expect(msg.timestamp).to.not.be.undefined;
|
||||
expect(msg.contentTopic).toBe(TestContentTopic);
|
||||
expect(msg.msg.version).toBe(1);
|
||||
expect(msg.payload).toEqual(payload);
|
||||
expect(msg.timestamp).toBeDefined();
|
||||
});
|
||||
|
||||
it("Asymmetric, toWire", async function () {
|
||||
@ -212,22 +211,22 @@ describe("RLN codec with version 1", () => {
|
||||
|
||||
const bytes = await rlnEncoder.toWire({ payload });
|
||||
|
||||
expect(bytes).to.not.be.undefined;
|
||||
expect(bytes).toBeDefined();
|
||||
const protoResult = await rlnDecoder.fromWireToProtoObj(bytes!);
|
||||
|
||||
expect(protoResult).to.not.be.undefined;
|
||||
expect(protoResult).toBeDefined();
|
||||
const msg = (await rlnDecoder.fromProtoObj(protoResult!))!;
|
||||
|
||||
expect(msg.rateLimitProof).to.not.be.undefined;
|
||||
expect(msg.verify()).to.be.true;
|
||||
expect(msg.verifyNoRoot()).to.be.true;
|
||||
expect(msg.epoch).to.not.be.undefined;
|
||||
expect(msg.epoch).to.be.gt(0);
|
||||
expect(msg.rateLimitProof).toBeDefined();
|
||||
expect(msg.verify()).toBe(true);
|
||||
expect(msg.verifyNoRoot()).toBe(true);
|
||||
expect(msg.epoch).toBeDefined();
|
||||
expect(msg.epoch).toBeGreaterThan(0);
|
||||
|
||||
expect(msg.contentTopic).to.eq(TestContentTopic);
|
||||
expect(msg.msg.version).to.eq(1);
|
||||
expect(msg.payload).to.deep.eq(payload);
|
||||
expect(msg.timestamp).to.not.be.undefined;
|
||||
expect(msg.contentTopic).toBe(TestContentTopic);
|
||||
expect(msg.msg.version).toBe(1);
|
||||
expect(msg.payload).toEqual(payload);
|
||||
expect(msg.timestamp).toBeDefined();
|
||||
});
|
||||
|
||||
it("Asymmetric, toProtoObj", async function () {
|
||||
@ -254,23 +253,23 @@ describe("RLN codec with version 1", () => {
|
||||
|
||||
const proto = await rlnEncoder.toProtoObj({ payload });
|
||||
|
||||
expect(proto).to.not.be.undefined;
|
||||
expect(proto).toBeDefined();
|
||||
const msg = (await rlnDecoder.fromProtoObj(
|
||||
proto!
|
||||
)) as RlnMessage<MessageV0>;
|
||||
|
||||
expect(msg).to.not.be.undefined;
|
||||
expect(msg.rateLimitProof).to.not.be.undefined;
|
||||
expect(msg).toBeDefined();
|
||||
expect(msg.rateLimitProof).toBeDefined();
|
||||
|
||||
expect(msg.verify()).to.be.true;
|
||||
expect(msg.verifyNoRoot()).to.be.true;
|
||||
expect(msg.epoch).to.not.be.undefined;
|
||||
expect(msg.epoch).to.be.gt(0);
|
||||
expect(msg.verify()).toBe(true);
|
||||
expect(msg.verifyNoRoot()).toBe(true);
|
||||
expect(msg.epoch).toBeDefined();
|
||||
expect(msg.epoch).toBeGreaterThan(0);
|
||||
|
||||
expect(msg.contentTopic).to.eq(TestContentTopic);
|
||||
expect(msg.msg.version).to.eq(1);
|
||||
expect(msg.payload).to.deep.eq(payload);
|
||||
expect(msg.timestamp).to.not.be.undefined;
|
||||
expect(msg.contentTopic).toBe(TestContentTopic);
|
||||
expect(msg.msg.version).toBe(1);
|
||||
expect(msg.payload).toEqual(payload);
|
||||
expect(msg.timestamp).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
@ -296,7 +295,7 @@ describe("RLN Codec - epoch", () => {
|
||||
|
||||
const proto = await rlnEncoder.toProtoObj({ payload });
|
||||
|
||||
expect(proto).to.not.be.undefined;
|
||||
expect(proto).toBeDefined();
|
||||
const msg = (await rlnDecoder.fromProtoObj(
|
||||
proto!
|
||||
)) as RlnMessage<MessageV0>;
|
||||
@ -304,18 +303,18 @@ describe("RLN Codec - epoch", () => {
|
||||
const epochBytes = proto!.rateLimitProof!.epoch;
|
||||
const epoch = epochBytesToInt(epochBytes);
|
||||
|
||||
expect(msg).to.not.be.undefined;
|
||||
expect(msg.rateLimitProof).to.not.be.undefined;
|
||||
expect(msg).toBeDefined();
|
||||
expect(msg.rateLimitProof).toBeDefined();
|
||||
|
||||
expect(msg.verify()).to.be.true;
|
||||
expect(msg.verifyNoRoot()).to.be.true;
|
||||
expect(msg.epoch).to.not.be.undefined;
|
||||
expect(msg.epoch!.toString(10).length).to.eq(9);
|
||||
expect(msg.epoch).to.eq(epoch);
|
||||
expect(msg.verify()).toBe(true);
|
||||
expect(msg.verifyNoRoot()).toBe(true);
|
||||
expect(msg.epoch).toBeDefined();
|
||||
expect(msg.epoch!.toString(10).length).toBe(9);
|
||||
expect(msg.epoch).toBe(epoch);
|
||||
|
||||
expect(msg.contentTopic).to.eq(TestContentTopic);
|
||||
expect(msg.msg.version).to.eq(0);
|
||||
expect(msg.payload).to.deep.eq(payload);
|
||||
expect(msg.timestamp).to.not.be.undefined;
|
||||
expect(msg.contentTopic).toBe(TestContentTopic);
|
||||
expect(msg.msg.version).toBe(0);
|
||||
expect(msg.payload).toEqual(payload);
|
||||
expect(msg.timestamp).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
@ -7,8 +7,8 @@ import {
|
||||
RateLimitProof,
|
||||
} from "js-waku/lib/interfaces";
|
||||
|
||||
import { RlnMessage, toRLNSignal } from "./message.js";
|
||||
import { MembershipKey, RLNInstance } from "./rln.js";
|
||||
import { RlnMessage, toRLNSignal } from "./message";
|
||||
import { MembershipKey, RLNInstance } from "./rln";
|
||||
|
||||
const log = debug("waku:rln:encoder");
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { expect } from "chai";
|
||||
import fc from "fast-check";
|
||||
|
||||
import { epochBytesToInt, epochIntToBytes } from "./epoch.js";
|
||||
import { epochBytesToInt, epochIntToBytes } from "./epoch";
|
||||
|
||||
describe("epoch serialization", () => {
|
||||
it("Round trip", async function () {
|
||||
@ -10,7 +9,7 @@ describe("epoch serialization", () => {
|
||||
const bytes = epochIntToBytes(date);
|
||||
const _date = epochBytesToInt(bytes);
|
||||
|
||||
expect(_date.valueOf()).to.eq(date.valueOf());
|
||||
expect(_date.valueOf()).toBe(date.valueOf());
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
import { assert, expect } from "chai";
|
||||
|
||||
import * as rln from "./index.js";
|
||||
import * as rln from "./index";
|
||||
|
||||
describe("js-rln", () => {
|
||||
it("should verify a proof", async function () {
|
||||
@ -43,9 +41,9 @@ describe("js-rln", () => {
|
||||
try {
|
||||
// verify the proof
|
||||
const verifResult = rlnInstance.verifyRLNProof(proof, uint8Msg);
|
||||
expect(verifResult).to.be.true;
|
||||
expect(verifResult).toBe(true);
|
||||
} catch (err) {
|
||||
assert.fail(0, 1, "should not have failed proof verification");
|
||||
throw Error("should not have failed proof verification");
|
||||
}
|
||||
|
||||
try {
|
||||
@ -53,7 +51,7 @@ describe("js-rln", () => {
|
||||
uint8Msg[4] = 4;
|
||||
// verify the proof
|
||||
const verifResult = rlnInstance.verifyRLNProof(proof, uint8Msg);
|
||||
expect(verifResult).to.be.false;
|
||||
expect(verifResult).toBe(false);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
@ -98,9 +96,9 @@ describe("js-rln", () => {
|
||||
try {
|
||||
// verify the proof
|
||||
const verifResult = rlnInstance.verifyRLNProof(proof, uint8Msg);
|
||||
expect(verifResult).to.be.true;
|
||||
expect(verifResult).toBe(true);
|
||||
} catch (err) {
|
||||
assert.fail(0, 1, "should not have failed proof verification");
|
||||
throw Error("should not have failed proof verification");
|
||||
}
|
||||
|
||||
try {
|
||||
@ -108,7 +106,7 @@ describe("js-rln", () => {
|
||||
uint8Msg[4] = 4;
|
||||
// verify the proof
|
||||
const verifResult = rlnInstance.verifyRLNProof(proof, uint8Msg);
|
||||
expect(verifResult).to.be.false;
|
||||
expect(verifResult).toBe(false);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
@ -120,10 +118,10 @@ describe("js-rln", () => {
|
||||
const memKeys2 = rlnInstance.generateSeededMembershipKey(seed);
|
||||
|
||||
memKeys1.IDCommitment.forEach((element, index) => {
|
||||
expect(element).to.equal(memKeys2.IDCommitment[index]);
|
||||
expect(element).toBe(memKeys2.IDCommitment[index]);
|
||||
});
|
||||
memKeys1.IDKey.forEach((element, index) => {
|
||||
expect(element).to.equal(memKeys2.IDKey[index]);
|
||||
expect(element).toBe(memKeys2.IDKey[index]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
import { RLNDecoder, RLNEncoder } from "./codec.js";
|
||||
import type { Proof, RLNInstance } from "./rln.js";
|
||||
import { MembershipKey } from "./rln.js";
|
||||
import { RLNDecoder, RLNEncoder } from "./codec";
|
||||
import type { Proof, RLNInstance } from "./rln";
|
||||
import { MembershipKey } from "./rln";
|
||||
|
||||
// reexport the create function, dynamically imported from rln.ts
|
||||
export async function create(): Promise<RLNInstance> {
|
||||
// A dependency graph that contains any wasm must all be imported
|
||||
// asynchronously. This file does the single async import, so
|
||||
// that no one else needs to worry about it again.
|
||||
const rlnModule = await import("./rln.js");
|
||||
const rlnModule = await import("./rln");
|
||||
return await rlnModule.create();
|
||||
}
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { utils } from "js-waku";
|
||||
import { Message, RateLimitProof } from "js-waku/lib/interfaces";
|
||||
|
||||
import { epochBytesToInt } from "./epoch.js";
|
||||
import { RLNInstance } from "./rln.js";
|
||||
import { epochBytesToInt } from "./epoch";
|
||||
import { RLNInstance } from "./rln";
|
||||
|
||||
export function toRLNSignal(msg: Partial<Message>): Uint8Array {
|
||||
const contentTopicBytes = utils.utf8ToBytes(msg.contentTopic ?? "");
|
||||
|
||||
@ -37,7 +37,7 @@
|
||||
// "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
|
||||
// "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */,
|
||||
"lib": ["es2020", "dom"],
|
||||
"types": ["node", "mocha"],
|
||||
"types": ["node", "jest"],
|
||||
"typeRoots": ["node_modules/@types", "src/types"]
|
||||
},
|
||||
"include": ["src"],
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
{
|
||||
"extends": "./tsconfig.dev",
|
||||
"compilerOptions": {
|
||||
"noEmit": false
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user