Added TypeScript standard linter to tests
This commit is contained in:
parent
e58d012615
commit
572fd159b0
12 changed files with 41 additions and 33 deletions
14
package.json
14
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"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ export class Block {
|
|||
return target
|
||||
}
|
||||
|
||||
static calculateMerkleRoot (transactions: Array<Transaction>, forWitness: boolean | void): Buffer {
|
||||
static calculateMerkleRoot (transactions: Array<Transaction>, forWitness?: boolean): Buffer {
|
||||
typeforce([{ getHash: types.Function }], transactions)
|
||||
if (transactions.length === 0) throw errorMerkleNoTxes
|
||||
if (forWitness && !txesHaveWitness(transactions)) throw errorWitnessNotSegwit
|
||||
|
|
|
@ -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<Buffer>, b: Array<Buffer>): boolean {
|
||||
if (a.length !== b.length) return false
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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(<Buffer>x) || ((<PaymentOpts>opts).allowIncomplete && (<number>x === OPS.OP_0)) !== undefined
|
||||
return bscript.isCanonicalScriptSignature(<Buffer>x) ||
|
||||
((<PaymentOpts>opts).allowIncomplete &&
|
||||
(<number> 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 = <Array<Buffer | number>>bscript.decompile(output)
|
||||
o.m = <number>chunks[0] - OP_INT_BASE
|
||||
o.n = <number>chunks[chunks.length - 2] - OP_INT_BASE
|
||||
o.m = <number> chunks[0] - OP_INT_BASE // eslint-disable-line
|
||||
o.n = <number> chunks[chunks.length - 2] - OP_INT_BASE // eslint-disable-line
|
||||
o.pubkeys = <Array<Buffer>>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 (
|
||||
<number>(<Payment>o).m <= 0 ||
|
||||
<number>(<Payment>o).n > 16 ||
|
||||
<number>(<Payment>o).m > <number>(<Payment>o).n ||
|
||||
<number>(<Payment>o).m <= 0 || // eslint-disable-line
|
||||
<number>(<Payment>o).n > 16 || // eslint-disable-line
|
||||
<number>(<Payment>o).m > <number>(<Payment>o).n || // eslint-disable-line
|
||||
o.n !== chunks.length - 3) throw new TypeError('Output is invalid')
|
||||
if (!(<Array<Buffer>>o.pubkeys).every(x => ecc.isPoint(x))) throw new TypeError('Output is invalid')
|
||||
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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(<Buffer>a.pubkey || <Buffer>o.pubkey)
|
||||
if (a.pubkey || o.pubkey) return bcrypto.hash160(<Buffer> a.pubkey || <Buffer>o.pubkey) // eslint-disable-line
|
||||
})
|
||||
lazy.prop(o, 'output', function () {
|
||||
if (!o.hash) return
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
|
@ -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(<Buffer>a.pubkey || <Buffer>o.pubkey)
|
||||
if (a.pubkey || o.pubkey) return bcrypto.hash160(<Buffer> a.pubkey || <Buffer>o.pubkey) // eslint-disable-line
|
||||
})
|
||||
lazy.prop(o, 'output', function () {
|
||||
if (!o.hash) return
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
|
@ -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<number | Buffer>): boolean {
|
||||
const buffer = bscript.compile(script)
|
||||
|
|
Loading…
Reference in a new issue