Skip to content
Snippets Groups Projects
Commit 224b37a3 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

Fix: make tests pass

parent a103ba2e
Branches
Tags
No related merge requests found
...@@ -52,7 +52,7 @@ function PeeringService(server, pair, dal) { ...@@ -52,7 +52,7 @@ function PeeringService(server, pair, dal) {
this.submitP = function(peering, eraseIfAlreadyRecorded, cautious){ this.submitP = function(peering, eraseIfAlreadyRecorded, cautious){
let thePeer = new Peer(peering); let thePeer = new Peer(peering);
let sp = thePeer.block.split('-'); let sp = thePeer.block.split('-');
let blockNumber = sp[0]; let blockNumber = parseInt(sp[0]);
let blockHash = sp[1]; let blockHash = sp[1];
let sigTime = 0; let sigTime = 0;
let block; let block;
...@@ -84,7 +84,7 @@ function PeeringService(server, pair, dal) { ...@@ -84,7 +84,7 @@ function PeeringService(server, pair, dal) {
if(found){ if(found){
// Already existing peer // Already existing peer
var sp2 = found.block.split('-'); var sp2 = found.block.split('-');
var previousBlockNumber = sp2[0]; var previousBlockNumber = parseInt(sp2[0]);
if(blockNumber <= previousBlockNumber && !eraseIfAlreadyRecorded){ if(blockNumber <= previousBlockNumber && !eraseIfAlreadyRecorded){
throw constants.ERROR.PEER.ALREADY_RECORDED; throw constants.ERROR.PEER.ALREADY_RECORDED;
} }
...@@ -373,8 +373,9 @@ function PeeringService(server, pair, dal) { ...@@ -373,8 +373,9 @@ function PeeringService(server, pair, dal) {
let peers = yield dal.findAllPeersNEWUPBut([selfPubkey]); let peers = yield dal.findAllPeersNEWUPBut([selfPubkey]);
peers = _.shuffle(peers); peers = _.shuffle(peers);
for (let i = 0, len = peers.length; i < len; i++) { for (let i = 0, len = peers.length; i < len; i++) {
var p = new Peer(peers[i]); let p = new Peer(peers[i]);
logger.info("Try with %s %s", p.getURL(), p.pubkey.substr(0, 6)); logger.info("Try with %s %s", p.getURL(), p.pubkey.substr(0, 6));
try {
let node = yield Q.nfcall(p.connect); let node = yield Q.nfcall(p.connect);
let okUP = yield processAscendingUntilNoBlock(p, node, current); let okUP = yield processAscendingUntilNoBlock(p, node, current);
if (okUP) { if (okUP) {
...@@ -386,7 +387,6 @@ function PeeringService(server, pair, dal) { ...@@ -386,7 +387,6 @@ function PeeringService(server, pair, dal) {
yield processLastTen(p, node, nowCurrent); yield processLastTen(p, node, nowCurrent);
} }
} }
try {
// Try to fork as a final treatment // Try to fork as a final treatment
let nowCurrent = yield dal.getCurrentBlockOrNull(); let nowCurrent = yield dal.getCurrentBlockOrNull();
yield server.BlockchainService.tryToFork(nowCurrent); yield server.BlockchainService.tryToFork(nowCurrent);
......
"use strict"; "use strict";
var co = require('co');
var Q = require('q'); var Q = require('q');
var _ = require('underscore'); var _ = require('underscore');
var should = require('should'); var should = require('should');
...@@ -102,105 +103,59 @@ describe("Network", function() { ...@@ -102,105 +103,59 @@ describe("Network", function() {
}, Q()) }, Q())
.then(function(){ .then(function(){
return co(function *() {
nodeS1 = vucoin_p('127.0.0.1', s1.conf.port); nodeS1 = vucoin_p('127.0.0.1', s1.conf.port);
nodeS2 = vucoin_p('127.0.0.1', s2.conf.port); nodeS2 = vucoin_p('127.0.0.1', s2.conf.port);
nodeS3 = vucoin_p('127.0.0.1', s3.conf.port); nodeS3 = vucoin_p('127.0.0.1', s3.conf.port);
// Server 1 // Server 1
return Q() yield cat.selfCertPromise(now);
.then(function() { yield toc.selfCertPromise(now);
return cat.selfCertPromise(now); yield tic.selfCertPromise(now);
}) yield toc.certPromise(cat);
.then(function() { yield cat.certPromise(toc);
return toc.selfCertPromise(now); yield cat.certPromise(tic);
}) yield cat.joinPromise();
.then(function() { yield toc.joinPromise();
return tic.selfCertPromise(now); yield tic.joinPromise();
}) yield commitS1();
.then(_.partial(toc.certPromise, cat))
.then(_.partial(cat.certPromise, toc))
.then(_.partial(cat.certPromise, tic))
.then(cat.joinPromise)
.then(toc.joinPromise)
.then(tic.joinPromise)
.then(commitS1);
})
.then(function(){
return Q()
.then(function(){
// Server 2 syncs block 0 // Server 2 syncs block 0
return sync(0, 0, s1, s2); yield sync(0, 0, s1, s2);
})
.then(function(){
// Server 3 syncs block 0 // Server 3 syncs block 0
return sync(0, 0, s1, s3); yield sync(0, 0, s1, s3);
}) yield nodeS1.getPeer().then((peer) => nodeS2.postPeer(new Peer(peer).getRawSigned()));
.then(function(){ yield nodeS2.getPeer().then((peer) => nodeS1.postPeer(new Peer(peer).getRawSigned()));
return nodeS1.getPeer().then(function(peer) { yield nodeS3.getPeer().then((peer) => nodeS1.postPeer(new Peer(peer).getRawSigned()));
return nodeS2.postPeer(new Peer(peer).getRawSigned()); yield commitS1();
}); yield [
})
.then(function(){
return nodeS2.getPeer().then(function(peer) {
return nodeS1.postPeer(new Peer(peer).getRawSigned());
});
})
.then(function(){
return nodeS3.getPeer().then(function(peer) {
return nodeS1.postPeer(new Peer(peer).getRawSigned());
});
})
.then(commitS1)
.then(function(){
return Q.all([
until(s2, 'block', 1), until(s2, 'block', 1),
until(s3, 'block', 1) until(s3, 'block', 1)
]); ];
})
.then(function(){
// A block was successfully spread accross the network // A block was successfully spread accross the network
s2.bma.closeConnections(); s2.bma.closeConnections();
}) yield commitS1();
.then(commitS1) yield [
.then(function(){
return Q.all([
until(s3, 'block', 1) until(s3, 'block', 1)
]); ];
})
.then(function(){
s2.bma.reopenConnections(); s2.bma.reopenConnections();
// Server 2 syncs block number 2 (it did not have it) // Server 2 syncs block number 2 (it did not have it)
return sync(2, 2, s1, s2); yield sync(2, 2, s1, s2);
}) yield s2.recomputeSelfPeer();
.then(function(){ yield [
return s2.recomputeSelfPeer();
})
.then(function(){
return nodeS2.getPeer().then(function(peer) {
return nodeS1.postPeer(new Peer(peer).getRawSigned());
});
})
.then(function(){
return Q.all([
until(s2, 'block', 2), until(s2, 'block', 2),
until(s3, 'block', 2), until(s3, 'block', 2),
commitS1() commitS1()
.then(commitS1) .then(commitS1)
]); ];
}) yield commitS3();
.then(commitS3) yield [
.then(function(){
return Q.all([
until(s1, 'block', 1), until(s1, 'block', 1),
until(s2, 'block', 1) until(s2, 'block', 1)
]); ];
}) yield commitS2();
.then(commitS2) yield [
.then(function(){
return Q.all([
until(s1, 'block', 1), until(s1, 'block', 1),
until(s3, 'block', 1) until(s3, 'block', 1)
]); ];
}); });
}) })
; ;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment