From 3a0aa08be3b996b099eb347a93d5d971a002c795 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Fri, 31 Jan 2014 11:13:34 -0500 Subject: [PATCH 1/5] added README for browser build --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 3afb4a4..3948c59 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,5 @@ npm install npm install -g grunt-cli grunt browserify - [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/bitpay/bitcore/trend.png)](https://bitdeli.com/free "Bitdeli Badge") From 304fdc013d324823af285bf7e0884d6c7be71a55 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Tue, 4 Feb 2014 16:02:09 -0300 Subject: [PATCH 2/5] starting address migration --- bitcore.js | 2 +- test/index.html | 1 + test/test.Address.js | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/test.Address.js diff --git a/bitcore.js b/bitcore.js index 3b01f7a..7bc20e5 100644 --- a/bitcore.js +++ b/bitcore.js @@ -5,7 +5,7 @@ module.exports.bignum = require('bignum'); module.exports.base58 = require('base58-native'); -//module.exports.Address = require('./Address'); +module.exports.Address = require('./Address'); diff --git a/test/index.html b/test/index.html index 773d3ff..726aa39 100644 --- a/test/index.html +++ b/test/index.html @@ -16,6 +16,7 @@ + diff --git a/test/test.Address.js b/test/test.Address.js new file mode 100644 index 0000000..c70818f --- /dev/null +++ b/test/test.Address.js @@ -0,0 +1,24 @@ +'use strict'; + +var chai = require('chai'); +var bitcore = require('../bitcore'); + +var expect = chai.expect; +var should = chai.should(); + +var Address = bitcore.Address.class(); + +describe('Address', function() { + it('should initialze the main object', function() { + should.exist(Address); + }); + it('should create a bignum from string', function() { + }); + it('should perform basic math operations', function() { + }); +}); + + + + + From 0a6ddaffa345fb99e8cde6c6938f2927cd3df0d1 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Wed, 5 Feb 2014 17:00:08 -0300 Subject: [PATCH 3/5] EncodedData working in the browser --- .gitignore | 1 + Address.js | 8 +++++--- Gruntfile.js | 12 ++++++++++-- bitcore.js | 4 ++-- browser/vendor_load.js | 5 +++++ test/adapter.js | 6 ++++++ test/index.html | 5 +++-- test/test.Address.js | 13 +++++++------ test/test.EncodedData.js | 28 ++++++++++++++++++++++++++++ test/{basic.js => test.basic.js} | 1 + util/EncodedData.js | 13 ++++++++----- 11 files changed, 76 insertions(+), 20 deletions(-) create mode 100644 browser/vendor_load.js create mode 100644 test/test.EncodedData.js rename test/{basic.js => test.basic.js} (99%) 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); From fc93218c560ea2940190d86f4388ca31702fc047 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Wed, 5 Feb 2014 18:14:00 -0300 Subject: [PATCH 4/5] Address working in the browser --- bitcore.js | 3 ++- test/index.html | 2 ++ test/test.Address.js | 13 ++++++++++++- test/test.EncodedData.js | 4 ++-- test/test.VersionedData.js | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 test/test.VersionedData.js diff --git a/bitcore.js b/bitcore.js index ebaa814..551a834 100644 --- a/bitcore.js +++ b/bitcore.js @@ -5,8 +5,9 @@ module.exports.bignum = require('bignum'); module.exports.base58 = require('base58-native'); -module.exports.Manu = require('./util/manu').class(); module.exports.EncodedData = require('./util/EncodedData'); +module.exports.VersionedData = require('./util/VersionedData'); +module.exports.Address= require('./Address'); if (typeof process.versions === 'undefined') { diff --git a/test/index.html b/test/index.html index 4420f74..0d62a92 100644 --- a/test/index.html +++ b/test/index.html @@ -18,6 +18,8 @@ + + diff --git a/test/test.Address.js b/test/test.Address.js index c62ede4..ec0787b 100644 --- a/test/test.Address.js +++ b/test/test.Address.js @@ -8,14 +8,25 @@ var should = chai.should(); var AddressModule = bitcore.Address; var Address; -describe.skip('Address', function() { +describe('Address', function() { it('should initialze the main object', function() { should.exist(AddressModule); }); it('should be able to create class', function() { Address = AddressModule.class(); + should.exist(Address); }); it('should be able to create Address object', 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"); + 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.EncodedData.js b/test/test.EncodedData.js index a5f7e5b..26c657b 100644 --- a/test/test.EncodedData.js +++ b/test/test.EncodedData.js @@ -16,8 +16,8 @@ describe('EncodedData', function() { EncodedData = EncodedDataModule.class(); should.exist(EncodedData); }); - it('should be able to create EncodedData object', function() { - var ed = new EncodedData(); + it('should be able to create an instance', function() { + var ed = new EncodedData('1GMx4HdDmN78xzGvdQYkwrVqkmLDG1aMNT'); should.exist(ed); }); }); diff --git a/test/test.VersionedData.js b/test/test.VersionedData.js new file mode 100644 index 0000000..0f18360 --- /dev/null +++ b/test/test.VersionedData.js @@ -0,0 +1,34 @@ +'use strict'; + +var chai = require('chai'); +var bitcore = require('../bitcore'); + +var should = chai.should(); + +var VersionedDataModule = bitcore.VersionedData; +var VersionedData; + +describe('VersionedData', function() { + it('should initialze the main object', function() { + should.exist(VersionedDataModule); + }); + it('should be able to create class', function() { + VersionedData = VersionedDataModule.class(); + should.exist(VersionedData); + }); + it('should be able to create an instance', function() { + var vd = new VersionedData(); + should.exist(vd); + }); + it('should get correct version', function() { + var vda = new VersionedData('1GMx4HdDmN78xzGvdQYkwrVqkmLDG1aMNT'); + var vdb = new VersionedData('3746djr32k2Lp23UUbdkCTQ6zhMJ7d8MD7'); + vda.version().should.equal(0); + vdb.version().should.equal(5); + }); +}); + + + + + From ce321e42d0e2ab9c212eb5b980840b9f2a1eecbf Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 6 Feb 2014 16:36:49 -0300 Subject: [PATCH 5/5] remove use-strict --- Address.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/Address.js b/Address.js index 35a430e..e429a31 100644 --- a/Address.js +++ b/Address.js @@ -1,5 +1,3 @@ -'use strict'; - require('classtool'); function ClassSpec(b) {