From c265065cd0fdf79c6631e33dfe9acdb9c87e5c6d Mon Sep 17 00:00:00 2001 From: junderw Date: Fri, 12 Apr 2019 10:28:26 +0900 Subject: [PATCH] Add classify types --- test/classify.js | 4 +- ts_test/block.ts | 12 +++--- ts_test/bufferutils.ts | 3 +- ts_test/classify.ts | 15 ++++--- ts_test/fixtureTypes.ts | 94 ++++++++++++++--------------------------- 5 files changed, 52 insertions(+), 76 deletions(-) diff --git a/test/classify.js b/test/classify.js index faf20cd..1a8aa64 100644 --- a/test/classify.js +++ b/test/classify.js @@ -91,7 +91,7 @@ describe('classify', () => { }); if (!fixtures.invalid[name]) return; - fixtures.invalid[name].inputs.forEach(f => { + fixtures.invalid[name].inputs.forEach((f) => { if (!f.input && !f.inputHex) return; it('returns false for ' + @@ -128,7 +128,7 @@ describe('classify', () => { }); if (!fixtures.invalid[name]) return; - fixtures.invalid[name].outputs.forEach(f => { + fixtures.invalid[name].outputs.forEach((f) => { if (!f.output && !f.outputHex) return; it('returns false for ' + diff --git a/ts_test/block.ts b/ts_test/block.ts index 1626f46..ab1ae7c 100644 --- a/ts_test/block.ts +++ b/ts_test/block.ts @@ -63,7 +63,7 @@ describe('Block', () => { describe('toBuffer/toHex', () => { fixtures.valid.forEach(f => { - let block; + let block: Block; beforeEach(() => { block = Block.fromHex(f.hex); @@ -78,7 +78,7 @@ describe('Block', () => { describe('getHash/getId', () => { fixtures.valid.forEach(f => { - let block; + let block: Block; beforeEach(() => { block = Block.fromHex(f.hex); @@ -93,7 +93,7 @@ describe('Block', () => { describe('getUTCDate', () => { fixtures.valid.forEach(f => { - let block; + let block: Block; beforeEach(() => { block = Block.fromHex(f.hex); @@ -117,7 +117,7 @@ describe('Block', () => { fixtures.valid.forEach(f => { if (f.hex.length === 160) return; - let block; + let block: Block; beforeEach(() => { block = Block.fromHex(f.hex); @@ -145,7 +145,7 @@ describe('Block', () => { fixtures.valid.forEach(f => { if (f.hex.length === 160) return; - let block; + let block: Block; beforeEach(() => { block = Block.fromHex(f.hex); @@ -159,7 +159,7 @@ describe('Block', () => { describe('checkProofOfWork', () => { fixtures.valid.forEach(f => { - let block; + let block: Block; beforeEach(() => { block = Block.fromHex(f.hex); diff --git a/ts_test/bufferutils.ts b/ts_test/bufferutils.ts index a19806c..14c5a97 100644 --- a/ts_test/bufferutils.ts +++ b/ts_test/bufferutils.ts @@ -1,8 +1,9 @@ +import { FixtureBufferUtils } from './fixtureTypes'; const { describe, it } = require('mocha'); const assert = require('assert'); const bufferutils = require('../src/bufferutils'); -const fixtures = require('../ts_test/fixtures/bufferutils.json'); +const fixtures: FixtureBufferUtils = require('../ts_test/fixtures/bufferutils.json'); describe('bufferutils', () => { describe('readUInt64LE', () => { diff --git a/ts_test/classify.ts b/ts_test/classify.ts index 2e21a01..2c5826d 100644 --- a/ts_test/classify.ts +++ b/ts_test/classify.ts @@ -1,9 +1,14 @@ +import { + FixtureTemplateInput, + FixtureTemplateOutput, + FixtureTemplates, +} from './fixtureTypes'; const { describe, it } = require('mocha'); const assert = require('assert'); const bscript = require('../src/script'); const classify = require('../src/classify'); -const fixtures = require('../ts_test/fixtures/templates.json'); +const fixtures: FixtureTemplates = require('../ts_test/fixtures/templates.json'); const multisig = require('../src/templates/multisig'); const nullData = require('../src/templates/nulldata'); @@ -104,7 +109,7 @@ describe('classify', () => { if (!fixtures.invalid[name]) return; - fixtures.invalid[name].inputs.forEach(f => { + fixtures.invalid[name].inputs.forEach((f: FixtureTemplateInput) => { if (!f.input && !f.inputHex) return; it( @@ -114,7 +119,7 @@ describe('classify', () => { (f.input || f.inputHex) + ')', () => { - let input; + let input: Buffer; if (f.input) { input = bscript.fromASM(f.input); @@ -153,7 +158,7 @@ describe('classify', () => { if (!fixtures.invalid[name]) return; - fixtures.invalid[name].outputs.forEach(f => { + fixtures.invalid[name].outputs.forEach((f: FixtureTemplateOutput) => { if (!f.output && !f.outputHex) return; it( @@ -163,7 +168,7 @@ describe('classify', () => { (f.output || f.outputHex) + ')', () => { - let output; + let output: Buffer; if (f.output) { output = bscript.fromASM(f.output); diff --git a/ts_test/fixtureTypes.ts b/ts_test/fixtureTypes.ts index f8f5c23..95e5170 100644 --- a/ts_test/fixtureTypes.ts +++ b/ts_test/fixtureTypes.ts @@ -258,6 +258,27 @@ export interface FixtureSignature { }; }>; } +export interface FixtureTemplateInput { + description?: string; + input?: string; + inputHex?: string; + output?: string; + signatures?: string[]; + exception?: string; + type?: string; +} +export interface FixtureTemplateOutput { + exception?: string; + commitment?: string; + description?: string; + scriptPubKeyHex?: string; + outputHex?: string; + hash?: string; + m?: number; + output?: string; + pubKeys?: string[]; + signatures?: string[]; +} export interface FixtureTemplates { valid: Array<{ type: string; @@ -283,83 +304,32 @@ export interface FixtureTemplates { }>; invalid: { pubKey: { - inputs: Array<{ - description: string; - input: string; - }>; - outputs: Array<{ - description: string; - outputHex?: string; - output?: string; - }>; + inputs: FixtureTemplateInput[]; + outputs: FixtureTemplateOutput[]; }; pubKeyHash: { - inputs: Array<{ - description: string; - input: string; - }>; - outputs: Array<{ - description?: string; - outputHex?: string; - exception?: string; - hash?: string; - }>; + inputs: FixtureTemplateInput[]; + outputs: FixtureTemplateOutput[]; }; scriptHash: { - inputs: Array<{ - description: string; - input: string; - }>; - outputs: Array<{ - description?: string; - outputHex?: string; - exception?: string; - hash?: string; - }>; + inputs: FixtureTemplateInput[]; + outputs: FixtureTemplateOutput[]; }; multisig: { - inputs: Array<{ - output: string; - signatures: string[]; - exception?: string; - description?: string; - type?: string; - }>; - outputs: Array<{ - description?: string; - output?: string; - exception?: string; - m?: number; - pubKeys?: string[]; - signatures?: string[]; - }>; + inputs: FixtureTemplateInput[]; + outputs: FixtureTemplateOutput[]; }; witnessPubKeyHash: { inputs: []; - outputs: Array<{ - description?: string; - outputHex?: string; - exception?: string; - hash?: string; - }>; + outputs: FixtureTemplateOutput[]; }; witnessScriptHash: { inputs: []; - outputs: Array<{ - description?: string; - outputHex?: string; - exception?: string; - hash?: string; - }>; + outputs: FixtureTemplateOutput[]; }; witnessCommitment: { inputs: []; - outputs: Array<{ - exception?: string; - commitment?: string; - description?: string; - scriptPubKeyHex?: string; - }>; + outputs: FixtureTemplateOutput[]; }; }; }