script: add fromASM failing test case and fix

This commit is contained in:
Daniel Cousens 2016-12-17 14:29:42 +11:00 committed by Daniel Cousens
parent d0b4f0adf7
commit a86e905611
3 changed files with 15 additions and 0 deletions

View file

@ -145,6 +145,7 @@ function fromASM (asm) {
return compile(asm.split(' ').map(function (chunkStr) { return compile(asm.split(' ').map(function (chunkStr) {
// opcode? // opcode?
if (OPS[chunkStr] !== undefined) return OPS[chunkStr] if (OPS[chunkStr] !== undefined) return OPS[chunkStr]
typeforce(types.Hex, chunkStr)
// data! // data!
return new Buffer(chunkStr, 'hex') return new Buffer(chunkStr, 'hex')

View file

@ -189,6 +189,12 @@
"description": "Not enough data: OP_PUSHDATA4 0xffffffff", "description": "Not enough data: OP_PUSHDATA4 0xffffffff",
"script": "4effffffff01" "script": "4effffffff01"
} }
],
"fromASM": [
{
"description": "Expected Hex, got String \"0xff\"",
"script": "0xff OP_CHECKSIG"
}
] ]
} }
} }

View file

@ -28,6 +28,14 @@ describe('script', function () {
assert.strictEqual(bscript.toASM(scriptSig), f.asm) 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 () { describe('isPushOnly', function () {