diff --git a/ethers/signer.nim b/ethers/signer.nim index 5f5d226..b414f02 100644 --- a/ethers/signer.nim +++ b/ethers/signer.nim @@ -14,8 +14,8 @@ type type SignerError* = object of EthersError -template raiseSignerError(message: string) = - raise newException(SignerError, message) +template raiseSignerError(message: string, parent: ref ProviderError = nil) = + raise newException(SignerError, message, parent) method provider*(signer: Signer): Provider {.base, gcsafe.} = doAssert false, "not implemented" @@ -123,8 +123,8 @@ method populateTransaction*(signer: Signer, except ProviderError as e: # send a 0-valued transaction with the errored nonce to prevent stuck txs discard await signer.cancelTransaction(populated) - raiseSignerError "estimateGas failed. *A cancellation transaction " & - "(0-valued tx to ourselves with the estimateGas nonce) has been sent " & - "to prevent stuck transactions.* Error: " & e.msg + raiseSignerError "Estimate gas failed -- A cancellation transaction " & + "has been sent to prevent stuck transactions. See parent exception " & + "for revert reason.", e return populated diff --git a/ethers/testing.nim b/ethers/testing.nim index 5d38c1f..dcf48de 100644 --- a/ethers/testing.nim +++ b/ethers/testing.nim @@ -1,7 +1,8 @@ import std/strutils import ./provider +import ./signer -proc revertReason*(e: ref ProviderError): string = +proc revertReason*(e: ref EthersError): string = var msg = e.msg const revertPrefixes = @[ # hardhat @@ -22,7 +23,7 @@ proc reverts*[T](call: Future[T]): Future[bool] {.async.} = else: discard await call return false - except ProviderError: + except ProviderError, SignerError: return true proc reverts*[T](call: Future[T], reason: string): Future[bool] {.async.} = @@ -32,5 +33,11 @@ proc reverts*[T](call: Future[T], reason: string): Future[bool] {.async.} = else: discard await call return false - except ProviderError as error: - return reason == error.revertReason + except EthersError as error: + var passed = reason == error.revertReason + if not passed and + not error.parent.isNil and + error.parent of (ref EthersError): + let revertReason = (ref EthersError)(error.parent).revertReason + passed = reason == revertReason + return passed