From 6afa07f1118dd9ace27c7a2861f6cc3c5ca469a8 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 11 Jul 2019 12:32:38 -0400 Subject: [PATCH] code review --- packages/embark-blockchain-connector/src/provider.js | 10 +++++++--- packages/embark-blockchain-process/src/blockchain.js | 7 ++++++- packages/embark-blockchain-process/src/simulator.js | 9 +++++++-- packages/embark-test-runner/src/test.js | 6 +++++- packages/embark-utils/src/accountParser.js | 2 +- packages/embark/src/test/accountParser.js | 5 ++--- 6 files changed, 28 insertions(+), 11 deletions(-) diff --git a/packages/embark-blockchain-connector/src/provider.js b/packages/embark-blockchain-connector/src/provider.js index 5d486c04e..90e0951a5 100644 --- a/packages/embark-blockchain-connector/src/provider.js +++ b/packages/embark-blockchain-connector/src/provider.js @@ -74,11 +74,15 @@ class Provider { self.logger.warn('Error while getting the node\'s accounts.', err.message || err); } - self.blockchainAccounts = AccountParser.parseAccountsConfig(self.blockchainConfig.accounts, self.web3, dappPath(), self.logger, accounts); + try { + self.blockchainAccounts = AccountParser.parseAccountsConfig(self.blockchainConfig.accounts, self.web3, dappPath(), self.logger, accounts); - accounts = accounts.concat(self.blockchainAccounts); + accounts = accounts.concat(self.blockchainAccounts); - self.accounts = AccountParser.parseAccountsConfig(self.accountsConfig, self.web3, dappPath(), self.logger, accounts); + self.accounts = AccountParser.parseAccountsConfig(self.accountsConfig, self.web3, dappPath(), self.logger, accounts); + } catch (_e) { + process.exit(1); + } if (!self.accounts.length) { self.accounts = accounts; diff --git a/packages/embark-blockchain-process/src/blockchain.js b/packages/embark-blockchain-process/src/blockchain.js index 69fab8665..7dc9a3fa7 100644 --- a/packages/embark-blockchain-process/src/blockchain.js +++ b/packages/embark-blockchain-process/src/blockchain.js @@ -163,7 +163,12 @@ Blockchain.prototype.initProxy = function () { Blockchain.prototype.setupProxy = async function () { if (!this.proxyIpc) this.proxyIpc = new IPC({ipcRole: 'client'}); - const addresses = AccountParser.parseAccountsConfig(this.userConfig.accounts, false, dappPath(), this.logger); + let addresses; + try { + addresses = AccountParser.parseAccountsConfig(this.userConfig.accounts, false, dappPath(), this.logger); + } catch (_e) { + process.exit(1); + } let wsProxy; if (this.config.wsRPC) { diff --git a/packages/embark-blockchain-process/src/simulator.js b/packages/embark-blockchain-process/src/simulator.js index 8c58ea386..60fc80e4b 100644 --- a/packages/embark-blockchain-process/src/simulator.js +++ b/packages/embark-blockchain-process/src/simulator.js @@ -13,7 +13,7 @@ export class Simulator { this.logger = options.logger; } - /*eslint complexity: ["error", 25]*/ + /*eslint complexity: ["error", 26]*/ run(options) { let cmds = []; @@ -42,7 +42,12 @@ export class Simulator { let simulatorAccounts = this.blockchainConfig.simulatorAccounts || options.simulatorAccounts; if (simulatorAccounts && simulatorAccounts.length > 0) { let web3 = new (require('web3'))(); - let parsedAccounts = AccountParser.parseAccountsConfig(simulatorAccounts, web3, dappPath(), this.logger); + let parsedAccounts; + try { + parsedAccounts = AccountParser.parseAccountsConfig(simulatorAccounts, web3, dappPath(), this.logger); + } catch (_e) { + process.exit(1); + } parsedAccounts.forEach((account) => { let cmd = '--account="' + account.privateKey + ','+account.hexBalance + '"'; cmds.push(cmd); diff --git a/packages/embark-test-runner/src/test.js b/packages/embark-test-runner/src/test.js index 3ac2428d4..5f55a333d 100644 --- a/packages/embark-test-runner/src/test.js +++ b/packages/embark-test-runner/src/test.js @@ -157,7 +157,11 @@ class Test { this.events.request("blockchain:get", (web3) => { if (accounts) { - self.simOptions.accounts = AccountParser.parseAccountsConfig(accounts, web3, this.dappPath); + try { + self.simOptions.accounts = AccountParser.parseAccountsConfig(accounts, web3, this.dappPath); + } catch (_e) { + process.exit(1); + } } else { self.simOptions.accounts = null; } diff --git a/packages/embark-utils/src/accountParser.js b/packages/embark-utils/src/accountParser.js index f86a25482..b87b33c1c 100644 --- a/packages/embark-utils/src/accountParser.js +++ b/packages/embark-utils/src/accountParser.js @@ -16,7 +16,7 @@ class AccountParser { accountsConfig.forEach(accountConfig => { let account = AccountParser.getAccount(accountConfig, web3, dappPath, logger, nodeAccounts); if (account === ERROR_ACCOUNT) { - process.exit(1); + throw new Error('Error getting the account'); } if (!account) { return; diff --git a/packages/embark/src/test/accountParser.js b/packages/embark/src/test/accountParser.js index 3471415c4..9cb02e6f8 100644 --- a/packages/embark/src/test/accountParser.js +++ b/packages/embark/src/test/accountParser.js @@ -4,7 +4,6 @@ const assert = require('assert'); const sinon = require('sinon'); let TestLogger = require('../lib/utils/test_logger'); const Web3 = require('web3'); -const fs = require('../lib/core/fs'); import { dappPath, getWeiBalanceFromString, getHexBalanceFromString, AccountParser } from 'embark-utils'; i18n.setOrDetectLocale('en'); @@ -75,12 +74,12 @@ describe('embark.AccountParser', function () { ]); }); - it('should return nothing with bad config', function () { + it('should return an error with bad config', function () { const account = AccountParser.getAccount({ badConfig: 'not working' }, web3, dappPath(), testLogger); - assert.strictEqual(account, null); + assert.strictEqual(account, 'ERROR_ACCOUNT'); }); it('should just return the addresses when no web3', function () {