diff --git a/bitcore.js b/bitcore.js index 551a8341a..89eeef3ab 100644 --- a/bitcore.js +++ b/bitcore.js @@ -7,7 +7,14 @@ module.exports.bignum = require('bignum'); module.exports.base58 = require('base58-native'); module.exports.EncodedData = require('./util/EncodedData'); module.exports.VersionedData = require('./util/VersionedData'); -module.exports.Address= require('./Address'); +module.exports.Address = require('./Address'); +module.exports.config = require('./config'); +module.exports.log = require('./util/log'); +module.exports.Opcode = require('./Opcode'); +module.exports.util = require('./util/util'); +module.exports.Script = require('./Script'); +module.exports.SINKey = require('./SINKey'); +//module.exports.Transaction = require('./Transaction'); if (typeof process.versions === 'undefined') { diff --git a/browser/vendor_load.js b/browser/vendor_load.js index 9a4251f38..4e9748306 100644 --- a/browser/vendor_load.js +++ b/browser/vendor_load.js @@ -1,5 +1,5 @@ // load modules needed for testing in the browser -var fs = require('fs'); +//var fs = require('fs'); diff --git a/networks.js b/networks.js index d5086f103..97a1fa99e 100644 --- a/networks.js +++ b/networks.js @@ -16,21 +16,21 @@ exports.livenet = { bits: 486604799 }, genesisBlockTx: { - 'outs': [{ - 'v': hex('00F2052A01000000'), // 50 BTC - 's': new Put() + outs: [{ + v: hex('00F2052A01000000'), // 50 BTC + s: new Put() .word8(65) // 65 bytes of data follow .put(hex('04678AFDB0FE5548271967F1A67130B7105CD6A828E03909A67962E0EA1F61DEB649F6BC3F4CEF38C4F35504E51EC112DE5C384DF7BA0B8D578A4C702B6BF11D5F')) .word8(0xAC) // OP_CHECKSIG .buffer() }], - 'lock_time': 0, - 'version': 1, - 'hash': hex('3BA3EDFD7A7B12B27AC72C3E67768F617FC81BC3888A51323A9FB8AA4B1E5E4A'), - 'ins': [{ - 'q': 0xFFFFFFFF, - 'o': hex("0000000000000000000000000000000000000000000000000000000000000000FFFFFFFF"), - 's': new Put() + lock_time: 0, + version: 1, + hash: hex('3BA3EDFD7A7B12B27AC72C3E67768F617FC81BC3888A51323A9FB8AA4B1E5E4A'), + ins: [{ + q: 0xFFFFFFFF, + o: hex("0000000000000000000000000000000000000000000000000000000000000000FFFFFFFF"), + s: new Put() .put(hex('04FFFF001D010445')) .put(new Buffer('The Times 03/Jan/2009 Chancellor on brink of ' + 'second bailout for banks', 'ascii')) diff --git a/sin-test.js b/sin-test.js deleted file mode 100644 index df00923bf..000000000 --- a/sin-test.js +++ /dev/null @@ -1,7 +0,0 @@ - -var SINKey = require('./SINKey').class(); - -var sk = new SINKey(); -sk.generate(); -console.dir(sk.storeObj()); - diff --git a/test/index.html b/test/index.html index 0d62a92fd..8cf9a0ff7 100644 --- a/test/index.html +++ b/test/index.html @@ -20,6 +20,9 @@ + + + diff --git a/test/test.Address.js b/test/test.Address.js index ec0787bc0..5713cf5c4 100644 --- a/test/test.Address.js +++ b/test/test.Address.js @@ -16,14 +16,14 @@ describe('Address', function() { Address = AddressModule.class(); should.exist(Address); }); - it('should be able to create Address object', function() { + it('should be able to create instance', function() { var a = new Address('1KfyjCgBSMsLqiCbakfSdeoBUqMqLUiu3T'); should.exist(a); }); it('should validate correctly', function() { - var a = new Address("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"); - var m = new Address("32QBdjycLwbDTuGafUwaU5p5GxzSLPYoF6"); - var b = new Address("11111111111111111111111111122222234"); + var a = new Address('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'); + var m = new Address('32QBdjycLwbDTuGafUwaU5p5GxzSLPYoF6'); + var b = new Address('11111111111111111111111111122222234'); a.validate.bind(a).should.not.throw(Error); m.validate.bind(m).should.not.throw(Error); b.validate.bind(b).should.throw(Error); diff --git a/test/test.Opcode.js b/test/test.Opcode.js new file mode 100644 index 000000000..fa78f5e59 --- /dev/null +++ b/test/test.Opcode.js @@ -0,0 +1,43 @@ +'use strict'; + +var chai = require('chai'); +var bitcore = require('../bitcore'); + +var should = chai.should(); + +var OpcodeModule = bitcore.Opcode; +var Opcode; + +describe('Opcode', function() { + it('should initialze the main object', function() { + should.exist(OpcodeModule); + }); + it('should be able to create class', function() { + Opcode = OpcodeModule.class(); + should.exist(Opcode); + }); + it('should be able to create instance', function() { + var oc = new Opcode(); + should.exist(oc); + }); + it.skip('should be able to create some constants', function() { + // TODO: test works in node but not in browser + for (var i in Opcode.map) { + console.log('var '+i + ' = ' + Opcode.map[i] + ';'); + eval('var '+i + ' = ' + Opcode.map[i] + ';'); + console.log(eval(i)); + } + should.exist(OP_VER); + should.exist(OP_HASH160); + should.exist(OP_RETURN); + should.exist(OP_EQUALVERIFY); + should.exist(OP_CHECKSIG); + should.exist(OP_CHECKMULTISIG); + + }); +}); + + + + + diff --git a/test/test.SIN.js b/test/test.SIN.js new file mode 100644 index 000000000..469c318fd --- /dev/null +++ b/test/test.SIN.js @@ -0,0 +1,30 @@ +'use strict'; + + + +var chai = require('chai'); +var bitcore = require('../bitcore'); + +var should = chai.should(); + +var SINKeyModule = bitcore.SINKey; +var SINKey; + + +describe('SINKey', function() { + it('should initialze the main object', function() { + should.exist(SINKeyModule); + }); + it('should be able to create class', function() { + SINKey = SINKeyModule.class(); + should.exist(SINKey); + }); + it('should be able to create instance', function() { + var sk = new SINKey(); + sk.generate(); + should.exist(sk.created); + should.exist(sk.privKey.private); + should.exist(sk.privKey.public); + should.exist(sk.privKey.compressed); + }); +}); diff --git a/test/test.Script.js b/test/test.Script.js new file mode 100644 index 000000000..31e8523a0 --- /dev/null +++ b/test/test.Script.js @@ -0,0 +1,40 @@ +'use strict'; + +var chai = require('chai'); +var bitcore = require('../bitcore'); + +var should = chai.should(); + +var ScriptModule = bitcore.Script; +var Address = bitcore.Address.class(); +var Script; + +describe('Script', function() { + it('should initialze the main object', function() { + should.exist(ScriptModule); + }); + it('should be able to create class', function() { + Script = ScriptModule.class(); + should.exist(Script); + }); + it('should be able to create instance', function() { + var s = new Script(); + should.exist(s); + }); + it('should be able to create Script from Address', function() { + var addr = new Address('1J57QmkaQ6JohJoQyaUJwngJ2vTQ3C6gHi'); + var script = Script.createPubKeyHashOut(addr.payload()); + should.exist(script); + script.isPubkeyHash().should.be.true; + }); + it('isP2SH should work', function() { + var addr = new Address('1J57QmkaQ6JohJoQyaUJwngJ2vTQ3C6gHi'); + var script = Script.createPubKeyHashOut(addr.payload()); + script.isP2SH().should.be.false; + }); +}); + + + + + diff --git a/test/test.Transaction.js b/test/test.Transaction.js new file mode 100644 index 000000000..02da04a9e --- /dev/null +++ b/test/test.Transaction.js @@ -0,0 +1,28 @@ +'use strict'; + +var chai = require('chai'); +var bitcore = require('../bitcore'); + +var should = chai.should(); + +var TransactionModule = bitcore.Transaction; +var Transaction; + +describe.skip('Transaction', function() { + it('should initialze the main object', function() { + should.exist(TransactionModule); + }); + it('should be able to create class', function() { + Transaction = TransactionModule.class(); + should.exist(Transaction); + }); + it('should be able to create instance', function() { + var t = new Transaction(); + should.exist(t); + }); +}); + + + + + diff --git a/test/test.misc.js b/test/test.misc.js new file mode 100644 index 000000000..ab4364ade --- /dev/null +++ b/test/test.misc.js @@ -0,0 +1,24 @@ +'use strict'; + +var chai = require('chai'); +var bitcore = require('../bitcore'); + +var should = chai.should(); + +describe('Miscelaneous stuff', function() { + it('should initialze the config object', function() { + should.exist(bitcore.config); + }); + it('should initialze the log object', function() { + should.exist(bitcore.log); + }); + it('should initialze the util object', function() { + should.exist(bitcore.util); + }); + +}); + + + + + diff --git a/util/util.js b/util/util.js index f12a38ff1..5568610ad 100644 --- a/util/util.js +++ b/util/util.js @@ -1,4 +1,5 @@ -require('buffertools'); +'use strict'; + var crypto = require('crypto'); var bignum = require('bignum'); var Binary = require('binary'); @@ -327,7 +328,8 @@ var varStrBuf = exports.varStrBuf = function varStrBuf(s) { exports.NULL_HASH = new Buffer(32).fill(0); exports.EMPTY_BUFFER = new Buffer(0); exports.ZERO_VALUE = new Buffer(8).fill(0); -INT64_MAX = new Buffer('ffffffffffffffff', 'hex'); +var INT64_MAX = new Buffer('ffffffffffffffff', 'hex'); +exports.INT64_MAX = INT64_MAX; // How much of Bitcoin's internal integer coin representation // makes 1 BTC