From ce5babde83359f4a15b48731d2f2bfa5248423d1 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 2 Nov 2016 14:24:31 +1100 Subject: [PATCH] templates: fix nullData return value --- src/templates/nulldata.js | 2 +- test/templates.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/templates/nulldata.js b/src/templates/nulldata.js index e996107..5b6af90 100644 --- a/src/templates/nulldata.js +++ b/src/templates/nulldata.js @@ -21,7 +21,7 @@ function encode (data) { function decode (buffer) { typeforce(check, buffer) - return buffer.slice(1) + return buffer.slice(2) } module.exports = { diff --git a/test/templates.js b/test/templates.js index f693b4d..6edcfbd 100644 --- a/test/templates.js +++ b/test/templates.js @@ -348,16 +348,20 @@ describe('script-templates', function () { }) }) - describe('nullData.output.encode', function () { + describe('nullData.output', function () { fixtures.valid.forEach(function (f) { if (f.type !== 'nulldata') return var data = new Buffer(f.data, 'hex') var scriptPubKey = bscript.nullData.output.encode(data) - it('returns ' + f.scriptPubKey, function () { + it('encodes to ' + f.scriptPubKey, function () { assert.strictEqual(bscript.toASM(scriptPubKey), f.scriptPubKey) }) + + it('decodes to ' + f.data, function () { + assert.deepEqual(bscript.nullData.output.decode(scriptPubKey), data) + }) }) }) })