From a81ed322d1ce919249bb9453532f3fdee26ac2ab Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Fri, 6 Jul 2018 15:16:04 -0400 Subject: [PATCH] fix conflict in test and provider --- lib/cmd.js | 2 +- lib/tests/reporter.js | 24 ++++++++++++------------ lib/tests/test.js | 10 ++++++++-- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/lib/cmd.js b/lib/cmd.js index e0798b48..51ab0988 100644 --- a/lib/cmd.js +++ b/lib/cmd.js @@ -189,7 +189,7 @@ class Cmd { test() { program .command('test [file]') - .option('-d , --gasDetails', __('When set, will print the gas cost for each contract')) + .option('-d , --gasDetails', __('When set, will print the gas cost for each contract deploy')) .option('--locale [locale]', __('language to use (default: en)')) .option('--loglevel [loglevel]', __('level of logging to display') + ' ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'warn') .description(__('run tests')) diff --git a/lib/tests/reporter.js b/lib/tests/reporter.js index b1927b4d..75d8ff01 100644 --- a/lib/tests/reporter.js +++ b/lib/tests/reporter.js @@ -17,23 +17,23 @@ class EmbarkSpec extends Base { self.stats.test.gasUsed = 0; function onContractReceipt(receipt) { - self.stats.totalGasCost += receipt.gasUsed; - if (self.gasDetails) { - const fmt = color('bright pass', ' ') + - color('green', ' %s') + - ' deployed for ' + - color(self.getGasColor(receipt.gasUsed), '%s') + - color('light', ' gas'); + const fmt = color('bright pass', ' ') + + color('suite', ' %s') + + color('light', ' deployed for ') + + color(self.getGasColor(receipt.gasUsed), '%s') + + color('light', ' gas'); - console.log(fmt, receipt.className, receipt.gasUsed); - } + console.log(fmt, receipt.className, receipt.gasUsed); } + function onBlockHeader(blockHeader) { self.stats.totalGasCost += blockHeader.gasUsed; self.stats.test.gasUsed += blockHeader.gasUsed; } - self.embarkEvents.on("deploy:contract:receipt", onContractReceipt); + if (self.gasDetails) { + self.embarkEvents.on("deploy:contract:receipt", onContractReceipt); + } self.embarkEvents.on("block:header", onBlockHeader); function indent() { @@ -94,10 +94,10 @@ class EmbarkSpec extends Base { } getGasColor(gasCost) { - if (gasCost <= this.gasLimit/10) { + if (gasCost <= this.gasLimit / 10) { return 'fast'; } - if (gasCost <= 3 * (this.gasLimit/4)) { + if (gasCost <= 3 * (this.gasLimit / 4)) { return 'medium'; } return 'slow'; diff --git a/lib/tests/test.js b/lib/tests/test.js index 1c684213..5de48aaa 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -45,6 +45,7 @@ class Test { } initWeb3Provider(callback) { + const self = this; if (this.provider) { this.provider.stop(); } @@ -71,8 +72,13 @@ class Test { return callback(err); } - this.provider = new Provider(providerOptions); - this.provider.startWeb3Provider(callback); + return self.provider.startWeb3Provider((err) => { + if (err) { + return callback(err); + } + self.subscribeToPendingTransactions(); + callback(); + }); }); }