2015-08-04 11:50:15 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var benchmark = require('benchmark');
|
|
|
|
var async = require('async');
|
2015-08-31 13:49:59 -07:00
|
|
|
var sinon = require('sinon');
|
2015-10-16 21:56:29 -07:00
|
|
|
var bitcore = require('bitcore-lib');
|
2015-08-31 13:49:59 -07:00
|
|
|
var Block = bitcore.Block;
|
|
|
|
var AddressService = require('../lib/services/address');
|
2015-08-04 11:50:15 -07:00
|
|
|
var maxTime = 20;
|
|
|
|
|
|
|
|
var blockData1 = require('./data/block-367238.json');
|
|
|
|
var blockData2 = require('./data/block-367239.json');
|
|
|
|
var blockData3 = require('./data/block-367240.json');
|
|
|
|
|
2015-08-31 13:49:59 -07:00
|
|
|
console.log('Address Service Block Handler');
|
|
|
|
console.log('-----------------------------');
|
2015-08-04 11:50:15 -07:00
|
|
|
|
|
|
|
async.series([
|
|
|
|
function(next) {
|
|
|
|
|
|
|
|
var c = 0;
|
|
|
|
var blocks = [
|
|
|
|
Block.fromBuffer(new Buffer(blockData1, 'hex')),
|
|
|
|
Block.fromBuffer(new Buffer(blockData2, 'hex')),
|
|
|
|
Block.fromBuffer(new Buffer(blockData3, 'hex'))
|
|
|
|
];
|
|
|
|
var blocksLength = 3;
|
2015-08-31 13:49:59 -07:00
|
|
|
var node = {
|
|
|
|
services: {
|
|
|
|
bitcoind : {
|
|
|
|
on: sinon.stub()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var addressService = new AddressService({node: node});
|
2015-08-04 11:50:15 -07:00
|
|
|
|
|
|
|
function blockHandler(deffered) {
|
|
|
|
if (c >= blocksLength) {
|
|
|
|
c = 0;
|
|
|
|
}
|
|
|
|
var block = blocks[c];
|
2015-08-31 13:49:59 -07:00
|
|
|
addressService.blockHandler(block, true, function(err, operations) {
|
2015-08-04 11:50:15 -07:00
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
deffered.resolve();
|
|
|
|
});
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
|
|
|
|
var suite = new benchmark.Suite();
|
|
|
|
|
|
|
|
suite.add('blockHandler', blockHandler, {
|
|
|
|
defer: true,
|
|
|
|
maxTime: maxTime
|
|
|
|
});
|
|
|
|
|
|
|
|
suite
|
|
|
|
.on('cycle', function(event) {
|
|
|
|
console.log(String(event.target));
|
|
|
|
})
|
|
|
|
.on('complete', function() {
|
|
|
|
console.log('Fastest is ' + this.filter('fastest').pluck('name'));
|
|
|
|
console.log('----------------------------------------------------------------------');
|
|
|
|
next();
|
|
|
|
})
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
], function(err) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
console.log('Finished');
|
|
|
|
process.exit();
|
|
|
|
});
|