diff --git a/Gruntfile.js b/Gruntfile.js
index d432885..090f98a 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -13,13 +13,11 @@ module.exports = function(grunt) {
shell: {
browserify: {
options: {
- stdout: true
+ stdout: true,
+ stderr: true
},
- command: 'node ./browserify.js > browser/bundle.js',
- },
- browserifyData: {
- command: 'browserify -t brfs -s testdata test/testdata.js -o browser/testdata.js'
- },
+ command: 'node ./browser/browserify.js',
+ }
},
watch: {
readme: {
@@ -28,7 +26,7 @@ module.exports = function(grunt) {
},
scripts: {
files: ['**/*.js', '**/*.html', '!**/node_modules/**', '!browser/bundle.js', '!browser/testdata.js'],
- tasks: ['shell' /*, 'mochaTest'*/ ],
+ tasks: ['shell'],
},
},
mochaTest: {
diff --git a/browserify.js b/browser/browserify.js
similarity index 65%
rename from browserify.js
rename to browser/browserify.js
index eedd0e6..d1b627f 100644
--- a/browserify.js
+++ b/browser/browserify.js
@@ -1,7 +1,6 @@
'use strict';
/*
- * Example for usage of browserify with soop
*
* The key parameter 'pack'
* The supplied 'custom_prelude.js' file is needed for
@@ -11,27 +10,23 @@
var fs = require('fs');
var browserify = require('browserify');
var browserPack = require('browser-pack');
-var opts = {};
-
-var preludePath = 'node_modules/soop/example/custom_prelude.js';
var pack = function (params) {
+ var preludePath = 'node_modules/soop/example/custom_prelude.js';
params.raw = true;
params.sourceMapPrefix = '//#';
- params.prelude= fs.readFileSync(preludePath, 'utf8');
- params.preludePath= preludePath;
+ params.prelude = fs.readFileSync(preludePath, 'utf8');
+ params.preludePath = preludePath;
return browserPack(params);
};
-opts.pack = pack;
-opts.debug = true;
-
var modules = [
'Address',
'Block',
'Bloom',
'Buffers.monkey',
+ 'Connection',
'Deserialize',
'Gruntfile',
'Number.monkey',
@@ -51,12 +46,18 @@ var modules = [
'config',
'const',
'networks',
- 'bitcore',
];
+var opts = {};
+opts.pack = pack;
+opts.debug = true;
+opts.standalone = 'bitcore';
+opts.insertGlobals = true;
+
var b = browserify(opts);
b.require('browserify-bignum/bignumber.js', {expose: 'bignum'} );
b.require('browserify-buffertools/buffertools.js', {expose:'buffertools'});
+b.require('./bitcore', {expose: 'bitcore'});
b.require('buffer', {expose: 'buffer'});
b.require('base58-native');
b.require('./Key.js', {expose: 'KeyModule'});
@@ -65,27 +66,20 @@ b.require('./util/util');
b.require('./util/EncodedData');
b.require('./util/VersionedData');
b.add('./browser/bignum_config.js');
-b.require('./test/testdata.js', {expose: './testdata'});
-b.transform('brfs');
+modules.forEach(function(m) {
+ b.require('./' + m + '.js' ,{expose: './'+m} );
+});
+b.require('soop');
-b.require('./Connection', {expose: './Connection'});
+b.bundle().pipe(fs.createWriteStream('browser/bundle.js'));
-modules.forEach(function(m) {
- b.require('./' + m + '.js' ,{expose:m} );
- });
-var bopts = {
- transform: ['brfs']
- // detectGlobals: true,
- // insertGlobals: 'Buffer',
- // insertGlobalVars: {
- // Buffer: function () {
- // return 'require("buffer").Buffer';
- // },
- // },
-};
+opts.standalone = 'testdata';
+var tb = browserify(opts);
+tb.require('./test/testdata', {expose: 'testdata'});
+tb.transform('brfs');
-b.bundle(bopts).pipe(process.stdout);
+tb.bundle().pipe(fs.createWriteStream('browser/testdata.js'));
diff --git a/test/adapter.js b/test/adapter.js
index 0f8573b..10b12d7 100644
--- a/test/adapter.js
+++ b/test/adapter.js
@@ -1,20 +1,6 @@
'use strict';
-
-if (typeof require === 'undefined') {
- var that = this;
- that.require = function(name) {
- var split = name.split('/');
- if (split.length > 0) {
- name = split.pop();
- }
- var module = that[name];
- if (!module) {
- if (!bitcore[name])
- throw new Error('Cannot find module "' + name + '"');
- return bitcore[name];
- }
- return module;
- };
- this.Buffer = require('Buffer');
-
-}
+if (typeof process === 'undefined') {
+ var bitcore = require('bitcore');
+ var testdata = require('testdata');
+ var Buffer = bitcore.Buffer;
+}
diff --git a/test/index.html b/test/index.html
index 798acd8..a21f79e 100644
--- a/test/index.html
+++ b/test/index.html
@@ -12,14 +12,8 @@
-
-
-
-
-
+
+
@@ -44,8 +38,6 @@
-
diff --git a/test/test.PeerManager.js b/test/test.PeerManager.js
index b60de02..5f3aa7f 100644
--- a/test/test.PeerManager.js
+++ b/test/test.PeerManager.js
@@ -5,7 +5,7 @@ var bitcore = bitcore || require('../bitcore');
var should = chai.should();
-var PeerManagerModule = bitcore.PeerManager || require('PeerManager');
+var PeerManagerModule = bitcore.PeerManager || require('./PeerManager');
var PeerManager;
diff --git a/test/test.Script.js b/test/test.Script.js
index d8a188a..1b9e2fb 100644
--- a/test/test.Script.js
+++ b/test/test.Script.js
@@ -9,7 +9,7 @@ var ScriptModule = bitcore.Script;
var Address = bitcore.Address;
var networks = bitcore.networks;
var Script;
-var test_data = require('./testdata');
+var testdata = testdata || require('./testdata');
describe('Script', function() {
it('should initialze the main object', function() {
@@ -84,7 +84,7 @@ describe('Script', function() {
});
});
- test_data.dataScriptAll.forEach(function(datum) {
+ testdata.dataScriptAll.forEach(function(datum) {
if (datum.length < 2) throw new Error('Invalid test data');
var human = datum[0] + ' ' + datum[1];
it('should parse script from human readable ' + human, function() {
diff --git a/test/test.ScriptInterpreter.js b/test/test.ScriptInterpreter.js
index f2c0284..166fd0c 100644
--- a/test/test.ScriptInterpreter.js
+++ b/test/test.ScriptInterpreter.js
@@ -4,7 +4,7 @@ var chai = chai || require('chai');
var bitcore = bitcore || require('../bitcore');
var should = chai.should();
-var test_data = require('./testdata');
+var testdata = testdata || require('./testdata');
var ScriptInterpreterModule = bitcore.ScriptInterpreter;
var Script = bitcore.Script;
@@ -23,7 +23,7 @@ describe('ScriptInterpreter', function() {
should.exist(si);
});
var i = 0;
- test_data.dataScriptValid.forEach(function(datum) {
+ testdata.dataScriptValid.forEach(function(datum) {
if (datum.length < 2) throw new Error('Invalid test data');
var scriptSig = datum[0]; // script inputs
var scriptPubKey = datum[1]; // output script
diff --git a/test/test.Transaction.js b/test/test.Transaction.js
index 24d9d6c..ff2dc4b 100644
--- a/test/test.Transaction.js
+++ b/test/test.Transaction.js
@@ -11,7 +11,7 @@ var In;
var Out;
var Script = bitcore.Script;
var buffertools = require('buffertools');
-var test_data = require('./testdata');
+var testdata = testdata || require('./testdata');
describe('Transaction', function() {
it('should initialze the main object', function() {
@@ -35,7 +35,7 @@ describe('Transaction', function() {
// Inner arrays are either [ "comment" ]
// or [[[prevout hash, prevout index, prevout scriptPubKey], [input 2], ...],"], serializedTransaction, enforceP2SH
// ... where all scripts are stringified scripts.
- test_data.dataTxValid.forEach(function(datum) {
+ testdata.dataTxValid.forEach(function(datum) {
if (datum.length === 3) {
it.skip('valid tx=' + datum[1], function(done) {
var inputs = datum[0];
@@ -47,6 +47,7 @@ describe('Transaction', function() {
map[[hash, index]] = scriptPubKey; //Script.fromStringContent(scriptPubKey);
console.log(scriptPubKey.getStringContent());
console.log('********************************');
+ done();
});
var raw = new Buffer(datum[1], 'hex');
diff --git a/test/test.basic.js b/test/test.basic.js
index e728542..ac3df36 100644
--- a/test/test.basic.js
+++ b/test/test.basic.js
@@ -3,18 +3,7 @@
var chai = chai || require('chai');
var bitcore = bitcore || require('../bitcore');
-var test_data;
-if (typeof dataValid !== 'undefined' ) {
- test_data = {
- dataValid: dataValid,
- dataInvalid: dataInvalid,
- };
-
-}
-else {
- test_data = require('./testdata');
-}
-
+var testdata = testdata || require('./testdata');
var should = chai.should();
var Address = bitcore.Address;
@@ -122,7 +111,7 @@ function is_invalid(datum) {
}
describe('Valid base58 keys', function() {
- test_data.dataValid.forEach(function(datum) {
+ testdata.dataValid.forEach(function(datum) {
it('valid ' + datum[0], function() {
is_valid(datum);
});
@@ -130,7 +119,7 @@ describe('Valid base58 keys', function() {
});
describe('Invalid base58 keys', function() {
- test_data.dataInvalid.forEach(function(datum) {
+ testdata.dataInvalid.forEach(function(datum) {
it('invalid ' + datum, function() {
is_invalid(datum);
});
diff --git a/test/test.misc.js b/test/test.misc.js
index 2eb1ad9..d5528b9 100644
--- a/test/test.misc.js
+++ b/test/test.misc.js
@@ -2,16 +2,15 @@
var chai = chai || require('chai');
var bitcore = bitcore || require('../bitcore');
+var buffertools = require('buffertools');
var should = chai.should();
-var test_data = require('./testdata');
+var testdata = testdata || require('./testdata');
var bignum = bitcore.bignum;
var base58 = bitcore.base58;
var base58Check = base58.base58Check;
-var util = bitcore.util;
-var buffertools = require('buffertools');
describe('Miscelaneous stuff', function() {
it('should initialze the config object', function() {
@@ -20,9 +19,6 @@ describe('Miscelaneous stuff', function() {
it('should initialze the log object', function() {
should.exist(bitcore.log);
});
- it('should initialze the util object', function() {
- should.exist(bitcore.util);
- });
it('should initialze the const object', function() {
should.exist(bitcore.const);
});
@@ -59,7 +55,7 @@ describe('Miscelaneous stuff', function() {
var m = '1QCJj1gPZKx2EwzGo9Ri8mMBs39STvDYcv';
base58Check.encode(base58Check.decode(m)).should.equal(m);
});
- test_data.dataEncodeDecode.forEach(function(datum) {
+ testdata.dataEncodeDecode.forEach(function(datum) {
it('base58 encode/decode checks ' + datum, function() {
// from bitcoin/bitcoin tests:
// Goal: test low-level base58 encoding functionality
diff --git a/test/test.util.js b/test/test.util.js
index 24f57b1..e3de356 100644
--- a/test/test.util.js
+++ b/test/test.util.js
@@ -1,3 +1,4 @@
+'use strict';
var chai = chai || require('chai');
var bitcore = bitcore || require('../bitcore');
@@ -6,6 +7,11 @@ var should = chai.should();
var buffertools = require('buffertools');
describe('util', function() {
+ describe('exist', function() {
+ it('should initialze the util object', function() {
+ should.exist(bitcore.util);
+ });
+ });
describe('#parseValue', function() {
it('should convert floating points to satoshis correctly', function() {
function test_value(datum) {
@@ -16,14 +22,14 @@ describe('util', function() {
bn.toString().should.equal(intStr);
}
var dataValues = [
- ["0", "0"],
- ["1.0", "100000000"],
- ["0.1", "10000000"],
- [".1", "10000000"],
- ["0.0005", "50000"],
- [".000000001", "0"],
- [".000000009", "0"],
- [".00000000000000001", "0"]
+ ['0', '0'],
+ ['1.0', '100000000'],
+ ['0.1', '10000000'],
+ ['.1', '10000000'],
+ ['0.0005', '50000'],
+ ['.000000001', '0'],
+ ['.000000009', '0'],
+ ['.00000000000000001', '0']
];
dataValues.forEach(function(datum) {
test_value(datum);
@@ -92,7 +98,7 @@ describe('util', function() {
});
describe('#getVarIntSize', function() {
var data = [
- [0, 1 ],
+ [0, 1],
[1, 1],
[252, 1],
[253, 3],