Browse Source

Merge pull request #51 from maraoz/feature/browserify-Address

browserify Address and dependencies
patch-2
Ryan X. Charles 11 years ago
parent
commit
f066d3e0ce
  1. 1
      .gitignore
  2. 6
      Address.js
  3. 12
      Gruntfile.js
  4. 1
      README.md
  5. 5
      bitcore.js
  6. 5
      browser/vendor_load.js
  7. 6
      test/adapter.js
  8. 6
      test/index.html
  9. 36
      test/test.Address.js
  10. 28
      test/test.EncodedData.js
  11. 34
      test/test.VersionedData.js
  12. 1
      test/test.basic.js
  13. 13
      util/EncodedData.js

1
.gitignore

@ -1,5 +1,6 @@
build/
browser/bundle.js
browser/vendor.js
node_modules/
*.swp
*~

6
Address.js

@ -5,7 +5,7 @@ function ClassSpec(b) {
function Address() {
Address.super(this, arguments);
};
}
Address.superclass = superclass;
superclass.applyEncodingsTo(Address);
@ -13,10 +13,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);

12
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'*/],
},
},

1
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")

5
bitcore.js

@ -5,8 +5,9 @@
module.exports.bignum = require('bignum');
module.exports.base58 = require('base58-native');
//module.exports.Address = require('./Address');
module.exports.EncodedData = require('./util/EncodedData');
module.exports.VersionedData = require('./util/VersionedData');
module.exports.Address= require('./Address');
if (typeof process.versions === 'undefined') {

5
browser/vendor_load.js

@ -0,0 +1,5 @@
// load modules needed for testing in the browser
var fs = require('fs');

6
test/adapter.js

@ -15,3 +15,9 @@ if (typeof require === 'undefined') {
};
}
if (typeof module === 'undefined') {
var that = this;
that.module = bitcore.module;
}

6
test/index.html

@ -8,14 +8,18 @@
</head>
<body>
<div id="mocha"></div>
<script src="adapter.js"></script>
<script src="../browser/vendor.js"></script>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/chai/chai.js"></script>
<script>mocha.setup('bdd')</script>
<script src="../browser/bundle.js"></script>
<script src="adapter.js"></script>
<script src="test.main.js"></script>
<script src="test.base58.js"></script>
<script src="test.EncodedData.js"></script>
<script src="test.VersionedData.js"></script>
<script src="test.Address.js"></script>
<script>
mocha.run();
</script>

36
test/test.Address.js

@ -0,0 +1,36 @@
'use strict';
var chai = require('chai');
var bitcore = require('../bitcore');
var should = chai.should();
var AddressModule = bitcore.Address;
var Address;
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);
});
});

28
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 an instance', function() {
var ed = new EncodedData('1GMx4HdDmN78xzGvdQYkwrVqkmLDG1aMNT');
should.exist(ed);
});
});

34
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);
});
});

1
test/basic.js → test/test.basic.js

@ -1,3 +1,4 @@
'use strict';
var assert = require('assert');
var fs = require('fs');

13
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);

Loading…
Cancel
Save