@ -57,7 +57,7 @@ export function callFunction (from, to, data, value, gasLimit, funAbi, txRunner,
* @param { Object } execResult - execution result given by the VM
* @return { Object } - { error : true / false , message : DOMNode }
* /
export function checkVMError ( execResult , abi , contract ) {
export function checkVMError ( execResult , compiledContracts ) {
const errorCode = {
OUT_OF_GAS : 'out of gas' ,
STACK_UNDERFLOW : 'stack underflow' ,
@ -91,9 +91,12 @@ export function checkVMError (execResult, abi, contract) {
const returnData = execResult . returnValue
const returnDataHex = returnData . slice ( 0 , 4 ) . toString ( 'hex' )
let customError
if ( abi ) {
if ( compiledContracts ) {
let decodedCustomErrorInputsClean
for ( const item of abi ) {
for ( const file of Object . keys ( compiledContracts ) ) {
for ( const contractName of Object . keys ( compiledContracts [ file ] ) ) {
const contract = compiledContracts [ file ] [ contractName ]
for ( const item of contract . abi ) {
if ( item . type === 'error' ) {
// ethers doesn't crash anymore if "error" type is specified, but it doesn't extract the errors. see:
// https://github.com/ethers-io/ethers.js/commit/bd05aed070ac9e1421a3e2bff2ceea150bedf9b7
@ -114,13 +117,13 @@ export function checkVMError (execResult, abi, contract) {
const functionSignature = Object . keys ( fn . functions ) [ 0 ]
// we check in the 'devdoc' if there's a developer documentation for this error
try {
devdoc = ( contract . object . devdoc . errors && contract . obje ct . devdoc . errors [ functionSignature ] [ 0 ] ) || { }
devdoc = ( contract . devdoc . errors && contract . devdoc . errors [ functionSignature ] [ 0 ] ) || { }
} catch ( e ) {
console . error ( e . message )
}
// we check in the 'userdoc' if there's an user documentation for this error
try {
const userdoc = ( contract . object . userdoc . errors && contract . obje ct . userdoc . errors [ functionSignature ] [ 0 ] ) || { }
const userdoc = ( contract . userdoc . errors && contract . userdoc . errors [ functionSignature ] [ 0 ] ) || { }
if ( userdoc && ( userdoc as any ) . notice ) customError += ' : ' + ( userdoc as any ) . notice // we append the user doc if any
} catch ( e ) {
console . error ( e . message )
@ -143,6 +146,8 @@ export function checkVMError (execResult, abi, contract) {
}
}
}
}
}
if ( decodedCustomErrorInputsClean ) {
msg = '\tThe transaction has been reverted to the initial state.\nError provided by the contract:'
msg += ` \ n ${ customError } `