Merge pull request #249 from maraoz/feature/fix-tests

Fix tests and bootstrap bitcoind datadir
This commit is contained in:
Manuel Aráoz 2014-02-11 19:42:04 -02:00
commit 402bd19336
9 changed files with 93 additions and 77 deletions

View File

@ -29,6 +29,17 @@ switch(process.env.NODE_ENV) {
break; break;
} }
var dataDir = process.env.BITCOIND_DATADIR;
var isWin = /^win/.test(process.platform);
var isMac = /^darwin/.test(process.platform);
var isLinux = /^linux/.test(process.platform);
if (!dataDir) {
if (isWin) dataDir = '%APPDATA%\\Bitcoin\\';
if (isMac) dataDir = process.env.HOME + '/Library/Application Support/Bitcoin/';
if (isLinux) dataDir = process.env.HOME + '/.bitcoin/';
}
dataDir += ((process.env.INSIGHT_NETWORK || 'testnet')==='testnet'?'testnet3':'');
module.exports = { module.exports = {
root: rootPath, root: rootPath,
appName: 'Insight ' + env, appName: 'Insight ' + env,
@ -41,9 +52,7 @@ module.exports = {
host: process.env.BITCOIND_HOST || '127.0.0.1', host: process.env.BITCOIND_HOST || '127.0.0.1',
port: b_port, port: b_port,
p2pPort: p2p_port, p2pPort: p2p_port,
dataDir: (process.env.BITCOIND_DATADIR + dataDir: dataDir,
((process.env.INSIGHT_NETWORK || 'testnet')==='testnet'?'testnet3':'')),
// DO NOT CHANGE THIS! // DO NOT CHANGE THIS!
disableAgent: true disableAgent: true
}, },

View File

@ -27,6 +27,7 @@ function spec() {
this.peerman = new this.PeerManager(); this.peerman = new this.PeerManager();
this.load_peers(); this.load_peers();
this.sync.init(opts, function() { this.sync.init(opts, function() {
if (!cb) return;
return cb(); return cb();
}); });
}; };

View File

@ -475,7 +475,7 @@ function spec(b) {
} }
else { else {
console.log ('WARN in TX: %s could not parse OUTPUT %d', tx.txid, o.n); //console.log ('WARN in TX: %s could not parse OUTPUT %d', tx.txid, o.n);
return next_out(); return next_out();
} }
}, },

View File

@ -72,6 +72,11 @@ Check out the <a href="http://github.com/bitpay/insight" target="_blank">source
<a href="https://code.google.com/p/leveldb/" target="_blank" class="leveldb" title="LevelDB"></a> <a href="https://code.google.com/p/leveldb/" target="_blank" class="leveldb" title="LevelDB"></a>
<a href="http://nodejs.org" target="_blank" class="nodejs" title="NodeJs"></a> <a href="http://nodejs.org" target="_blank" class="nodejs" title="NodeJs"></a>
</div> </div>
<p>
Insight is still in development, so be sure to report any bugs
and provide feedback for improvement at our <a href="https://github.com/bitpay/insight/issues">
github issue tracker</a>.
</p>
</div> <!-- END OF COL-3 --> </div> <!-- END OF COL-3 -->
</div> </div>
</div> </div>

View File

@ -1,28 +1,28 @@
#!/usr/bin/env node #!/usr/bin/env node
'use strict'; 'use strict';
process.env.NODE_ENV = process.env.NODE_ENV || 'development'; process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var assert = require('assert'), var assert = require('assert'),
fs = require('fs'), fs = require('fs'),
Address = require('../../app/models/Address').class(), Address = require('../../app/models/Address').class(),
TransactionDb = require('../../lib/TransactionDb').class(), TransactionDb = require('../../lib/TransactionDb').class(),
addrValid = JSON.parse(fs.readFileSync('test/integration/addr.json')); addrValid = JSON.parse(fs.readFileSync('test/integration/addr.json'));
var txDb; var txDb;
describe('Address balances', function(){ describe('Address balances', function() {
before(function(c) { before(function(c) {
txDb = new TransactionDb(); txDb = new TransactionDb();
return c(); return c();
}); });
addrValid.forEach( function(v) { addrValid.forEach(function(v) {
if (v.disabled) { if (v.disabled) {
console.log(v.addr + " => disabled in JSON"); console.log(v.addr + ' => disabled in JSON');
} } else {
else { it('Address info for: ' + v.addr, function(done) {
it('Info for: ' + v.addr, function(done) {
this.timeout(5000); this.timeout(5000);
var a = new Address(v.addr, txDb); var a = new Address(v.addr, txDb);
@ -31,23 +31,22 @@ describe('Address balances', function(){
if (err) done(err); if (err) done(err);
assert.equal(v.addr, a.addrStr); assert.equal(v.addr, a.addrStr);
if (v.txApperances) if (v.txApperances)
assert.equal(v.txApperances, a.txApperances, 'txApperances: ' + a.txApperances ); assert.equal(v.txApperances, a.txApperances, 'txApperances: ' + a.txApperances);
if (v.totalReceived) assert.equal(v.totalReceived, a.totalReceived, 'received: ' + a.totalReceived ); if (v.totalReceived) assert.equal(v.totalReceived, a.totalReceived, 'received: ' + a.totalReceived);
if (v.totalSent) assert.equal(v.totalSent, a.totalSent, 'send: ' + a.totalSent); if (v.totalSent) assert.equal(v.totalSent, a.totalSent, 'send: ' + a.totalSent);
if (v.balance) assert.equal(v.balance, a.balance, 'balance: ' + a.balance); if (v.balance) assert.equal(v.balance, a.balance, 'balance: ' + a.balance);
if (v.transactions) { if (v.transactions) {
v.transactions.forEach( function(tx) { v.transactions.forEach(function(tx) {
assert(a.transactions.indexOf(tx)>-1,'have tx '+tx); assert(a.transactions.indexOf(tx) > -1, 'have tx ' + tx);
}); });
} }
done(); done();
}); });
}); });
} }
}); });
}); });

View File

@ -43,9 +43,9 @@
}, },
{ {
"addr": "mzW2hdZN2um7WBvTDerdahKqRgj3md9C29", "addr": "mzW2hdZN2um7WBvTDerdahKqRgj3md9C29",
"txApperances": 6047, "txApperances": 2041,
"balance": 1199.74393851, "balance": 1199.74393853,
"totalReceived": 1199.74393851, "totalReceived": 1199.74393853,
"totalSent": 0 "totalSent": 0
}, },
{ {

View File

@ -1,4 +1,5 @@
#!/usr/bin/env node #!/usr/bin/env node
'use strict'; 'use strict';
process.env.NODE_ENV = process.env.NODE_ENV || 'development'; process.env.NODE_ENV = process.env.NODE_ENV || 'development';
@ -7,14 +8,13 @@ process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var TESTING_BLOCK = '000000000185678d3d7ecc9962c96418174431f93fe20bf216d5565272423f74'; var TESTING_BLOCK = '000000000185678d3d7ecc9962c96418174431f93fe20bf216d5565272423f74';
var var
assert = require('assert'), assert = require('assert'),
// config = require('../../config/config'), // config = require('../../config/config'),
BlockDb = require('../../lib/BlockDb').class(); BlockDb = require('../../lib/BlockDb').class();
var bDb; var bDb;
describe('BlockDb fromHashWithInfo', function(){ describe('BlockDb fromHashWithInfo', function() {
before(function(c) { before(function(c) {
bDb = new BlockDb(); bDb = new BlockDb();
@ -23,11 +23,15 @@ describe('BlockDb fromHashWithInfo', function(){
it('should poll block\'s info from bitcoind', function(done) { it('should poll block\'s info from bitcoind', function(done) {
bDb.fromHashWithInfo(TESTING_BLOCK, function(err, b2) { bDb.fromHashWithInfo(TESTING_BLOCK, function(err, b2) {
if (err) done(err); if (err) done(err);
assert.equal(b2.hash, TESTING_BLOCK); assert.equal(b2.hash, TESTING_BLOCK, 'hash');
assert.equal(b2.info.hash, TESTING_BLOCK); assert.equal(b2.info.hash, TESTING_BLOCK, 'info.hash');
assert.equal(b2.info.chainwork, '000000000000000000000000000000000000000000000000001b6dc969ffe847'); assert.equal(b2.info.height, 71619);
done(); assert.equal(b2.info.nonce, 3960980741);
assert.equal(b2.info.bits, '1c018c14');
assert.equal(b2.info.merkleroot, '9a326cb524aa2e5bc926b8c1f6de5b01257929ee02158054b55aae93a55ec9dd');
assert.equal(b2.info.nextblockhash, '000000000121941b3b10d76fbe67b35993df91eb3398e9153e140b4f6213cb84');
done();
}); });
}); });
it('return true in has', function(done) { it('return true in has', function(done) {
@ -37,4 +41,3 @@ describe('BlockDb fromHashWithInfo', function(){
}); });
}); });
}); });

View File

@ -0,0 +1,17 @@
'use strict';
var BlockDb = require('../../lib/BlockDb').class();
var height_needed = 180000;
var bDb = new BlockDb();
var expect = require('chai').expect;
describe('Node check', function() {
it('should contain block ' + height_needed, function(done) {
bDb.blockIndex(height_needed, function(err, b) {
expect(err).to.equal(null);
expect(b).to.not.equal(null);
done();
});
});
});

View File

@ -7,65 +7,48 @@ var PeerSync = require('../../lib/PeerSync.js').class();
describe('PeerSync', function() { describe('PeerSync', function() {
var ps; var ps;
beforeEach(function() { beforeEach(function(done) {
ps = new PeerSync(); ps = new PeerSync();
ps.init({verbose: false}); ps.init({
verbose: false
}, done);
}); });
afterEach(function(){ afterEach(function() {
ps.close(); ps.close();
}); });
describe('#init()', function() { describe('#init()', function() {
it.skip('should return with no errors', function() { it('should return with no errors', function() {
var other_ps = new PeerSync(); var other_ps = new PeerSync();
expect(other_ps.init.bind(other_ps)).not.to.throw(Error); expect(other_ps.init.bind(other_ps)).not.to.
throw (Error);
other_ps.close(); other_ps.close();
}); });
}); });
describe('#handle_inv()', function() { describe('#handleInv()', function() {
var inv_info = { var inv_info = {
message: {invs: []}, message: {
conn: {sendGetData: sinon.spy()} invs: []
},
conn: {
sendGetData: sinon.spy()
}
}; };
it.skip('should return with no errors', function(){ it('should return with no errors', function() {
expect(function() { expect(function() {
ps.handle_inv(inv_info); ps.handleInv(inv_info);
}).not.to.throw(Error); }).not.to.
throw (Error);
}); });
it.skip('should call sendGetData', function() { it('should call sendGetData', function() {
ps.handle_inv(inv_info); ps.handleInv(inv_info);
expect(inv_info.conn.sendGetData.calledTwice).to.be.ok; expect(inv_info.conn.sendGetData.calledTwice).to.be.ok;
}); });
}); });
describe('#handle_tx()', function() {
var tx_info = {
message: { tx: {getStandardizedObject: function(){
return {hash: 'dac28b5c5e70c16942718f3a22438348c1b709e01d398795fce8fc455178b973'};}}}
};
it.skip('should call storeTxs', function(){
var spy = sinon.spy(ps.sync, 'storeTxs');
ps.handle_tx(tx_info);
expect(spy.calledOnce).to.be.ok;
});
});
describe('#handle_block()', function() {
var block_info = {
message: { block: {calcHash: function(){
return new Buffer('01234');
}, txs: [{hash: new Buffer('cabafeca')}, {hash: new Buffer('bacacafe')}]}}
};
it.skip('should call storeBlock', function(){
var spy = sinon.spy(ps.sync, 'storeBlock');
ps.handle_block(block_info);
expect(spy.calledOnce).to.be.ok;
});
});
describe('#run()', function() { describe('#run()', function() {
it.skip('should setup peerman', function() { it('should setup peerman', function() {
var startSpy = sinon.spy(ps.peerman, 'start'); var startSpy = sinon.spy(ps.peerman, 'start');
var onSpy = sinon.spy(ps.peerman, 'on'); var onSpy = sinon.spy(ps.peerman, 'on');
ps.run(); ps.run();
@ -75,4 +58,3 @@ describe('PeerSync', function() {
}); });
}); });
}); });