Browse Source

Add classify types

addTSTests
junderw 6 years ago
parent
commit
c265065cd0
No known key found for this signature in database GPG Key ID: B256185D3A971908
  1. 4
      test/classify.js
  2. 12
      ts_test/block.ts
  3. 3
      ts_test/bufferutils.ts
  4. 15
      ts_test/classify.ts
  5. 94
      ts_test/fixtureTypes.ts

4
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 ' +

12
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);

3
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', () => {

15
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);

94
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[];
};
};
}

Loading…
Cancel
Save