Skip to content

Commit f06bb8a

Browse files
committed
ethereum: Add eth_call revert cases
1 parent a48125a commit f06bb8a

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

chain/ethereum/src/ethereum_adapter.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ const ETH_CALL_GAS: u32 = 50_000_000;
121121
// subgraphs come across other errors. See
122122
// https://github.com/ethereum/go-ethereum/blob/dfeb2f7e8001aef1005a8d5e1605bae1de0b4f12/core/vm/errors.go#L25-L38
123123
const GETH_ETH_CALL_ERRORS: &[&str] = &[
124+
// Hardhat format.
125+
"error: transaction reverted",
126+
// Ganache and Moonbeam format.
127+
"vm exception while processing transaction: revert",
128+
// Geth errors
124129
"execution reverted",
125130
"invalid jump destination",
126131
"invalid opcode",
@@ -477,7 +482,7 @@ impl EthereumAdapter {
477482
let web3 = self.web3.clone();
478483

479484
// Ganache does not support calls by block hash.
480-
// See https://github.com/trufflesuite/ganache-cli/issues/745
485+
// See https://github.com/trufflesuite/ganache-cli/issues/973
481486
let block_id = if !self.supports_eip_1898 {
482487
BlockId::Number(block_ptr.number.into())
483488
} else {
@@ -504,8 +509,7 @@ impl EthereumAdapter {
504509
.call(req, Some(block_id))
505510
.then(|result| {
506511
// Try to check if the call was reverted. The JSON-RPC response for reverts is
507-
// not standardized, so we have ad-hoc checks for each of Geth, Parity and
508-
// Ganache.
512+
// not standardized, so we have ad-hoc checks for each Ethereum client.
509513

510514
// 0xfe is the "designated bad instruction" of the EVM, and Solidity uses it for
511515
// asserts.
@@ -521,9 +525,6 @@ impl EthereumAdapter {
521525
// See f0af4ab0-6b7c-4b68-9141-5b79346a5f61.
522526
const PARITY_OUT_OF_GAS: &str = "Out of gas";
523527

524-
const GANACHE_VM_EXECUTION_ERROR: i64 = -32000;
525-
const GANACHE_REVERT_MESSAGE: &str =
526-
"VM Exception while processing transaction: revert";
527528
const PARITY_VM_EXECUTION_ERROR: i64 = -32015;
528529
const PARITY_REVERT_PREFIX: &str = "Reverted 0x";
529530

@@ -594,14 +595,6 @@ impl EthereumAdapter {
594595
}
595596
}
596597

597-
// Check for Ganache revert.
598-
Err(web3::Error::Rpc(ref rpc_error))
599-
if rpc_error.code.code() == GANACHE_VM_EXECUTION_ERROR
600-
&& rpc_error.message.starts_with(GANACHE_REVERT_MESSAGE) =>
601-
{
602-
Err(EthereumContractCallError::Revert(rpc_error.message.clone()))
603-
}
604-
605598
// The error was not identified as a revert.
606599
Err(err) => Err(EthereumContractCallError::Web3Error(err)),
607600
}

0 commit comments

Comments
 (0)