From 25fef4f8d756f5bbf5a2a05e38233248a8eb43ac Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Wed, 2 Aug 2023 19:07:50 -0400 Subject: [PATCH] Fixed receipt wait not throwing on reverted transactions. --- src.ts/providers/provider.ts | 24 ++++++++++++++++++++---- src.ts/utils/errors.ts | 12 ++++++++++-- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src.ts/providers/provider.ts b/src.ts/providers/provider.ts index 6a9ec29fdf..bcab2b0c6d 100644 --- a/src.ts/providers/provider.ts +++ b/src.ts/providers/provider.ts @@ -1460,12 +1460,27 @@ export class TransactionResponse implements TransactionLike, Transaction return; }; + const checkReceipt = (receipt: null | TransactionReceipt) => { + if (receipt == null || receipt.status !== 0) { return receipt; } + assert(false, "transaction execution reverted", "CALL_EXCEPTION", { + action: "sendTransaction", + data: null, reason: null, invocation: null, revert: null, + transaction: { + to: receipt.to, + from: receipt.from, + data: "" // @TODO: in v7, split out sendTransaction properties + }, receipt + }); + }; + const receipt = await this.provider.getTransactionReceipt(this.hash); - if (confirms === 0) { return receipt; } + if (confirms === 0) { return checkReceipt(receipt); } if (receipt) { - if ((await receipt.confirmations()) >= confirms) { return receipt; } + if ((await receipt.confirmations()) >= confirms) { + return checkReceipt(receipt); + } } else { // Check for a replacement; throws if a replacement was found @@ -1496,9 +1511,10 @@ export class TransactionResponse implements TransactionLike, Transaction // Done; return it! if ((await receipt.confirmations()) >= confirms) { cancel(); - resolve(receipt); + try { + resolve(checkReceipt(receipt)); + } catch (error) { reject(error); } } - }; cancellers.push(() => { this.provider.off(this.hash, txListener); }); this.provider.on(this.hash, txListener); diff --git a/src.ts/utils/errors.ts b/src.ts/utils/errors.ts index 4056b18031..ac56ad2a85 100644 --- a/src.ts/utils/errors.ts +++ b/src.ts/utils/errors.ts @@ -385,9 +385,9 @@ export interface UnexpectedArgumentError extends EthersError<"UNEXPECTED_ARGUMEN // Blockchain Errors /** - * The action that resulted in the error. + * The action that resulted in the call exception. */ -export type CallExceptionAction = "call" | "estimateGas" | "getTransactionResult" | "unknown"; +export type CallExceptionAction = "call" | "estimateGas" | "getTransactionResult" | "sendTransaction" | "unknown"; /** * The related transaction that caused the error. @@ -402,6 +402,7 @@ export type CallExceptionTransaction = { * This **Error** indicates a transaction reverted. */ export interface CallExceptionError extends EthersError<"CALL_EXCEPTION"> { + /** * The action being performed when the revert was encountered. */ @@ -439,8 +440,15 @@ export interface CallExceptionError extends EthersError<"CALL_EXCEPTION"> { name: string; args: Array; } + + /** + * If the error occurred in a transaction that was mined + * (with a status of ``0``), this is the receipt. + */ + receipt?: TransactionReceipt; // @TODO: in v7, make this `null | TransactionReceipt` } + /** * The sending account has insufficient funds to cover the * entire transaction cost.