Commit 07b2fbb1 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

Merge pull request #359 from Insoleet/master

Adding test for ping/pong + sync checking
parents 766f5ca5 25b8e21b
......@@ -80,6 +80,10 @@ function Synchroniser (server, host, port, conf, interactive) {
logger.info('Downloading Blockchain...');
watcher.writeStatus('Connecting to ' + host + '...');
var rCurrent = yield Q.nbind(node.blockchain.current, node)();
var remoteVersion = rCurrent.version;
if (remoteVersion < 2) {
throw Error("Could not sync with remote host. UCP version is " + remoteVersion + " (Must be >= 2)")
}
var localNumber = lCurrent ? lCurrent.number : -1;
var remoteNumber = Math.min(rCurrent.number, to || rCurrent.number);
......
......@@ -10,6 +10,7 @@ var user = require('./tools/user');
var http = require('./tools/http');
var constants = require('../../app/lib/constants');
var rp = require('request-promise');
var ws = require('ws');
var server = ucoin({
memory: true
......@@ -143,6 +144,41 @@ describe("HTTP API", function() {
});
});
});
describe("/ws", function() {
it('/block should exist', function(done) {
var client = new ws('ws://127.0.0.1:7777/ws/block');
client.on('open', function open() {
client.terminate();
done();
});
});
it('/block should send a block', function(done) {
var completed = false
var client = new ws('ws://127.0.0.1:7777/ws/block');
client.on('message', function message(data, flags) {
var block = JSON.parse(data);
should(block).have.property('number', 4);
if (!completed) {
completed = true;
done();
}
});
});
it('/block should answer to pings', function(done) {
var client = new ws('ws://127.0.0.1:7777/ws/block');
client.on('pong', function message(data, flags) {
client.terminate();
done();
});
client.on('open', function open() {
client.ping();
});
});
});
});
function expectJSON(promise, json) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment