From 24dffb710e2e91bfeac623929548580f53e7fb53 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 19 Apr 2018 12:24:43 +0200 Subject: [PATCH] testingPairs for inetrnal testing (#118) --- lerna.json | 2 +- package.json | 2 +- packages/util-crypto/package.json | 2 +- packages/util-keyring/package.json | 6 ++--- packages/util-keyring/src/pair/getMeta.js | 5 ++-- packages/util-keyring/src/pair/index.js | 8 +++--- packages/util-keyring/src/pair/index.spec.js | 2 +- packages/util-keyring/src/pair/setMeta.js | 5 ++-- packages/util-keyring/src/pair/types.js | 6 ++--- packages/util-keyring/src/testing.js | 26 +++++++------------ packages/util-keyring/src/testingPairs.js | 25 ++++++++++++++++++ .../{testing.spec.js => testingPairs.spec.js} | 2 +- packages/util-keyring/src/types.js | 7 +++++ packages/util-rlp/package.json | 4 +-- packages/util-triehash/package.json | 8 +++--- packages/util/package.json | 4 +-- yarn.lock | 12 ++++----- 17 files changed, 75 insertions(+), 51 deletions(-) create mode 100644 packages/util-keyring/src/testingPairs.js rename packages/util-keyring/src/{testing.spec.js => testingPairs.spec.js} (89%) diff --git a/lerna.json b/lerna.json index ff18932b5..3acdfc634 100644 --- a/lerna.json +++ b/lerna.json @@ -10,5 +10,5 @@ "packages": [ "packages/*" ], - "version": "0.18.6" + "version": "0.19.0" } diff --git a/package.json b/package.json index 0909d47e7..a194dda4a 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "test": "jest --coverage" }, "devDependencies": { - "@polkadot/dev": "^0.17.6", + "@polkadot/dev": "^0.17.8", "lerna": "^2.5.1" } } diff --git a/packages/util-crypto/package.json b/packages/util-crypto/package.json index 21e792c24..f921440dc 100644 --- a/packages/util-crypto/package.json +++ b/packages/util-crypto/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/util-crypto", - "version": "0.18.6", + "version": "0.19.0", "description": "A collection of useful crypto utilities for @polkadot", "main": "index.js", "keywords": [ diff --git a/packages/util-keyring/package.json b/packages/util-keyring/package.json index 81f595311..536bcaf13 100644 --- a/packages/util-keyring/package.json +++ b/packages/util-keyring/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/util-keyring", - "version": "0.18.6", + "version": "0.19.0", "description": "Keyring management", "main": "index.js", "engines": { @@ -31,8 +31,8 @@ "test": "echo \"Tests only available from root wrapper\"" }, "dependencies": { - "@polkadot/util": "^0.18.6", - "@polkadot/util-crypto": "^0.18.6", + "@polkadot/util": "^0.19.0", + "@polkadot/util-crypto": "^0.19.0", "babel-runtime": "^6.26.0" } } diff --git a/packages/util-keyring/src/pair/getMeta.js b/packages/util-keyring/src/pair/getMeta.js index 9c55d16f7..ac30951d1 100644 --- a/packages/util-keyring/src/pair/getMeta.js +++ b/packages/util-keyring/src/pair/getMeta.js @@ -3,8 +3,9 @@ // of the ISC license. See the LICENSE file for details. // @flow -import type { PairState, PairState$Meta } from './types'; +import type { KeyringPair$Meta } from '../types'; +import type { PairState } from './types'; -module.exports = function getMeta (state: PairState): PairState$Meta { +module.exports = function getMeta (state: PairState): KeyringPair$Meta { return state.meta; }; diff --git a/packages/util-keyring/src/pair/index.js b/packages/util-keyring/src/pair/index.js index 9cafb7b9e..91eba76fd 100644 --- a/packages/util-keyring/src/pair/index.js +++ b/packages/util-keyring/src/pair/index.js @@ -4,8 +4,8 @@ // @flow import type { KeypairType } from '@polkadot/util-crypto/types'; -import type { KeyringPair } from '../types'; -import type { PairState, PairState$Meta } from './types'; +import type { KeyringPair, KeyringPair$Meta } from '../types'; +import type { PairState } from './types'; const naclSign = require('@polkadot/util-crypto/nacl/sign'); const naclVerify = require('@polkadot/util-crypto/nacl/verify'); @@ -29,11 +29,11 @@ module.exports = function pair ({ publicKey, secretKey }: KeypairType): KeyringP }, encodePkcs8: (passphrase?: Uint8Array | string): Uint8Array => encode(secretKey, passphrase), - getMeta: (): PairState$Meta => + getMeta: (): KeyringPair$Meta => getMeta(state), publicKey: (): Uint8Array => publicKey, - setMeta: (meta: PairState$Meta): void => + setMeta: (meta: KeyringPair$Meta): void => setMeta(state, meta), sign: (message: Uint8Array): Uint8Array => naclSign(message, secretKey), diff --git a/packages/util-keyring/src/pair/index.spec.js b/packages/util-keyring/src/pair/index.spec.js index 61c596426..7a50f5cc8 100644 --- a/packages/util-keyring/src/pair/index.spec.js +++ b/packages/util-keyring/src/pair/index.spec.js @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. -const keyring = require('../testing')(); +const keyring = require('../testingPairs')(); // aligned with @polkadot/util-crypto tests describe('pair', () => { diff --git a/packages/util-keyring/src/pair/setMeta.js b/packages/util-keyring/src/pair/setMeta.js index 51f130819..e35613c99 100644 --- a/packages/util-keyring/src/pair/setMeta.js +++ b/packages/util-keyring/src/pair/setMeta.js @@ -3,8 +3,9 @@ // of the ISC license. See the LICENSE file for details. // @flow -import type { PairState, PairState$Meta } from './types'; +import type { KeyringPair$Meta } from '../types'; +import type { PairState } from './types'; -module.exports = function setMeta (state: PairState, meta: PairState$Meta): void { +module.exports = function setMeta (state: PairState, meta: KeyringPair$Meta): void { state.meta = meta; }; diff --git a/packages/util-keyring/src/pair/types.js b/packages/util-keyring/src/pair/types.js index 72b67c7db..5679e08e7 100644 --- a/packages/util-keyring/src/pair/types.js +++ b/packages/util-keyring/src/pair/types.js @@ -3,10 +3,8 @@ // of the ISC license. See the LICENSE file for details. // @flow -export type PairState$Meta = { - [string]: string -}; +import type { KeyringPair$Meta } from '../types'; export type PairState = { - meta: PairState$Meta + meta: KeyringPair$Meta }; diff --git a/packages/util-keyring/src/testing.js b/packages/util-keyring/src/testing.js index fd1e92923..64c721304 100644 --- a/packages/util-keyring/src/testing.js +++ b/packages/util-keyring/src/testing.js @@ -3,11 +3,7 @@ // of the ISC license. See the LICENSE file for details. // @flow -import type { KeyringPair } from './types'; - -type TestKeyring = { - [string]: KeyringPair -}; +import type { KeyringInstance } from './types'; const hexToU8a = require('@polkadot/util/hex/toU8a'); const u8aFromString = require('@polkadot/util/u8a/fromString'); @@ -15,11 +11,7 @@ const u8aFromString = require('@polkadot/util/u8a/fromString'); const createKeyring = require('./index'); function padSeed (seed: string): Uint8Array { - while (seed.length < 32) { - seed += ' '; - } - - return u8aFromString(seed); + return u8aFromString(seed.padEnd(32, ' ')); } const SEEDS = { @@ -41,14 +33,14 @@ const SEEDS = { hexToU8a('0x9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60') }; -module.exports = function testKeyring (): TestKeyring { +module.exports = function testKeyring (): KeyringInstance { const keyring = createKeyring(); - return Object - .keys(SEEDS) - .reduce((result, key) => { - result[key] = keyring.addFromSeed(SEEDS[key]); + Object.keys(SEEDS).forEach((name) => { + keyring + .addFromSeed(SEEDS[name]) + .setMeta({ name }); + }); - return result; - }, {}); + return keyring; }; diff --git a/packages/util-keyring/src/testingPairs.js b/packages/util-keyring/src/testingPairs.js new file mode 100644 index 000000000..8c17ee290 --- /dev/null +++ b/packages/util-keyring/src/testingPairs.js @@ -0,0 +1,25 @@ +// Copyright 2017-2018 Jaco Greeff +// This software may be modified and distributed under the terms +// of the ISC license. See the LICENSE file for details. +// @flow + +import type { KeyringPair } from './types'; + +type TestKeyringMap = { + [string]: KeyringPair +}; + +const createKeyring = require('./testing'); + +module.exports = function testKeyringPairs (): TestKeyringMap { + const keyring = createKeyring(); + const pairs = keyring.getPairs(); + + return pairs.reduce((result, pair) => { + const { name } = pair.getMeta(); + + result[(name: string)] = pair; + + return result; + }, {}); +}; diff --git a/packages/util-keyring/src/testing.spec.js b/packages/util-keyring/src/testingPairs.spec.js similarity index 89% rename from packages/util-keyring/src/testing.spec.js rename to packages/util-keyring/src/testingPairs.spec.js index 49b0a014f..2ccc7a57c 100644 --- a/packages/util-keyring/src/testing.spec.js +++ b/packages/util-keyring/src/testingPairs.spec.js @@ -5,7 +5,7 @@ describe('testing', () => { it('creates without failing', () => { expect( - require('./testing') + require('./testingPairs') ).toBeDefined(); }); }); diff --git a/packages/util-keyring/src/types.js b/packages/util-keyring/src/types.js index d49d1b984..f4b41bbeb 100644 --- a/packages/util-keyring/src/types.js +++ b/packages/util-keyring/src/types.js @@ -3,10 +3,17 @@ // of the ISC license. See the LICENSE file for details. // @flow +export type KeyringPair$Meta = { + // flowlint-next-line unclear-type:off + [string]: any +} + export type KeyringPair = { decodePkcs8: (encoded: Uint8Array, passphrase: Uint8Array | string) => void, encodePkcs8: (passphrase: Uint8Array | string) => Uint8Array, + getMeta: () => KeyringPair$Meta, publicKey: () => Uint8Array, + setMeta: (meta: KeyringPair$Meta) => void, sign (message: Uint8Array): Uint8Array, verify (message: Uint8Array, signature: Uint8Array): boolean }; diff --git a/packages/util-rlp/package.json b/packages/util-rlp/package.json index 2ad90da63..6406ab6b5 100644 --- a/packages/util-rlp/package.json +++ b/packages/util-rlp/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/util-rlp", - "version": "0.18.6", + "version": "0.19.0", "description": "RLP encoding and decoding", "main": "index.js", "keywords": [ @@ -29,7 +29,7 @@ "test": "echo \"Tests only available from root wrapper\"" }, "dependencies": { - "@polkadot/util": "^0.18.6", + "@polkadot/util": "^0.19.0", "babel-runtime": "^6.26.0" }, "devDependencies": { diff --git a/packages/util-triehash/package.json b/packages/util-triehash/package.json index 15693c1aa..af8c094cd 100644 --- a/packages/util-triehash/package.json +++ b/packages/util-triehash/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/util-triehash", - "version": "0.18.6", + "version": "0.19.0", "description": "Creation of triehash values", "main": "index.js", "keywords": [ @@ -29,9 +29,9 @@ "test": "echo \"Tests only available from root wrapper\"" }, "dependencies": { - "@polkadot/util": "^0.18.6", - "@polkadot/util-crypto": "^0.18.6", - "@polkadot/util-rlp": "^0.18.6", + "@polkadot/util": "^0.19.0", + "@polkadot/util-crypto": "^0.19.0", + "@polkadot/util-rlp": "^0.19.0", "babel-runtime": "^6.26.0" } } diff --git a/packages/util/package.json b/packages/util/package.json index 1decc03a1..d4d307ace 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/util", - "version": "0.18.6", + "version": "0.19.0", "description": "A collection of useful utilities for @polkadot", "main": "index.js", "keywords": [ @@ -29,7 +29,7 @@ "test": "echo \"Tests only available from root wrapper\"" }, "devDependencies": { - "@polkadot/api-jsonrpc": "^0.8.13" + "@polkadot/api-jsonrpc": "^0.8.14" }, "dependencies": { "babel-runtime": "^6.26.0", diff --git a/yarn.lock b/yarn.lock index 8756c15a0..fe7bbbefe 100644 --- a/yarn.lock +++ b/yarn.lock @@ -79,15 +79,15 @@ lodash "^4.2.0" to-fast-properties "^2.0.0" -"@polkadot/api-jsonrpc@^0.8.13": - version "0.8.13" - resolved "https://registry.yarnpkg.com/@polkadot/api-jsonrpc/-/api-jsonrpc-0.8.13.tgz#60a0241204cef405936b21e009970c5a7295d909" +"@polkadot/api-jsonrpc@^0.8.14": + version "0.8.14" + resolved "https://registry.yarnpkg.com/@polkadot/api-jsonrpc/-/api-jsonrpc-0.8.14.tgz#94be22fcd1802ddbd87c35e52b8916e1f9135dd6" dependencies: babel-runtime "^6.26.0" -"@polkadot/dev@^0.17.6": - version "0.17.6" - resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.17.6.tgz#8935c83ee71d32bf343e83fe537deb20b5764be0" +"@polkadot/dev@^0.17.8": + version "0.17.8" + resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.17.8.tgz#d22daea75e88587250c4f8d7ebdda1dd957570df" dependencies: babel-cli "^6.26.0" babel-core "^6.26.0"