diff --git a/RpcClient.js b/RpcClient.js index 80a1972..38df00f 100644 --- a/RpcClient.js +++ b/RpcClient.js @@ -123,17 +123,19 @@ function ClassSpec(b) { }; for(var k in apiCalls) { - var spec = apiCalls[k].split(' '); - for (var i = 0; i < spec.length; i++) { - if(types[spec[i]]) { - spec[i] = types[spec[i]]; - } else { - spec[i] = types.string; + if (apiCalls.hasOwnProperty(k)) { + var spec = apiCalls[k].split(' '); + for (var i = 0; i < spec.length; i++) { + if(types[spec[i]]) { + spec[i] = types[spec[i]]; + } else { + spec[i] = types.string; + } } - }; - var methodName = k.toLowerCase(); - constructor.prototype[k] = createRPCMethod(methodName, spec); - constructor.prototype[methodName] = constructor.prototype[k]; + var methodName = k.toLowerCase(); + constructor.prototype[k] = createRPCMethod(methodName, spec); + constructor.prototype[methodName] = constructor.prototype[k]; + } } } diff --git a/WalletKey.js b/WalletKey.js index 3f6c92e..e0e6aaa 100644 --- a/WalletKey.js +++ b/WalletKey.js @@ -8,6 +8,8 @@ function ClassSpec(b) { var Address = require('./Address').class(); function WalletKey(cfg) { + if (!cfg) cfg = {}; + if (!cfg.network) throw new Error('network parameter is required'); this.network = cfg.network; // required this.created = cfg.created; this.privKey = cfg.privKey; diff --git a/bitcore.js b/bitcore.js index 145ee39..c557f44 100644 --- a/bitcore.js +++ b/bitcore.js @@ -5,21 +5,32 @@ module.exports.bignum = require('bignum'); module.exports.base58 = require('base58-native'); +module.exports.buffertools = require('buffertools'); +module.exports.config = require('./config'); +module.exports.const = require('./const'); +module.exports.Deserialize = require('./Deserialize'); +module.exports.log = require('./util/log'); +module.exports.networks = require('./networks'); +module.exports.util = require('./util/util'); module.exports.EncodedData = require('./util/EncodedData'); module.exports.VersionedData = require('./util/VersionedData'); module.exports.Address = require('./Address'); -module.exports.config = require('./config'); -module.exports.log = require('./util/log'); -module.exports.networks = require('./networks'); 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'); module.exports.Peer = require('./Peer'); +module.exports.PeerManager = require('./PeerManager'); module.exports.Block = require('./Block'); module.exports.Connection = require('./Connection'); module.exports.ScriptInterpreter = require('./ScriptInterpreter'); +module.exports.Bloom = require('./Bloom'); +module.exports.Key = require('./Key').Key; +module.exports.SINKey = require('./SINKey'); +module.exports.SIN = require('./SIN'); +module.exports.PrivateKey = require('./PrivateKey'); +module.exports.RpcClient = require('./RpcClient'); +module.exports.Wallet = require('./Wallet'); +module.exports.WalletKey = require('./WalletKey'); if (typeof process.versions === 'undefined') { diff --git a/package.json b/package.json index 7e6478b..aa98b89 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ }, "scripts": {}, "dependencies": { - "classtool": "=1.0.0", + "classtool": "git://github.com/bitpay/classtool.git", "base58-native": "=0.1.3", "bindings": "=1.1.1", "bufferput": "=0.1.1", diff --git a/test/adapter.js b/test/adapter.js index 80a63ce..312667b 100644 --- a/test/adapter.js +++ b/test/adapter.js @@ -16,8 +16,3 @@ if (typeof require === 'undefined') { } - -if (typeof module === 'undefined') { - var that = this; - that.module = bitcore.module; -} diff --git a/test/index.html b/test/index.html index 008a49c..810bfeb 100644 --- a/test/index.html +++ b/test/index.html @@ -15,19 +15,30 @@ - - - - - - - - + - + + + + + + + + + + + + + + diff --git a/test/test.Bloom.js b/test/test.Bloom.js new file mode 100644 index 0000000..bec1f51 --- /dev/null +++ b/test/test.Bloom.js @@ -0,0 +1,28 @@ +'use strict'; + +var chai = require('chai'); +var bitcore = require('../bitcore'); + +var should = chai.should(); + +var BloomModule = bitcore.Script; +var Bloom; + +describe('Bloom', function() { + it('should initialze the main object', function() { + should.exist(BloomModule); + }); + it('should be able to create class', function() { + Bloom = BloomModule.class(); + should.exist(Bloom); + }); + it('should be able to create instance', function() { + var s = new Bloom(); + should.exist(s); + }); +}); + + + + + diff --git a/test/test.Key.js b/test/test.Key.js new file mode 100644 index 0000000..a8d4982 --- /dev/null +++ b/test/test.Key.js @@ -0,0 +1,23 @@ +'use strict'; + +var chai = require('chai'); +var bitcore = require('../bitcore'); + +var should = chai.should(); + +var Key = bitcore.Key; + +describe.skip('Key', function() { + it('should initialze the main object', function() { + should.exist(Key); + }); + it('should be able to create instance', function() { + var k = new Key(); + should.exist(k); + }); +}); + + + + + diff --git a/test/test.PeerManager.js b/test/test.PeerManager.js new file mode 100644 index 0000000..fc36379 --- /dev/null +++ b/test/test.PeerManager.js @@ -0,0 +1,37 @@ +'use strict'; + +var chai = require('chai'); +var bitcore = require('../bitcore'); + +var should = chai.should(); + +var PeerManagerModule = bitcore.PeerManager; +var PeerManager; + +describe('PeerManager', function() { + it('should initialze the main object', function() { + should.exist(PeerManagerModule); + }); + it('should be able to create class', function() { + PeerManager = PeerManagerModule.class(); + should.exist(PeerManager); + }); + it('should be able to create instance', function() { + var pm = new PeerManager(); + should.exist(pm); + }); + it('should be able to start instance', function() { + var pm = new PeerManager(); + pm.start.bind(pm).should.not.throw(); + }); + it('should be able to stop instance', function() { + var pm = new PeerManager(); + pm.start(); + pm.stop.bind(pm).should.not.throw(); + }); +}); + + + + + diff --git a/test/test.PrivateKey.js b/test/test.PrivateKey.js new file mode 100644 index 0000000..b7ab9c3 --- /dev/null +++ b/test/test.PrivateKey.js @@ -0,0 +1,28 @@ +'use strict'; + +var chai = require('chai'); +var bitcore = require('../bitcore'); + +var should = chai.should(); + +var PrivateKeyModule = bitcore.PrivateKey; +var PrivateKey; + +describe('PrivateKey', function() { + it('should initialze the main object', function() { + should.exist(PrivateKeyModule); + }); + it('should be able to create class', function() { + PrivateKey = PrivateKeyModule.class(); + should.exist(PrivateKey); + }); + it('should be able to create instance', function() { + var pk = new PrivateKey(); + should.exist(pk); + }); +}); + + + + + diff --git a/test/test.RpcClient.js b/test/test.RpcClient.js new file mode 100644 index 0000000..cbc795a --- /dev/null +++ b/test/test.RpcClient.js @@ -0,0 +1,28 @@ +'use strict'; + +var chai = require('chai'); +var bitcore = require('../bitcore'); + +var should = chai.should(); + +var RpcClientModule = bitcore.RpcClient; +var RpcClient; + RpcClient = RpcClientModule.class(); + +describe('RpcClient', function() { + it('should initialze the main object', function() { + should.exist(RpcClientModule); + }); + it('should be able to create class', function() { + should.exist(RpcClient); + }); + it('should be able to create instance', function() { + var s = new RpcClient(); + should.exist(s); + }); +}); + + + + + diff --git a/test/test.SIN.js b/test/test.SIN.js index 469c318..12c32fc 100644 --- a/test/test.SIN.js +++ b/test/test.SIN.js @@ -1,30 +1,28 @@ 'use strict'; - - var chai = require('chai'); var bitcore = require('../bitcore'); var should = chai.should(); -var SINKeyModule = bitcore.SINKey; -var SINKey; +var SINModule = bitcore.SIN; +var SIN; - -describe('SINKey', function() { +describe('SIN', function() { it('should initialze the main object', function() { - should.exist(SINKeyModule); + should.exist(SINModule); }); it('should be able to create class', function() { - SINKey = SINKeyModule.class(); - should.exist(SINKey); + SIN = SINModule.class(); + should.exist(SIN); }); 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); + var s = new SIN(); + should.exist(s); }); }); + + + + + diff --git a/test/test.SINKey.js b/test/test.SINKey.js new file mode 100644 index 0000000..469c318 --- /dev/null +++ b/test/test.SINKey.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.Wallet.js b/test/test.Wallet.js new file mode 100644 index 0000000..906603e --- /dev/null +++ b/test/test.Wallet.js @@ -0,0 +1,28 @@ +'use strict'; + +var chai = require('chai'); +var bitcore = require('../bitcore'); + +var should = chai.should(); + +var WalletModule = bitcore.Wallet; +var Wallet; + +describe('Wallet', function() { + it('should initialze the main object', function() { + should.exist(WalletModule); + }); + it('should be able to create class', function() { + Wallet = WalletModule.class(); + should.exist(Wallet); + }); + it('should be able to create instance', function() { + var s = new Wallet(); + should.exist(s); + }); +}); + + + + + diff --git a/test/test.WalletKey.js b/test/test.WalletKey.js new file mode 100644 index 0000000..9d127ec --- /dev/null +++ b/test/test.WalletKey.js @@ -0,0 +1,31 @@ +'use strict'; + +var chai = require('chai'); +var bitcore = require('../bitcore'); + +var should = chai.should(); + +var WalletKeyModule = bitcore.WalletKey; +var networks = bitcore.networks; +var WalletKey; + +describe('WalletKey', function() { + it('should initialze the main object', function() { + should.exist(WalletKeyModule); + }); + it('should be able to create class', function() { + WalletKey = WalletKeyModule.class(); + should.exist(WalletKey); + }); + it('should be able to create instance', function() { + var s = new WalletKey({ + network: networks.livenet + }); + should.exist(s); + }); +}); + + + + + diff --git a/test/test.base58.js b/test/test.base58.js deleted file mode 100644 index 54d57eb..0000000 --- a/test/test.base58.js +++ /dev/null @@ -1,45 +0,0 @@ -'use strict'; - -var chai = require('chai'); -var bitcore = require('../bitcore'); - -var expect = chai.expect; -var should = chai.should(); - -var bignum = bitcore.bignum; -var base58 = bitcore.base58; -var base58Check = base58.base58Check; - -describe('bignum module basics', function() { - it('should initialze the main object', function() { - should.exist(bitcore.bignum); - }); - it('should create a bignum from string', function() { - var n = bignum('9832087987979879879879879879879879879879879879'); - should.exist(n); - }); - it('should perform basic math operations', function() { - var b = bignum('782910138827292261791972728324982') - .sub('182373273283402171237474774728373') - .div(13); - b.toNumber().should.equal(46195143503376160811884457968969); - }); -}); - - -describe('base58 module', function() { - it('should initialze the main object', function() { - should.exist(bitcore.base58); - }); - it('should obtain the same string in base58 roundtrip', function() { - var m = 'mqqa8xSMVDyf9QxihGnPtap6Mh6qemUkcu'; - base58.encode(base58.decode(m)).should.equal(m); - }); - it('should obtain the same string in base58Check roundtrip', function() { - var m = '1QCJj1gPZKx2EwzGo9Ri8mMBs39STvDYcv'; - base58Check.encode(base58Check.decode(m)).should.equal(m); - }); -}); - - - diff --git a/test/test.misc.js b/test/test.misc.js index ab4364a..58720e1 100644 --- a/test/test.misc.js +++ b/test/test.misc.js @@ -5,6 +5,10 @@ var bitcore = require('../bitcore'); var should = chai.should(); +var bignum = bitcore.bignum; +var base58 = bitcore.base58; +var base58Check = base58.base58Check; + describe('Miscelaneous stuff', function() { it('should initialze the config object', function() { should.exist(bitcore.config); @@ -15,6 +19,42 @@ describe('Miscelaneous stuff', function() { it('should initialze the util object', function() { should.exist(bitcore.util); }); + it('should initialze the const object', function() { + should.exist(bitcore.const); + }); + it('should initialze the Deserialize object', function() { + should.exist(bitcore.Deserialize); + should.exist(bitcore.Deserialize.intFromCompact); + }); + + + // bignum + it('should initialze the bignum object', function() { + should.exist(bitcore.bignum); + }); + it('should create a bignum from string', function() { + var n = bignum('9832087987979879879879879879879879879879879879'); + should.exist(n); + }); + it('should perform basic math operations for bignum', function() { + var b = bignum('782910138827292261791972728324982') + .sub('182373273283402171237474774728373') + .div(13); + b.toNumber().should.equal(46195143503376160811884457968969); + }); + + // base58 + it('should initialze the base58 object', function() { + should.exist(bitcore.base58); + }); + it('should obtain the same string in base58 roundtrip', function() { + var m = 'mqqa8xSMVDyf9QxihGnPtap6Mh6qemUkcu'; + base58.encode(base58.decode(m)).should.equal(m); + }); + it('should obtain the same string in base58Check roundtrip', function() { + var m = '1QCJj1gPZKx2EwzGo9Ri8mMBs39STvDYcv'; + base58Check.encode(base58Check.decode(m)).should.equal(m); + }); }); @@ -22,3 +62,4 @@ describe('Miscelaneous stuff', function() { +