github.com/igggame/nebulas-go@v2.1.0+incompatible/nebtestkit/cases/network/downloader.test.js (about) 1 'use strict'; 2 3 var LocalNodes = require('../../local-nodes'); 4 var BigNumber = require('bignumber.js'); 5 var expect = require('chai').expect; 6 var sleep = require("system-sleep") 7 var os = require('os'); 8 9 var nodeCnt = 6; 10 var validators = 6; 11 var blockInterval = 5; 12 var dynastyInterval = 60; 13 var reward = new BigNumber("48e16"); 14 var initial = new BigNumber("1e18"); 15 var nodes = new LocalNodes(nodeCnt); 16 var connected = 0; 17 nodes.Start(); 18 19 describe('check downloader', function () { 20 before(function (done) { 21 this.timeout(300000); 22 setTimeout(done, 5000); 23 }); 24 25 it('check', function (done) { 26 // start servers 27 console.log("start servers"); 28 while (true) { 29 if (connected == nodeCnt - 1) break; 30 var nodeInfo = nodes.RPC(0).api.nodeInfo().then(function (resp) { 31 console.log(resp) 32 connected = resp.route_table.length 33 }); 34 sleep(3000); 35 } 36 37 let height = 0; 38 while (true) { 39 nodes.RPC(0).api.blockDump(1).then(function (resp) { 40 var block = JSON.parse(resp.data)[0]; 41 console.log(block); 42 if (height < block.height) { 43 height = block.height; 44 console.log("H", height); 45 } 46 }); 47 console.log(height); 48 if (height > 3) { 49 console.log("√ the height of current tail block is higher than 3"); 50 break; 51 } 52 sleep(3000); 53 } 54 55 nodes.RPC(5).admin.changeNetworkID(10); 56 sleep(15000); 57 var blockA; 58 nodes.RPC(0).api.blockDump(1).then(function (resp) { 59 blockA = JSON.parse(resp.data)[0]; 60 }); 61 62 var blockB; 63 nodes.RPC(5).api.blockDump(1).then(function (resp) { 64 blockB = JSON.parse(resp.data)[0]; 65 }); 66 sleep(3000); 67 console.log(blockA, " vs ", blockB); 68 expect(blockA.hash).not.to.be.equal(blockB.hash); 69 console.log("√ changed a node networkID to 10 and the node go to forked"); 70 71 72 nodes.RPC(5).admin.changeNetworkID(1); 73 sleep(20000); 74 nodes.RPC(0).api.blockDump(1).then(function (resp) { 75 blockA = JSON.parse(resp.data)[0]; 76 }); 77 78 // var blockSeed = JSON.parse(nodes.RPC(0).api.blockDump(1).data)[0]; 79 nodes.RPC(5).api.blockDump(1).then(function (resp) { 80 blockB = JSON.parse(resp.data)[0]; 81 }); 82 sleep(3000); 83 console.log(blockA, " vs ", blockB); 84 expect(blockA.hash).to.be.equal(blockB.hash); 85 console.log("√ recover the node networkID to 1 and the node is synchronized"); 86 sleep(10000); 87 88 nodes.Stop(); 89 done(); 90 }); 91 });