From a86e9056112be4157f6aa5257e233260a41af7a7 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Sat, 17 Dec 2016 14:29:42 +1100 Subject: [PATCH] script: add fromASM failing test case and fix --- src/script.js | 1 + test/fixtures/script.json | 6 ++++++ test/script.js | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/src/script.js b/src/script.js index 62c5d3a..4245bf1 100644 --- a/src/script.js +++ b/src/script.js @@ -145,6 +145,7 @@ function fromASM (asm) { return compile(asm.split(' ').map(function (chunkStr) { // opcode? if (OPS[chunkStr] !== undefined) return OPS[chunkStr] + typeforce(types.Hex, chunkStr) // data! return new Buffer(chunkStr, 'hex') diff --git a/test/fixtures/script.json b/test/fixtures/script.json index c6a0eea..e0ef536 100644 --- a/test/fixtures/script.json +++ b/test/fixtures/script.json @@ -189,6 +189,12 @@ "description": "Not enough data: OP_PUSHDATA4 0xffffffff", "script": "4effffffff01" } + ], + "fromASM": [ + { + "description": "Expected Hex, got String \"0xff\"", + "script": "0xff OP_CHECKSIG" + } ] } } diff --git a/test/script.js b/test/script.js index e164cb7..b9680bf 100644 --- a/test/script.js +++ b/test/script.js @@ -28,6 +28,14 @@ describe('script', function () { assert.strictEqual(bscript.toASM(scriptSig), f.asm) }) }) + + fixtures.invalid.fromASM.forEach(function (f) { + it('throws ' + f.description, function () { + assert.throws(function () { + bscript.fromASM(f.script) + }, new RegExp(f.description)) + }) + }) }) describe('isPushOnly', function () {