insight-ui-zcash/test/lib/PeerSync.js

79 lines
2.1 KiB
JavaScript
Raw Normal View History

2014-01-15 07:53:44 -08:00
'use strict';
2014-01-16 11:12:32 -08:00
var chai = require('chai'),
expect = chai.expect,
sinon = require('sinon');
2014-01-15 07:53:44 -08:00
var PeerSync = require('../../lib/PeerSync.js').class();
2014-01-16 11:12:32 -08:00
describe('PeerSync', function() {
var ps;
2014-01-16 08:01:10 -08:00
beforeEach(function() {
ps = new PeerSync();
2014-01-16 16:08:50 -08:00
ps.init({verbose: false});
2014-01-16 11:12:32 -08:00
});
afterEach(function(){
ps.close();
2014-01-16 08:01:10 -08:00
});
2014-01-15 07:53:44 -08:00
describe('#init()', function() {
2014-01-22 05:01:08 -08:00
it.skip('should return with no errors', function() {
2014-01-16 11:12:32 -08:00
var other_ps = new PeerSync();
expect(other_ps.init.bind(other_ps)).not.to.throw(Error);
other_ps.close();
2014-01-15 07:53:44 -08:00
});
});
2014-01-16 08:01:10 -08:00
describe('#handle_inv()', function() {
var inv_info = {
2014-01-16 11:12:32 -08:00
message: {invs: []},
conn: {sendGetData: sinon.spy()}
};
2014-01-22 05:01:08 -08:00
it.skip('should return with no errors', function(){
2014-01-16 11:12:32 -08:00
expect(function() {
ps.handle_inv(inv_info);
}).not.to.throw(Error);
});
2014-01-22 05:01:08 -08:00
it.skip('should call sendGetData', function() {
2014-01-16 11:12:32 -08:00
ps.handle_inv(inv_info);
2014-01-16 11:47:06 -08:00
expect(inv_info.conn.sendGetData.calledTwice).to.be.ok;
2014-01-16 11:12:32 -08:00
});
2014-01-16 08:01:10 -08:00
});
2014-01-16 08:01:10 -08:00
describe('#handle_tx()', function() {
var tx_info = {
message: { tx: {getStandardizedObject: function(){
2014-01-16 16:08:50 -08:00
return {hash: 'dac28b5c5e70c16942718f3a22438348c1b709e01d398795fce8fc455178b973'};}}}
};
2014-01-22 05:01:08 -08:00
it.skip('should call storeTxs', function(){
var spy = sinon.spy(ps.sync, 'storeTxs');
ps.handle_tx(tx_info);
2014-01-16 16:08:50 -08:00
expect(spy.calledOnce).to.be.ok;
});
2014-01-16 08:01:10 -08:00
});
2014-01-16 08:01:10 -08:00
describe('#handle_block()', function() {
2014-01-16 16:08:50 -08:00
var block_info = {
message: { block: {calcHash: function(){
return new Buffer('01234');
}, txs: [{hash: new Buffer('cabafeca')}, {hash: new Buffer('bacacafe')}]}}
};
2014-01-22 05:01:08 -08:00
it.skip('should call storeBlock', function(){
2014-01-16 16:08:50 -08:00
var spy = sinon.spy(ps.sync, 'storeBlock');
ps.handle_block(block_info);
expect(spy.calledOnce).to.be.ok;
});
2014-01-16 08:01:10 -08:00
});
2014-01-16 08:01:10 -08:00
describe('#run()', function() {
2014-01-22 05:01:08 -08:00
it.skip('should setup peerman', function() {
2014-01-16 16:08:50 -08:00
var startSpy = sinon.spy(ps.peerman, 'start');
var onSpy = sinon.spy(ps.peerman, 'on');
ps.run();
expect(startSpy.called).to.be.ok;
expect(onSpy.called).to.be.ok;
});
2014-01-16 08:01:10 -08:00
});
2014-01-15 07:53:44 -08:00
});