diff --git a/app/lib/logger.ts b/app/lib/logger.ts index 74fda628f263c88a2ab283ebc9793c4e1bdc7fa0..e6631ca62a618d1a49198970fe0f6eba03eb978b 100644 --- a/app/lib/logger.ts +++ b/app/lib/logger.ts @@ -9,7 +9,7 @@ const winston = require('winston'); const util = require('util'); -const CallbackLogger = winston.transports.CallbackLogger = function (options:any) { +const CallbackLogger:any = winston.transports.CallbackLogger = function (options:any) { this.name = 'customLogger'; this.level = options.level || 'info'; @@ -119,6 +119,21 @@ logger.mute = () => { } }; +logger.unmute = () => { + if (muted) { + muted = false + logger.add(winston.transports.Console, { + level: 'trace', + levels: customLevels.levels, + handleExceptions: false, + colorize: true, + timestamp: function() { + return moment().format(); + } + }) + } +} + /** * Convenience function to get logger directly */ diff --git a/app/modules/bma/lib/network.ts b/app/modules/bma/lib/network.ts index 9d2c252c6a7e5808e070f278a20ed248fbc97480..89fda152eeb68d34ab55b853ee184517e97dd575 100644 --- a/app/modules/bma/lib/network.ts +++ b/app/modules/bma/lib/network.ts @@ -229,7 +229,7 @@ export class BmaApi { resolve(httpServer); }); }); - this.logger && this.logger.info(name + ' listening on http://' + (netInterface.match(/:/) ? '[' + netInterface + ']' : netInterface) + ':' + port); + this.logger && this.logger.info(this.name + ' listening on http://' + (netInterface.match(/:/) ? '[' + netInterface + ']' : netInterface) + ':' + port); } catch (e) { this.logger && this.logger.warn('Could NOT listen to http://' + netInterface + ':' + port); this.logger && this.logger.warn(e); diff --git a/app/modules/prover/lib/blockProver.ts b/app/modules/prover/lib/blockProver.ts index bf6d27c719eacee10a7b5acb97c43ad810953db9..dd56f1693f15734c769ce9adc3b0f6eccfa93234 100644 --- a/app/modules/prover/lib/blockProver.ts +++ b/app/modules/prover/lib/blockProver.ts @@ -67,6 +67,10 @@ export class WorkerFarm { return this.stopPromise; } + shutDownEngine() { + this.theEngine.shutDown() + } + /** * Starts a new computation of PoW * @param stuff The necessary data for computing the PoW @@ -106,7 +110,7 @@ export class BlockProver { } } - getWorker() { + getWorker(): Promise<WorkerFarm> { if (!this.workerFarmPromise) { this.workerFarmPromise = (async () => { return new WorkerFarm(this.server, this.logger) @@ -121,6 +125,9 @@ export class BlockProver { let farm = await this.getWorker(); if (farm.isComputing() && !farm.isStopping()) { await farm.stopPoW() + } else { + // We force the stop anyway, just to be sure + await farm.stopPoW() } if (this.waitResolve) { this.waitResolve(); diff --git a/app/modules/prover/lib/engine.ts b/app/modules/prover/lib/engine.ts index 2a6f83ddfd30caa77b73788c0d9f423843e87581..05d3b1233e024e5c7273ce9c4196699e08dbcad0 100644 --- a/app/modules/prover/lib/engine.ts +++ b/app/modules/prover/lib/engine.ts @@ -52,4 +52,8 @@ export class PowEngine { setOnInfoMessage(callback:any) { return this.cluster.onInfoMessage = callback } + + async shutDown() { + return this.cluster.shutDownWorkers() + } } diff --git a/app/modules/prover/lib/permanentProver.ts b/app/modules/prover/lib/permanentProver.ts index 65a5d0bed3441a74125145ed2bddc5b98f219705..a5914b13e18b53c8bec8b8e71fc575e676766a9e 100644 --- a/app/modules/prover/lib/permanentProver.ts +++ b/app/modules/prover/lib/permanentProver.ts @@ -8,6 +8,12 @@ import {parsers} from "../../../lib/common-libs/parsers/index" const querablep = require('querablep'); +interface Querable<T> extends Promise<T> { + isFulfilled(): boolean + isResolved(): boolean + isRejected(): boolean +} + export class PermanentProver { logger:any @@ -16,7 +22,7 @@ export class PermanentProver { generator:BlockGeneratorWhichProves loops:number - private permanenceStarted = false + private permanencePromise:Querable<any>|null = null private blockchainChangedResolver:any = null private promiseOfWaitingBetween2BlocksOfOurs:any = null @@ -25,7 +31,7 @@ export class PermanentProver { private continuePromise:any = null private pullingResolveCallback:any = null private timeoutPullingCallback:any = null - private pullingFinishedPromise:any = null + private pullingFinishedPromise:Querable<any>|null = null private timeoutPulling:any = null constructor(private server:any) { @@ -47,8 +53,7 @@ export class PermanentProver { } allowedToStart() { - if (!this.permanenceStarted) { - this.permanenceStarted = true + if (!this.permanencePromise || !this.permanencePromise.isFulfilled()) { this.startPermanence() } this.resolveContinuePromise(true); @@ -56,7 +61,7 @@ export class PermanentProver { // When we detected a pulling, we stop the PoW loop pullingDetected() { - if (this.pullingFinishedPromise.isResolved()) { + if (this.pullingFinishedPromise && this.pullingFinishedPromise.isResolved()) { this.pullingFinishedPromise = querablep(Promise.race([ // We wait for end of pulling signal new Promise((res) => this.pullingResolveCallback = res), @@ -79,6 +84,12 @@ export class PermanentProver { } async startPermanence() { + + let permanenceResolve = () => {} + this.permanencePromise = querablep(new Promise(res => { + permanenceResolve = res + })) + /****************** * Main proof loop *****************/ @@ -199,6 +210,8 @@ export class PermanentProver { // Informative variable this.logger.trace('PoW loops = %s', this.loops); } + + permanenceResolve() } async blockchainChanged(gottenBlock:any) { diff --git a/app/modules/prover/lib/powCluster.ts b/app/modules/prover/lib/powCluster.ts index 057cb48bd9c175282d5ef509c3b2fcab7c61b4bd..4994cfc17e300058056a21d012bb0c8fcdfa1bf2 100644 --- a/app/modules/prover/lib/powCluster.ts +++ b/app/modules/prover/lib/powCluster.ts @@ -54,7 +54,7 @@ export class Master { // Stop the slaves' current work this.cancelWork() } - // this.logger.debug(`ENGINE c#${this.clusterId}#${this.slavesMap[worker.id].index}:`, message) + this.logger.warn(`ENGINE c#${this.clusterId}#${this.slavesMap[worker.id].index}:`, message) } initCluster() { @@ -154,6 +154,15 @@ export class Master { return p } + async shutDownWorkers() { + if (this.workersOnline) { + await Promise.all(this.workersOnline) + await Promise.all(this.slaves.map(async (s:any) => { + s.worker.kill() + })) + } + } + proveByWorkers(stuff:any) { // Eventually spawn the workers @@ -166,7 +175,9 @@ export class Master { this.currentPromise = this.newPromise(uuid) return (async () => { + this.logger.info(`Waiting workers to be all online...`) await Promise.all(this.workersOnline) + this.logger.info(`All online!`) if (!this.currentPromise) { this.logger.info(`Proof canceled during workers' initialization`) @@ -174,7 +185,9 @@ export class Master { } // Start the salves' job - this.slaves.forEach((s:any) => { + this.logger.info(`Sending newPow signal for each of %s workers...`, this.slaves.length) + this.slaves.forEach((s:any, index) => { + this.logger.info(`Sending signal for worker #%s`, index) s.worker.send({ uuid, command: 'newPoW', diff --git a/app/modules/prover/lib/proof.ts b/app/modules/prover/lib/proof.ts index e569f5a362c205887a964541ff9016e749aa14b7..2f43297a0a5173932f3bbd12fc37fa00c4f89886 100644 --- a/app/modules/prover/lib/proof.ts +++ b/app/modules/prover/lib/proof.ts @@ -34,6 +34,7 @@ process.on('uncaughtException', (err:any) => { process.on('message', async (message) => { + console.log('proof => command:', message.command) switch (message.command) { case 'newPoW': @@ -41,11 +42,15 @@ process.on('message', async (message) => { askedStop = true // Very important: do not await if the computation is already done, to keep the lock on JS engine + console.log('computing.isFulfilled ?', computing.isFulfilled()) if (!computing.isFulfilled()) { await computing; } + console.log('beginNewProofOfWork()...') + const res = await beginNewProofOfWork(message.value); + console.log('proof.res!') answer(message, res); })() break; diff --git a/package.json b/package.json index bd5989233c3591a1b5235878f00fac7b408e6ec5..9c9925aa271485a6981c240308772f8c4ce4edd8 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "test": "nyc --reporter html mocha", "start": "node bin/duniter start", "build": "tsc && cd \"node_modules/duniter-ui\" && npm install && npm run build", - "test-travis": "nyc --reporter lcovonly mocha" + "test-travis": "nyc mocha test/" }, "nyc": { "require": [ diff --git a/test/dal/source_dal.js b/test/dal/source_dal.js index f117c41aaf535a39c17c068361cdb4524a7b7c30..a7ae8860040bbcb405c3f018c03c3789ed7a97e9 100644 --- a/test/dal/source_dal.js +++ b/test/dal/source_dal.js @@ -4,7 +4,6 @@ const should = require('should'); const FileDAL = require('../../app/lib/dal/fileDAL').FileDAL const dir = require('../../app/lib/system/directory'); const indexer = require('../../app/lib/indexer').Indexer -const toolbox = require('../integration/tools/toolbox'); let dal; diff --git a/test/dal/triming.js b/test/dal/triming.js index 000173abb5a0ade31a0d74ecd435514ce5f70bda..114decf96c45caf5239bfbd6e69665a4a0cf2865 100644 --- a/test/dal/triming.js +++ b/test/dal/triming.js @@ -140,5 +140,7 @@ describe("Triming", function(){ (yield server.dal.bindexDAL.head(13)).should.have.property('number').equal(0); yield server.commit(); should.not.exists(yield server.dal.bindexDAL.head(14)); // Trimed + + yield server.closeCluster() })); }); diff --git a/test/integration/branches.js b/test/integration/branches.js index 7c61d30dccde62b9059d6f01f00c6bbb6e19cf80..c0cb175ee6074d0d34b643d2867ce350fd95233d 100644 --- a/test/integration/branches.js +++ b/test/integration/branches.js @@ -7,6 +7,7 @@ const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; const rp = require('request-promise'); const httpTest = require('./tools/http'); +const shutDownEngine = require('./tools/shutDownEngine'); const expectAnswer = httpTest.expectAnswer; @@ -38,6 +39,10 @@ describe("Branches", () => co(function*() { yield bmapi.openConnections(); })); + after(() => { + return shutDownEngine(s1) + }) + describe("Server 1 /blockchain", function() { it('should have a 3 blocks fork window size', function() { diff --git a/test/integration/branches2.js b/test/integration/branches2.js index 39e071991f28c095d36a7c597615989c013f5ef4..92e50e44b01e275018f7f8d50b61cd906120c4ef 100644 --- a/test/integration/branches2.js +++ b/test/integration/branches2.js @@ -10,6 +10,7 @@ const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); const sync = require('./tools/sync'); +const shutDownEngine = require('./tools/shutDownEngine'); const expectJSON = httpTest.expectJSON; const expectHttpCode = httpTest.expectHttpCode; @@ -109,6 +110,13 @@ describe("SelfFork", function() { return require('../../app/modules/crawler').CrawlerDependency.duniter.methods.pullBlocks(s1, s2p.pubkey); })); + after(() => { + return Promise.all([ + shutDownEngine(s1), + shutDownEngine(s2) + ]) + }) + describe("Server 1 /blockchain", function() { it('/block/0 should exist', function() { diff --git a/test/integration/branches_pending_data.js b/test/integration/branches_pending_data.js index 378fc700006ea9f7a336db331c7ef2251ee9f458..434bac240728ff6f4ab9f95900f5500c85df8721 100644 --- a/test/integration/branches_pending_data.js +++ b/test/integration/branches_pending_data.js @@ -8,6 +8,7 @@ const user = require('./tools/user'); const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); +const shutDownEngine = require('./tools/shutDownEngine'); const expectJSON = httpTest.expectJSON; const expectAnswer = httpTest.expectAnswer; @@ -65,6 +66,12 @@ describe("Pending data", function() { }); }); + after(() => { + return Promise.all([ + shutDownEngine(s1) + ]) + }) + describe("Server 1 /blockchain", function() { it('/current should exist', function() { diff --git a/test/integration/branches_revert.js b/test/integration/branches_revert.js index 71153f8c7ca9121ea72598673907d4b91d17530f..7adffa3cfc90fad31ad9e85247630e002749b2b3 100644 --- a/test/integration/branches_revert.js +++ b/test/integration/branches_revert.js @@ -60,4 +60,8 @@ describe("Revert root", function() { yield s1.expectError('/blockchain/block/0', 404, 'Block not found'); yield s1.expectError('/wot/lookup/cat', 404, 'No matching identity'); // Revert completely removes the identity })); + + after(() => { + return s1.closeCluster() + }) }); diff --git a/test/integration/branches_revert2.js b/test/integration/branches_revert2.js index 2e963444e095645d534f2dd544e73e48ab09ba77..747549fe03e2a63f8a2e7b35b597405cf196f738 100644 --- a/test/integration/branches_revert2.js +++ b/test/integration/branches_revert2.js @@ -8,6 +8,7 @@ const user = require('./tools/user'); const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); +const shutDownEngine = require('./tools/shutDownEngine'); require('../../app/modules/prover/lib/constants').Constants.CORES_MAXIMUM_USE_IN_PARALLEL = 1 require('../../app/modules/bma').BmaDependency.duniter.methods.noLimit(); // Disables the HTTP limiter @@ -65,6 +66,12 @@ describe("Revert two blocks", function() { }); }); + after(() => { + return Promise.all([ + shutDownEngine(s1) + ]) + }) + describe("before revert", () => { it('/block/0 should exist', function() { diff --git a/test/integration/branches_revert_balance.js b/test/integration/branches_revert_balance.js index 79a07f075462a942f05d2a4fe4a8a14247f0b920..94d6330cb1720593f804074f01b24a5e6a9db687 100644 --- a/test/integration/branches_revert_balance.js +++ b/test/integration/branches_revert_balance.js @@ -78,4 +78,8 @@ describe("Revert balance", () => { block.documentType = 'block' // yield s1.singleWritePromise(block) })) + + after(() => { + return s1.closeCluster() + }) }) diff --git a/test/integration/branches_revert_memberships.js b/test/integration/branches_revert_memberships.js index d6101ce35a8dc592b8df55db35e1550c33d5af47..6ffa1b4d24288977b16c203d37e865a3769763ad 100644 --- a/test/integration/branches_revert_memberships.js +++ b/test/integration/branches_revert_memberships.js @@ -169,6 +169,10 @@ describe("Revert memberships", function() { yield shouldHavePendingMS(0); // Undone memberships are lost })); + after(() => { + return s1.closeCluster() + }) + /********* * * Identity state testing functions diff --git a/test/integration/branches_switch.js b/test/integration/branches_switch.js index 64128e1d022b3db7a679c774193cfa47abad163e..9d3fd18ec47096da06caf5f16930bcd372621717 100644 --- a/test/integration/branches_switch.js +++ b/test/integration/branches_switch.js @@ -9,6 +9,7 @@ const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); const sync = require('./tools/sync'); +const shutDownEngine = require('./tools/shutDownEngine'); const constants = require('../../app/lib/constants'); const expectJSON = httpTest.expectJSON; @@ -91,6 +92,13 @@ describe("Switch", function() { // S1 should have switched to the other branch })); + after(() => { + return Promise.all([ + shutDownEngine(s1), + shutDownEngine(s2) + ]) + }) + describe("Server 1 /blockchain", function() { it('/block/8 should exist on S1', function() { diff --git a/test/integration/certification_chainability.js b/test/integration/certification_chainability.js index 2e12d916d482671df1ced635ae7a84ce5fcf73d5..5fe071663d931a76547ae8aac4e59b19442d601c 100644 --- a/test/integration/certification_chainability.js +++ b/test/integration/certification_chainability.js @@ -10,6 +10,7 @@ const constants = require('../../app/lib/constants'); const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); +const shutDownEngine = require('./tools/shutDownEngine'); const expectAnswer = httpTest.expectAnswer; @@ -82,6 +83,12 @@ describe("Certification chainability", function() { }); }); + after(() => { + return Promise.all([ + shutDownEngine(s1) + ]) + }) + it('block 0 should have 2 certs', function() { return expectAnswer(rp('http://127.0.0.1:9225/blockchain/block/0', { json: true }), function(res) { res.should.have.property('number').equal(0); diff --git a/test/integration/certifier-is-member.js b/test/integration/certifier-is-member.js index 54562479e65abc5c1020fda6c14a975fc16c955d..b0e9af46df034313d731b6ffcec80c5d5fece36a 100644 --- a/test/integration/certifier-is-member.js +++ b/test/integration/certifier-is-member.js @@ -84,4 +84,8 @@ describe("Certifier must be a member", function() { yield s1.commit({ time: now + 23 }); yield tic.cert(tac); })); + + after(() => { + return s1.closeCluster() + }) }); diff --git a/test/integration/collapse.js b/test/integration/collapse.js index b1f35d6ace782c8bb0fe5949bcd529b069a4b7c1..465a07df60b8b16f77cd23846b338c5bca680175 100644 --- a/test/integration/collapse.js +++ b/test/integration/collapse.js @@ -7,6 +7,7 @@ const bma = require('../../app/modules/bma').BmaDependency.duniter.methods const user = require('./tools/user'); const commit = require('./tools/commit'); const httpTest = require('./tools/http'); +const shutDownEngine = require('./tools/shutDownEngine'); const rp = require('request-promise'); const MEMORY_MODE = true; @@ -55,6 +56,12 @@ describe("Community collapse", function() { }); }); + after(() => { + return Promise.all([ + shutDownEngine(s1) + ]) + }) + it('should be handled', function() { return httpTest.expectJSON(rp('http://127.0.0.1:9340/blockchain/block/2', { json: true }), { number: 2 diff --git a/test/integration/continuous-proof.js b/test/integration/continuous-proof.js index 1b04ecbc680c94f6e60c75e9f35079c05ff79a1d..2a461524987cdcd99fe31918894b5bd3a6ff22f6 100644 --- a/test/integration/continuous-proof.js +++ b/test/integration/continuous-proof.js @@ -23,7 +23,9 @@ const s1 = toolbox.server({ pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' } -}); +}) + +let s2, s3 const i1 = user('i1', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); const i2 = user('i2', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); @@ -55,6 +57,7 @@ describe("Continous proof-of-work", function() { s1.conf.powSecurityRetryDelay = 10 * 60 * 1000; yield s1.revert(); s1.permaProver.loops = 0; + yield s1.stopBlockComputation(); })); it('should be able to start generation and find a block', () => co(function*() { @@ -75,6 +78,7 @@ describe("Continous proof-of-work", function() { // If we wait a bit, the loop should be ended yield new Promise((resolve) => setTimeout(resolve, 100)); // s1.permaProver.should.have.property('loops').equal(5); + yield s1.stopBlockComputation(); })); it('should be able to cancel generation because of a blockchain switch', () => co(function*() { @@ -110,5 +114,12 @@ describe("Continous proof-of-work", function() { s3.startBlockComputation() ]; yield s3.expectJSON('/blockchain/current', { number: 15 }); + yield s3.stopBlockComputation(); })); + + after(() => { + return Promise.all([ + s1.closeCluster() + ]) + }) }); diff --git a/test/integration/crosschain-test.js b/test/integration/crosschain-test.js index ae5c90827073d196c289d77aaa9c31d6092b470b..4965fc0433114e86e42a548994a64145fa1895d8 100644 --- a/test/integration/crosschain-test.js +++ b/test/integration/crosschain-test.js @@ -100,6 +100,13 @@ describe("Crosschain transactions", function() { }) ); + after(() => { + return Promise.all([ + sB.closeCluster(), + sM.closeCluster() + ]) + }) + describe("check initial sources", function(){ it('toc should now have 120 BETA_BROUZOUF from Transaction sources due to initial TX', checkHaveSources(tocB, 1, 120)); it('tic should now have 120 META_BROUZOUF from Transaction sources due to initial TX', checkHaveSources(ticM, 1, 120)); @@ -278,6 +285,13 @@ describe("Crosschain transactions", function() { }); }); + after(() => { + return Promise.all([ + sB.closeCluster(), + sM.closeCluster() + ]) + }) + describe("check initial sources", function(){ it('toc should now have 120 BETA_BROUZOUF from Transaction sources due to initial TX', checkHaveSources(tocB, 1, 120)); it('tic should now have 120 META_BROUZOUF from Transaction sources due to initial TX', checkHaveSources(ticM, 1, 120)); diff --git a/test/integration/documents-currency.js b/test/integration/documents-currency.js deleted file mode 100644 index b774680df01953763df4d4e848ebb4b657ec0047..0000000000000000000000000000000000000000 --- a/test/integration/documents-currency.js +++ /dev/null @@ -1,165 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const toolbox_1 = require("./tools/toolbox"); -const co = require('co'); -const should = require('should'); -const user = require('./tools/user'); -const commit = require('./tools/commit'); -const s1 = toolbox_1.NewTestingServer({ - currency: 'currency_one', - pair: { - pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', - sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' - } -}); -const s2 = toolbox_1.NewTestingServer({ - currency: 'currency_two', - pair: { - pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', - sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F' - } -}); -const cat1 = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' }, { server: s1 }); -const tac1 = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE' }, { server: s1 }); -const toc2 = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F' }, { server: s2 }); -const tic2 = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7' }, { server: s2 }); -describe("Document pool currency", function () { - before(() => co(function* () { - yield s1.prepareForNetwork(); - yield s2.prepareForNetwork(); - // Publishing identities - yield cat1.createIdentity(); - yield tac1.createIdentity(); - yield cat1.join(); - yield tac1.join(); - yield toc2.createIdentity(); - yield tic2.createIdentity(); - yield toc2.join(); - yield tic2.join(); - })); - it('Identity with wrong currency should be rejected', () => co(function* () { - const idtyCat1 = yield s1.lookup2identity(cat1.pub); - idtyCat1.getRawSigned(); - try { - yield s2.postIdentity(idtyCat1); - throw "Identity should not have been accepted, since it has an unknown currency name"; - } - catch (e) { - should.exist(e.error); - e.should.be.an.Object(); - e.error.message.should.match(/Signature does not match/); - } - })); - it('Identity absorption with wrong currency should be rejected', () => co(function* () { - try { - const cert = yield toc2.makeCert(cat1, s1); - yield s2.postCert(cert); - throw "Certification should not have been accepted, since it has an unknown currency name"; - } - catch (e) { - should.exist(e.error); - e.should.be.an.Object(); - e.error.message.should.match(/Signature does not match/); - } - })); - it('Certification with wrong currency should be rejected', () => co(function* () { - try { - const cert = yield toc2.makeCert(tic2, null, { - currency: "wrong_currency" - }); - yield s2.postCert(cert); - throw "Certification should not have been accepted, since it has an unknown currency name"; - } - catch (e) { - should.exist(e.error); - e.should.be.an.Object(); - e.error.message.should.match(/Wrong signature for certification/); - } - })); - it('Membership with wrong currency should be rejected', () => co(function* () { - try { - const join = yield toc2.makeMembership('IN', null, { - currency: "wrong_currency" - }); - yield s2.postMembership(join); - throw "Membership should not have been accepted, since it has an unknown currency name"; - } - catch (e) { - should.exist(e.error); - e.should.be.an.Object(); - e.error.message.should.match(/wrong signature for membership/); - } - })); - it('Revocation with wrong currency should be rejected', () => co(function* () { - try { - const revocation = yield toc2.makeRevocation(null, { - currency: "wrong_currency" - }); - yield s2.postRevocation(revocation); - throw "Revocation should not have been accepted, since it has an unknown currency name"; - } - catch (e) { - should.exist(e.error); - e.should.be.an.Object(); - e.error.message.should.match(/Wrong signature for revocation/); - } - })); - it('Block with wrong currency should be rejected', () => co(function* () { - yield toc2.cert(tic2); - yield tic2.cert(toc2); - yield s2.commit(); - const b2 = yield s2.makeNext({ currency: "wrong_currency" }); - try { - yield s2.postBlock(b2); - throw "Currency should have been rejected"; - } - catch (e) { - should.exist(e.error); - e.should.be.an.Object(); - e.error.message.should.match(/Wrong inner hash/); // Because currency is dynamically replaced - } - })); - it('Transaction with wrong currency should be rejected', () => co(function* () { - try { - yield cat1.cert(tac1); - yield tac1.cert(cat1); - yield s1.commit(); - yield s1.commit(); - const current = yield s1.get('/blockchain/current'); - const tx = cat1.makeTX([{ - src: "1500:1:D:DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo:1", - unlock: "SIG(0)" - }], [{ - qty: 1500, - base: 1, - lock: "XHX(8AFC8DF633FC158F9DB4864ABED696C1AA0FE5D617A7B5F7AB8DE7CA2EFCD4CB)" - }], { - currency: "wrong_currency", - blockstamp: [current.number, current.hash].join('-') - }); - yield s1.postRawTX(tx); - throw "Transaction should not have been accepted, since it has an unknown currency name"; - } - catch (e) { - should.exist(e.error); - e.should.be.an.Object(); - e.error.message.should.match(/Signature from a transaction must match/); - } - })); - it('Peer with wrong currency should be rejected', () => co(function* () { - try { - const peer = yield toc2.makePeer(['BASIC_MERKLED_API localhost 10901'], { - version: 10, - currency: "wrong_currency" - }); - yield s2.postPeer(peer); - throw "Peer should not have been accepted, since it has an unknown currency name"; - } - catch (e) { - should.exist(e.error); - e.should.be.an.Object(); - e.error.message.should.match(/Signature from a peer must match/); - } - })); -}); -//# sourceMappingURL=documents-currency.js.map \ No newline at end of file diff --git a/test/integration/documents-currency.ts b/test/integration/documents-currency.ts index e76deaa883be224c064513fb8edd0e611483c306..9bb855c4000f92a8619dcb26d3434d6be9351f26 100644 --- a/test/integration/documents-currency.ts +++ b/test/integration/documents-currency.ts @@ -43,6 +43,13 @@ describe("Document pool currency", function() { yield tic2.join(); })); + after(() => { + return Promise.all([ + s1.closeCluster(), + s2.closeCluster() + ]) + }) + it('Identity with wrong currency should be rejected', () => co(function*() { const idtyCat1 = yield s1.lookup2identity(cat1.pub); idtyCat1.getRawSigned() diff --git a/test/integration/http_api.js b/test/integration/http_api.js index e12c6233ccdd9cf0c2d59875ccc766cee6115c36..5c9a3244638cdd72962ae8aa83d8587124dd88e6 100644 --- a/test/integration/http_api.js +++ b/test/integration/http_api.js @@ -8,6 +8,7 @@ const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; const user = require('./tools/user'); const http = require('./tools/http'); +const shutDownEngine = require('./tools/shutDownEngine'); const constants = require('../../app/lib/constants'); const rp = require('request-promise'); const ws = require('ws'); @@ -58,6 +59,12 @@ describe("HTTP API", function() { yield commit(); })); + after(() => { + return Promise.all([ + shutDownEngine(server) + ]) + }) + function makeBlockAndPost(theServer) { return function() { return require('../../app/modules/prover').ProverDependency.duniter.methods.generateAndProveTheNext(theServer) diff --git a/test/integration/identity-absorption.js b/test/integration/identity-absorption.js index 88734c94ab31d116b990737454bcbdbecbe655ba..2181711a8901a187b44f518d24130675a3ad3341 100644 --- a/test/integration/identity-absorption.js +++ b/test/integration/identity-absorption.js @@ -8,6 +8,7 @@ const user = require('./tools/user'); const rp = require('request-promise'); const httpTest = require('./tools/http'); const toolbox = require('./tools/toolbox'); +const shutDownEngine = require('./tools/shutDownEngine'); const expectAnswer = httpTest.expectAnswer; @@ -59,6 +60,13 @@ describe("Identity absorption", function() { }); }); + after(() => { + return Promise.all([ + shutDownEngine(s1), + shutDownEngine(s2) + ]) + }) + it('cat should exist on server 1', function() { return expectAnswer(rp('http://127.0.0.1:4450/wot/lookup/cat', { json: true }), function(res) { res.should.have.property('results').length(1); diff --git a/test/integration/identity-clean-test.js b/test/integration/identity-clean-test.js index 7e46bb0e07aae6035be9398561616ef074affa5c..fbcf23513413ce50e15e4057a7c2bf4b209cbdae 100644 --- a/test/integration/identity-clean-test.js +++ b/test/integration/identity-clean-test.js @@ -8,6 +8,7 @@ const user = require('./tools/user'); const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); +const shutDownEngine = require('./tools/shutDownEngine'); const expectAnswer = httpTest.expectAnswer; @@ -71,6 +72,12 @@ describe("Identities cleaned", function() { }); }); + after(() => { + return Promise.all([ + shutDownEngine(s1) + ]) + }) + it('should have 2 members', function() { return expectAnswer(rp('http://127.0.0.1:7733/wot/members', { json: true }), function(res) { res.should.have.property('results').length(2); diff --git a/test/integration/identity-expiry.js b/test/integration/identity-expiry.js index 1104f5c993c931bf6972762d7b4025e256f416be..ec7319d60f5ae5c963989ade4a5a068698377b99 100644 --- a/test/integration/identity-expiry.js +++ b/test/integration/identity-expiry.js @@ -11,6 +11,7 @@ const constants = require('../../app/lib/constants'); const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); +const shutDownEngine = require('./tools/shutDownEngine'); const expectAnswer = httpTest.expectAnswer; const expectError = httpTest.expectError; @@ -72,6 +73,10 @@ describe("Identities expiry", function() { }); }); + after(() => { + return shutDownEngine(s1) + }) + it('should have requirements failing for tic', function() { // tic has been cleaned up, since its identity has expired after the root block return expectError(404, 'No identity matching this pubkey or uid', rp('http://127.0.0.1:8560/wot/requirements/DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', { json: true })); diff --git a/test/integration/identity-implicit-revocation.js b/test/integration/identity-implicit-revocation.js index 704cb92bdbf7184414a4b934aedc1b62fb2c2950..1a19e7d1988d2175e11a1de47debb167794863bf 100644 --- a/test/integration/identity-implicit-revocation.js +++ b/test/integration/identity-implicit-revocation.js @@ -56,6 +56,12 @@ describe("Implicit revocation", function() { yield s1.commit({ time: now + 20 }); })); + after(() => { + return Promise.all([ + s1.closeCluster() + ]) + }) + it('block#4 should have kicked tic', () => s1.expectThat('/blockchain/block/5', (res) => { assert.deepEqual(res.excluded, [ 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV' diff --git a/test/integration/identity-kicking-by-certs.js b/test/integration/identity-kicking-by-certs.js index e1da87805ea7ad3d6d14ac6c96fb505357fcfd64..3ad439eb58eb52f78ba9c74a9162722514c89e2e 100644 --- a/test/integration/identity-kicking-by-certs.js +++ b/test/integration/identity-kicking-by-certs.js @@ -79,6 +79,12 @@ describe("Identities kicking by certs", function() { yield s1.commit({ time: now + 8 }); })); + after(() => { + return Promise.all([ + s1.closeCluster() + ]) + }) + it('block#7 should have kicked 2 member', () => s1.expectJSON('/blockchain/block/7', (res) => { assert.deepEqual(res.excluded, [ '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', diff --git a/test/integration/identity-kicking.js b/test/integration/identity-kicking.js index 76e15b59bb1b5d849a4e345b8b8a6c7b5f092a04..753d47abae133b902f5ffe479104dc22beabdcdb 100644 --- a/test/integration/identity-kicking.js +++ b/test/integration/identity-kicking.js @@ -10,6 +10,7 @@ const constants = require('../../app/lib/constants'); const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); +const shutDownEngine = require('./tools/shutDownEngine'); const expectAnswer = httpTest.expectAnswer; @@ -90,6 +91,12 @@ describe("Identities kicking", function() { }); }); + after(() => { + return Promise.all([ + shutDownEngine(s1) + ]) + }) + /** * */ diff --git a/test/integration/identity-pulling.js b/test/integration/identity-pulling.js index 2f1a2f3c122ab63b952aa94447743b9188cfae8d..33ce0fa4e0eebad7aeb10aab4a29e17040d1aa5f 100644 --- a/test/integration/identity-pulling.js +++ b/test/integration/identity-pulling.js @@ -42,6 +42,13 @@ describe("Identity pulling", function() { yield tac1.join(); })); + after(() => { + return Promise.all([ + s1.closeCluster(), + s2.closeCluster() + ]) + }) + it('toc, tic and tuc can create their account on s2', () => co(function*() { yield toc2.createIdentity(); yield tic2.createIdentity(); diff --git a/test/integration/identity-same-pubkey.js b/test/integration/identity-same-pubkey.js index cf2f307eb53a68f51bb631077ae073a27770caf9..f1243e1b705c74152d65cac7b12fe5d8507f7171 100644 --- a/test/integration/identity-same-pubkey.js +++ b/test/integration/identity-same-pubkey.js @@ -35,6 +35,12 @@ describe("Identities with shared pubkey", function() { yield cat1.cert(catb); })); + after(() => { + return Promise.all([ + s1.closeCluster() + ]) + }) + it('should exit 2 pubkey result', () => s1.expect('/wot/lookup/cat', (res) => { res.results.should.have.length(2); res.results[0].should.have.property('pubkey').equal('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd'); diff --git a/test/integration/identity-test.js b/test/integration/identity-test.js index 46a0ee0a038b3b377c3a3bebbd309cd5627e68c6..824aaa08e9cb8c79ba477122c6c2852dcc727a2f 100644 --- a/test/integration/identity-test.js +++ b/test/integration/identity-test.js @@ -10,6 +10,7 @@ const constants = require('../../app/lib/constants'); const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); +const shutDownEngine = require('./tools/shutDownEngine'); require('../../app/modules/bma').BmaDependency.duniter.methods.noLimit(); // Disables the HTTP limiter @@ -113,6 +114,12 @@ describe("Identities collision", function() { }); }); + after(() => { + return Promise.all([ + shutDownEngine(s1) + ]) + }) + it('should have 4 members', function() { return expectAnswer(rp('http://127.0.0.1:7799/wot/members', { json: true }), function(res) { res.should.have.property('results').length(4); diff --git a/test/integration/lookup.js b/test/integration/lookup.js index 5bdbcf79c30396e9ec0ab7a1b365b0fa119fb87a..c67a1508b76638492a7e0300fa6bd305e4cabb48 100644 --- a/test/integration/lookup.js +++ b/test/integration/lookup.js @@ -7,6 +7,7 @@ const bma = require('../../app/modules/bma').BmaDependency.duniter.methods const user = require('./tools/user'); const rp = require('request-promise'); const httpTest = require('./tools/http'); +const shutDownEngine = require('./tools/shutDownEngine'); const MEMORY_MODE = true; const commonConf = { @@ -50,6 +51,12 @@ describe("Lookup identity grouping", () => { yield tic1.join(); })); + after(() => { + return Promise.all([ + shutDownEngine(s1) + ]) + }) + it('cat should have only 1 identity in 1 pubkey', () => httpTest.expectAnswer(rp('http://127.0.0.1:4452/wot/lookup/cat', { json: true }), (res) => { res.should.have.property('results').length(1); // cat pubkey diff --git a/test/integration/membership_chainability.js b/test/integration/membership_chainability.ts similarity index 57% rename from test/integration/membership_chainability.js rename to test/integration/membership_chainability.ts index d480a0b0893add5b00d8d2317d4da0b762a9b7fd..b49ed7ddb4d0106c3ca719329d63f5489f43ce9e 100644 --- a/test/integration/membership_chainability.js +++ b/test/integration/membership_chainability.ts @@ -1,15 +1,12 @@ -"use strict" - -const co = require('co') -const should = require('should') const toolbox = require('./tools/toolbox') +const logger = require('../../app/lib/logger').NewLogger() describe("Membership chainability", function() { describe("before July 2017", () => { const now = 1482220000 - let s1, cat + let s1:any, cat:any const conf = { msPeriod: 20, @@ -21,27 +18,37 @@ describe("Membership chainability", function() { medianTimeBlocks: 1 // The medianTime always equals previous block's medianTime } - before(() => co(function*() { - const res1 = yield toolbox.simpleNodeWith2Users(conf) + before(async () => { + require('../../app/lib/logger').NewLogger().unmute() + logger.warn('Before() ...') + const res1 = await toolbox.simpleNodeWith2Users(conf) + logger.warn('res1 = OK') s1 = res1.s1 cat = res1.cat - yield s1.commit({ time: now }) - yield s1.commit({ time: now }) - yield s1.commit({ time: now, actives: [ + await s1.commit({ time: now }) + logger.warn('commit1 = OK') + await s1.commit({ time: now }) + logger.warn('commit2 = OK') + await s1.commit({ time: now, actives: [ 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd:rppB5NEwmdMUCxw3N/QPMk+V1h2Jpn0yxTzdO2xxcNN3MACv6x8vNTChWwM6DOq+kXiQHTczFzoux+82WkMfDQ==:1-12D7B9BEBE941F6929A4A61CDC06DEEEFCB00FD1DA72E42FFF7B19A338D421E1:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:cat' ]}) - })) + logger.warn('commit3 = OK') + }) - it('current should be the 2nd', () => s1.expect('/blockchain/current', (res) => { + it('current should be the 2nd', () => s1.expect('/blockchain/current', (res:any) => { res.should.have.property('number').equal(2) res.should.have.property('actives').length(1) })) + + after(async () => { + await s1.closeCluster() + }) }) describe("after July 2017", () => { const now = 1498860000 - let s1, cat + let s1:any, cat:any const conf = { msPeriod: 20, @@ -53,41 +60,52 @@ describe("Membership chainability", function() { medianTimeBlocks: 1 // The medianTime always equals previous block's medianTime } - before(() => co(function*() { - const res1 = yield toolbox.simpleNodeWith2Users(conf) + before(async () => { + require('../../app/lib/logger').NewLogger().unmute() + logger.warn('before2') + const res1 = await toolbox.simpleNodeWith2Users(conf) + logger.warn('res2 = OK') s1 = res1.s1 + logger.warn('res2 = OK1') cat = res1.cat - yield s1.commit({ time: now }) - yield s1.commit({ time: now + 20 }) - })) + logger.warn('res2 = OK2') + await s1.commit({ time: now }) + logger.warn('commit2.0 = OK') + await s1.commit({ time: now + 20 }) + logger.warn('commit2.1 = OK') + }) - it('should refuse a block with a too early membership in it', () => co(function*() { - yield toolbox.shouldFail(s1.commit({ + it('should refuse a block with a too early membership in it', async () => { + await toolbox.shouldFail(s1.commit({ time: now + 20, actives: ['HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd:SiCD1MSyDiZKWLp/SP/2Vj5T3JMgjNnIIKMI//yvKRdWMzKjEn6/ZT+TCjyjnl85qRfmEuWv1jLmQSoe8GXSDg==:1-0DEE2A8EA05322FCC4355D5F0E7A2830F4A22ACEBDC4B62399484E091A5CCF27:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:cat'] }), '500 - "{\\n \\"ucode\\": 1002,\\n \\"message\\": \\"ruleMembershipPeriod\\"\\n}"') - })) + }) - it('should not be able to renew immediately', () => co(function*() { - yield cat.join() - yield s1.commit({ time: now + 20 }) - yield s1.expect('/blockchain/block/2', (res) => { + it('should not be able to renew immediately', async () => { + await cat.join() + await s1.commit({ time: now + 20 }) + await s1.expect('/blockchain/block/2', (res:any) => { res.should.have.property('number').equal(2) res.should.have.property('joiners').length(0) }) - })) + }) - it('should be able to renew after 20 sec', () => co(function*() { - yield s1.commit({ time: now + 20 }) - yield s1.expect('/blockchain/block/3', (res) => { + it('should be able to renew after 20 sec', async () => { + await s1.commit({ time: now + 20 }) + await s1.expect('/blockchain/block/3', (res:any) => { res.should.have.property('number').equal(3) res.should.have.property('actives').length(1) }) - })) + }) - it('current should be the 4th', () => s1.expect('/blockchain/current', (res) => { + it('current should be the 4th', () => s1.expect('/blockchain/current', (res:any) => { res.should.have.property('number').equal(3) res.should.have.property('actives').length(1) })) + + after(async () => { + await s1.closeCluster() + }) }) }) diff --git a/test/integration/peer-outdated.js b/test/integration/peer-outdated.js index d9d4721bef961d6318fedda1899651e32edc2336..260b17ec7da6036e8ef60e7e5fc6f4100346b3c4 100644 --- a/test/integration/peer-outdated.js +++ b/test/integration/peer-outdated.js @@ -59,6 +59,13 @@ describe("Peer document expiry", function() { yield s2.syncFrom(s1, 0, 2); })); + after(() => { + return Promise.all([ + s1.closeCluster(), + s2.closeCluster() + ]) + }) + it('sending back V1 peer document should return the latest known one', () => co(function*() { let res; try { diff --git a/test/integration/peerings.js b/test/integration/peerings.js index f1dbdb253f0d4f96a98ae312e4cf181e85e49618..0c4415eb7ebc91c288dc15e589b409bdc24f52c9 100644 --- a/test/integration/peerings.js +++ b/test/integration/peerings.js @@ -13,6 +13,7 @@ const commit = require('./tools/commit'); const sync = require('./tools/sync'); const contacter = require('../../app/modules/crawler').CrawlerDependency.duniter.methods.contacter; const until = require('./tools/until'); +const shutDownEngine = require('./tools/shutDownEngine'); const multicaster = require('../../app/lib/streams/multicaster'); const PeerDTO = require('../../app/lib/dto/PeerDTO').PeerDTO @@ -154,6 +155,14 @@ describe("Network", function() { ; }); + after(() => { + return Promise.all([ + shutDownEngine(s1), + shutDownEngine(s2), + shutDownEngine(s3) + ]) + }) + describe("Server 1", function() { it('should have a 3 leaves merkle for peers', function() { diff --git a/test/integration/peers-same-pubkey.js b/test/integration/peers-same-pubkey.js index 414f42e9ee569ce2c38e4038aabf1d6bfa44545d..02eab132e25d4271bdeeeff9164dae9ca37efd94 100644 --- a/test/integration/peers-same-pubkey.js +++ b/test/integration/peers-same-pubkey.js @@ -86,6 +86,14 @@ describe("Peer document", function() { ]; })); + after(() => { + return Promise.all([ + s1.closeCluster(), + s2.closeCluster(), + s3.closeCluster() + ]) + }) + describe("Server 1", function() { it('should have a 1 leaves merkle for peers', () => s1.expectJSON('/network/peering/peers', { diff --git a/test/integration/revocation-test.js b/test/integration/revocation-test.js index ab0aff83139c830f4619b8eee70e5c40970d8897..086d516c156fde1a6bc3de68bf52ae61a3a76c3e 100644 --- a/test/integration/revocation-test.js +++ b/test/integration/revocation-test.js @@ -9,6 +9,7 @@ const user = require('./tools/user'); const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); +const shutDownEngine = require('./tools/shutDownEngine'); const expectAnswer = httpTest.expectAnswer; @@ -83,6 +84,13 @@ describe("Revocation", function() { }); }); + after(() => { + return Promise.all([ + shutDownEngine(s1), + shutDownEngine(s2) + ]) + }) + it('should have 3 members', function() { return expectAnswer(rp('http://127.0.0.1:9964/wot/members', { json: true }), function(res) { res.should.have.property('results').length(3); diff --git a/test/integration/server-import-export.js b/test/integration/server-import-export.js index da836bfc6041cbb26e513ea3ff4f8626cddfee80..b4ab2c49f01675a046f76078abf489d2f5b88bb9 100644 --- a/test/integration/server-import-export.js +++ b/test/integration/server-import-export.js @@ -16,12 +16,12 @@ const serverConfig = { } }; -let s1; +let s0, s1; describe('Import/Export', () => { before(() => co(function *() { - const s0 = toolbox.server(_.extend({ homename: 'dev_unit_tests1' }, serverConfig)); + s0 = toolbox.server(_.extend({ homename: 'dev_unit_tests1' }, serverConfig)); yield s0.resetHome(); s1 = toolbox.server(_.extend({ homename: 'dev_unit_tests1' }, serverConfig)); @@ -39,6 +39,13 @@ describe('Import/Export', () => { yield s1.commit(); })); + after(() => { + return Promise.all([ + s0.closeCluster(), + s1.closeCluster() + ]) + }) + it('should be able to export data', () => co(function *() { const archive = yield s1.exportAllDataAsZIP(); const output = require('fs').createWriteStream(s1.home + '/export.zip'); diff --git a/test/integration/server-sandbox.js b/test/integration/server-sandbox.js index b4ad927fcfafd24500e7289f39d97dcdd64d66de..b600b5102989069a442b3d0eb2d84d74996cecc8 100644 --- a/test/integration/server-sandbox.js +++ b/test/integration/server-sandbox.js @@ -69,6 +69,14 @@ describe("Sandboxes", function() { s3.dal.idtyDAL.setSandboxSize(3); })); + after(() => { + return Promise.all([ + s1.closeCluster(), + s2.closeCluster(), + s3.closeCluster() + ]) + }) + describe('Identities', () => { diff --git a/test/integration/sources_property.js b/test/integration/sources_property.js index db5aa482273dc91c2288c0efc0a7b2bf4180a516..d77f46b049081c21fa5d7f696f6231ddd8141e5f 100644 --- a/test/integration/sources_property.js +++ b/test/integration/sources_property.js @@ -33,6 +33,12 @@ describe("Sources property", function() { yield s1.commit({ time: now + 1 }); })); + after(() => { + return Promise.all([ + s1.closeCluster() + ]) + }) + it('it should exist block#1 with UD of 200', () => s1.expect('/blockchain/block/1', (block) => { should.exists(block); assert.equal(block.number, 1); diff --git a/test/integration/start_generate_blocks.js b/test/integration/start_generate_blocks.js index 1042306756c8e7dcc5192b31b742ddab7c8cf7fb..00ef3d9c6a6462fbf3968e806e695e2548906abd 100644 --- a/test/integration/start_generate_blocks.js +++ b/test/integration/start_generate_blocks.js @@ -13,6 +13,7 @@ const multicaster = require('../../app/lib/streams/multicaster'); const PeerDTO = require('../../app/lib/dto/PeerDTO').PeerDTO const contacter = require('../../app/modules/crawler').CrawlerDependency.duniter.methods.contacter; const sync = require('./tools/sync'); +const shutDownEngine = require('./tools/shutDownEngine'); const expectJSON = httpTest.expectJSON; @@ -108,6 +109,13 @@ describe("Generation", function() { }); }); + after(() => { + return Promise.all([ + shutDownEngine(s1), + shutDownEngine(s2) + ]) + }) + describe("Server 1 /blockchain", function() { it('/current should exist', function() { diff --git a/test/integration/tests.js b/test/integration/tests.js index 950aa719a26c9c4aba00da2d23b15d65e7476111..71d6b83201c1edfb8a12282bef4d241ee7801006 100644 --- a/test/integration/tests.js +++ b/test/integration/tests.js @@ -12,6 +12,7 @@ const user = require('./tools/user'); const jspckg = require('../../package'); const commit = require('./tools/commit'); const httpTest = require('./tools/http'); +const shutDownEngine = require('./tools/shutDownEngine'); const rp = require('request-promise'); const expectAnswer = httpTest.expectAnswer; @@ -235,6 +236,12 @@ describe("Integration", function() { }); }); + after(() => { + return Promise.all([ + shutDownEngine(node3) + ]) + }) + it('toc should give only 1 result with 3 certification by others', () => expectAnswer(rp('http://127.0.0.1:9997/wot/lookup/toc', { json: true }), function(res) { should.exists(res); assert.equal(res.results.length, 1); diff --git a/test/integration/tools/commit.js b/test/integration/tools/commit.js index 95aa8f25a6a56d30039e24677db23e669a4ffa85..fdd9e57349168f6189ca5cf96b484328b0ead0aa 100644 --- a/test/integration/tools/commit.js +++ b/test/integration/tools/commit.js @@ -13,12 +13,16 @@ module.exports = function makeBlockAndPost(theServer, extraProps) { manualValues = _.extend(manualValues, extraProps); } return co(function *() { + logger.warn('!utProver?', !theServer._utProver) if (!theServer._utProver) { theServer._utProver = new BlockProver(theServer) theServer._utGenerator = require('../../../app/modules/prover').ProverDependency.duniter.methods.blockGenerator(theServer, theServer._utProver) } + logger.warn('proving...') let proven = yield theServer._utGenerator.makeNextBlock(null, null, manualValues) + logger.warn('proven:', proven) const block = yield postBlock(theServer)(proven); + logger.warn('posted:', block) return block }); }; diff --git a/test/integration/tools/shutDownEngine.js b/test/integration/tools/shutDownEngine.js new file mode 100644 index 0000000000000000000000000000000000000000..d01d6308584574ce82ae7ed5a15c4f78f13d19ce --- /dev/null +++ b/test/integration/tools/shutDownEngine.js @@ -0,0 +1,8 @@ +const co = require('co') + +module.exports = (server) => co(function*() { + if (server._utProver) { + const farm = yield server._utProver.getWorker(); + return farm.shutDownEngine(); + } +}) diff --git a/test/integration/tools/toolbox.js b/test/integration/tools/toolbox.js deleted file mode 100644 index bfdd0a28869169feef5b76935fe4fcf066b12324..0000000000000000000000000000000000000000 --- a/test/integration/tools/toolbox.js +++ /dev/null @@ -1,367 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const server_1 = require("../../../server"); -const BlockDTO_1 = require("../../../app/lib/dto/BlockDTO"); -const IdentityDTO_1 = require("../../../app/lib/dto/IdentityDTO"); -const PeerDTO_1 = require("../../../app/lib/dto/PeerDTO"); -const _ = require('underscore'); -const rp = require('request-promise'); -const httpTest = require('../tools/http'); -const sync = require('../tools/sync'); -const commit = require('../tools/commit'); -const user = require('../tools/user'); -const until = require('../tools/until'); -const bma = require('../../../app/modules/bma').BmaDependency.duniter.methods.bma; -const multicaster = require('../../../app/lib/streams/multicaster'); -const dtos = require('../../../app/modules/bma').BmaDependency.duniter.methods.dtos; -const logger = require('../../../app/lib/logger').NewLogger('toolbox'); -require('../../../app/modules/bma').BmaDependency.duniter.methods.noLimit(); // Disables the HTTP limiter -const MEMORY_MODE = true; -const CURRENCY_NAME = 'duniter_unit_test_currency'; -const HOST = '127.0.0.1'; -let PORT = 10000; -exports.shouldFail = (promise, message = null) => __awaiter(this, void 0, void 0, function* () { - try { - yield promise; - throw '{ "message": "Should have thrown an error" }'; - } - catch (e) { - let err = e; - if (typeof e === "string") { - err = JSON.parse(e); - } - err.should.have.property('message').equal(message); - } -}); -exports.simpleNetworkOf2NodesAnd2Users = (options) => __awaiter(this, void 0, void 0, function* () { - const catKeyring = { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' }; - const tacKeyring = { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE' }; - const s1 = exports.NewTestingServer(_.extend({ pair: catKeyring }, options || {})); - const s2 = exports.NewTestingServer(_.extend({ pair: tacKeyring }, options || {})); - const cat = user('cat', catKeyring, { server: s1 }); - const tac = user('tac', tacKeyring, { server: s1 }); - yield s1.initDalBmaConnections(); - yield s2.initDalBmaConnections(); - yield s2.sharePeeringWith(s1); - // await s2.post('/network/peering/peers', await s1.get('/network/peering')); - // await s1.submitPeerP(await s2.get('/network/peering')); - yield cat.createIdentity(); - yield tac.createIdentity(); - yield cat.cert(tac); - yield tac.cert(cat); - yield cat.join(); - yield tac.join(); - // Each server forwards to each other - require('../../../app/modules/router').duniter.methods.routeToNetwork(s1); - require('../../../app/modules/router').duniter.methods.routeToNetwork(s2); - return { s1, s2, cat, tac }; -}); -exports.simpleNodeWith2Users = (options) => __awaiter(this, void 0, void 0, function* () { - const catKeyring = { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' }; - const tacKeyring = { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE' }; - const s1 = exports.NewTestingServer(_.extend({ pair: catKeyring }, options || {})); - const cat = user('cat', catKeyring, { server: s1 }); - const tac = user('tac', tacKeyring, { server: s1 }); - yield s1.initDalBmaConnections(); - yield cat.createIdentity(); - yield tac.createIdentity(); - yield cat.cert(tac); - yield tac.cert(cat); - yield cat.join(); - yield tac.join(); - return { s1, cat, tac }; -}); -exports.simpleNodeWith2otherUsers = (options) => __awaiter(this, void 0, void 0, function* () { - const ticKeyring = { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7' }; - const tocKeyring = { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F' }; - const s1 = exports.NewTestingServer(_.extend({ pair: ticKeyring }, options || {})); - const tic = user('cat', ticKeyring, { server: s1 }); - const toc = user('tac', tocKeyring, { server: s1 }); - yield s1.initDalBmaConnections(); - yield tic.createIdentity(); - yield toc.createIdentity(); - yield tic.cert(toc); - yield toc.cert(tic); - yield tic.join(); - yield toc.join(); - return { s1, tic, toc }; -}); -exports.createUser = (uid, pub, sec, defaultServer) => __awaiter(this, void 0, void 0, function* () { - const keyring = { pub: pub, sec: sec }; - return user(uid, keyring, { server: defaultServer }); -}); -exports.fakeSyncServer = (readBlocksMethod, readParticularBlockMethod, onPeersRequested) => __awaiter(this, void 0, void 0, function* () { - const host = HOST; - const port = PORT++; - // Meaningful variables - const NO_HTTP_LOGS = false; - const NO_STATIC_PATH = null; - // A fake HTTP limiter with no limit at all - const noLimit = { - canAnswerNow: () => true, - processRequest: () => { } - }; - const fakeServer = yield require('../../../app/modules/bma').BmaDependency.duniter.methods.createServersAndListen("Fake Duniter Server", { conf: {} }, [{ - ip: host, - port: port - }], NO_HTTP_LOGS, logger, NO_STATIC_PATH, (app, httpMethods) => { - // Mock BMA method for sync mocking - httpMethods.httpGET('/network/peering', () => __awaiter(this, void 0, void 0, function* () { - return { - endpoints: [['BASIC_MERKLED_API', host, port].join(' ')] - }; - }), dtos.Peer, noLimit); - // Mock BMA method for sync mocking - httpMethods.httpGET('/network/peering/peers', onPeersRequested, dtos.MerkleOfPeers, noLimit); - // Another mock BMA method for sync mocking - httpMethods.httpGET('/blockchain/blocks/:count/:from', (req) => { - // What do we do on /blockchain/blocks request - let count = parseInt(req.params.count); - let from = parseInt(req.params.from); - return readBlocksMethod(count, from); - }, dtos.Blocks, noLimit); - // Another mock BMA method for sync mocking - httpMethods.httpGET('/blockchain/block/:number', (req) => { - // What do we do on /blockchain/blocks request - let number = parseInt(req.params.number); - return readParticularBlockMethod(number); - }, dtos.Block, noLimit); - }); - yield fakeServer.openConnections(); - return { - host: host, - port: port - }; -}); -/** - * Creates a new memory duniter server for Unit Test purposes. - * @param conf - */ -exports.server = (conf) => exports.NewTestingServer(conf); -exports.NewTestingServer = (conf) => { - const port = PORT++; - const commonConf = { - port: port, - ipv4: HOST, - remoteipv4: HOST, - currency: conf.currency || CURRENCY_NAME, - httpLogs: true, - forksize: 3 - }; - if (conf.sigQty === undefined) { - conf.sigQty = 1; - } - const server = new server_1.Server('~/.config/duniter/' + (conf.homename || 'dev_unit_tests'), conf.memory !== undefined ? conf.memory : MEMORY_MODE, _.extend(conf, commonConf)); - return new TestingServer(port, server); -}; -class TestingServer { - constructor(port, server) { - this.port = port; - this.server = server; - server.getMainEndpoint = require('../../../app/modules/bma').BmaDependency.duniter.methods.getMainEndpoint; - } - get BlockchainService() { - return this.server.BlockchainService; - } - get PeeringService() { - return this.server.PeeringService; - } - get conf() { - return this.server.conf; - } - get dal() { - return this.server.dal; - } - get logger() { - return this.server.logger; - } - get home() { - return this.server.home; - } - revert() { - return this.server.revert(); - } - resetHome() { - return this.server.resetHome(); - } - on(event, f) { - return this.server.on(event, f); - } - recomputeSelfPeer() { - return this.server.recomputeSelfPeer(); - } - singleWritePromise(obj) { - return this.server.singleWritePromise(obj); - } - exportAllDataAsZIP() { - return this.server.exportAllDataAsZIP(); - } - unplugFileSystem() { - return this.server.unplugFileSystem(); - } - importAllDataFromZIP(zipFile) { - return this.server.importAllDataFromZIP(zipFile); - } - push(chunk, encoding) { - return this.server.push(chunk, encoding); - } - pipe(writable) { - return this.server.pipe(writable); - } - initDalBmaConnections() { - return __awaiter(this, void 0, void 0, function* () { - yield this.server.initWithDAL(); - const bmapi = yield bma(this.server); - this.bma = bmapi; - const res = yield bmapi.openConnections(); - return res; - }); - } - url(uri) { - return 'http://' + [HOST, this.port].join(':') + uri; - } - get(uri) { - return rp(this.url(uri), { json: true }); - } - post(uri, obj) { - return rp(this.url(uri), { method: 'POST', json: true, body: obj }); - } - expect(uri, expectations) { - return typeof expectations == 'function' ? httpTest.expectAnswer(rp(this.url(uri), { json: true }), expectations) : httpTest.expectJSON(rp(this.url(uri), { json: true }), expectations); - } - expectThat(uri, expectations) { - return httpTest.expectAnswer(rp(this.url(uri), { json: true }), expectations); - } - expectJSON(uri, expectations) { - return httpTest.expectJSON(rp(this.url(uri), { json: true }), expectations); - } - expectError(uri, code, message) { - return httpTest.expectError(code, message, rp(this.url(uri), { json: true })); - } - syncFrom(otherServer, fromIncuded, toIncluded) { - return sync(fromIncuded, toIncluded, otherServer, this.server); - } - until(type, count) { - return until(this.server, type, count); - } - commit(options = null) { - return __awaiter(this, void 0, void 0, function* () { - const raw = yield commit(this.server)(options); - return JSON.parse(raw); - }); - } - commitExpectError(options) { - return __awaiter(this, void 0, void 0, function* () { - try { - const raw = yield commit(this.server)(options); - JSON.parse(raw); - throw { message: 'Commit operation should have thrown an error' }; - } - catch (e) { - if (e.statusCode) { - throw JSON.parse(e.error); - } - } - }); - } - lookup2identity(search) { - return __awaiter(this, void 0, void 0, function* () { - const lookup = yield this.get('/wot/lookup/' + search); - return IdentityDTO_1.IdentityDTO.fromJSONObject({ - issuer: lookup.results[0].pubkey, - currency: this.server.conf.currency, - uid: lookup.results[0].uids[0].uid, - buid: lookup.results[0].uids[0].meta.timestamp, - sig: lookup.results[0].uids[0].self - }); - }); - } - readBlock(number) { - return __awaiter(this, void 0, void 0, function* () { - const block = yield this.get('/blockchain/block/' + number); - return BlockDTO_1.BlockDTO.fromJSONObject(block); - }); - } - makeNext(overrideProps) { - return __awaiter(this, void 0, void 0, function* () { - const block = yield require('../../../app/modules/prover').ProverDependency.duniter.methods.generateAndProveTheNext(this.server, null, null, overrideProps || {}); - return BlockDTO_1.BlockDTO.fromJSONObject(block); - }); - } - sharePeeringWith(otherServer) { - return __awaiter(this, void 0, void 0, function* () { - let p = yield this.get('/network/peering'); - yield otherServer.post('/network/peering/peers', { - peer: PeerDTO_1.PeerDTO.fromJSONObject(p).getRawSigned() - }); - }); - } - postIdentity(idty) { - return this.post('/wot/add', { - identity: idty.getRawSigned() - }); - } - postCert(cert) { - return this.post('/wot/certify', { - cert: cert.getRawSigned() - }); - } - postMembership(ms) { - return this.post('/blockchain/membership', { - membership: ms.getRawSigned() - }); - } - postRevocation(rev) { - return this.post('/wot/revoke', { - revocation: rev.getRaw() - }); - } - postBlock(block) { - return this.post('/blockchain/block', { - block: block.getRawSigned() - }); - } - postRawTX(rawTX) { - return this.post('/tx/process', { - transaction: rawTX - }); - } - postPeer(peer) { - return this.post('/network/peering/peers', { - peer: peer.getRawSigned() - }); - } - prepareForNetwork() { - return __awaiter(this, void 0, void 0, function* () { - yield this.server.initWithDAL(); - const bmaAPI = yield bma(this.server); - yield bmaAPI.openConnections(); - this.bma = bmaAPI; - require('../../../app/modules/router').duniter.methods.routeToNetwork(this.server); - // Extra: for /wot/requirements URL - require('../../../app/modules/prover').ProverDependency.duniter.methods.hookServer(this.server); - }); - } - startBlockComputation() { - if (!this.prover) { - this.prover = require('../../../app/modules/prover').ProverDependency.duniter.methods.prover(this.server); - this.permaProver = this.prover.permaProver; - this.server.pipe(this.prover); - } - this.prover.startService(); - } - // server.startBlockComputation = () => this.prover.startService(); - stopBlockComputation() { - return this.prover.stopService(); - } -} -exports.TestingServer = TestingServer; -//# sourceMappingURL=toolbox.js.map \ No newline at end of file diff --git a/test/integration/tools/toolbox.ts b/test/integration/tools/toolbox.ts index 130be667a02cdb93d5cabe49cccf9ab6888ee6c2..2efb96025d6474104a0653545a1935fee0a94c37 100644 --- a/test/integration/tools/toolbox.ts +++ b/test/integration/tools/toolbox.ts @@ -332,7 +332,9 @@ export class TestingServer { async commit(options:any = null) { + logger.warn('committing...') const raw = await commit(this.server)(options); + logger.warn('raw!', raw) return JSON.parse(raw); } @@ -441,4 +443,12 @@ export class TestingServer { stopBlockComputation() { return this.prover.stopService(); } + + async closeCluster() { + const server:any = this.server + if (server._utProver) { + const farm = await server._utProver.getWorker() + await farm.shutDownEngine() + } + } } \ No newline at end of file diff --git a/test/integration/transactions-chaining.js b/test/integration/transactions-chaining.js index ccd78a7d1849e5be85ea4a8960678148f8e38fb0..bfa886d57201bfc8d3e92910cb439da726fa1e46 100644 --- a/test/integration/transactions-chaining.js +++ b/test/integration/transactions-chaining.js @@ -45,6 +45,12 @@ describe("Transaction chaining", function() { yield s1.commit({ time: now + 7210 }); })); + after(() => { + return Promise.all([ + s1.closeCluster() + ]) + }) + describe("Sources", function(){ it('it should exist block#2 with UD of 1200', () => s1.expect('/blockchain/block/2', (block) => { diff --git a/test/integration/transactions-cltv.js b/test/integration/transactions-cltv.js index 61138251754a46d7357935de8507d61373701696..a65fdf9b3f7ef6e9ce45edc5fe3de755c9ea794d 100644 --- a/test/integration/transactions-cltv.js +++ b/test/integration/transactions-cltv.js @@ -33,6 +33,12 @@ describe("Transactions: CLTV", function() { yield s1.commit({ time: now + 1 }); })); + after(() => { + return Promise.all([ + s1.closeCluster() + ]) + }) + it('it should exist block#1 with UD of 200', () => s1.expect('/blockchain/block/1', (block) => { should.exists(block); assert.equal(block.number, 1); diff --git a/test/integration/transactions-csv.js b/test/integration/transactions-csv.js index fbf95d4518cf963fd90c948ec1276f43f9c3eb53..a0fe299dbe12b633dc8dfe55efcd3bb2cc2b1373 100644 --- a/test/integration/transactions-csv.js +++ b/test/integration/transactions-csv.js @@ -33,6 +33,12 @@ describe("Transactions: CSV", function() { yield s1.commit({ time: now + 1 }); })); + after(() => { + return Promise.all([ + s1.closeCluster() + ]) + }) + it('it should exist block#1 with UD of 200', () => s1.expect('/blockchain/block/1', (block) => { should.exists(block); assert.equal(block.number, 1); diff --git a/test/integration/transactions-pruning.js b/test/integration/transactions-pruning.js index fdb1d534c1605d94444790471c5c179f2015c8ec..8cb396b71b0e17615b91c665206ddb68d11664fd 100644 --- a/test/integration/transactions-pruning.js +++ b/test/integration/transactions-pruning.js @@ -44,6 +44,12 @@ describe("Transactions pruning", function() { yield cat1.send(100, tac1); })); + after(() => { + return Promise.all([ + s1.closeCluster() + ]) + }) + it('double spending transactions should both exist first', () => s1.expect('/tx/history/HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', (res) => { res.history.should.have.property('sending').length(2); })); diff --git a/test/integration/transactions-test.js b/test/integration/transactions-test.js index eb0e7f5a7995c95a8d95d76dba724633616f67f2..6ebaa22ef64c2975b288bfabbaf59af060f31b6a 100644 --- a/test/integration/transactions-test.js +++ b/test/integration/transactions-test.js @@ -63,6 +63,12 @@ describe("Testing transactions", function() { }); })); + after(() => { + return Promise.all([ + s1.closeCluster() + ]) + }) + describe("Sources", function(){ it('it should exist block#2 with UD of 1200', () => s1.expect('/blockchain/block/2', (block) => { diff --git a/test/integration/v0.4-times.js b/test/integration/v0.4-times.js index 419a231dec95ef14d451093ed47c9f9229e28ee4..6e72d66fe7902d69273f4628c5664704596f583e 100644 --- a/test/integration/v0.4-times.js +++ b/test/integration/v0.4-times.js @@ -22,6 +22,12 @@ describe("Protocol 0.4 Times", function() { yield s1.commit({ time: now }); // We must issue a normal root block, because always medianTime(0) == time(0) })); + after(() => { + return Promise.all([ + s1.closeCluster() + ]) + }) + it('a V4 block should not accept a time = medianTime + avgGenTime * 1.189', () => co(function*() { yield s1.commit({ medianTime: now, time: Math.ceil(now + conf.avgGenTime * 1.189) }); yield s1.revert(); diff --git a/test/integration/v0.5-identity-blockstamp.js b/test/integration/v0.5-identity-blockstamp.js index 06dd57f795812e683df2b0605efd627596237f60..a7c3682de991e4404ae2d8e9ec015e5fdacb0970 100644 --- a/test/integration/v0.5-identity-blockstamp.js +++ b/test/integration/v0.5-identity-blockstamp.js @@ -27,6 +27,13 @@ describe("Protocol 0.5 Identity blockstamp", function() { tuc = yield toolbox.createUser('tuc', '3conGDUXdrTGbQPMQQhEC4Ubu1MCAnFrAYvUaewbUhtk', '5ks7qQ8Fpkin7ycXpxQSxxjVhs8VTzpM3vEBMqM7NfC1ZiFJ93uQryDcoM93Mj77T6hDAABdeHZJDFnkDb35bgiU', s1); })); + after(() => { + return Promise.all([ + s1.closeCluster(), + s2.closeCluster() + ]) + }) + it('should be able to create tuc on s1', () => co(function*() { yield s1.commit({ time: now }); yield s1.commit({ time: now }); diff --git a/test/integration/v0.5-transactions.js b/test/integration/v0.5-transactions.js index dc4180c06e13fbecdaf038e6582a656ecf8563d0..70118b3db6936f98d59d425d6c514be4e9eed0a3 100644 --- a/test/integration/v0.5-transactions.js +++ b/test/integration/v0.5-transactions.js @@ -30,6 +30,12 @@ describe("Protocol 0.5 Transaction version", function() { yield cat.sendP(51, tac); })); + after(() => { + return Promise.all([ + s1.closeCluster() + ]) + }) + it('should not have a block with v5 transaction, but v3', () => co(function*() { const block = yield s1.commit({ time: now + 100 }); should.exists(block.transactions[0]); diff --git a/test/integration/v0.6-difficulties.js b/test/integration/v0.6-difficulties.js index f4b7e76b0337ef314b558838883159c653582a22..67912b3954eb7c8db9546cfc5d7b8fc07867f7f7 100644 --- a/test/integration/v0.6-difficulties.js +++ b/test/integration/v0.6-difficulties.js @@ -28,6 +28,13 @@ describe("Protocol 0.6 Difficulties", function() { ]; })); + after(() => { + return Promise.all([ + s1.closeCluster(), + s2.closeCluster() + ]) + }) + it('should be able to emit a block#1 by a different user', () => co(function*() { yield [ s1.commit({ time: now }), // medianOfBlocksInFrame = MEDIAN([1]) = 1 diff --git a/test/integration/v1.0-double-dividend.js b/test/integration/v1.0-double-dividend.js index bc51db461ba5a4951ffc5d8b060c8c5846b97b0b..e467ebe4c37a32929371a434d1ea2379ba25662f 100644 --- a/test/integration/v1.0-double-dividend.js +++ b/test/integration/v1.0-double-dividend.js @@ -50,6 +50,12 @@ describe("Protocol 1.0 Dividend Update", function() { yield s1.commit({ time: now + 16 }); })); + after(() => { + return Promise.all([ + s1.closeCluster() + ]) + }) + it('should have block#2 with no UD', () => s1.expectThat('/blockchain/block/2', (json) => { should.not.exist(json.dividend); })); diff --git a/test/integration/v1.0-g1-dividend-long-run.js b/test/integration/v1.0-g1-dividend-long-run.js index 48b0e70f6f966167d5810883076995c984c816b5..0bdf7797d3ad6cb43e6ae9d4149142c26403ac07 100644 --- a/test/integration/v1.0-g1-dividend-long-run.js +++ b/test/integration/v1.0-g1-dividend-long-run.js @@ -51,6 +51,12 @@ describe("Protocol 1.0 Ğ1 Dividend - long run", function() { } })); + after(() => { + return Promise.all([ + s1.closeCluster() + ]) + }) + it('should have block#0 has no UD', () => s1.expectThat('/blockchain/block/0', (json) => { should.not.exist(json.dividend); json.should.have.property('medianTime').equal(start); // 2016-03-08 16:03:10 UTC+0 diff --git a/test/integration/v1.0-g1-dividend.js b/test/integration/v1.0-g1-dividend.js index d3dd6b946c3eb32ef38f7ed93fed169ae891eda1..89374fce88462bcaa8b24cbe9ff60cdded990c6d 100644 --- a/test/integration/v1.0-g1-dividend.js +++ b/test/integration/v1.0-g1-dividend.js @@ -48,6 +48,12 @@ describe("Protocol 1.0 Ğ1 Dividend", function() { } })); + after(() => { + return Promise.all([ + s1.closeCluster() + ]) + }) + it('should have block#0 has no UD', () => s1.expectThat('/blockchain/block/0', (json) => { should.not.exist(json.dividend); json.should.have.property('medianTime').equal(start); // 2016-03-08 16:03:10 UTC+0 diff --git a/test/integration/v1.1-dividend.js b/test/integration/v1.1-dividend.js index 63efcee345d3ce3bf61864667a3d05941958a596..8da4b2684328b8fd259688cb730b6526c1b150b7 100644 --- a/test/integration/v1.1-dividend.js +++ b/test/integration/v1.1-dividend.js @@ -53,6 +53,12 @@ describe("Protocol 1.1 Dividend", function() { yield s1.commit({ time: now + 10 + 10 * 5 }); })); + after(() => { + return Promise.all([ + s1.closeCluster() + ]) + }) + it('should exit 2 dividends for cat', () => s1.expect('/tx/sources/HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', (res) => { res.should.have.property('pubkey').equal('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd'); res.should.have.property('sources').length(4); diff --git a/test/integration/wotb.js b/test/integration/wotb.js index 168cc575925168c32c67b2793835bdfb68b09ffd..d336cbbd7b6ccf3e83bf3642320f247015efeac4 100644 --- a/test/integration/wotb.js +++ b/test/integration/wotb.js @@ -7,6 +7,7 @@ const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; const user = require('./tools/user'); const commit = require('./tools/commit'); +const shutDownEngine = require('./tools/shutDownEngine'); const MEMORY_MODE = true; const commonConf = { @@ -107,6 +108,12 @@ describe("WOTB module", function() { }); }); + after(() => { + return Promise.all([ + shutDownEngine(s1) + ]) + }) + it('the wotb_id should be affected to new members', function() { return co(function *() { let icat = yield s1.dal.getWrittenIdtyByUID("cat"); @@ -198,6 +205,12 @@ describe("WOTB module", function() { }); }); + after(() => { + return Promise.all([ + shutDownEngine(s2) + ]) + }) + it('a leaver should still have links but be disabled', function() { return co(function *() { wotb.isEnabled(0).should.equal(true); @@ -254,6 +267,12 @@ describe("WOTB module", function() { }); }); + after(() => { + return Promise.all([ + shutDownEngine(s3) + ]) + }) + it('two first commits: the WoT is new and OK', function() { return co(function *() { yield commit(s3)({ time: now });