Skip to content

Commit

Permalink
Added initial code coverage testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Jul 13, 2020
1 parent d0a79c6 commit 0c1d55b
Show file tree
Hide file tree
Showing 22 changed files with 79 additions and 13 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
Expand All @@ -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
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -53,18 +55,20 @@
"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",
"rollup-plugin-uglify": "^6.0.4",
"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"
}
}
3 changes: 3 additions & 0 deletions packages/cli/src.ts/cli.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* istanbul ignore file */

"use strict";

import fs from "fs";
Expand Down Expand Up @@ -988,3 +990,4 @@ export class CLI {
}
}
}

2 changes: 2 additions & 0 deletions packages/cli/src.ts/prompt.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* istanbul ignore file */

"use strict";

export type PromptOptions = {
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src.ts/solc.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* istanbul ignore file */

'use strict';

import fs from "fs";
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src.ts/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* istanbul ignore file */

"use strict";

import { ethers } from "ethers";
Expand Down
1 change: 1 addition & 0 deletions packages/hash/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions packages/hdnode/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
1 change: 1 addition & 0 deletions packages/sha2/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions packages/tests/src.ts/reporter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* istanbul ignore file */

'use strict';

// Maximum time in seconds to suppress output
Expand Down
2 changes: 2 additions & 0 deletions packages/tests/src.ts/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* istanbul ignore file */

'use strict';

import { ethers } from "ethers";
Expand Down
4 changes: 3 additions & 1 deletion packages/wallet/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]");
}
Expand All @@ -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);
}
Expand All @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/web/src.ts/geturl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function getResponse(request: http.ClientRequest): Promise<GetUrlResponse> {
});

resp.on("error", (error) => {
/* istanbul ignore next */
(<any>error).response = response;
reject(error);
});
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions packages/wordlists/src.ts/lang-cz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 3 additions & 0 deletions packages/wordlists/src.ts/lang-en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
7 changes: 4 additions & 3 deletions packages/wordlists/src.ts/lang-es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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)];
}
}

Expand Down
7 changes: 4 additions & 3 deletions packages/wordlists/src.ts/lang-fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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)];
}
}

Expand Down
3 changes: 3 additions & 0 deletions packages/wordlists/src.ts/lang-it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 4 additions & 0 deletions packages/wordlists/src.ts/lang-ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions packages/wordlists/src.ts/lang-ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions packages/wordlists/src.ts/lang-zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 3 additions & 0 deletions packages/wordlists/src.ts/wordlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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)
Expand Down

0 comments on commit 0c1d55b

Please sign in to comment.