From 5891fe574d5d714ebc3aabacb34d81fa16cdd8c7 Mon Sep 17 00:00:00 2001 From: John Kane Date: Tue, 12 Sep 2023 22:37:55 +0100 Subject: [PATCH] feat: map held as its own result type Instead of treating held as an error result, treat it as its own third thing between success and failure. --- .../journal/utils/emitExecutionEvent.ts | 10 +- packages/core/src/types/execution-events.ts | 17 ++- .../hardhat-plugin/src/ui/UiEventHandler.tsx | 10 +- .../src/ui/VerboseEventHandler.ts | 108 ++++++++++++------ .../components/execution/BatchExecution.tsx | 9 ++ packages/hardhat-plugin/src/ui/types.ts | 10 +- 6 files changed, 119 insertions(+), 45 deletions(-) diff --git a/packages/core/src/internal/journal/utils/emitExecutionEvent.ts b/packages/core/src/internal/journal/utils/emitExecutionEvent.ts index 8b2e09b8d..db7c4b12a 100644 --- a/packages/core/src/internal/journal/utils/emitExecutionEvent.ts +++ b/packages/core/src/internal/journal/utils/emitExecutionEvent.ts @@ -219,8 +219,9 @@ function convertExecutionResultToEventResult( } case ExecutionResultType.STRATEGY_HELD: { return { - type: ExecutionEventResultType.ERROR, - error: result.reason, + type: ExecutionEventResultType.HELD, + heldId: result.heldId, + reason: result.reason, }; } } @@ -249,8 +250,9 @@ function convertStaticCallResultToExecutionEventResult( } case ExecutionResultType.STRATEGY_HELD: { return { - type: ExecutionEventResultType.ERROR, - error: result.reason, + type: ExecutionEventResultType.HELD, + heldId: result.heldId, + reason: result.reason, }; } } diff --git a/packages/core/src/types/execution-events.ts b/packages/core/src/types/execution-events.ts index b870fd99e..a29d6f2c9 100644 --- a/packages/core/src/types/execution-events.ts +++ b/packages/core/src/types/execution-events.ts @@ -360,6 +360,7 @@ export enum ExecutionEventNetworkInteractionType { export enum ExecutionEventResultType { SUCCESS = "SUCCESS", ERROR = "ERROR", + HELD = "HELD", } /** @@ -367,7 +368,10 @@ export enum ExecutionEventResultType { * * @beta */ -export type ExecutionEventResult = ExecutionEventSuccess | ExecutionEventError; +export type ExecutionEventResult = + | ExecutionEventSuccess + | ExecutionEventError + | ExecutionEventHeld; /** * A successful result of a future's execution. @@ -389,6 +393,17 @@ export interface ExecutionEventError { error: string; } +/** + * A hold result of a future's execution. + * + * @beta + */ +export interface ExecutionEventHeld { + type: ExecutionEventResultType.HELD; + heldId: number; + reason: string; +} + /** * A mapping of execution event types to their corresponding event. * diff --git a/packages/hardhat-plugin/src/ui/UiEventHandler.tsx b/packages/hardhat-plugin/src/ui/UiEventHandler.tsx index 8e85f0adb..da998878f 100644 --- a/packages/hardhat-plugin/src/ui/UiEventHandler.tsx +++ b/packages/hardhat-plugin/src/ui/UiEventHandler.tsx @@ -40,6 +40,7 @@ import { UiBatches, UiFuture, UiFutureErrored, + UiFutureHeld, UiFutureStatusType, UiFutureSuccess, UiState, @@ -396,7 +397,7 @@ export class UiEventHandler implements ExecutionEventListener { private _getFutureStatusFromEventResult( result: ExecutionEventResult - ): UiFutureSuccess | UiFutureErrored { + ): UiFutureSuccess | UiFutureErrored | UiFutureHeld { switch (result.type) { case ExecutionEventResultType.SUCCESS: { return { @@ -410,6 +411,13 @@ export class UiEventHandler implements ExecutionEventListener { message: result.error, }; } + case ExecutionEventResultType.HELD: { + return { + type: UiFutureStatusType.HELD, + heldId: result.heldId, + reason: result.reason, + }; + } } } diff --git a/packages/hardhat-plugin/src/ui/VerboseEventHandler.ts b/packages/hardhat-plugin/src/ui/VerboseEventHandler.ts index 260eb022c..b8ad6e9cf 100644 --- a/packages/hardhat-plugin/src/ui/VerboseEventHandler.ts +++ b/packages/hardhat-plugin/src/ui/VerboseEventHandler.ts @@ -47,16 +47,24 @@ export class VerboseEventHandler implements ExecutionEventListener { public deploymentExecutionStateComplete( event: DeploymentExecutionStateCompleteEvent ): void { - if (event.result.type === ExecutionEventResultType.SUCCESS) { - console.log( - `Successfully completed the execution of deployment future ${ - event.futureId - } with address ${event.result.result ?? "undefined"}` - ); - } else { - console.log( - `Execution of future ${event.futureId} failed with reason: ${event.result.error}` - ); + switch (event.result.type) { + case ExecutionEventResultType.SUCCESS: { + return console.log( + `Successfully completed the execution of deployment future ${ + event.futureId + } with address ${event.result.result ?? "undefined"}` + ); + } + case ExecutionEventResultType.ERROR: { + return console.log( + `Execution of future ${event.futureId} failed with reason: ${event.result.error}` + ); + } + case ExecutionEventResultType.HELD: { + return console.log( + `Execution of future ${event.futureId}/${event.result.heldId} held with reason: ${event.result.reason}` + ); + } } } @@ -69,14 +77,22 @@ export class VerboseEventHandler implements ExecutionEventListener { public callExecutionStateComplete( event: CallExecutionStateCompleteEvent ): void { - if (event.result.type === ExecutionEventResultType.SUCCESS) { - console.log( - `Successfully completed the execution of call future ${event.futureId}` - ); - } else { - console.log( - `Execution of future ${event.futureId} failed with reason: ${event.result.error}` - ); + switch (event.result.type) { + case ExecutionEventResultType.SUCCESS: { + return console.log( + `Successfully completed the execution of call future ${event.futureId}` + ); + } + case ExecutionEventResultType.ERROR: { + return console.log( + `Execution of call future ${event.futureId} failed with reason: ${event.result.error}` + ); + } + case ExecutionEventResultType.HELD: { + return console.log( + `Execution of call future ${event.futureId}/${event.result.heldId} held with reason: ${event.result.reason}` + ); + } } } @@ -89,16 +105,24 @@ export class VerboseEventHandler implements ExecutionEventListener { public staticCallExecutionStateComplete( event: StaticCallExecutionStateCompleteEvent ): void { - if (event.result.type === ExecutionEventResultType.SUCCESS) { - console.log( - `Successfully completed the execution of static call future ${ - event.futureId - } with result ${event.result.result ?? "undefined"}` - ); - } else { - console.log( - `Execution of future ${event.futureId} failed with reason: ${event.result.error}` - ); + switch (event.result.type) { + case ExecutionEventResultType.SUCCESS: { + return console.log( + `Successfully completed the execution of static call future ${ + event.futureId + } with result ${event.result.result ?? "undefined"}` + ); + } + case ExecutionEventResultType.ERROR: { + return console.log( + `Execution of static call future ${event.futureId} failed with reason: ${event.result.error}` + ); + } + case ExecutionEventResultType.HELD: { + return console.log( + `Execution of static call future ${event.futureId}/${event.result.heldId} held with reason: ${event.result.reason}` + ); + } } } @@ -111,16 +135,24 @@ export class VerboseEventHandler implements ExecutionEventListener { public sendDataExecutionStateComplete( event: SendDataExecutionStateCompleteEvent ): void { - if (event.result.type === ExecutionEventResultType.SUCCESS) { - console.log( - `Successfully completed the execution of send data future ${ - event.futureId - } in tx ${event.result.result ?? "undefined"}` - ); - } else { - console.log( - `Execution of future ${event.futureId} failed with reason: ${event.result.error}` - ); + switch (event.result.type) { + case ExecutionEventResultType.SUCCESS: { + return console.log( + `Successfully completed the execution of send data future ${ + event.futureId + } in tx ${event.result.result ?? "undefined"}` + ); + } + case ExecutionEventResultType.ERROR: { + return console.log( + `Execution of future ${event.futureId} failed with reason: ${event.result.error}` + ); + } + case ExecutionEventResultType.HELD: { + return console.log( + `Execution of send future ${event.futureId}/${event.result.heldId} held with reason: ${event.result.reason}` + ); + } } } diff --git a/packages/hardhat-plugin/src/ui/components/execution/BatchExecution.tsx b/packages/hardhat-plugin/src/ui/components/execution/BatchExecution.tsx index e89a42529..16b028c46 100644 --- a/packages/hardhat-plugin/src/ui/components/execution/BatchExecution.tsx +++ b/packages/hardhat-plugin/src/ui/components/execution/BatchExecution.tsx @@ -78,6 +78,9 @@ const StatusBadge = ({ future }: { future: UiFuture }) => { case UiFutureStatusType.ERRORED: badge = ; break; + case UiFutureStatusType.HELD: + badge = 🔶; + break; } return ( @@ -139,6 +142,12 @@ function resolveFutureColors(future: UiFuture): { borderStyle: "bold", textColor: "white", }; + case UiFutureStatusType.HELD: + return { + borderColor: "yellow", + borderStyle: "bold", + textColor: "white", + }; } } diff --git a/packages/hardhat-plugin/src/ui/types.ts b/packages/hardhat-plugin/src/ui/types.ts index c99831e88..266d0ba0f 100644 --- a/packages/hardhat-plugin/src/ui/types.ts +++ b/packages/hardhat-plugin/src/ui/types.ts @@ -5,6 +5,7 @@ export enum UiFutureStatusType { SUCCESS = "SUCCESS", PENDING = "PENDING", ERRORED = "ERRORED", + HELD = "HELD", } export enum UiStateDeploymentStatus { @@ -31,11 +32,18 @@ export interface UiFutureErrored { message: string; } +export interface UiFutureHeld { + type: UiFutureStatusType.HELD; + heldId: number; + reason: string; +} + export type UiFutureStatus = | UiFutureUnstarted | UiFutureSuccess | UiFuturePending - | UiFutureErrored; + | UiFutureErrored + | UiFutureHeld; export interface UiFuture { status: UiFutureStatus;