Skip to content

Commit

Permalink
fix(jest): fix a flaky crypto test - createKeyPair
Browse files Browse the repository at this point in the history
  • Loading branch information
danwbyrne committed Mar 14, 2019
1 parent 76b8e5d commit cd1e029
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions packages/neo-one-client-common/src/crypto.ts
Expand Up @@ -22,11 +22,10 @@ import { p256 } from './precomputed';
import { ScriptBuilder } from './ScriptBuilder';

// tslint:disable-next-line no-let
let ecCache: any;
let ecCache: EC | undefined;
const ec = () => {
if (ecCache === undefined) {
// tslint:disable-next-line no-any
ecCache = new EC(p256) as any;
ecCache = new EC(p256);
}

return ecCache;
Expand Down Expand Up @@ -172,6 +171,11 @@ const privateKeyToPublicKey = (privateKey: PrivateKey): ECPoint => {

const createKeyPair = (): { readonly privateKey: PrivateKey; readonly publicKey: ECPoint } => {
const key = ec().genKeyPair();
const validation = key.validate();

if (!validation.result) {
return createKeyPair();
}

return {
privateKey: common.bufferToPrivateKey(key.getPrivate().toArrayLike(Buffer, 'be')),
Expand Down
2 changes: 1 addition & 1 deletion scripts/e2e/One.js
Expand Up @@ -66,7 +66,7 @@ class One {

this.dir = tmp.dirSync();
this.dirName = this.dir.name;
this.serverPort = await this.getAvailableMinPortForRange(15);
this.serverPort = await this.getAvailableMinPortForRange(30);
this.httpServerPort = this.serverPort + 1;
this.minPort = this.serverPort + 2;
const [cmd, args] = this._createCommand('start server --static-neo-one');
Expand Down

0 comments on commit cd1e029

Please sign in to comment.