From 21f60721863c974e0565009100891db53b7fb42c Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Wed, 26 Sep 2018 15:41:49 +1000 Subject: Handle revert with reason when decoding call result We use in-process ganache which throws on an RPC error. This means all of our tests get a nice revert error thrown when testing against ganache. This is not possible with RPC providers and a revert with reason result is returned. Our callAsync doesn't handle this and attempts to decode the revert with reason error log as a successful log, which results in an error while decoding. This only works with our fork of ethers https://github.com/ethers-io/ethers.js/pull/188 and will need to be re-worked when updating to Ethers.js 4 --- packages/dev-utils/src/web3_factory.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'packages/dev-utils') diff --git a/packages/dev-utils/src/web3_factory.ts b/packages/dev-utils/src/web3_factory.ts index 8e713fa68..7c86d3df4 100644 --- a/packages/dev-utils/src/web3_factory.ts +++ b/packages/dev-utils/src/web3_factory.ts @@ -14,6 +14,7 @@ import { env, EnvVars } from './env'; export interface Web3Config { hasAddresses?: boolean; // default: true shouldUseInProcessGanache?: boolean; // default: false + shouldThrowErrorsOnGanacheRPCResponse?: boolean; // default: true rpcUrl?: string; // default: localhost:8545 shouldUseFakeGasEstimate?: boolean; // default: true } @@ -41,15 +42,19 @@ export const web3Factory = { if (!_.isUndefined(config.rpcUrl)) { throw new Error('Cannot use both GanacheSubrovider and RPCSubprovider'); } + const shouldThrowErrorsOnGanacheRPCResponse = + _.isUndefined(config.shouldThrowErrorsOnGanacheRPCResponse) || + config.shouldThrowErrorsOnGanacheRPCResponse; provider.addProvider( new GanacheSubprovider({ + vmErrorsOnRPCResponse: shouldThrowErrorsOnGanacheRPCResponse, gasLimit: constants.GAS_LIMIT, logger, verbose: env.parseBoolean(EnvVars.VerboseGanache), port: 8545, network_id: 50, mnemonic: 'concert load couple harbor equip island argue ramp clarify fence smart topic', - }), + } as any), // TODO remove any once types are merged in DefinitelyTyped ); } else { provider.addProvider(new RPCSubprovider(config.rpcUrl || constants.RPC_URL)); -- cgit v1.2.3