diff --git a/Block.js b/Block.js index f0abb5e82..9854aa0a5 100644 --- a/Block.js +++ b/Block.js @@ -35,7 +35,7 @@ function spec(b) { this.active = data.active || false; this.chainWork = data.chainWork || util.EMPTY_BUFFER; this.txs = data.txs || []; - }; + } Block.prototype.getHeader = function getHeader() { var buf = new Buffer(80); diff --git a/Connection.js b/Connection.js index 6e9e36596..64664172b 100644 --- a/Connection.js +++ b/Connection.js @@ -17,6 +17,7 @@ function spec(b) { var Transaction = require('./Transaction').class(); var util = b.util || require('./util/util'); var Parser = b.Parser || require('./util/BinaryParser').class(); + var buffertools = b.buffertools || require('buffertools'); var doubleSha256 = b.doubleSha256 || util.twoSha256; var nonce = util.generateNonce(); @@ -114,7 +115,7 @@ function spec(b) { switch (message.command) { case 'version': // Did we connect to ourself? - if (nonce.compare(message.nonce) === 0) { + if (buffertools.compare(nonce, message.nonce) === 0) { this.socket.end(); return; } @@ -376,7 +377,7 @@ function spec(b) { if (checksum !== null) { var checksumConfirm = doubleSha256(payload).slice(0, 4); - if (checksumConfirm.compare(checksum) !== 0) { + if (buffertools.compare(checksumConfirm, checksum) !== 0) { log.err('['+this.peer+'] '+ 'Checksum failed', { cmd: command, diff --git a/Script.js b/Script.js index 33c4deef7..5d9856c95 100644 --- a/Script.js +++ b/Script.js @@ -4,7 +4,8 @@ function spec(b) { var config = b.config || require('./config'); var log = b.log || require('./util/log'); - var Opcode = require('./Opcode').class(); + var Opcode = b.Opcode || require('./Opcode').class(); + var buffertools = b.buffertools || require('buffertools'); // Make opcodes available as pseudo-constants for (var i in Opcode.map) { @@ -396,7 +397,7 @@ function spec(b) { if (Buffer.isBuffer(chunk)) { for (var i = 0, l = this.chunks.length; i < l; i++) { if (Buffer.isBuffer(this.chunks[i]) && - this.chunks[i].compare(chunk) == 0) { + buffertools.compare(this.chunks[i], chunk) === 0) { this.chunks.splice(i, 1); dirty = true; } diff --git a/ScriptInterpreter.js b/ScriptInterpreter.js index c83d18dcf..515e0bea8 100644 --- a/ScriptInterpreter.js +++ b/ScriptInterpreter.js @@ -5,7 +5,8 @@ function spec(b) { var config = b.config || require('./config'); var log = b.log || require('./util/log'); - var Opcode = require('./Opcode').class(); + var Opcode = b.Opcode || require('./Opcode').class(); + var buffertools = b.buffertools || require('buffertools'); // Make opcodes available as pseudo-constants for (var i in Opcode.map) { @@ -385,7 +386,7 @@ function spec(b) { // (x1 x2 - bool) var v1 = this.stackTop(2); var v2 = this.stackTop(1); - var value = v1.compare(v2) == 0; + var value = buffertools.compare(v1, v2) === 0; // OP_NOTEQUAL is disabled because it would be too easy to say // something like n != 1 and have some wiseguy pass in 1 with extra diff --git a/bitcore.js b/bitcore.js index e99952f17..a2c33ac81 100644 --- a/bitcore.js +++ b/bitcore.js @@ -17,6 +17,7 @@ module.exports.SINKey = require('./SINKey'); module.exports.Transaction = require('./Transaction'); module.exports.Peer = require('./Peer'); module.exports.Block = require('./Block'); +module.exports.Connection = require('./Connection'); if (typeof process.versions === 'undefined') { diff --git a/test/test.Block.js b/test/test.Block.js index 8932d6b39..b65baa50f 100644 --- a/test/test.Block.js +++ b/test/test.Block.js @@ -17,7 +17,7 @@ describe('Block', function() { should.exist(Block); }); it('should be able to create instance', function() { - var p = new Block("localhost", 8333); + var p = new Block(); should.exist(p); }); }); diff --git a/test/test.Connection.js b/test/test.Connection.js new file mode 100644 index 000000000..0c568c01a --- /dev/null +++ b/test/test.Connection.js @@ -0,0 +1,29 @@ +'use strict'; + +var chai = require('chai'); +var bitcore = require('../bitcore'); + +var should = chai.should(); + +var ConnectionModule = bitcore.Connection; +var Connection; + +describe('Connection', function() { + it('should initialze the main object', function() { + should.exist(ConnectionModule); + }); + it('should be able to create class', function() { + Connection = ConnectionModule.class(); + should.exist(Connection); + }); + it('should be able to create instance', function() { + var mSocket, mPeer; + var c = new Connection(mSocket, mPeer); + should.exist(c); + }); +}); + + + + + diff --git a/test/test.Peer.js b/test/test.Peer.js index a2ff648a3..477574b28 100644 --- a/test/test.Peer.js +++ b/test/test.Peer.js @@ -17,7 +17,7 @@ describe('Peer', function() { should.exist(Peer); }); it('should be able to create instance', function() { - var p = new Peer("localhost", 8333); + var p = new Peer('localhost', 8333); should.exist(p); }); }); diff --git a/test/test.ScriptInterpreter.js b/test/test.ScriptInterpreter.js new file mode 100644 index 000000000..909a4270f --- /dev/null +++ b/test/test.ScriptInterpreter.js @@ -0,0 +1,28 @@ +'use strict'; + +var chai = require('chai'); +var bitcore = require('../bitcore'); + +var should = chai.should(); + +var ScriptInterpreterModule = bitcore.ScriptInterpreter; +var ScriptInterpreter; + +describe('ScriptInterpreter', function() { + it('should initialze the main object', function() { + should.exist(ScriptInterpreterModule); + }); + it('should be able to create class', function() { + ScriptInterpreter = ScriptInterpreterModule.class(); + should.exist(ScriptInterpreter); + }); + it('should be able to create instance', function() { + var si = new ScriptInterpreter(); + should.exist(si); + }); +}); + + + + +