From a801663c6da4eb52d932539d7e9b861dad36f55d Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Mon, 5 Jan 2015 17:31:51 -0500 Subject: [PATCH 1/3] Fixed bug in Safari for PublicKey and Script instance checking in Address --- lib/address.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/address.js b/lib/address.js index 96d1a06..b773f9d 100644 --- a/lib/address.js +++ b/lib/address.js @@ -213,8 +213,9 @@ Address._transformBuffer = function(buffer, network, type){ * @private */ Address._transformPublicKey = function(pubkey){ + var PublicKey = require('./publickey'); var info = {}; - if (!pubkey.constructor || (pubkey.constructor.name && pubkey.constructor.name !== 'PublicKey')) { + if (!(pubkey instanceof PublicKey)) { throw new TypeError('Address must be an instance of PublicKey.'); } info.hashBuffer = Hash.sha256ripemd160(pubkey.toBuffer()); @@ -230,8 +231,9 @@ Address._transformPublicKey = function(pubkey){ * @private */ Address._transformScript = function(script, network){ + var Script = require('./script'); var info = {}; - if (!script.constructor || (script.constructor.name && script.constructor.name !== 'Script')) { + if (!(script instanceof Script)) { throw new TypeError('Address must be an instance of Script.'); } if (script.isScriptHashOut()) { From ff4a6f549d8ccf9a350bdc7d9df74032dff90d23 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Mon, 5 Jan 2015 23:27:20 -0500 Subject: [PATCH 2/3] Fixed bugs in IE11 --- lib/address.js | 6 ++++-- lib/script/script.js | 5 ++--- test/hdkeycache.js | 2 ++ test/mocha.opts | 1 + test/paymentprotocol/index.js | 2 ++ test/transaction/transaction.js | 1 + test/util/preconditions.js | 3 ++- 7 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/address.js b/lib/address.js index b773f9d..118d011 100644 --- a/lib/address.js +++ b/lib/address.js @@ -100,15 +100,17 @@ function Address(data, network, type) { * @returns {Object} An "info" object with "type", "network", and "hashBuffer" */ Address.prototype._classifyArguments = function(data, network, type) { + var PublicKey = require('./publickey'); + var Script = require('./script'); /* jshint maxcomplexity: 10 */ // transform and validate input data if ((data instanceof Buffer || data instanceof Uint8Array) && data.length === 20) { return Address._transformHash(data); } else if ((data instanceof Buffer || data instanceof Uint8Array) && data.length === 21) { return Address._transformBuffer(data, network, type); - } else if (data.constructor && (data.constructor.name && data.constructor.name === 'PublicKey')) { + } else if (data instanceof PublicKey) { return Address._transformPublicKey(data); - } else if (data.constructor && (data.constructor.name && data.constructor.name === 'Script')) { + } else if (data instanceof Script) { return Address._transformScript(data, network); } else if (typeof(data) === 'string') { return Address._transformString(data, network, type); diff --git a/lib/script/script.js b/lib/script/script.js index f7820cb..c06d636 100644 --- a/lib/script/script.js +++ b/lib/script/script.js @@ -177,7 +177,6 @@ Script.fromString = function(str) { Script.prototype.toString = function() { var str = ''; - for (var i = 0; i < this.chunks.length; i++) { var chunk = this.chunks[i]; var opcodenum = chunk.opcodenum; @@ -459,7 +458,7 @@ Script.prototype._addByType = function(obj, prepend) { this._addOpcode(obj, prepend); } else if (typeof obj === 'number') { this._addOpcode(obj, prepend); - } else if (obj.constructor && obj.constructor.name && obj.constructor.name === 'Opcode') { + } else if (obj instanceof Opcode) { this._addOpcode(obj, prepend); } else if (BufferUtil.isBuffer(obj)) { this._addBuffer(obj, prepend); @@ -484,7 +483,7 @@ Script.prototype._addOpcode = function(opcode, prepend) { var op; if (typeof opcode === 'number') { op = opcode; - } else if (opcode.constructor && opcode.constructor.name && opcode.constructor.name === 'Opcode') { + } else if (opcode instanceof Opcode) { op = opcode.toNumber(); } else { op = Opcode(opcode).toNumber(); diff --git a/test/hdkeycache.js b/test/hdkeycache.js index 57635d4..db1f4fc 100644 --- a/test/hdkeycache.js +++ b/test/hdkeycache.js @@ -8,6 +8,8 @@ var HDPrivateKey = bitcore.HDPrivateKey; var xprivkey = 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'; describe('HDKey cache', function() { + this.timeout(10000); + /* jshint unused: false */ var cache = bitcore._HDKeyCache; var master = new HDPrivateKey(xprivkey); diff --git a/test/mocha.opts b/test/mocha.opts index 4a52320..9409cf5 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1 +1,2 @@ --recursive +--timeout 5000 diff --git a/test/paymentprotocol/index.js b/test/paymentprotocol/index.js index 17fd076..4ba58ca 100644 --- a/test/paymentprotocol/index.js +++ b/test/paymentprotocol/index.js @@ -279,6 +279,8 @@ var bitpayRequest = new Buffer('' describe('PaymentProtocol', function() { + this.timeout(15000); + it('should be able to create class', function() { should.exist(PaymentProtocol); }); diff --git a/test/transaction/transaction.js b/test/transaction/transaction.js index 742be1e..2aeeaa8 100644 --- a/test/transaction/transaction.js +++ b/test/transaction/transaction.js @@ -84,6 +84,7 @@ describe('Transaction', function() { }); describe('transaction creation test vector', function() { + this.timeout(5000); var index = 0; transactionVector.forEach(function(vector) { index++; diff --git a/test/util/preconditions.js b/test/util/preconditions.js index 5db9bb9..74a727f 100644 --- a/test/util/preconditions.js +++ b/test/util/preconditions.js @@ -52,7 +52,8 @@ describe('preconditions', function() { $.checkArgumentType(1, PrivateKey); } catch (e) { error = e; - e.message.should.equal('Invalid Argument for (unknown name), expected PrivateKey but got number'); + var fail = !(~e.message.indexOf('Invalid Argument for (unknown name)')); + fail.should.equal(false); } should.exist(error); }); From bce28cd227d6e6c2a746ff655909c5e9e567ddad Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Tue, 6 Jan 2015 12:00:28 -0500 Subject: [PATCH 3/3] Fixed bug in IE11 that would cause MAX_MONEY verification test to fail. --- lib/transaction/output.js | 1 - lib/transaction/transaction.js | 4 ++-- test/script/interpreter.js | 6 ++++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/transaction/output.js b/lib/transaction/output.js index 896f833..9b31f66 100644 --- a/lib/transaction/output.js +++ b/lib/transaction/output.js @@ -83,7 +83,6 @@ Output.prototype.setScript = function(script) { this._scriptBuffer = script; this._script = null; } else { - console.log(script); throw new TypeError('Unrecognized Argument'); } return this; diff --git a/lib/transaction/transaction.js b/lib/transaction/transaction.js index 5370e25..3a1f833 100644 --- a/lib/transaction/transaction.js +++ b/lib/transaction/transaction.js @@ -656,11 +656,11 @@ Transaction.prototype.verify = function() { var valueoutbn = BN(0); for (var i = 0; i < this.outputs.length; i++) { var txout = this.outputs[i]; - var valuebn = BN(txout.satoshis.toString(16)); + var valuebn = txout._satoshis; if (valuebn.lt(0)) { return 'transaction txout ' + i + ' negative'; } - if (valuebn.gt(Transaction.MAX_MONEY)) { + if (valuebn.gt(BN(Transaction.MAX_MONEY, 10))) { return 'transaction txout ' + i + ' greater than MAX_MONEY'; } valueoutbn = valueoutbn.add(valuebn); diff --git a/test/script/interpreter.js b/test/script/interpreter.js index 46bda12..3394c68 100644 --- a/test/script/interpreter.js +++ b/test/script/interpreter.js @@ -259,7 +259,8 @@ describe('Interpreter', function() { return; } c++; - it('should pass tx_' + (expected ? '' : 'in') + 'valid vector ' + c, function() { + var cc = c; //copy to local + it('should pass tx_' + (expected ? '' : 'in') + 'valid vector ' + cc, function() { var inputs = vector[0]; var txhex = vector[1]; var flags = getFlags(vector[2]); @@ -291,9 +292,10 @@ describe('Interpreter', function() { } }); var txVerified = tx.verify(); - txVerified = _.isBoolean(txVerified); + txVerified = (txVerified === true) ? true : false; allInputsVerified = allInputsVerified && txVerified; allInputsVerified.should.equal(expected); + }); }); };