Drop tests for p2p
This commit is contained in:
parent
eaa07363a9
commit
456b4345f0
@ -1,353 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai');
|
||||
|
||||
var should = chai.should();
|
||||
|
||||
var bitcore = require('../..');
|
||||
var Data = require('../data/messages');
|
||||
var Messages = bitcore.transport.Messages;
|
||||
var Networks = bitcore.Networks;
|
||||
|
||||
describe('Messages', function() {
|
||||
|
||||
describe('Version', function() {
|
||||
it('should be able to create instance', function() {
|
||||
var message = new Messages.Version();
|
||||
message.command.should.equal('version');
|
||||
message.version.should.equal(70000);
|
||||
message.subversion.should.equal('/BitcoinX:0.1/');
|
||||
should.exist(message.nonce);
|
||||
});
|
||||
|
||||
it('should be able to serialize the payload', function() {
|
||||
var message = new Messages.Version();
|
||||
var payload = message.getPayload();
|
||||
should.exist(payload);
|
||||
});
|
||||
|
||||
it('should be able to serialize the message', function() {
|
||||
var message = new Messages.Version();
|
||||
var buffer = message.serialize(Networks.livenet);
|
||||
should.exist(buffer);
|
||||
});
|
||||
|
||||
it('should be able to parse payload', function() {
|
||||
var payload = new Buffer(Data.VERSION.payload, 'hex');
|
||||
new Messages.Version().fromBuffer(payload);
|
||||
});
|
||||
});
|
||||
|
||||
describe('VerAck', function() {
|
||||
it('should be able to create instance', function() {
|
||||
var message = new Messages.VerAck();
|
||||
message.command.should.equal('verack');
|
||||
});
|
||||
|
||||
it('should be able to serialize the payload', function() {
|
||||
var message = new Messages.VerAck();
|
||||
var payload = message.getPayload();
|
||||
should.exist(payload);
|
||||
});
|
||||
|
||||
it('should be able to serialize the message', function() {
|
||||
var message = new Messages.VerAck();
|
||||
var buffer = message.serialize(Networks.livenet);
|
||||
should.exist(buffer);
|
||||
});
|
||||
|
||||
it('should be able to parse payload', function() {
|
||||
var payload = new Buffer(Data.VERACK.payload, 'hex');
|
||||
new Messages.VerAck().fromBuffer(payload);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Inventory', function() {
|
||||
it('should be able to create instance', function() {
|
||||
var message = new Messages.Inventory();
|
||||
message.command.should.equal('inv');
|
||||
});
|
||||
|
||||
it('should be able to serialize the payload', function() {
|
||||
var message = new Messages.Inventory();
|
||||
var payload = message.getPayload();
|
||||
should.exist(payload);
|
||||
});
|
||||
|
||||
it('should be able to serialize the message', function() {
|
||||
var message = new Messages.Inventory();
|
||||
var buffer = message.serialize(Networks.livenet);
|
||||
should.exist(buffer);
|
||||
});
|
||||
|
||||
it('should be able to parse payload', function() {
|
||||
var payload = new Buffer(Data.INV.payload, 'hex');
|
||||
new Messages.Inventory().fromBuffer(payload);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Addresses', function() {
|
||||
it('should be able to create instance', function() {
|
||||
var message = new Messages.Addresses();
|
||||
message.command.should.equal('addr');
|
||||
});
|
||||
|
||||
it('should be able to serialize the payload', function() {
|
||||
var message = new Messages.Addresses();
|
||||
var payload = message.getPayload();
|
||||
should.exist(payload);
|
||||
});
|
||||
|
||||
it('should be able to serialize the message', function() {
|
||||
var message = new Messages.Addresses();
|
||||
var buffer = message.serialize(Networks.livenet);
|
||||
should.exist(buffer);
|
||||
});
|
||||
|
||||
it('should be able to parse payload', function() {
|
||||
var payload = new Buffer(Data.ADDR.payload, 'hex');
|
||||
new Messages.Addresses().fromBuffer(payload);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Ping', function() {
|
||||
it('should be able to create instance', function() {
|
||||
var message = new Messages.Ping();
|
||||
message.command.should.equal('ping');
|
||||
});
|
||||
|
||||
it('should be able to serialize the payload', function() {
|
||||
var message = new Messages.Ping();
|
||||
var payload = message.getPayload();
|
||||
should.exist(payload);
|
||||
});
|
||||
|
||||
it('should be able to serialize the message', function() {
|
||||
var message = new Messages.Ping();
|
||||
var buffer = message.serialize(Networks.livenet);
|
||||
should.exist(buffer);
|
||||
});
|
||||
|
||||
it('should be able to parse payload', function() {
|
||||
var payload = new Buffer(Data.PING.payload, 'hex');
|
||||
new Messages.Ping().fromBuffer(payload);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Pong', function() {
|
||||
it('should be able to create instance', function() {
|
||||
var message = new Messages.Pong();
|
||||
message.command.should.equal('pong');
|
||||
});
|
||||
|
||||
it('should be able to serialize the payload', function() {
|
||||
var message = new Messages.Pong();
|
||||
var payload = message.getPayload();
|
||||
should.exist(payload);
|
||||
});
|
||||
|
||||
it('should be able to serialize the message', function() {
|
||||
var message = new Messages.Pong();
|
||||
var buffer = message.serialize(Networks.livenet);
|
||||
should.exist(buffer);
|
||||
});
|
||||
|
||||
it('should be able to parse payload', function() {
|
||||
var payload = new Buffer(Data.PING.payload, 'hex');
|
||||
new Messages.Pong().fromBuffer(payload);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Alert', function() {
|
||||
it('should be able to create instance', function() {
|
||||
var message = new Messages.Alert();
|
||||
message.command.should.equal('alert');
|
||||
});
|
||||
|
||||
it('should be able to serialize the payload', function() {
|
||||
var message = new Messages.Alert();
|
||||
var payload = message.getPayload();
|
||||
should.exist(payload);
|
||||
});
|
||||
|
||||
it('should be able to serialize the message', function() {
|
||||
var message = new Messages.Alert();
|
||||
var buffer = message.serialize(Networks.livenet);
|
||||
should.exist(buffer);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Reject', function() {
|
||||
it('should be able to create instance', function() {
|
||||
var message = new Messages.Reject();
|
||||
message.command.should.equal('reject');
|
||||
});
|
||||
|
||||
it('should be able to serialize the payload', function() {
|
||||
var message = new Messages.Reject();
|
||||
var payload = message.getPayload();
|
||||
should.exist(payload);
|
||||
});
|
||||
|
||||
it('should be able to serialize the message', function() {
|
||||
var message = new Messages.Reject();
|
||||
var buffer = message.serialize(Networks.livenet);
|
||||
should.exist(buffer);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Block', function() {
|
||||
var blockHex = 'f9beb4d91d0100000100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b7c0101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000';
|
||||
var block = new bitcore.Block(new Buffer(blockHex, 'hex'));
|
||||
|
||||
it('should be able to create instance', function() {
|
||||
var message = new Messages.Block(block);
|
||||
message.command.should.equal('block');
|
||||
});
|
||||
|
||||
it('should be able to serialize the payload', function() {
|
||||
var message = new Messages.Block(block);
|
||||
var payload = message.getPayload();
|
||||
should.exist(payload);
|
||||
});
|
||||
|
||||
it('should be able to serialize the message', function() {
|
||||
var message = new Messages.Block(block);
|
||||
var buffer = message.serialize(Networks.livenet);
|
||||
should.exist(buffer);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GetBlocks', function() {
|
||||
it('should be able to create instance', function() {
|
||||
var message = new Messages.GetBlocks();
|
||||
message.command.should.equal('getblocks');
|
||||
});
|
||||
|
||||
it('should be able to serialize the payload', function() {
|
||||
var message = new Messages.GetBlocks();
|
||||
var payload = message.getPayload();
|
||||
should.exist(payload);
|
||||
});
|
||||
|
||||
it('should be able to serialize the message', function() {
|
||||
var message = new Messages.GetBlocks();
|
||||
var buffer = message.serialize(Networks.livenet);
|
||||
should.exist(buffer);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GetHeaders', function() {
|
||||
it('should be able to create instance', function() {
|
||||
var message = new Messages.GetHeaders();
|
||||
message.command.should.equal('getheaders');
|
||||
});
|
||||
|
||||
it('should be able to serialize the payload', function() {
|
||||
var message = new Messages.GetHeaders();
|
||||
var payload = message.getPayload();
|
||||
should.exist(payload);
|
||||
});
|
||||
|
||||
it('should be able to serialize the message', function() {
|
||||
var message = new Messages.GetHeaders();
|
||||
var buffer = message.serialize(Networks.livenet);
|
||||
should.exist(buffer);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GetData', function() {
|
||||
it('should be able to create instance', function() {
|
||||
var message = new Messages.GetData();
|
||||
message.command.should.equal('getdata');
|
||||
});
|
||||
|
||||
it('should be able to serialize the payload', function() {
|
||||
var message = new Messages.GetData();
|
||||
var payload = message.getPayload();
|
||||
should.exist(payload);
|
||||
});
|
||||
|
||||
it('should be able to serialize the message', function() {
|
||||
var message = new Messages.GetData();
|
||||
var buffer = message.serialize(Networks.livenet);
|
||||
should.exist(buffer);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GetData', function() {
|
||||
it('should be able to create instance', function() {
|
||||
var message = new Messages.GetData();
|
||||
message.command.should.equal('getdata');
|
||||
});
|
||||
|
||||
it('should be able to serialize the payload', function() {
|
||||
var message = new Messages.GetData();
|
||||
var payload = message.getPayload();
|
||||
should.exist(payload);
|
||||
});
|
||||
|
||||
it('should be able to serialize the message', function() {
|
||||
var message = new Messages.GetData();
|
||||
var buffer = message.serialize(Networks.livenet);
|
||||
should.exist(buffer);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GetAddresses', function() {
|
||||
it('should be able to create instance', function() {
|
||||
var message = new Messages.GetAddresses();
|
||||
message.command.should.equal('getaddr');
|
||||
});
|
||||
|
||||
it('should be able to serialize the payload', function() {
|
||||
var message = new Messages.GetAddresses();
|
||||
var payload = message.getPayload();
|
||||
should.exist(payload);
|
||||
});
|
||||
|
||||
it('should be able to serialize the message', function() {
|
||||
var message = new Messages.GetAddresses();
|
||||
var buffer = message.serialize(Networks.livenet);
|
||||
should.exist(buffer);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Headers', function() {
|
||||
it('should be able to create instance', function() {
|
||||
var message = new Messages.Headers();
|
||||
message.command.should.equal('headers');
|
||||
});
|
||||
|
||||
it('should be able to serialize the payload', function() {
|
||||
var message = new Messages.Headers();
|
||||
var payload = message.getPayload();
|
||||
should.exist(payload);
|
||||
});
|
||||
|
||||
it('should be able to serialize the message', function() {
|
||||
var message = new Messages.Headers();
|
||||
var buffer = message.serialize(Networks.livenet);
|
||||
should.exist(buffer);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Transaction', function() {
|
||||
it('should be able to create instance', function() {
|
||||
var message = new Messages.Transaction(new bitcore.Transaction());
|
||||
message.command.should.equal('tx');
|
||||
});
|
||||
|
||||
it('should be able to serialize the payload', function() {
|
||||
var message = new Messages.Transaction(new bitcore.Transaction());
|
||||
var payload = message.getPayload();
|
||||
should.exist(payload);
|
||||
});
|
||||
|
||||
it('should be able to serialize the message', function() {
|
||||
var message = new Messages.Transaction(new bitcore.Transaction());
|
||||
var buffer = message.serialize(Networks.livenet);
|
||||
should.exist(buffer);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1,75 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai');
|
||||
var Net = require('net');
|
||||
var Socks5Client = require('socks5-client');
|
||||
|
||||
/* jshint unused: false */
|
||||
var should = chai.should();
|
||||
var expect = chai.expect;
|
||||
|
||||
var bitcore = require('../..');
|
||||
var Peer = bitcore.transport.Peer;
|
||||
var Networks = bitcore.Networks;
|
||||
|
||||
describe('Peer', function() {
|
||||
|
||||
it('should be able to create instance', function() {
|
||||
var peer = new Peer('localhost');
|
||||
peer.host.should.equal('localhost');
|
||||
peer.network.should.equal(Networks.livenet);
|
||||
peer.port.should.equal(Networks.livenet.port);
|
||||
});
|
||||
|
||||
it('should be able to create instance setting a port', function() {
|
||||
var peer = new Peer('localhost', 8111);
|
||||
peer.host.should.equal('localhost');
|
||||
peer.network.should.equal(Networks.livenet);
|
||||
peer.port.should.equal(8111);
|
||||
});
|
||||
|
||||
it('should be able to create instance setting a network', function() {
|
||||
var peer = new Peer('localhost', Networks.testnet);
|
||||
peer.host.should.equal('localhost');
|
||||
peer.network.should.equal(Networks.testnet);
|
||||
peer.port.should.equal(Networks.testnet.port);
|
||||
});
|
||||
|
||||
it('should be able to create instance setting port and network', function() {
|
||||
var peer = new Peer('localhost', 8111, Networks.testnet);
|
||||
peer.host.should.equal('localhost');
|
||||
peer.network.should.equal(Networks.testnet);
|
||||
peer.port.should.equal(8111);
|
||||
});
|
||||
|
||||
it('should support creating instance without new', function() {
|
||||
var peer = Peer('localhost', 8111, Networks.testnet);
|
||||
peer.host.should.equal('localhost');
|
||||
peer.network.should.equal(Networks.testnet);
|
||||
peer.port.should.equal(8111);
|
||||
});
|
||||
|
||||
if (typeof(window) === 'undefined'){
|
||||
|
||||
// Node.js Tests
|
||||
|
||||
it('should be able to set a proxy', function() {
|
||||
var peer, peer2, socket;
|
||||
|
||||
peer = new Peer('localhost');
|
||||
expect(peer.proxy).to.be.undefined();
|
||||
socket = peer._getSocket();
|
||||
socket.should.be.instanceof(Net.Socket);
|
||||
|
||||
peer2 = peer.setProxy('127.0.0.1', 9050);
|
||||
peer2.proxy.host.should.equal('127.0.0.1');
|
||||
peer2.proxy.port.should.equal(9050);
|
||||
socket = peer2._getSocket();
|
||||
socket.should.be.instanceof(Socks5Client);
|
||||
|
||||
peer.should.equal(peer2);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
@ -1,104 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
if (typeof(window) === 'undefined'){
|
||||
|
||||
// Node.js Tests
|
||||
|
||||
var chai = require('chai');
|
||||
|
||||
/* jshint unused: false */
|
||||
var should = chai.should();
|
||||
var expect = chai.expect;
|
||||
|
||||
var dns = require('dns');
|
||||
var sinon = require('sinon');
|
||||
|
||||
var bitcore = require('../..');
|
||||
var Peer = bitcore.transport.Peer;
|
||||
var MessagesData = require('../data/messages');
|
||||
var Messages = bitcore.transport.Messages;
|
||||
var Pool = bitcore.transport.Pool;
|
||||
var Networks = bitcore.Networks;
|
||||
|
||||
describe('Pool', function() {
|
||||
|
||||
it('should be able to create instance', function() {
|
||||
var pool = new Pool();
|
||||
should.exist(pool.network);
|
||||
expect(pool.network).to.satisfy(function(network){
|
||||
if (network === Networks.testnet || network === Networks.livenet) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to create instance setting the network', function() {
|
||||
var pool = new Peer(Networks.testnet);
|
||||
pool.network.should.equal(Networks.livenet);
|
||||
});
|
||||
|
||||
it('should discover peers via dns', function() {
|
||||
var stub = sinon.stub(dns, 'resolve', function(seed, callback){
|
||||
callback(null, ['10.10.10.1', '10.10.10.2', '10.10.10.3']);
|
||||
});
|
||||
var pool = new Pool(Networks.livenet);
|
||||
pool.connect();
|
||||
pool.disconnect();
|
||||
pool._addrs.length.should.equal(3);
|
||||
stub.restore();
|
||||
});
|
||||
|
||||
it('should not discover peers via dns', function() {
|
||||
var pool = new Pool();
|
||||
pool._addAddr({ip: {v4: '10.10.10.1'}});
|
||||
pool.connect();
|
||||
pool.disconnect();
|
||||
pool._addrs.length.should.equal(1);
|
||||
});
|
||||
|
||||
it('should add new addrs as they are announced over the network', function(done) {
|
||||
|
||||
// only emit an event, no need to connect
|
||||
var peerConnectStub = sinon.stub(Peer.prototype, 'connect', function(){
|
||||
this._readMessage();
|
||||
this.emit('ready');
|
||||
});
|
||||
|
||||
// mock a addr peer event
|
||||
var peerMessageStub = sinon.stub(Peer.prototype, '_readMessage', function(){
|
||||
var payload = new Buffer(MessagesData.ADDR.payload, 'hex');
|
||||
var message = new Messages.Addresses().fromBuffer(payload);
|
||||
this.emit(message.command, message);
|
||||
});
|
||||
|
||||
var pool = new Pool();
|
||||
|
||||
pool._addAddr({ip: {v4: 'localhost'}});
|
||||
|
||||
// listen for the event
|
||||
pool.on('peeraddr', function(peer, message) {
|
||||
pool._addrs.length.should.equal(502);
|
||||
|
||||
// restore stubs
|
||||
peerConnectStub.restore();
|
||||
peerMessageStub.restore();
|
||||
|
||||
for (var i = 0; i < pool._addrs.length; i++) {
|
||||
should.exist(pool._addrs[i].hash);
|
||||
should.exist(pool._addrs[i].ip);
|
||||
should.exist(pool._addrs[i].ip.v4);
|
||||
}
|
||||
|
||||
// done
|
||||
done();
|
||||
});
|
||||
|
||||
pool.connect();
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user