set color of gas cost

This commit is contained in:
Jonathan Rainville 2018-06-28 16:14:34 -04:00
parent 2648d0536e
commit 555e1f3c9e
3 changed files with 20 additions and 5 deletions

View File

@ -8,6 +8,7 @@ class EmbarkSpec extends Base {
const self = this; const self = this;
self.embarkEvents = options.reporterOptions.events; self.embarkEvents = options.reporterOptions.events;
self.gasDetails = options.reporterOptions.gasDetails; self.gasDetails = options.reporterOptions.gasDetails;
self.gasLimit = options.reporterOptions.gasLimit;
let indents = 0; let indents = 0;
let n = 0; let n = 0;
self.stats.gasCost = 0; self.stats.gasCost = 0;
@ -18,7 +19,7 @@ class EmbarkSpec extends Base {
const fmt = color('bright pass', ' ') + const fmt = color('bright pass', ' ') +
color('green', ' %s') + color('green', ' %s') +
' deployed for ' + ' deployed for ' +
color('green', '%s') + color(self.getGasColor(receipt.gasUsed), '%s') +
color('light', ' gas'); color('light', ' gas');
console.log(fmt, receipt.className, receipt.gasUsed); 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() { epilogue() {
const stats = this.stats; const stats = this.stats;
let fmt; let fmt;
@ -93,7 +104,7 @@ class EmbarkSpec extends Base {
// passes // passes
fmt = color('bright pass', ' ') + fmt = color('bright pass', ' ') +
color('green', ' %d passing') + color('green', ' %d passing') +
color('light', ' (%s gas)'); color(this.getGasColor(stats.gasCost), ' (%s gas)');
console.log(fmt, console.log(fmt,
stats.passes || 0, stats.passes || 0,

View File

@ -101,7 +101,11 @@ module.exports = {
function executeForAllFiles(files, next) { function executeForAllFiles(files, next) {
async.eachLimit(files, 1, (file, eachCb) => { async.eachLimit(files, 1, (file, eachCb) => {
const mocha = new Mocha(); 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.addFile(file);
mocha.suite.timeout(0); mocha.suite.timeout(0);

View File

@ -98,6 +98,8 @@ class Test {
trackContracts: false trackContracts: false
//ipcRole: 'client' // disabled for now due to issues with ipc file //ipcRole: 'client' // disabled for now due to issues with ipc file
}); });
this.engine.deployManager.gasLimit = 6000000;
this.engine.contractsManager.gasLimit = 6000000;
} }
init(callback) { init(callback) {
@ -282,8 +284,6 @@ class Test {
}); });
}, },
function deploy(accounts, next) { function deploy(accounts, next) {
self.engine.deployManager.gasLimit = 6000000;
self.engine.contractsManager.gasLimit = 6000000;
self.engine.deployManager.fatalErrors = true; self.engine.deployManager.fatalErrors = true;
self.engine.deployManager.deployOnlyOnConfig = true; self.engine.deployManager.deployOnlyOnConfig = true;
self.engine.events.request('deploy:contracts', () => { self.engine.events.request('deploy:contracts', () => {