set color of gas cost

This commit is contained in:
Jonathan Rainville 2018-06-28 16:14:34 -04:00 committed by Iuri Matias
parent 17c5238847
commit d0851d70ba
3 changed files with 20 additions and 5 deletions

View File

@ -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,

View File

@ -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);

View File

@ -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', () => {