From deb8b0f7d87e18e4fa6f3606042fc5673aad1dd6 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Fri, 22 Sep 2017 11:33:32 +1000 Subject: [PATCH] tests: script tests can validate template fixtures too --- test/script.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/test/script.js b/test/script.js index 4adf293..07f907f 100644 --- a/test/script.js +++ b/test/script.js @@ -5,6 +5,7 @@ var bscript = require('../src/script') var minimalData = require('minimaldata') var fixtures = require('./fixtures/script.json') +var fixtures2 = require('./fixtures/templates.json') describe('script', function () { // TODO @@ -23,8 +24,8 @@ describe('script', function () { describe('fromASM/toASM', function () { fixtures.valid.forEach(function (f) { it('encodes/decodes ' + f.asm, function () { - var scriptSig = bscript.fromASM(f.asm) - assert.strictEqual(bscript.toASM(scriptSig), f.asm) + var script = bscript.fromASM(f.asm) + assert.strictEqual(bscript.toASM(script), f.asm) }) }) @@ -37,6 +38,28 @@ describe('script', function () { }) }) + describe('fromASM/toASM (templates)', function () { + fixtures2.valid.forEach(function (f) { + if (f.inputHex) { + var ih = bscript.toASM(Buffer.from(f.inputHex, 'hex')) + + it('encodes/decodes ' + ih, function () { + var script = bscript.fromASM(f.input) + assert.strictEqual(script.toString('hex'), f.inputHex) + assert.strictEqual(bscript.toASM(script), f.input) + }) + } + + if (f.outputHex) { + it('encodes/decodes ' + f.output, function () { + var script = bscript.fromASM(f.output) + assert.strictEqual(script.toString('hex'), f.outputHex) + assert.strictEqual(bscript.toASM(script), f.output) + }) + } + }) + }) + describe('isPushOnly', function () { fixtures.valid.forEach(function (f) { it('returns ' + !!f.stack + ' for ' + f.asm, function () {