use callbacks instead of exiting

This commit is contained in:
Jonathan Rainville 2019-07-12 10:51:26 -04:00
parent 6afa07f111
commit 1491028665
6 changed files with 21 additions and 10 deletions

View File

@ -1,4 +1,4 @@
/*global contract, config, it, assert*/ /*global contract, config, it, assert, web3*/
const SimpleStorage = require('Embark/contracts/SimpleStorage'); const SimpleStorage = require('Embark/contracts/SimpleStorage');
let accounts; let accounts;
@ -17,7 +17,7 @@ config({
} }
} }
}, (_err, web3_accounts) => { }, (_err, web3_accounts) => {
accounts = web3_accounts accounts = web3_accounts;
}); });
contract("SimpleStorage", function () { contract("SimpleStorage", function () {

View File

@ -64,7 +64,11 @@ class BlockchainConnector {
embark.registerActionForEvent("contracts:deploy:afterAll", this.subscribeToContractEvents.bind(this)); embark.registerActionForEvent("contracts:deploy:afterAll", this.subscribeToContractEvents.bind(this));
if (!this.web3) { if (!this.web3) {
this.initWeb3(); this.initWeb3(err => {
if (err) {
this.logger.error(__('Error initiating Web3 provider'), err.message || err);
}
});
} else { } else {
this.isWeb3Ready = true; this.isWeb3Ready = true;
} }
@ -177,7 +181,10 @@ class BlockchainConnector {
if (err) { if (err) {
return self.logger.error(err); return self.logger.error(err);
} }
self.provider.startWeb3Provider(async () => { self.provider.startWeb3Provider(async (err) => {
if (err) {
return cb(err);
}
try { try {
const blockNumber = await self.web3.eth.getBlockNumber(); const blockNumber = await self.web3.eth.getBlockNumber();
await self.web3.eth.getBlock(blockNumber); await self.web3.eth.getBlock(blockNumber);

View File

@ -17,6 +17,7 @@ class Provider {
this.isDev = options.isDev; this.isDev = options.isDev;
this.events = options.events; this.events = options.events;
this.nonceCache = {}; this.nonceCache = {};
this.accounts = [];
this.events.setCommandHandler("blockchain:provider:contract:accounts:get", cb => { this.events.setCommandHandler("blockchain:provider:contract:accounts:get", cb => {
const accounts = this.accounts.map(a => a.address || a); const accounts = this.accounts.map(a => a.address || a);
@ -80,8 +81,8 @@ class Provider {
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) { } catch (e) {
process.exit(1); return callback(e);
} }
if (!self.accounts.length) { if (!self.accounts.length) {

View File

@ -166,7 +166,8 @@ Blockchain.prototype.setupProxy = async function () {
let addresses; let addresses;
try { try {
addresses = AccountParser.parseAccountsConfig(this.userConfig.accounts, false, dappPath(), this.logger); addresses = AccountParser.parseAccountsConfig(this.userConfig.accounts, false, dappPath(), this.logger);
} catch (_e) { } catch (e) {
this.logger.error(e.message);
process.exit(1); process.exit(1);
} }

View File

@ -45,7 +45,8 @@ export class Simulator {
let parsedAccounts; let parsedAccounts;
try { try {
parsedAccounts = AccountParser.parseAccountsConfig(simulatorAccounts, web3, dappPath(), this.logger); parsedAccounts = AccountParser.parseAccountsConfig(simulatorAccounts, web3, dappPath(), this.logger);
} catch (_e) { } catch (e) {
this.logger.error(e.message);
process.exit(1); process.exit(1);
} }
parsedAccounts.forEach((account) => { parsedAccounts.forEach((account) => {

View File

@ -159,8 +159,8 @@ class Test {
if (accounts) { if (accounts) {
try { try {
self.simOptions.accounts = AccountParser.parseAccountsConfig(accounts, web3, this.dappPath); self.simOptions.accounts = AccountParser.parseAccountsConfig(accounts, web3, this.dappPath);
} catch (_e) { } catch (e) {
process.exit(1); return callback(e);
} }
} else { } else {
self.simOptions.accounts = null; self.simOptions.accounts = null;
@ -255,6 +255,7 @@ class Test {
} }
], (err, accounts) => { ], (err, accounts) => {
if (err) { if (err) {
self.logger.error(err.message || err);
// TODO Do not exit in case of not a normal run (eg after a change) // TODO Do not exit in case of not a normal run (eg after a change)
if (!self.options.inProcess) process.exit(1); if (!self.options.inProcess) process.exit(1);
} }