From ddb3e6de70082e2698fd3e33baeedda6f58bcb41 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Tue, 18 Mar 2014 19:17:43 -0300 Subject: [PATCH] invalid script test passing! --- Script.js | 4 +--- ScriptInterpreter.js | 5 +++-- test/test.ScriptInterpreter.js | 12 +++++------- test/test.examples.js | 4 ++-- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Script.js b/Script.js index 2ef22c40c..37d705cca 100644 --- a/Script.js +++ b/Script.js @@ -33,11 +33,9 @@ function Script(buffer) { } else { this.buffer = util.EMPTY_BUFFER; } - console.log(buffertools.toHex(this.buffer)); this.chunks = []; this.parse(); - console.log(this.chunks); -}; +} this.class = Script; Script.TX_UNKNOWN = TX_UNKNOWN; diff --git a/ScriptInterpreter.js b/ScriptInterpreter.js index 0f5210f09..dce95817c 100644 --- a/ScriptInterpreter.js +++ b/ScriptInterpreter.js @@ -811,7 +811,7 @@ ScriptInterpreter.prototype.stackTop = function stackTop(offset) { }; ScriptInterpreter.prototype.stackBack = function stackBack() { - return this.stack[-1]; + return this.stack[this.stack.length -1]; }; /** @@ -944,7 +944,8 @@ function verifyStep3(scriptSig, scriptPubKey, txTo, nIn, return; } - assert.notEqual(siCopy.length, 0); + if (siCopy.length === 0) + throw new Error('siCopy should have length != 0'); var subscript = new Script(siCopy.stackPop()); diff --git a/test/test.ScriptInterpreter.js b/test/test.ScriptInterpreter.js index f245fcfa8..e4f579b31 100644 --- a/test/test.ScriptInterpreter.js +++ b/test/test.ScriptInterpreter.js @@ -31,19 +31,17 @@ describe('ScriptInterpreter', function() { var scriptPubKey = datum[1]; // output script var human = scriptSig + ' ' + scriptPubKey; it('should ' + (!valid ? 'not ' : '') + 'validate script ' + human, function(done) { - console.log((!valid ? 'invalid ' : 'valid ') + human + ';' + (i++) + ' - ' + datum[2]); try { - ScriptInterpreter.verify( - Script.fromHumanReadable(scriptSig), - Script.fromHumanReadable(scriptPubKey), - null, 0, 0, // tx, output index, and hashtype + ScriptInterpreter.verifyFull( + Script.fromHumanReadable(scriptSig), // scriptSig + Script.fromHumanReadable(scriptPubKey), // scriptPubKey + null, 0, 0, // tx, output index, hashtype + { verifyP2SH: !valid}, // only verify P2SH for invalid data set function(err, result) { if (valid) { should.not.exist(err); } else { var failed = (typeof err !== 'undefined') || (result === false); - console.log('err=' + err); - console.log('result=' + result); failed.should.equal(true); } if (typeof result !== 'undefined') { diff --git a/test/test.examples.js b/test/test.examples.js index 55c9ccd2f..4115bc7c5 100644 --- a/test/test.examples.js +++ b/test/test.examples.js @@ -15,8 +15,8 @@ var examples = [ ]; describe('Examples', function() { - //before(mute); - //after(unmute); + before(mute); + after(unmute); examples.forEach(function(example) { it('valid '+example, function() { var ex = require('../examples/'+example);