fix tests
This commit is contained in:
parent
34c61bc762
commit
8c10a06d79
|
@ -26,8 +26,8 @@
|
|||
"build-types": "tsc --declaration --project tsconfig.build.json --incremental --outDir lib --emitDeclarationOnly",
|
||||
"build-web": "webpack --mode production --entry ./lib/web.js --output ./dist/bls.min.js",
|
||||
"check-types": "tsc --noEmit",
|
||||
"lint": "eslint --ext .ts src/",
|
||||
"lint:fix": "eslint --ext .ts src/ --fix",
|
||||
"lint": "eslint --color --ext .ts src/",
|
||||
"lint:fix": "yarn run lint --fix",
|
||||
"pretest": "yarn check-types",
|
||||
"prepublishOnly": "yarn build",
|
||||
"test:unit": "nyc --cache-dir .nyc_output/.cache -r lcov -e .ts mocha --colors -r ts-node/register 'test/unit/**/*.test.ts' && nyc report",
|
||||
|
@ -41,8 +41,7 @@
|
|||
"@chainsafe/eth2-bls-wasm": "^0.1.0",
|
||||
"@chainsafe/eth2.0-types": "^0.1.0",
|
||||
"assert": "^1.4.1",
|
||||
"bls-wasm": "^0.2.7",
|
||||
"js-sha256": "^0.9.0"
|
||||
"bls-wasm": "^0.2.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.2.3",
|
||||
|
@ -67,6 +66,7 @@
|
|||
"codecov": "^3.1.0",
|
||||
"eslint": "^5.14.1",
|
||||
"js-yaml": "^3.13.1",
|
||||
"js-sha256": "^0.9.0",
|
||||
"mocha": "^6.2.0",
|
||||
"nyc": "^13.3.0",
|
||||
"sinon": "^7.2.7",
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
import blsWasmWrapper from "@chainsafe/eth2-bls-wasm";
|
||||
|
||||
let blsWrapper: typeof blsWasmWrapper | null = null;
|
||||
|
||||
export async function init(): Promise<typeof blsWasmWrapper> {
|
||||
if(blsWrapper) return blsWrapper;
|
||||
await blsWasmWrapper.init();
|
||||
blsWrapper = blsWasmWrapper;
|
||||
return blsWrapper;
|
||||
|
|
|
@ -5,6 +5,7 @@ import {Signature} from "./signature";
|
|||
import {BLSPubkey, BLSSecretKey, BLSSignature, Domain, Hash} from "@chainsafe/eth2.0-types";
|
||||
import {init} from "./context";
|
||||
import {PUBLIC_KEY_LENGTH} from "./constants";
|
||||
|
||||
export {Keypair, PrivateKey, PublicKey, Signature};
|
||||
|
||||
|
||||
|
|
|
@ -30,6 +30,13 @@ export class PrivateKey {
|
|||
return new PrivateKey(context.deserializeHexStrToSecretKey(value));
|
||||
}
|
||||
|
||||
public static fromInt(num: number): PrivateKey {
|
||||
const context = getContext();
|
||||
const secretKey = new context.SecretKey();
|
||||
secretKey.setInt(num);
|
||||
return new PrivateKey(secretKey);
|
||||
}
|
||||
|
||||
public static random(): PrivateKey {
|
||||
const context = getContext();
|
||||
const secretKey = new context.SecretKey();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
export {verifyInValidSignatureBenchmark} from './verifyInValidSignature';
|
||||
export {verifyValidSignatureBenchmark} from './verifyValidSignature';
|
||||
export {verifyValidAggregatedSignature} from './verifyValidAggregatedSignature';
|
||||
export {verifyInvalidAggregatedSignature} from './verifyInvalidAggregatedSignature';
|
||||
export {aggregateSignaturesBenchmark} from './signatureAggregation';
|
||||
// export {verifyInValidSignatureBenchmark} from "./verifyInValidSignature";
|
||||
export {verifyValidSignatureBenchmark} from "./verifyValidSignature";
|
||||
// export {verifyValidAggregatedSignature} from "./verifyValidAggregatedSignature";
|
||||
// export {verifyInvalidAggregatedSignature} from "./verifyInvalidAggregatedSignature";
|
||||
// export {aggregateSignaturesBenchmark} from "./signatureAggregation";
|
|
@ -41,7 +41,7 @@ export function verifyValidAggregatedSignature(dir: string): BenchSuite {
|
|||
const sha256 = require("js-sha256");
|
||||
const {aggregateSignatures} = require("../../../src");
|
||||
const message = Buffer.from(sha256.arrayBuffer(Math.random().toString(36)));
|
||||
const signatures = [];
|
||||
const signatures: any[] = [];
|
||||
global.messages = [];
|
||||
global.keypairs.forEach((keypair) => {
|
||||
signatures.push(keypair.privateKey.signMessage(message, global.domain).toBytesCompressed());
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import {BenchSuite} from "@chainsafe/benchmark-utils";
|
||||
import {verify} from "../../../src";
|
||||
import {sha256} from "js-sha256";
|
||||
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
|
@ -19,6 +20,10 @@ global.require = require;
|
|||
global.domain = Buffer.alloc(8);
|
||||
global.verify = verify;
|
||||
|
||||
global.message = Buffer.from(sha256.arrayBuffer(Math.random().toString(36)));
|
||||
|
||||
|
||||
|
||||
export function verifyValidSignatureBenchmark(dir: string): BenchSuite {
|
||||
|
||||
// Set the function test
|
||||
|
@ -32,11 +37,11 @@ export function verifyValidSignatureBenchmark(dir: string): BenchSuite {
|
|||
name: FUNCTION_NAME,
|
||||
testFunctions: [verifyValidSignature],
|
||||
setup: function() {
|
||||
const {Keypair} = require("../../../src");
|
||||
const {sha256} = require('js-sha256');
|
||||
const keypair = Keypair.generate();
|
||||
let i = 0;
|
||||
const {Keypair, PrivateKey} = require("../../../src");
|
||||
const keypair = new Keypair(PrivateKey.fromInt(i));
|
||||
i = i+1;
|
||||
global.publicKey = keypair.publicKey.toBytesCompressed();
|
||||
global.message = Buffer.from(sha256.arrayBuffer(Math.random().toString(36)));
|
||||
global.signature = keypair.privateKey.signMessage(Buffer.from(global.message), global.domain).toBytesCompressed();
|
||||
},
|
||||
file: dir + FUNCTION_NAME + ".txt"
|
||||
|
|
Reference in New Issue