Browse Source

Added TypeScript standard linter to tests

fixTypes
junderw 6 years ago
parent
commit
572fd159b0
No known key found for this signature in database GPG Key ID: B256185D3A971908
  1. 14
      package.json
  2. 2
      src/block.ts
  3. 4
      src/payments/embed.ts
  4. 2
      src/payments/index.ts
  5. 2
      src/payments/lazy.ts
  6. 18
      src/payments/p2ms.ts
  7. 4
      src/payments/p2pk.ts
  8. 6
      src/payments/p2pkh.ts
  9. 7
      src/payments/p2sh.ts
  10. 6
      src/payments/p2wpkh.ts
  11. 7
      src/payments/p2wsh.ts
  12. 2
      src/templates/nulldata.ts

14
package.json

@ -24,7 +24,7 @@
"nobuild:coverage-html": "nyc report --reporter=html", "nobuild:coverage-html": "nyc report --reporter=html",
"nobuild:coverage": "nyc --check-coverage --branches 90 --functions 90 --lines 90 mocha", "nobuild:coverage": "nyc --check-coverage --branches 90 --functions 90 --lines 90 mocha",
"nobuild:integration": "mocha --timeout 50000 test/integration/", "nobuild:integration": "mocha --timeout 50000 test/integration/",
"nobuild:standard": "standard", "nobuild:standard": "standard src/**/*.ts",
"nobuild:unit": "mocha", "nobuild:unit": "mocha",
"prepare": "npm run build", "prepare": "npm run build",
"standard": "npm run build && npm run nobuild:standard", "standard": "npm run build && npm run nobuild:standard",
@ -63,12 +63,20 @@
"bn.js": "^4.11.8", "bn.js": "^4.11.8",
"bs58": "^4.0.0", "bs58": "^4.0.0",
"dhttp": "^3.0.0", "dhttp": "^3.0.0",
"eslint-plugin-typescript": "^0.14.0",
"hoodwink": "^2.0.0", "hoodwink": "^2.0.0",
"minimaldata": "^1.0.2", "minimaldata": "^1.0.2",
"mocha": "^5.2.0", "mocha": "^5.2.0",
"nyc": "^11.8.0", "nyc": "^11.8.0",
"proxyquire": "^2.0.1", "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"
]
}
} }

2
src/block.ts

@ -124,7 +124,7 @@ export class Block {
return target return target
} }
static calculateMerkleRoot (transactions: Array<Transaction>, forWitness: boolean | void): Buffer { static calculateMerkleRoot (transactions: Array<Transaction>, forWitness?: boolean): Buffer {
typeforce([{ getHash: types.Function }], transactions) typeforce([{ getHash: types.Function }], transactions)
if (transactions.length === 0) throw errorMerkleNoTxes if (transactions.length === 0) throw errorMerkleNoTxes
if (forWitness && !txesHaveWitness(transactions)) throw errorWitnessNotSegwit if (forWitness && !txesHaveWitness(transactions)) throw errorWitnessNotSegwit

4
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 bscript from '../script'
import * as lazy from './lazy' import * as lazy from './lazy'
import { bitcoin as BITCOIN_NETWORK } from '../networks' import { bitcoin as BITCOIN_NETWORK } from '../networks'
const typef = require('typeforce') const typef = require('typeforce')
import { OPS } from '../script' const OPS = bscript.OPS
function stacksEqual (a: Array<Buffer>, b: Array<Buffer>): boolean { function stacksEqual (a: Array<Buffer>, b: Array<Buffer>): boolean {
if (a.length !== b.length) return false if (a.length !== b.length) return false

2
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 { p2data as embed } from './embed'
import { p2ms } from './p2ms' import { p2ms } from './p2ms'
import { p2pk } from './p2pk' import { p2pk } from './p2pk'

2
src/payments/lazy.ts

@ -18,7 +18,7 @@ export function prop (object: Object, name: string, f: ()=>any): void {
}) })
} }
export function value <T>(f: ()=>T): ()=>T { export function value <T> (f: ()=>T): ()=>T {
let value: T let value: T
return function (): T { return function (): T {
if (value !== undefined) return value if (value !== undefined) return value

18
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 bscript from '../script'
import * as lazy from './lazy' import * as lazy from './lazy'
import { bitcoin as BITCOIN_NETWORK } from '../networks' import { bitcoin as BITCOIN_NETWORK } from '../networks'
const OPS = bscript.OPS
const typef = require('typeforce') const typef = require('typeforce')
import { OPS } from '../script'
const ecc = require('tiny-secp256k1') const ecc = require('tiny-secp256k1')
const OP_INT_BASE = OPS.OP_RESERVED // OP_1 - 1 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 || {}) opts = Object.assign({ validate: true }, opts || {})
function isAcceptableSignature (x: Buffer | number) { 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({ typef({
@ -51,8 +53,8 @@ export function p2ms (a: Payment, opts?: PaymentOpts): Payment {
if (decoded) return if (decoded) return
decoded = true decoded = true
chunks = <Array<Buffer | number>>bscript.decompile(output) chunks = <Array<Buffer | number>>bscript.decompile(output)
o.m = <number>chunks[0] - OP_INT_BASE o.m = <number> chunks[0] - OP_INT_BASE // eslint-disable-line
o.n = <number>chunks[chunks.length - 2] - OP_INT_BASE o.n = <number> chunks[chunks.length - 2] - OP_INT_BASE // eslint-disable-line
o.pubkeys = <Array<Buffer>>chunks.slice(1, -2) 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 (chunks[chunks.length - 1] !== OPS.OP_CHECKMULTISIG) throw new TypeError('Output is invalid')
if ( if (
<number>(<Payment>o).m <= 0 || <number>(<Payment>o).m <= 0 || // eslint-disable-line
<number>(<Payment>o).n > 16 || <number>(<Payment>o).n > 16 || // eslint-disable-line
<number>(<Payment>o).m > <number>(<Payment>o).n || <number>(<Payment>o).m > <number>(<Payment>o).n || // eslint-disable-line
o.n !== chunks.length - 3) throw new TypeError('Output is invalid') 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') if (!(<Array<Buffer>>o.pubkeys).every(x => ecc.isPoint(x))) throw new TypeError('Output is invalid')

4
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 bscript from '../script'
import * as lazy from './lazy' import * as lazy from './lazy'
import { bitcoin as BITCOIN_NETWORK } from '../networks' import { bitcoin as BITCOIN_NETWORK } from '../networks'
const typef = require('typeforce') const typef = require('typeforce')
import { OPS } from '../script' const OPS = bscript.OPS
const ecc = require('tiny-secp256k1') const ecc = require('tiny-secp256k1')
// input: {signature} // input: {signature}

6
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 bscript from '../script'
import * as bcrypto from '../crypto' import * as bcrypto from '../crypto'
import * as lazy from './lazy' import * as lazy from './lazy'
import { bitcoin as BITCOIN_NETWORK } from '../networks' import { bitcoin as BITCOIN_NETWORK } from '../networks'
const typef = require('typeforce') const typef = require('typeforce')
import { OPS } from '../script' const OPS = bscript.OPS
const ecc = require('tiny-secp256k1') const ecc = require('tiny-secp256k1')
const bs58check = require('bs58check') const bs58check = require('bs58check')
@ -54,7 +54,7 @@ export function p2pkh (a: Payment, opts?: PaymentOpts): Payment {
lazy.prop(o, 'hash', function () { lazy.prop(o, 'hash', function () {
if (a.output) return a.output.slice(3, 23) if (a.output) return a.output.slice(3, 23)
if (a.address) return _address().hash 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 () { lazy.prop(o, 'output', function () {
if (!o.hash) return if (!o.hash) return

7
src/payments/p2sh.ts

@ -1,11 +1,10 @@
import { Payment, PaymentOpts } from './index' import { Payment, PaymentOpts } from './index' // eslint-disable-line
import { Network } from '../networks' import { Network, bitcoin as BITCOIN_NETWORK } from '../networks' // eslint-disable-line
import * as bscript from '../script' import * as bscript from '../script'
import * as bcrypto from '../crypto' import * as bcrypto from '../crypto'
import * as lazy from './lazy' import * as lazy from './lazy'
import { bitcoin as BITCOIN_NETWORK } from '../networks'
const typef = require('typeforce') const typef = require('typeforce')
import { OPS } from '../script' const OPS = bscript.OPS
const bs58check = require('bs58check') const bs58check = require('bs58check')

6
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 bscript from '../script'
import * as bcrypto from '../crypto' import * as bcrypto from '../crypto'
import * as lazy from './lazy' import * as lazy from './lazy'
import { bitcoin as BITCOIN_NETWORK } from '../networks' import { bitcoin as BITCOIN_NETWORK } from '../networks'
const typef = require('typeforce') const typef = require('typeforce')
import { OPS } from '../script' const OPS = bscript.OPS
const ecc = require('tiny-secp256k1') const ecc = require('tiny-secp256k1')
const bech32 = require('bech32') const bech32 = require('bech32')
@ -59,7 +59,7 @@ export function p2wpkh (a: Payment, opts?: PaymentOpts): Payment {
lazy.prop(o, 'hash', function () { lazy.prop(o, 'hash', function () {
if (a.output) return a.output.slice(2, 22) if (a.output) return a.output.slice(2, 22)
if (a.address) return _address().data 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 () { lazy.prop(o, 'output', function () {
if (!o.hash) return if (!o.hash) return

7
src/payments/p2wsh.ts

@ -1,11 +1,10 @@
import { Payment, PaymentOpts } from './index' import { Payment, PaymentOpts } from './index' // eslint-disable-line
import { Network } from '../networks' import { Network, bitcoin as BITCOIN_NETWORK } from '../networks' // eslint-disable-line
import * as bscript from '../script' import * as bscript from '../script'
import * as bcrypto from '../crypto' import * as bcrypto from '../crypto'
import * as lazy from './lazy' import * as lazy from './lazy'
import { bitcoin as BITCOIN_NETWORK } from '../networks'
const typef = require('typeforce') const typef = require('typeforce')
import { OPS } from '../script' const OPS = bscript.OPS
const bech32 = require('bech32') const bech32 = require('bech32')

2
src/templates/nulldata.ts

@ -1,6 +1,6 @@
// OP_RETURN {data} // OP_RETURN {data}
import * as bscript from '../script' import * as bscript from '../script'
import { OPS } from '../script' const OPS = bscript.OPS
export function check (script: Buffer | Array<number | Buffer>): boolean { export function check (script: Buffer | Array<number | Buffer>): boolean {
const buffer = bscript.compile(script) const buffer = bscript.compile(script)

Loading…
Cancel
Save