testingPairs for inetrnal testing (#118)

This commit is contained in:
Jaco Greeff
2018-04-19 12:24:43 +02:00
committed by GitHub
parent 37bea69e58
commit 24dffb710e
17 changed files with 75 additions and 51 deletions
+1 -1
View File
@@ -10,5 +10,5 @@
"packages": [
"packages/*"
],
"version": "0.18.6"
"version": "0.19.0"
}
+1 -1
View File
@@ -10,7 +10,7 @@
"test": "jest --coverage"
},
"devDependencies": {
"@polkadot/dev": "^0.17.6",
"@polkadot/dev": "^0.17.8",
"lerna": "^2.5.1"
}
}
+1 -1
View File
@@ -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": [
+3 -3
View File
@@ -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"
}
}
+3 -2
View File
@@ -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;
};
+4 -4
View File
@@ -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),
+1 -1
View File
@@ -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', () => {
+3 -2
View File
@@ -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;
};
+2 -4
View File
@@ -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
};
+9 -17
View File
@@ -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;
};
+25
View File
@@ -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;
}, {});
};
@@ -5,7 +5,7 @@
describe('testing', () => {
it('creates without failing', () => {
expect(
require('./testing')
require('./testingPairs')
).toBeDefined();
});
});
+7
View File
@@ -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
};
+2 -2
View File
@@ -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": {
+4 -4
View File
@@ -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"
}
}
+2 -2
View File
@@ -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",
+6 -6
View File
@@ -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"