From 555e1f3c9e0c6ccff4216b0a195a4375efa36aab Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 28 Jun 2018 16:14:34 -0400 Subject: [PATCH] set color of gas cost --- lib/tests/reporter.js | 15 +++++++++++++-- lib/tests/run_tests.js | 6 +++++- lib/tests/test.js | 4 ++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/tests/reporter.js b/lib/tests/reporter.js index cbd7a8cc4..d67959f7e 100644 --- a/lib/tests/reporter.js +++ b/lib/tests/reporter.js @@ -8,6 +8,7 @@ class EmbarkSpec extends Base { const self = this; self.embarkEvents = options.reporterOptions.events; self.gasDetails = options.reporterOptions.gasDetails; + self.gasLimit = options.reporterOptions.gasLimit; let indents = 0; let n = 0; self.stats.gasCost = 0; @@ -18,7 +19,7 @@ class EmbarkSpec extends Base { const fmt = color('bright pass', ' ') + color('green', ' %s') + ' deployed for ' + - color('green', '%s') + + color(self.getGasColor(receipt.gasUsed), '%s') + color('light', ' gas'); console.log(fmt, receipt.className, receipt.gasUsed); @@ -84,6 +85,16 @@ class EmbarkSpec extends Base { }); } + getGasColor(gasCost) { + if (gasCost <= this.gasLimit/10) { + return 'fast'; + } + if (gasCost <= 3 * (this.gasLimit/4)) { + return 'medium'; + } + return 'slow'; + } + epilogue() { const stats = this.stats; let fmt; @@ -93,7 +104,7 @@ class EmbarkSpec extends Base { // passes fmt = color('bright pass', ' ') + color('green', ' %d passing') + - color('light', ' (%s gas)'); + color(this.getGasColor(stats.gasCost), ' (%s gas)'); console.log(fmt, stats.passes || 0, diff --git a/lib/tests/run_tests.js b/lib/tests/run_tests.js index ceaab2fae..d544e6ef0 100644 --- a/lib/tests/run_tests.js +++ b/lib/tests/run_tests.js @@ -101,7 +101,11 @@ module.exports = { function executeForAllFiles(files, next) { async.eachLimit(files, 1, (file, eachCb) => { const mocha = new Mocha(); - mocha.reporter(EmbarkSpec, {events: global.embark.engine.events, gasDetails: options.gasDetails}); + mocha.reporter(EmbarkSpec, { + events: global.embark.engine.events, + gasDetails: options.gasDetails, + gasLimit: global.embark.engine.deployManager.gasLimit + }); mocha.addFile(file); mocha.suite.timeout(0); diff --git a/lib/tests/test.js b/lib/tests/test.js index af7f81699..7c6c23588 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -98,6 +98,8 @@ class Test { trackContracts: false //ipcRole: 'client' // disabled for now due to issues with ipc file }); + this.engine.deployManager.gasLimit = 6000000; + this.engine.contractsManager.gasLimit = 6000000; } init(callback) { @@ -282,8 +284,6 @@ class Test { }); }, function deploy(accounts, next) { - self.engine.deployManager.gasLimit = 6000000; - self.engine.contractsManager.gasLimit = 6000000; self.engine.deployManager.fatalErrors = true; self.engine.deployManager.deployOnlyOnConfig = true; self.engine.events.request('deploy:contracts', () => {