Added initial code coverage testing.

This commit is contained in:
Richard Moore 2020-07-13 06:48:33 -04:00
parent d0a79c6a13
commit 0c1d55b6dc
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651
22 changed files with 79 additions and 13 deletions

@ -6,13 +6,14 @@ on:
- master
jobs:
test-node:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [8.x, 10.x, 12.x, 13.x]
node-version: [8.x, 10.x, 12.x, 13.x, 14.x]
steps:
- name: Use Node.js ${{ matrix.node-version }}
@ -22,8 +23,10 @@ jobs:
- uses: actions/checkout@v2
- run: npm ci
- run: npm run bootstrap
- run: npm run build-all
- run: npm run test-node
test-browser:
runs-on: ubuntu-latest
@ -39,5 +42,22 @@ jobs:
- uses: actions/checkout@v2
- run: npm ci
- run: npm run bootstrap
- run: npm run build-all
- run: npm run test-browser-${{ matrix.module }}
coverage:
name: Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v1
with:
node-version: 12.x
- uses: actions/checkout@v2
- run: npm ci
- run: npm run bootstrap
- run: npm run build-all
- run: npm run test-coverage

@ -22,11 +22,11 @@
"_dist-test-umd": "rollup -c rollup-tests.config.js",
"_test-browser-umd": "karma start --single-run --browsers ChromeHeadless karma-umd.conf.js",
"_test-browser-esm": "karma start --single-run --browsers ChromeHeadless karma-esm.conf.js",
"_test-node": "mocha --no-colors --reporter ./packages/tests/reporter ./packages/tests/lib/test-*.js",
"test-browser-umd": "npm run build-all && npm run _dist-test-umd && npm run _test-browser-umd",
"test-browser-esm": "npm run build-all && npm run _dist-test-esm && npm run _test-browser-esm",
"test-node": "npm run build-all && npm run _test-node",
"test-browser-umd": "npm run _dist-test-umd && npm run _test-browser-umd",
"test-browser-esm": "npm run _dist-test-esm && npm run _test-browser-esm",
"test-node": "mocha --no-colors --reporter ./packages/tests/reporter ./packages/tests/lib/test-*.js",
"test": "if [ \"$TEST\" == \"\" ]; then npm run test-node; else npm run \"test-$TEST\"; fi",
"test-coverage": "nyc mocha --reporter ./packages/tests/reporter-keepalive ./packages/tests/lib/test-*.js",
"lock-versions": "node ./admin/cmds/lock-versions",
"build-docs": "flatworm docs.wrm docs",
"serve-docs": "node ./admin/cmds/serve-docs.js",
@ -39,6 +39,8 @@
"sync-github": "node ./admin/cmds/cache-github"
},
"devDependencies": {
"@erquhart/rollup-plugin-node-builtins": "2.1.5",
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@types/assert": "^1.4.1",
"@types/mocha": "^5.2.0",
"@types/node": "^12.7.4",
@ -53,10 +55,10 @@
"libnpmpublish": "1.1.3",
"mocha": "^7.1.1",
"npm-packlist": "1.4.1",
"nyc": "15.1.0",
"rollup": "1.20.1",
"rollup-plugin-commonjs": "10.0.2",
"rollup-plugin-json": "4.0.0",
"@erquhart/rollup-plugin-node-builtins": "2.1.5",
"rollup-plugin-node-globals": "1.4.0",
"rollup-plugin-node-resolve": "5.2.0",
"rollup-plugin-terser": "^5.2.0",
@ -64,7 +66,9 @@
"rollup-pluginutils": "2.8.1",
"scrypt-js": "3.0.1",
"semver": "^5.6.0",
"source-map-support": "^0.5.19",
"tar": "4.4.8",
"ts-node": "^8.10.2",
"typescript": "3.8.3"
}
}

@ -1,3 +1,5 @@
/* istanbul ignore file */
"use strict";
import fs from "fs";
@ -988,3 +990,4 @@ export class CLI {
}
}
}

@ -1,3 +1,5 @@
/* istanbul ignore file */
"use strict";
export type PromptOptions = {

@ -1,3 +1,5 @@
/* istanbul ignore file */
'use strict';
import fs from "fs";

@ -1,3 +1,5 @@
/* istanbul ignore file */
"use strict";
import { ethers } from "ethers";

@ -27,6 +27,7 @@ export function isValidName(name: string): boolean {
}
export function namehash(name: string): string {
/* istanbul ignore if */
if (typeof(name) !== "string") {
logger.throwArgumentError("invalid address - " + String(name), "name", name);
}

@ -99,6 +99,7 @@ export class HDNode implements ExternallyOwnedAccount {
constructor(constructorGuard: any, privateKey: string, publicKey: string, parentFingerprint: string, chainCode: string, index: number, depth: number, mnemonicOrPath: Mnemonic | string) {
logger.checkNew(new.target, HDNode);
/* istanbul ignore if */
if (constructorGuard !== _constructorGuard) {
throw new Error("HDNode constructor cannot be called directly");
}

@ -25,6 +25,7 @@ export function sha512(data: BytesLike): string {
export function computeHmac(algorithm: SupportedAlgorithm, key: BytesLike, data: BytesLike): string {
/* istanbul ignore if */
if (!SupportedAlgorithm[algorithm]) {
logger.throwError("unsupported algorithm - " + algorithm, Logger.errors.UNSUPPORTED_OPERATION, {
operation: "computeHmac",

@ -1,3 +1,5 @@
/* istanbul ignore file */
'use strict';
// Maximum time in seconds to suppress output

@ -1,3 +1,5 @@
/* istanbul ignore file */
'use strict';
import { ethers } from "ethers";

@ -72,6 +72,7 @@ export class Wallet extends Signer implements ExternallyOwnedAccount {
} else {
if (SigningKey.isSigningKey(privateKey)) {
/* istanbul ignore if */
if (privateKey.curve !== "secp256k1") {
logger.throwArgumentError("unsupported curve; must be secp256k1", "privateKey", "[REDACTED]");
}
@ -84,6 +85,7 @@ export class Wallet extends Signer implements ExternallyOwnedAccount {
defineReadOnly(this, "address", computeAddress(this.publicKey));
}
/* istanbul ignore if */
if (provider && !Provider.isProvider(provider)) {
logger.throwArgumentError("invalid provider", "provider", provider);
}
@ -107,7 +109,7 @@ export class Wallet extends Signer implements ExternallyOwnedAccount {
return resolveProperties(transaction).then((tx) => {
if (tx.from != null) {
if (getAddress(tx.from) !== this.address) {
throw new Error("transaction from address mismatch");
logger.throwArgumentError("transaction from address mismatch", "transaction.from", transaction.from);
}
delete tx.from;
}

@ -49,6 +49,7 @@ function getResponse(request: http.ClientRequest): Promise<GetUrlResponse> {
});
resp.on("error", (error) => {
/* istanbul ignore next */
(<any>error).response = response;
reject(error);
});
@ -91,6 +92,7 @@ export async function getUrl(href: string, options?: Options): Promise<GetUrlRes
req = https.request(request);
break;
default:
/* istanbul ignore next */
logger.throwError(`unsupported protocol ${ url.protocol }`, Logger.errors.UNSUPPORTED_OPERATION, {
protocol: url.protocol,
operation: "request"

@ -9,6 +9,9 @@ let wordlist: Array<string> = null;
function loadWords(lang: Wordlist): void {
if (wordlist != null) { return; }
wordlist = words.replace(/([A-Z])/g, " $1").toLowerCase().substring(1).split(" ");
// Verify the computed list matches the official list
/* istanbul ignore if */
if (Wordlist.check(lang) !== "0x25f44555f4af25b51a711136e1c7d6e50ce9f8917d39d6b1f076b2bb4d2fac1a") {
wordlist = null;
throw new Error("BIP39 Wordlist for en (English) FAILED");

@ -11,6 +11,9 @@ let wordlist: Array<string> = null;
function loadWords(lang: Wordlist): void {
if (wordlist != null) { return; }
wordlist = words.replace(/([A-Z])/g, " $1").toLowerCase().substring(1).split(" ");
// Verify the computed list matches the official list
/* istanbul ignore if */
if (Wordlist.check(lang) !== "0x3c8acc1e7b08d8e76f9fda015ef48dc8c710a73cb7e0f77b2c18a9b5a7adde60") {
wordlist = null;
throw new Error("BIP39 Wordlist for en (English) FAILED");

@ -43,6 +43,9 @@ function loadWords(lang: Wordlist): void {
wordlist.forEach((word, index) => {
lookup[dropDiacritic(word)] = index;
});
// Verify the computed list matches the official list
/* istanbul ignore if */
if (Wordlist.check(lang) !== "0xf74fb7092aeacdfbf8959557de22098da512207fb9f109cb526994938cf40300") {
wordlist = null;
throw new Error("BIP39 Wordlist for es (Spanish) FAILED");
@ -61,9 +64,7 @@ class LangEs extends Wordlist {
getWordIndex(word: string): number {
loadWords(this);
const index = lookup[dropDiacritic(word)];
if (typeof(index) !== "number") { return -1; }
return index;
return lookup[dropDiacritic(word)];
}
}

@ -45,6 +45,9 @@ function loadWords(lang: Wordlist): void {
wordlist.forEach((word, index) => {
lookup[dropDiacritic(word)] = index;
});
// Verify the computed list matches the official list
/* istanbul ignore if */
if (Wordlist.check(lang) !== "0x51deb7ae009149dc61a6bd18a918eb7ac78d2775726c68e598b92d002519b045") {
wordlist = null;
throw new Error("BIP39 Wordlist for fr (French) FAILED");
@ -63,9 +66,7 @@ class LangFr extends Wordlist {
getWordIndex(word: string): number {
loadWords(this);
const index = lookup[dropDiacritic(word)];
if (typeof(index) !== "number") { return -1; }
return index;
return lookup[dropDiacritic(word)];
}
}

@ -9,6 +9,9 @@ let wordlist: Array<string> = null;
function loadWords(lang: Wordlist): void {
if (wordlist != null) { return; }
wordlist = words.replace(/([A-Z])/g, " $1").toLowerCase().substring(1).split(" ");
// Verify the computed list matches the official list
/* istanbul ignore if */
if (Wordlist.check(lang) !== "0x5c1362d88fd4cf614a96f3234941d29f7d37c08c5292fde03bf62c2db6ff7620") {
wordlist = null;
throw new Error("BIP39 Wordlist for it (Italian) FAILED");

@ -104,12 +104,16 @@ function loadWords(lang: Wordlist) {
// - kyoku
// - kiyoku
// This should ignore "if", but that doesn't work here??
/* istanbul ignore next */
if (hex(wordlist[442]) === KiYoKu && hex(wordlist[443]) === KyoKu) {
const tmp = wordlist[442];
wordlist[442] = wordlist[443];
wordlist[443] = tmp;
}
// Verify the computed list matches the official list
/* istanbul ignore if */
if (Wordlist.check(lang) !== "0xcb36b09e6baa935787fd762ce65e80b0c6a8dabdfbc3a7f86ac0e2c4fd111600") {
wordlist = null;
throw new Error("BIP39 Wordlist for ja (Japanese) FAILED");

@ -48,6 +48,8 @@ function loadWords(lang: Wordlist): void {
wordlist.sort();
// Verify the computed list matches the official list
/* istanbul ignore if */
if (Wordlist.check(lang) !== "0xf9eddeace9c5d3da9c93cf7d3cd38f6a13ed3affb933259ae865714e8a3ae71a") {
wordlist = null;
throw new Error("BIP39 Wordlist for ko (Korean) FAILED");

@ -47,6 +47,8 @@ function loadWords(lang: Wordlist) {
wordlist[lang.locale].push(toUtf8String(bytes));
}
// Verify the computed list matches the official list
/* istanbul ignore if */
if (Wordlist.check(lang) !== Checks[lang.locale]) {
wordlist[lang.locale] = null;
throw new Error("BIP39 Wordlist for " + lang.locale + " (Chinese) FAILED");

@ -35,6 +35,7 @@ export abstract class Wordlist {
const words = [];
for (let i = 0; i < 2048; i++) {
const word = wordlist.getWord(i);
/* istanbul ignore if */
if (i !== wordlist.getWordIndex(word)) { return "0x"; }
words.push(word);
}
@ -43,6 +44,8 @@ export abstract class Wordlist {
static register(lang: Wordlist, name?: string): void {
if (!name) { name = lang.locale; }
/* istanbul ignore if */
if (exportWordlist) {
try {
const anyGlobal = (window as any)