Merge pull request #128 from maraoz/bug/remove-testdata-from-bundle

Bug/remove testdata from bundle
This commit is contained in:
Ryan X. Charles 2014-03-10 14:29:26 -04:00
commit 20a433c192
11 changed files with 63 additions and 101 deletions

View File

@ -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: {

View File

@ -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');
b.require('./Connection', {expose: './Connection'});
modules.forEach(function(m) {
b.require('./' + m + '.js' ,{expose:m} );
});
b.require('./' + m + '.js' ,{expose: './'+m} );
});
b.require('soop');
var bopts = {
transform: ['brfs']
// detectGlobals: true,
// insertGlobals: 'Buffer',
// insertGlobalVars: {
// Buffer: function () {
// return 'require("buffer").Buffer';
// },
// },
};
b.bundle().pipe(fs.createWriteStream('browser/bundle.js'));
b.bundle(bopts).pipe(process.stdout);
opts.standalone = 'testdata';
var tb = browserify(opts);
tb.require('./test/testdata', {expose: 'testdata'});
tb.transform('brfs');
tb.bundle().pipe(fs.createWriteStream('browser/testdata.js'));

View File

@ -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;
}

View File

@ -12,14 +12,8 @@
<script src="../node_modules/chai/chai.js"></script>
<script>mocha.setup('bdd')</script>
<script src="../browser/bundle.js"></script>
<script>
var bitcore = require('bitcore');
this.Buffer = require('buffer').Buffer;
</script>
<!-- <script src="adapter.js"></script> -->
<script src="../browser/testdata.js"></script>
<script src="adapter.js"></script>
<script src="test.Address.js"></script>
<script src="test.basic.js"></script>
@ -44,8 +38,6 @@
<script src="test.VersionedData.js"></script>
<script src="test.Wallet.js"></script>
<script src="test.WalletKey.js"></script>
<!--
-->
<script>
mocha.run();
</script>

View File

@ -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;

View File

@ -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() {

View File

@ -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

View File

@ -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');

View File

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

View File

@ -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

View File

@ -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],