From 572fd159b0393e80bcc4bb29b5c6c3b82f691676 Mon Sep 17 00:00:00 2001 From: junderw Date: Sat, 29 Dec 2018 22:49:35 +0900 Subject: [PATCH] Added TypeScript standard linter to tests --- package.json | 14 +++++++++++--- src/block.ts | 2 +- src/payments/embed.ts | 4 ++-- src/payments/index.ts | 2 +- src/payments/lazy.ts | 2 +- src/payments/p2ms.ts | 18 ++++++++++-------- src/payments/p2pk.ts | 4 ++-- src/payments/p2pkh.ts | 6 +++--- src/payments/p2sh.ts | 7 +++---- src/payments/p2wpkh.ts | 6 +++--- src/payments/p2wsh.ts | 7 +++---- src/templates/nulldata.ts | 2 +- 12 files changed, 41 insertions(+), 33 deletions(-) diff --git a/package.json b/package.json index 4b9557e..2d89027 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "nobuild:coverage-html": "nyc report --reporter=html", "nobuild:coverage": "nyc --check-coverage --branches 90 --functions 90 --lines 90 mocha", "nobuild:integration": "mocha --timeout 50000 test/integration/", - "nobuild:standard": "standard", + "nobuild:standard": "standard src/**/*.ts", "nobuild:unit": "mocha", "prepare": "npm run build", "standard": "npm run build && npm run nobuild:standard", @@ -63,12 +63,20 @@ "bn.js": "^4.11.8", "bs58": "^4.0.0", "dhttp": "^3.0.0", + "eslint-plugin-typescript": "^0.14.0", "hoodwink": "^2.0.0", "minimaldata": "^1.0.2", "mocha": "^5.2.0", "nyc": "^11.8.0", "proxyquire": "^2.0.1", - "standard": "^11.0.1" + "standard": "^11.0.1", + "typescript-eslint-parser": "^21.0.2" }, - "license": "MIT" + "license": "MIT", + "standard": { + "parser": "typescript-eslint-parser", + "plugins": [ + "typescript" + ] + } } diff --git a/src/block.ts b/src/block.ts index 1483f2c..82700aa 100644 --- a/src/block.ts +++ b/src/block.ts @@ -124,7 +124,7 @@ export class Block { return target } - static calculateMerkleRoot (transactions: Array, forWitness: boolean | void): Buffer { + static calculateMerkleRoot (transactions: Array, forWitness?: boolean): Buffer { typeforce([{ getHash: types.Function }], transactions) if (transactions.length === 0) throw errorMerkleNoTxes if (forWitness && !txesHaveWitness(transactions)) throw errorWitnessNotSegwit diff --git a/src/payments/embed.ts b/src/payments/embed.ts index 7e82511..8cc8899 100644 --- a/src/payments/embed.ts +++ b/src/payments/embed.ts @@ -1,9 +1,9 @@ -import { Payment, PaymentOpts } from './index' +import { Payment, PaymentOpts } from './index' // eslint-disable-line import * as bscript from '../script' import * as lazy from './lazy' import { bitcoin as BITCOIN_NETWORK } from '../networks' const typef = require('typeforce') -import { OPS } from '../script' +const OPS = bscript.OPS function stacksEqual (a: Array, b: Array): boolean { if (a.length !== b.length) return false diff --git a/src/payments/index.ts b/src/payments/index.ts index 08a8409..7fc72d8 100644 --- a/src/payments/index.ts +++ b/src/payments/index.ts @@ -1,4 +1,4 @@ -import { Network } from '../networks' +import { Network } from '../networks' // eslint-disable-line import { p2data as embed } from './embed' import { p2ms } from './p2ms' import { p2pk } from './p2pk' diff --git a/src/payments/lazy.ts b/src/payments/lazy.ts index 1d4af68..a6f0951 100644 --- a/src/payments/lazy.ts +++ b/src/payments/lazy.ts @@ -18,7 +18,7 @@ export function prop (object: Object, name: string, f: ()=>any): void { }) } -export function value (f: ()=>T): ()=>T { +export function value (f: ()=>T): ()=>T { let value: T return function (): T { if (value !== undefined) return value diff --git a/src/payments/p2ms.ts b/src/payments/p2ms.ts index 3c5c679..67b9692 100644 --- a/src/payments/p2ms.ts +++ b/src/payments/p2ms.ts @@ -1,9 +1,9 @@ -import { Payment, PaymentOpts } from './index' +import { Payment, PaymentOpts } from './index' // eslint-disable-line import * as bscript from '../script' import * as lazy from './lazy' import { bitcoin as BITCOIN_NETWORK } from '../networks' +const OPS = bscript.OPS const typef = require('typeforce') -import { OPS } from '../script' const ecc = require('tiny-secp256k1') const OP_INT_BASE = OPS.OP_RESERVED // OP_1 - 1 @@ -28,7 +28,9 @@ export function p2ms (a: Payment, opts?: PaymentOpts): Payment { opts = Object.assign({ validate: true }, opts || {}) function isAcceptableSignature (x: Buffer | number) { - return bscript.isCanonicalScriptSignature(x) || ((opts).allowIncomplete && (x === OPS.OP_0)) !== undefined + return bscript.isCanonicalScriptSignature(x) || + ((opts).allowIncomplete && + ( x === OPS.OP_0)) !== undefined // eslint-disable-line } typef({ @@ -51,8 +53,8 @@ export function p2ms (a: Payment, opts?: PaymentOpts): Payment { if (decoded) return decoded = true chunks = >bscript.decompile(output) - o.m = chunks[0] - OP_INT_BASE - o.n = chunks[chunks.length - 2] - OP_INT_BASE + o.m = chunks[0] - OP_INT_BASE // eslint-disable-line + o.n = chunks[chunks.length - 2] - OP_INT_BASE // eslint-disable-line o.pubkeys = >chunks.slice(1, -2) } @@ -103,9 +105,9 @@ export function p2ms (a: Payment, opts?: PaymentOpts): Payment { if (chunks[chunks.length - 1] !== OPS.OP_CHECKMULTISIG) throw new TypeError('Output is invalid') if ( - (o).m <= 0 || - (o).n > 16 || - (o).m > (o).n || + (o).m <= 0 || // eslint-disable-line + (o).n > 16 || // eslint-disable-line + (o).m > (o).n || // eslint-disable-line o.n !== chunks.length - 3) throw new TypeError('Output is invalid') if (!(>o.pubkeys).every(x => ecc.isPoint(x))) throw new TypeError('Output is invalid') diff --git a/src/payments/p2pk.ts b/src/payments/p2pk.ts index f383a1c..0825955 100644 --- a/src/payments/p2pk.ts +++ b/src/payments/p2pk.ts @@ -1,9 +1,9 @@ -import { Payment, PaymentOpts } from './index' +import { Payment, PaymentOpts } from './index' // eslint-disable-line import * as bscript from '../script' import * as lazy from './lazy' import { bitcoin as BITCOIN_NETWORK } from '../networks' const typef = require('typeforce') -import { OPS } from '../script' +const OPS = bscript.OPS const ecc = require('tiny-secp256k1') // input: {signature} diff --git a/src/payments/p2pkh.ts b/src/payments/p2pkh.ts index 4fb49de..f12faf8 100644 --- a/src/payments/p2pkh.ts +++ b/src/payments/p2pkh.ts @@ -1,10 +1,10 @@ -import { Payment, PaymentOpts } from './index' +import { Payment, PaymentOpts } from './index' // eslint-disable-line import * as bscript from '../script' import * as bcrypto from '../crypto' import * as lazy from './lazy' import { bitcoin as BITCOIN_NETWORK } from '../networks' const typef = require('typeforce') -import { OPS } from '../script' +const OPS = bscript.OPS const ecc = require('tiny-secp256k1') const bs58check = require('bs58check') @@ -54,7 +54,7 @@ export function p2pkh (a: Payment, opts?: PaymentOpts): Payment { lazy.prop(o, 'hash', function () { if (a.output) return a.output.slice(3, 23) if (a.address) return _address().hash - if (a.pubkey || o.pubkey) return bcrypto.hash160(a.pubkey || o.pubkey) + if (a.pubkey || o.pubkey) return bcrypto.hash160( a.pubkey || o.pubkey) // eslint-disable-line }) lazy.prop(o, 'output', function () { if (!o.hash) return diff --git a/src/payments/p2sh.ts b/src/payments/p2sh.ts index d25b616..e0292f3 100644 --- a/src/payments/p2sh.ts +++ b/src/payments/p2sh.ts @@ -1,11 +1,10 @@ -import { Payment, PaymentOpts } from './index' -import { Network } from '../networks' +import { Payment, PaymentOpts } from './index' // eslint-disable-line +import { Network, bitcoin as BITCOIN_NETWORK } from '../networks' // eslint-disable-line import * as bscript from '../script' import * as bcrypto from '../crypto' import * as lazy from './lazy' -import { bitcoin as BITCOIN_NETWORK } from '../networks' const typef = require('typeforce') -import { OPS } from '../script' +const OPS = bscript.OPS const bs58check = require('bs58check') diff --git a/src/payments/p2wpkh.ts b/src/payments/p2wpkh.ts index 918e909..b40085b 100644 --- a/src/payments/p2wpkh.ts +++ b/src/payments/p2wpkh.ts @@ -1,10 +1,10 @@ -import { Payment, PaymentOpts } from './index' +import { Payment, PaymentOpts } from './index' // eslint-disable-line import * as bscript from '../script' import * as bcrypto from '../crypto' import * as lazy from './lazy' import { bitcoin as BITCOIN_NETWORK } from '../networks' const typef = require('typeforce') -import { OPS } from '../script' +const OPS = bscript.OPS const ecc = require('tiny-secp256k1') const bech32 = require('bech32') @@ -59,7 +59,7 @@ export function p2wpkh (a: Payment, opts?: PaymentOpts): Payment { lazy.prop(o, 'hash', function () { if (a.output) return a.output.slice(2, 22) if (a.address) return _address().data - if (a.pubkey || o.pubkey) return bcrypto.hash160(a.pubkey || o.pubkey) + if (a.pubkey || o.pubkey) return bcrypto.hash160( a.pubkey || o.pubkey) // eslint-disable-line }) lazy.prop(o, 'output', function () { if (!o.hash) return diff --git a/src/payments/p2wsh.ts b/src/payments/p2wsh.ts index 1a8e86e..7e2f237 100644 --- a/src/payments/p2wsh.ts +++ b/src/payments/p2wsh.ts @@ -1,11 +1,10 @@ -import { Payment, PaymentOpts } from './index' -import { Network } from '../networks' +import { Payment, PaymentOpts } from './index' // eslint-disable-line +import { Network, bitcoin as BITCOIN_NETWORK } from '../networks' // eslint-disable-line import * as bscript from '../script' import * as bcrypto from '../crypto' import * as lazy from './lazy' -import { bitcoin as BITCOIN_NETWORK } from '../networks' const typef = require('typeforce') -import { OPS } from '../script' +const OPS = bscript.OPS const bech32 = require('bech32') diff --git a/src/templates/nulldata.ts b/src/templates/nulldata.ts index 8889fb9..0833eac 100644 --- a/src/templates/nulldata.ts +++ b/src/templates/nulldata.ts @@ -1,6 +1,6 @@ // OP_RETURN {data} import * as bscript from '../script' -import { OPS } from '../script' +const OPS = bscript.OPS export function check (script: Buffer | Array): boolean { const buffer = bscript.compile(script)