diff --git a/app/service/PeeringService.ts b/app/service/PeeringService.ts index bba228ff6e8f5d2d72ed4f719600d728a441d37e..5d289550b26a773bb8c5cd88c7ebe4723514a71a 100644 --- a/app/service/PeeringService.ts +++ b/app/service/PeeringService.ts @@ -130,6 +130,7 @@ export class PeeringService { peerEntityOld.endpoints = thePeer.endpoints peerEntityOld.status = thePeer.status peerEntityOld.signature = thePeer.signature + peerEntityOld.blockstamp = thePeer.block } // Set the peer as UP again const peerEntity = peerEntityOld.toDBPeer() diff --git a/test/integration/network-update.js b/test/integration/network-update.js new file mode 100644 index 0000000000000000000000000000000000000000..ba2d7ee76fc0a72127e9bc37f6e57d6e5032ccb5 --- /dev/null +++ b/test/integration/network-update.js @@ -0,0 +1,112 @@ +"use strict"; + +const co = require('co'); +const _ = require('underscore'); +const rp = require('request-promise'); +const httpTest = require('./tools/http'); +const node = require('./tools/node'); +const user = require('./tools/user'); +const commit = require('./tools/commit'); +const sync = require('./tools/sync'); +const until = require('./tools/until'); +const toolbox = require('./tools/toolbox'); +const BlockDTO = require("../../app/lib/dto/BlockDTO"); + +const expectHttpCode = httpTest.expectHttpCode; +const expectAnswer = httpTest.expectAnswer; + +const MEMORY_MODE = true; +const commonConf = { + ipv4: '127.0.0.1', + remoteipv4: '127.0.0.1', + currency: 'bb', + httpLogs: true, + forksize: 3, + sigQty: 1 +}; + +const catKeyPair = { + pair: { + pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', + sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' + } +}; + +const tocKeyPair = { + pair: { + pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', + sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F' + } +}; + +const s1 = toolbox.server(_.clone(catKeyPair)); +const s2 = toolbox.server(_.clone(tocKeyPair)); + +const cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); +const toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + + +describe("Network updating", function() { + + before(function() { + + return co(function *() { + const commitS1 = commit(s1); + const commitS2 = commit(s2); + + yield [s1, s2].reduce((p, server) => co(function*() { + yield p; + yield server.initDalBmaConnections() + require('../../app/modules/router').duniter.methods.routeToNetwork(server); + }), Promise.resolve()); + + // Server 1 + yield cat.createIdentity(); + yield toc.createIdentity(); + yield toc.cert(cat); + yield cat.cert(toc); + yield cat.join(); + yield toc.join(); + for (const i in _.range(32)) { + yield commitS1(); // block#0 + } + // // s2 syncs from s1 + yield sync(0, 31, s1, s2); + + const b2 = yield s1.makeNext({}); + yield s1.postBlock(b2); + yield s2.postBlock(b2); + yield s1.recomputeSelfPeer(); // peer#1 + yield s1.sharePeeringWith(s2); + const b3 = yield s1.makeNext({}); + yield s1.postBlock(b3); + yield s2.postBlock(b3); + yield s1.recomputeSelfPeer(); // peer#1 + yield s1.sharePeeringWith(s2); + }); + }); + + describe("Server 1 /network/peering", function() { + + it('/peers?leaf=LEAFDATA', () => co(function*() { + const data = yield s1.get('/network/peering/peers?leaves=true'); + const leaf = data.leaves[0]; + const res = yield s1.get('/network/peering/peers?leaf=' + leaf); + res.leaf.value.should.have.property("pubkey").equal('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd'); + res.leaf.value.should.have.property("block").match(new RegExp('^3-')); + res.leaf.value.should.have.property("raw").match(new RegExp('.*Block: 3-.*')); + })); + }); + + describe("Server 2 /network/peering", function() { + + it('/peers?leaf=LEAFDATA', () => co(function*() { + const data = yield s2.get('/network/peering/peers?leaves=true'); + const leaf = data.leaves[0]; + const res = yield s2.get('/network/peering/peers?leaf=' + leaf); + res.leaf.value.should.have.property("pubkey").equal('DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo'); + res.leaf.value.should.have.property("block").match(new RegExp('^0-')); + res.leaf.value.should.have.property("raw").match(new RegExp('.*Block: 0-.*')); + })); + }); + }); diff --git a/test/integration/peers-same-pubkey.js b/test/integration/peers-same-pubkey.js index 02eab132e25d4271bdeeeff9164dae9ca37efd94..0f7612b97524717cd1347a82744e93119e6a554d 100644 --- a/test/integration/peers-same-pubkey.js +++ b/test/integration/peers-same-pubkey.js @@ -100,6 +100,24 @@ describe("Peer document", function() { leavesCount: 1 })); + it('leaf data', () => co(function*() { + const data = yield s1.get('/network/peering/peers?leaves=true'); + const leaf = data.leaves[0]; + const res = yield s1.get('/network/peering/peers?leaf=' + leaf); + res.leaf.value.should.have.property("pubkey").equal('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd'); + res.leaf.value.should.have.property("block").match(new RegExp('^3-')); + res.leaf.value.should.have.property("raw").match(new RegExp('.*Block: 3-.*')); + res.leaf.value.should.have.property("endpoints").length(3); + })); + + + it('peers', () => s1.expectThat('/network/peering', (res) => { + res.should.have.property("pubkey").equal('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd'); + res.should.have.property("block").match(new RegExp('^3-')); + res.should.have.property("endpoints").length(3); + })); + + it('peering should have been updated by node 1', () => s1.expectThat('/network/peering', (res) => { res.should.have.property("pubkey").equal('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd'); res.should.have.property("block").match(new RegExp('^3-')); @@ -118,6 +136,18 @@ describe("Peer document", function() { leavesCount: 1 })); + + it('leaf data', () => co(function*() { + const data = yield s2.get('/network/peering/peers?leaves=true'); + const leaf = data.leaves[0]; + const res = yield s2.get('/network/peering/peers?leaf=' + leaf); + res.leaf.value.should.have.property("pubkey").equal('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd'); + res.leaf.value.should.have.property("block").match(new RegExp('^3-')); + res.leaf.value.should.have.property("raw").match(new RegExp('.*Block: 3-.*')); + res.leaf.value.should.have.property("endpoints").length(3); + })); + + it('peering should have been updated by node 1', () => s2.expectThat('/network/peering', (res) => { res.should.have.property("pubkey").equal('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd'); res.should.have.property("block").match(new RegExp('^3-')); @@ -136,6 +166,16 @@ describe("Peer document", function() { leavesCount: 1 })); + it('leaf data', () => co(function*() { + const data = yield s3.get('/network/peering/peers?leaves=true'); + const leaf = data.leaves[0]; + const res = yield s3.get('/network/peering/peers?leaf=' + leaf); + res.leaf.value.should.have.property("pubkey").equal('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd'); + res.leaf.value.should.have.property("block").match(new RegExp('^3-')); + res.leaf.value.should.have.property("raw").match(new RegExp('.*Block: 3-.*')); + res.leaf.value.should.have.property("endpoints").length(3); + })); + it('peering should have been updated by node 1', () => s3.expectThat('/network/peering', (res) => { res.should.have.property("pubkey").equal('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd'); res.should.have.property("block").match(new RegExp('^3-'));