From 5af02e937aed9754394abeb30c8d61a25434d34d Mon Sep 17 00:00:00 2001 From: MattFaus Date: Tue, 11 Mar 2014 10:46:01 -0700 Subject: [PATCH] Work in progress. I have a problem with the verifyInput() callback calling itself whenever the test assertions throw an exception. I looked at the step and async libraries that are already installed via package.json, but I don't think either of these provide the functionality I need. --- Script.js | 4 ++-- Transaction.js | 2 +- test/test.Transaction.js | 29 +++++++++++++++++++++++------ 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Script.js b/Script.js index 37d705cca..ae4e47956 100644 --- a/Script.js +++ b/Script.js @@ -491,7 +491,7 @@ Script.prototype.toHumanReadable = function() { } } return s; - + }; Script.stringToBuffer = function(s) { @@ -505,7 +505,7 @@ Script.stringToBuffer = function(s) { //console.log('hex value'); buf.put(new Buffer(word.substring(2, word.length), 'hex')); } else { - var opcode = Opcode.map['OP_' + word]; + var opcode = Opcode.map['OP_' + word] || Opcode.map[word]; if (typeof opcode !== 'undefined') { // op code in string form //console.log('opcode'); diff --git a/Transaction.js b/Transaction.js index 6d287414c..31d4dcf38 100644 --- a/Transaction.js +++ b/Transaction.js @@ -655,7 +655,7 @@ Transaction.prototype.parse = function (parser) { var i, sLen, startPos = parser.pos; this.version = parser.word32le(); - + var txinCount = parser.varInt(); this.ins = []; diff --git a/test/test.Transaction.js b/test/test.Transaction.js index bfe46e90d..224d9d72d 100644 --- a/test/test.Transaction.js +++ b/test/test.Transaction.js @@ -1,6 +1,7 @@ 'use strict'; var chai = chai || require('chai'); +chai.Assertion.includeStack = true; var bitcore = bitcore || require('../bitcore'); var should = chai.should(); @@ -273,9 +274,10 @@ describe('Transaction', function() { inputs.forEach(function(vin) { var hash = vin[0]; var index = vin[1]; - var scriptPubKey = new Script(new Buffer(vin[2])); + debugger; + var scriptPubKey = Script.fromHumanReadable(vin[2]); inputScriptPubKeys.push(scriptPubKey); - console.log(scriptPubKey.getStringContent()); + console.log(scriptPubKey.toHumanReadable()); console.log('********************************'); done(); @@ -288,11 +290,26 @@ describe('Transaction', function() { var n = 0; inputScriptPubKeys.forEach(function(scriptPubKey) { - tx.verifyInput(0, scriptPubKey, function(err, results) { - should.not.exist(err); - should.exist(results); - results.should.equal(true); + var err = undefined; + var results = undefined; + var inputVerified = false; + + tx.verifyInput(n, scriptPubKey, function(e, r) { + // Exceptions raised inside this function will be handled + // ...by this function, so don't do it. + err = e; + results = r; + inputVerified = true; }); + + // TODO(mattfaus): Add a Promise or something that makes this code + // execute only after the verifyInput() callback has finished + while (!inputVerified) { } + + should.not.exist(err); + should.exist(results); + results.should.equal(true); + n += 1; });