From cbe2e2f28d164db01ac1e1b1f0d5c1d60db39cad Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 20 Apr 2016 12:54:32 -0700 Subject: [PATCH] add bad size push test. --- test/script-test.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test/script-test.js b/test/script-test.js index 9731186e..b9e80dd0 100644 --- a/test/script-test.js +++ b/test/script-test.js @@ -140,6 +140,46 @@ describe('Script', function() { return true; } + it('should handle bad size pushes correctly.', function () { + var err; + var stack = new bcoin.script.stack(); + var s = bcoin.script.fromTestString( + 'OP_1 OP_DUP OP_PUSHDATA1' + ); + assert(utils.equals(s.raw, new Buffer('51764c', 'hex'))); + try { + s.execute(stack); + } catch (e) { + err = e; + } + assert(err); + assert(err.code === 'BAD_OPCODE'); + var s = bcoin.script.fromTestString( + 'OP_1 OP_DUP OP_PUSHDATA2 0x01' + ); + assert(utils.equals(s.raw, new Buffer('51764d01', 'hex'))); + err = null; + try { + s.execute(stack); + } catch (e) { + err = e; + } + assert(err); + assert(err.code === 'BAD_OPCODE'); + var s = bcoin.script.fromTestString( + 'OP_1 OP_DUP OP_PUSHDATA4 0x0001' + ); + assert(utils.equals(s.raw, new Buffer('51764e0001', 'hex'))); + err = null; + try { + s.execute(stack); + } catch (e) { + err = e; + } + assert(err); + assert(err.code === 'BAD_OPCODE'); + }); + it('should handle CScriptNums correctly', function () { var s = bcoin.script.fromSymbolic([ new Buffer([0xff, 0xff, 0xff, 0x7f]), 'OP_NEGATE', 'OP_DUP', 'OP_ADD'