diff --git a/.gitignore b/.gitignore index 003c14c..5effac1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ build/ browser/bundle.js +browser/vendor.js node_modules/ *.swp *~ diff --git a/Address.js b/Address.js index b7c9866..35a430e 100644 --- a/Address.js +++ b/Address.js @@ -1,3 +1,5 @@ +'use strict'; + require('classtool'); function ClassSpec(b) { @@ -5,7 +7,7 @@ function ClassSpec(b) { function Address() { Address.super(this, arguments); - }; + } Address.superclass = superclass; superclass.applyEncodingsTo(Address); @@ -13,10 +15,10 @@ function ClassSpec(b) { Address.prototype.validate = function() { this.doAsBinary(function() { Address.super(this, 'validate', arguments); - if(this.data.length != 21) throw new Error('invalid data length'); + if(this.data.length !== 21) throw new Error('invalid data length'); }); }; return Address; -}; +} module.defineClass(ClassSpec); diff --git a/Gruntfile.js b/Gruntfile.js index a26a2c6..32d0f9d 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -14,14 +14,22 @@ module.exports = function(grunt) { src: ['bitcore.js'], dest: 'browser/bundle.js', options: { + debug: true, alias: ['browserify-bignum/bignumber.js:bignum'], - standalone: 'bitcore' + standalone: 'bitcore', + } + }, + vendor: { + src: ['browser/vendor_load.js'], + dest: 'browser/vendor.js', + options: { + } } }, watch: { scripts: { - files: ['**/*.js', '**/*.html', '!**/node_modules/**', '!**/bundle.js'], + files: ['**/*.js', '**/*.html', '!**/node_modules/**', '!**/bundle.js', '!**/vendor.js'], tasks: ['browserify'/*, 'mochaTest'*/], }, }, diff --git a/bitcore.js b/bitcore.js index 7bc20e5..ebaa814 100644 --- a/bitcore.js +++ b/bitcore.js @@ -5,8 +5,8 @@ module.exports.bignum = require('bignum'); module.exports.base58 = require('base58-native'); -module.exports.Address = require('./Address'); - +module.exports.Manu = require('./util/manu').class(); +module.exports.EncodedData = require('./util/EncodedData'); if (typeof process.versions === 'undefined') { diff --git a/browser/vendor_load.js b/browser/vendor_load.js new file mode 100644 index 0000000..9a4251f --- /dev/null +++ b/browser/vendor_load.js @@ -0,0 +1,5 @@ + +// load modules needed for testing in the browser + +var fs = require('fs'); + diff --git a/test/adapter.js b/test/adapter.js index b3639da..80a63ce 100644 --- a/test/adapter.js +++ b/test/adapter.js @@ -15,3 +15,9 @@ 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 726aa39..4420f74 100644 --- a/test/index.html +++ b/test/index.html @@ -8,15 +8,16 @@
- + + - + diff --git a/test/test.Address.js b/test/test.Address.js index c70818f..c62ede4 100644 --- a/test/test.Address.js +++ b/test/test.Address.js @@ -3,18 +3,19 @@ var chai = require('chai'); var bitcore = require('../bitcore'); -var expect = chai.expect; var should = chai.should(); -var Address = bitcore.Address.class(); +var AddressModule = bitcore.Address; +var Address; -describe('Address', function() { +describe.skip('Address', function() { it('should initialze the main object', function() { - should.exist(Address); + should.exist(AddressModule); }); - it('should create a bignum from string', function() { + it('should be able to create class', function() { + Address = AddressModule.class(); }); - it('should perform basic math operations', function() { + it('should be able to create Address object', function() { }); }); diff --git a/test/test.EncodedData.js b/test/test.EncodedData.js new file mode 100644 index 0000000..a5f7e5b --- /dev/null +++ b/test/test.EncodedData.js @@ -0,0 +1,28 @@ +'use strict'; + +var chai = require('chai'); +var bitcore = require('../bitcore'); + +var should = chai.should(); + +var EncodedDataModule = bitcore.EncodedData; +var EncodedData; + +describe('EncodedData', function() { + it('should initialze the main object', function() { + should.exist(EncodedDataModule); + }); + it('should be able to create class', function() { + EncodedData = EncodedDataModule.class(); + should.exist(EncodedData); + }); + it('should be able to create EncodedData object', function() { + var ed = new EncodedData(); + should.exist(ed); + }); +}); + + + + + diff --git a/test/basic.js b/test/test.basic.js similarity index 99% rename from test/basic.js rename to test/test.basic.js index 3939786..0b796c8 100644 --- a/test/basic.js +++ b/test/test.basic.js @@ -1,3 +1,4 @@ +'use strict'; var assert = require('assert'); var fs = require('fs'); diff --git a/util/EncodedData.js b/util/EncodedData.js index 5c1e87e..05557fa 100644 --- a/util/EncodedData.js +++ b/util/EncodedData.js @@ -130,17 +130,20 @@ function ClassSpec(b) { }, }; + var no_conversion = function() {return this.data;}; for(var k in encodings) { - if(!encodings[k].converters[k]) - encodings[k].converters[k] = function() {return this.data;}; - encodings[k]._encoding = k; + if(encodings.hasOwnProperty(k)){ + if(!encodings[k].converters[k]) + encodings[k].converters[k] = no_conversion; + encodings[k]._encoding = k; + } } EncodedData.applyEncodingsTo = function(aClass) { var tmp = {}; for(var k in encodings) { var enc = encodings[k]; - var obj = {}; + var obj = {}; for(var j in enc) { obj[j] = enc[j]; } @@ -152,5 +155,5 @@ function ClassSpec(b) { EncodedData.applyEncodingsTo(EncodedData); return EncodedData; -}; +} module.defineClass(ClassSpec);