fixing testdata inclusion in browser
This commit is contained in:
parent
8f3ae30612
commit
a2e6e88569
12
Gruntfile.js
12
Gruntfile.js
@ -12,14 +12,8 @@ module.exports = function(grunt) {
|
|||||||
grunt.initConfig({
|
grunt.initConfig({
|
||||||
shell: {
|
shell: {
|
||||||
browserify: {
|
browserify: {
|
||||||
options: {
|
command: 'node ./browserify.js',
|
||||||
stdout: true
|
}
|
||||||
},
|
|
||||||
command: 'node ./browserify.js > browser/bundle.js',
|
|
||||||
},
|
|
||||||
browserifyData: {
|
|
||||||
command: 'browserify -t brfs -s testdata test/testdata.js -o browser/testdata.js'
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
readme: {
|
readme: {
|
||||||
@ -28,7 +22,7 @@ module.exports = function(grunt) {
|
|||||||
},
|
},
|
||||||
scripts: {
|
scripts: {
|
||||||
files: ['**/*.js', '**/*.html', '!**/node_modules/**', '!browser/bundle.js', '!browser/testdata.js'],
|
files: ['**/*.js', '**/*.html', '!**/node_modules/**', '!browser/bundle.js', '!browser/testdata.js'],
|
||||||
tasks: ['shell' /*, 'mochaTest'*/ ],
|
tasks: ['shell'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
mochaTest: {
|
mochaTest: {
|
||||||
|
|||||||
10
bitcore.js
10
bitcore.js
@ -7,6 +7,7 @@
|
|||||||
module.exports.bignum = require('bignum');
|
module.exports.bignum = require('bignum');
|
||||||
module.exports.base58 = require('base58-native');
|
module.exports.base58 = require('base58-native');
|
||||||
module.exports.buffertools = require('buffertools');
|
module.exports.buffertools = require('buffertools');
|
||||||
|
module.exports.Buffer = Buffer;
|
||||||
|
|
||||||
module.exports.config = require('./config');
|
module.exports.config = require('./config');
|
||||||
module.exports.const = require('./const');
|
module.exports.const = require('./const');
|
||||||
@ -33,17 +34,12 @@ module.exports.PrivateKey = require('./PrivateKey');
|
|||||||
module.exports.RpcClient = require('./RpcClient');
|
module.exports.RpcClient = require('./RpcClient');
|
||||||
module.exports.Wallet = require('./Wallet');
|
module.exports.Wallet = require('./Wallet');
|
||||||
module.exports.WalletKey = require('./WalletKey');
|
module.exports.WalletKey = require('./WalletKey');
|
||||||
module.exports.Buffer = Buffer;
|
|
||||||
|
|
||||||
if (typeof process.versions === 'undefined') {
|
if (typeof process.versions === 'undefined') {
|
||||||
// Browser specific
|
// Browser specific
|
||||||
module.exports.bignum.config({EXPONENTIAL_AT: 9999999, DECIMAL_PLACES: 0, ROUNDING_MODE: 1});
|
module.exports.bignum.config({EXPONENTIAL_AT: 9999999, DECIMAL_PLACES: 0, ROUNDING_MODE: 1});
|
||||||
// module.exports.PeerManager = function () {
|
} else {
|
||||||
// throw new Error('PeerManager not availabe in browser Bitcore, under .bitcore. Use it with: require(\'PeerManager\');');
|
// Node specific
|
||||||
// };
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Nodejs specific
|
|
||||||
module.exports.PeerManager = require('./PeerManager');
|
module.exports.PeerManager = require('./PeerManager');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Example for usage of browserify with soop
|
|
||||||
*
|
*
|
||||||
* The key parameter 'pack'
|
* The key parameter 'pack'
|
||||||
* The supplied 'custom_prelude.js' file is needed for
|
* The supplied 'custom_prelude.js' file is needed for
|
||||||
@ -11,22 +10,17 @@
|
|||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var browserify = require('browserify');
|
var browserify = require('browserify');
|
||||||
var browserPack = require('browser-pack');
|
var browserPack = require('browser-pack');
|
||||||
var opts = {};
|
|
||||||
|
|
||||||
|
|
||||||
var preludePath = 'node_modules/soop/example/custom_prelude.js';
|
|
||||||
|
|
||||||
var pack = function (params) {
|
var pack = function (params) {
|
||||||
|
var preludePath = 'node_modules/soop/example/custom_prelude.js';
|
||||||
params.raw = true;
|
params.raw = true;
|
||||||
params.sourceMapPrefix = '//#';
|
params.sourceMapPrefix = '//#';
|
||||||
params.prelude= fs.readFileSync(preludePath, 'utf8');
|
params.prelude = fs.readFileSync(preludePath, 'utf8');
|
||||||
params.preludePath= preludePath;
|
params.preludePath = preludePath;
|
||||||
return browserPack(params);
|
return browserPack(params);
|
||||||
};
|
};
|
||||||
|
|
||||||
opts.pack = pack;
|
|
||||||
opts.debug = true;
|
|
||||||
|
|
||||||
var modules = [
|
var modules = [
|
||||||
'Address',
|
'Address',
|
||||||
'Block',
|
'Block',
|
||||||
@ -51,12 +45,18 @@ var modules = [
|
|||||||
'config',
|
'config',
|
||||||
'const',
|
'const',
|
||||||
'networks',
|
'networks',
|
||||||
'bitcore',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
var opts = {};
|
||||||
|
//opts.pack = pack;
|
||||||
|
opts.debug = true;
|
||||||
|
opts.standalone = 'bitcore';
|
||||||
|
opts.insertGlobals = true;
|
||||||
|
|
||||||
var b = browserify(opts);
|
var b = browserify(opts);
|
||||||
b.require('browserify-bignum/bignumber.js', {expose: 'bignum'} );
|
b.require('browserify-bignum/bignumber.js', {expose: 'bignum'} );
|
||||||
b.require('browserify-buffertools/buffertools.js', {expose:'buffertools'});
|
b.require('browserify-buffertools/buffertools.js', {expose:'buffertools'});
|
||||||
|
b.require('./bitcore', {expose: 'bitcore'});
|
||||||
b.require('buffer', {expose: 'buffer'});
|
b.require('buffer', {expose: 'buffer'});
|
||||||
b.require('base58-native');
|
b.require('base58-native');
|
||||||
b.require('./Key.js', {expose: 'KeyModule'});
|
b.require('./Key.js', {expose: 'KeyModule'});
|
||||||
@ -65,27 +65,21 @@ b.require('./util/util');
|
|||||||
b.require('./util/EncodedData');
|
b.require('./util/EncodedData');
|
||||||
b.require('./util/VersionedData');
|
b.require('./util/VersionedData');
|
||||||
b.add('./browser/bignum_config.js');
|
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) {
|
modules.forEach(function(m) {
|
||||||
b.require('./' + m + '.js' ,{expose:m} );
|
b.require('./' + m + '.js' ,{expose: './'+m} );
|
||||||
});
|
});
|
||||||
|
b.require('soop');
|
||||||
|
|
||||||
var bopts = {
|
b.bundle().pipe(fs.createWriteStream('browser/bundle.js'));
|
||||||
transform: ['brfs']
|
|
||||||
// detectGlobals: true,
|
|
||||||
// insertGlobals: 'Buffer',
|
|
||||||
// insertGlobalVars: {
|
|
||||||
// Buffer: function () {
|
|
||||||
// return 'require("buffer").Buffer';
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
};
|
|
||||||
|
|
||||||
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'));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,20 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
if (typeof process === 'undefined') {
|
||||||
if (typeof require === 'undefined') {
|
var bitcore = require('bitcore');
|
||||||
var that = this;
|
var testdata = require('testdata');
|
||||||
that.require = function(name) {
|
var Buffer = bitcore.Buffer;
|
||||||
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');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@ -12,14 +12,8 @@
|
|||||||
<script src="../node_modules/chai/chai.js"></script>
|
<script src="../node_modules/chai/chai.js"></script>
|
||||||
<script>mocha.setup('bdd')</script>
|
<script>mocha.setup('bdd')</script>
|
||||||
<script src="../browser/bundle.js"></script>
|
<script src="../browser/bundle.js"></script>
|
||||||
|
<script src="../browser/testdata.js"></script>
|
||||||
<script>
|
<script src="adapter.js"></script>
|
||||||
var bitcore = require('bitcore');
|
|
||||||
this.Buffer = require('buffer').Buffer;
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- <script src="adapter.js"></script> -->
|
|
||||||
|
|
||||||
<script src="test.Address.js"></script>
|
<script src="test.Address.js"></script>
|
||||||
<script src="test.basic.js"></script>
|
<script src="test.basic.js"></script>
|
||||||
@ -44,8 +38,6 @@
|
|||||||
<script src="test.VersionedData.js"></script>
|
<script src="test.VersionedData.js"></script>
|
||||||
<script src="test.Wallet.js"></script>
|
<script src="test.Wallet.js"></script>
|
||||||
<script src="test.WalletKey.js"></script>
|
<script src="test.WalletKey.js"></script>
|
||||||
<!--
|
|
||||||
-->
|
|
||||||
<script>
|
<script>
|
||||||
mocha.run();
|
mocha.run();
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var chai = chai || require('chai');
|
var chai = chai || require('chai');
|
||||||
var bitcore = bitcore || require('../bitcore');
|
var bitcore = bitcore || require('./bitcore');
|
||||||
|
|
||||||
var should = chai.should();
|
var should = chai.should();
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ var bitcore = bitcore || require('../bitcore');
|
|||||||
|
|
||||||
var should = chai.should();
|
var should = chai.should();
|
||||||
|
|
||||||
var PeerManagerModule = bitcore.PeerManager || require('PeerManager');
|
var PeerManagerModule = bitcore.PeerManager || require('soop').load('PeerManager');
|
||||||
|
|
||||||
var PeerManager;
|
var PeerManager;
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ var ScriptModule = bitcore.Script;
|
|||||||
var Address = bitcore.Address;
|
var Address = bitcore.Address;
|
||||||
var networks = bitcore.networks;
|
var networks = bitcore.networks;
|
||||||
var Script;
|
var Script;
|
||||||
var test_data = require('./testdata');
|
var testdata = testdata || require('./testdata');
|
||||||
|
|
||||||
describe('Script', function() {
|
describe('Script', function() {
|
||||||
it('should initialze the main object', 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');
|
if (datum.length < 2) throw new Error('Invalid test data');
|
||||||
var human = datum[0] + ' ' + datum[1];
|
var human = datum[0] + ' ' + datum[1];
|
||||||
it('should parse script from human readable ' + human, function() {
|
it('should parse script from human readable ' + human, function() {
|
||||||
|
|||||||
@ -4,7 +4,7 @@ var chai = chai || require('chai');
|
|||||||
var bitcore = bitcore || require('../bitcore');
|
var bitcore = bitcore || require('../bitcore');
|
||||||
|
|
||||||
var should = chai.should();
|
var should = chai.should();
|
||||||
var test_data = require('./testdata');
|
var testdata = testdata || require('./testdata');
|
||||||
|
|
||||||
var ScriptInterpreterModule = bitcore.ScriptInterpreter;
|
var ScriptInterpreterModule = bitcore.ScriptInterpreter;
|
||||||
var Script = bitcore.Script;
|
var Script = bitcore.Script;
|
||||||
@ -23,7 +23,7 @@ describe('ScriptInterpreter', function() {
|
|||||||
should.exist(si);
|
should.exist(si);
|
||||||
});
|
});
|
||||||
var i = 0;
|
var i = 0;
|
||||||
test_data.dataScriptValid.forEach(function(datum) {
|
testdata.dataScriptValid.forEach(function(datum) {
|
||||||
if (datum.length < 2) throw new Error('Invalid test data');
|
if (datum.length < 2) throw new Error('Invalid test data');
|
||||||
var scriptSig = datum[0]; // script inputs
|
var scriptSig = datum[0]; // script inputs
|
||||||
var scriptPubKey = datum[1]; // output script
|
var scriptPubKey = datum[1]; // output script
|
||||||
|
|||||||
@ -11,7 +11,7 @@ var In;
|
|||||||
var Out;
|
var Out;
|
||||||
var Script = bitcore.Script;
|
var Script = bitcore.Script;
|
||||||
var buffertools = require('buffertools');
|
var buffertools = require('buffertools');
|
||||||
var test_data = require('./testdata');
|
var testdata = testdata || require('./testdata');
|
||||||
|
|
||||||
describe('Transaction', function() {
|
describe('Transaction', function() {
|
||||||
it('should initialze the main object', function() {
|
it('should initialze the main object', function() {
|
||||||
@ -35,7 +35,7 @@ describe('Transaction', function() {
|
|||||||
// Inner arrays are either [ "comment" ]
|
// Inner arrays are either [ "comment" ]
|
||||||
// or [[[prevout hash, prevout index, prevout scriptPubKey], [input 2], ...],"], serializedTransaction, enforceP2SH
|
// or [[[prevout hash, prevout index, prevout scriptPubKey], [input 2], ...],"], serializedTransaction, enforceP2SH
|
||||||
// ... where all scripts are stringified scripts.
|
// ... where all scripts are stringified scripts.
|
||||||
test_data.dataTxValid.forEach(function(datum) {
|
testdata.dataTxValid.forEach(function(datum) {
|
||||||
if (datum.length === 3) {
|
if (datum.length === 3) {
|
||||||
it.skip('valid tx=' + datum[1], function(done) {
|
it.skip('valid tx=' + datum[1], function(done) {
|
||||||
var inputs = datum[0];
|
var inputs = datum[0];
|
||||||
@ -47,6 +47,7 @@ describe('Transaction', function() {
|
|||||||
map[[hash, index]] = scriptPubKey; //Script.fromStringContent(scriptPubKey);
|
map[[hash, index]] = scriptPubKey; //Script.fromStringContent(scriptPubKey);
|
||||||
console.log(scriptPubKey.getStringContent());
|
console.log(scriptPubKey.getStringContent());
|
||||||
console.log('********************************');
|
console.log('********************************');
|
||||||
|
done();
|
||||||
|
|
||||||
});
|
});
|
||||||
var raw = new Buffer(datum[1], 'hex');
|
var raw = new Buffer(datum[1], 'hex');
|
||||||
|
|||||||
@ -3,18 +3,7 @@
|
|||||||
var chai = chai || require('chai');
|
var chai = chai || require('chai');
|
||||||
var bitcore = bitcore || require('../bitcore');
|
var bitcore = bitcore || require('../bitcore');
|
||||||
|
|
||||||
var test_data;
|
var testdata = testdata || require('./testdata');
|
||||||
if (typeof dataValid !== 'undefined' ) {
|
|
||||||
test_data = {
|
|
||||||
dataValid: dataValid,
|
|
||||||
dataInvalid: dataInvalid,
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
test_data = require('./testdata');
|
|
||||||
}
|
|
||||||
|
|
||||||
var should = chai.should();
|
var should = chai.should();
|
||||||
|
|
||||||
var Address = bitcore.Address;
|
var Address = bitcore.Address;
|
||||||
@ -122,7 +111,7 @@ function is_invalid(datum) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe('Valid base58 keys', function() {
|
describe('Valid base58 keys', function() {
|
||||||
test_data.dataValid.forEach(function(datum) {
|
testdata.dataValid.forEach(function(datum) {
|
||||||
it('valid ' + datum[0], function() {
|
it('valid ' + datum[0], function() {
|
||||||
is_valid(datum);
|
is_valid(datum);
|
||||||
});
|
});
|
||||||
@ -130,7 +119,7 @@ describe('Valid base58 keys', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Invalid base58 keys', function() {
|
describe('Invalid base58 keys', function() {
|
||||||
test_data.dataInvalid.forEach(function(datum) {
|
testdata.dataInvalid.forEach(function(datum) {
|
||||||
it('invalid ' + datum, function() {
|
it('invalid ' + datum, function() {
|
||||||
is_invalid(datum);
|
is_invalid(datum);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -2,16 +2,15 @@
|
|||||||
|
|
||||||
var chai = chai || require('chai');
|
var chai = chai || require('chai');
|
||||||
var bitcore = bitcore || require('../bitcore');
|
var bitcore = bitcore || require('../bitcore');
|
||||||
|
var buffertools = require('buffertools');
|
||||||
|
|
||||||
var should = chai.should();
|
var should = chai.should();
|
||||||
|
|
||||||
var test_data = require('./testdata');
|
var testdata = testdata || require('./testdata');
|
||||||
|
|
||||||
var bignum = bitcore.bignum;
|
var bignum = bitcore.bignum;
|
||||||
var base58 = bitcore.base58;
|
var base58 = bitcore.base58;
|
||||||
var base58Check = base58.base58Check;
|
var base58Check = base58.base58Check;
|
||||||
var util = bitcore.util;
|
|
||||||
var buffertools = require('buffertools');
|
|
||||||
|
|
||||||
describe('Miscelaneous stuff', function() {
|
describe('Miscelaneous stuff', function() {
|
||||||
it('should initialze the config object', function() {
|
it('should initialze the config object', function() {
|
||||||
@ -20,9 +19,6 @@ describe('Miscelaneous stuff', function() {
|
|||||||
it('should initialze the log object', function() {
|
it('should initialze the log object', function() {
|
||||||
should.exist(bitcore.log);
|
should.exist(bitcore.log);
|
||||||
});
|
});
|
||||||
it('should initialze the util object', function() {
|
|
||||||
should.exist(bitcore.util);
|
|
||||||
});
|
|
||||||
it('should initialze the const object', function() {
|
it('should initialze the const object', function() {
|
||||||
should.exist(bitcore.const);
|
should.exist(bitcore.const);
|
||||||
});
|
});
|
||||||
@ -59,7 +55,7 @@ describe('Miscelaneous stuff', function() {
|
|||||||
var m = '1QCJj1gPZKx2EwzGo9Ri8mMBs39STvDYcv';
|
var m = '1QCJj1gPZKx2EwzGo9Ri8mMBs39STvDYcv';
|
||||||
base58Check.encode(base58Check.decode(m)).should.equal(m);
|
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() {
|
it('base58 encode/decode checks ' + datum, function() {
|
||||||
// from bitcoin/bitcoin tests:
|
// from bitcoin/bitcoin tests:
|
||||||
// Goal: test low-level base58 encoding functionality
|
// Goal: test low-level base58 encoding functionality
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
var chai = chai || require('chai');
|
var chai = chai || require('chai');
|
||||||
var bitcore = bitcore || require('../bitcore');
|
var bitcore = bitcore || require('../bitcore');
|
||||||
@ -6,6 +7,11 @@ var should = chai.should();
|
|||||||
var buffertools = require('buffertools');
|
var buffertools = require('buffertools');
|
||||||
|
|
||||||
describe('util', function() {
|
describe('util', function() {
|
||||||
|
describe('exist', function() {
|
||||||
|
it('should initialze the util object', function() {
|
||||||
|
should.exist(bitcore.util);
|
||||||
|
});
|
||||||
|
});
|
||||||
describe('#parseValue', function() {
|
describe('#parseValue', function() {
|
||||||
it('should convert floating points to satoshis correctly', function() {
|
it('should convert floating points to satoshis correctly', function() {
|
||||||
function test_value(datum) {
|
function test_value(datum) {
|
||||||
@ -16,14 +22,14 @@ describe('util', function() {
|
|||||||
bn.toString().should.equal(intStr);
|
bn.toString().should.equal(intStr);
|
||||||
}
|
}
|
||||||
var dataValues = [
|
var dataValues = [
|
||||||
["0", "0"],
|
['0', '0'],
|
||||||
["1.0", "100000000"],
|
['1.0', '100000000'],
|
||||||
["0.1", "10000000"],
|
['0.1', '10000000'],
|
||||||
[".1", "10000000"],
|
['.1', '10000000'],
|
||||||
["0.0005", "50000"],
|
['0.0005', '50000'],
|
||||||
[".000000001", "0"],
|
['.000000001', '0'],
|
||||||
[".000000009", "0"],
|
['.000000009', '0'],
|
||||||
[".00000000000000001", "0"]
|
['.00000000000000001', '0']
|
||||||
];
|
];
|
||||||
dataValues.forEach(function(datum) {
|
dataValues.forEach(function(datum) {
|
||||||
test_value(datum);
|
test_value(datum);
|
||||||
@ -92,7 +98,7 @@ describe('util', function() {
|
|||||||
});
|
});
|
||||||
describe('#getVarIntSize', function() {
|
describe('#getVarIntSize', function() {
|
||||||
var data = [
|
var data = [
|
||||||
[0, 1 ],
|
[0, 1],
|
||||||
[1, 1],
|
[1, 1],
|
||||||
[252, 1],
|
[252, 1],
|
||||||
[253, 3],
|
[253, 3],
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user