Skip to content

Commit dc79972

Browse files
committed
Ensure all stack trace entry types are handled
1 parent a50d68e commit dc79972

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

v-next/hardhat/src/internal/builtin-plugins/network-manager/edr/stack-traces/solidity-stack-trace.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import type {
2424
ContractTooLargeErrorStackTraceEntry,
2525
InternalFunctionCallStackEntry,
2626
ContractCallRunOutOfGasError,
27+
CheatcodeErrorStackTraceEntry,
2728
} from "@nomicfoundation/edr";
2829

2930
import {
@@ -102,6 +103,7 @@ export type SolidityStackTraceEntry =
102103
| UnmappedSolc063RevertErrorStackTraceEntry
103104
| ContractTooLargeErrorStackTraceEntry
104105
| InternalFunctionCallStackEntry
105-
| ContractCallRunOutOfGasError;
106+
| ContractCallRunOutOfGasError
107+
| CheatcodeErrorStackTraceEntry;
106108

107109
export type SolidityStackTrace = SolidityStackTraceEntry[];

v-next/hardhat/src/internal/builtin-plugins/network-manager/edr/stack-traces/stack-trace-solidity-errors.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export function encodeStackTraceEntry(
8989
case StackTraceEntryType.RETURNDATA_SIZE_ERROR:
9090
case StackTraceEntryType.NONCONTRACT_ACCOUNT_CALLED_ERROR:
9191
case StackTraceEntryType.CALL_FAILED_ERROR:
92+
case StackTraceEntryType.CHEATCODE_ERROR:
9293
case StackTraceEntryType.DIRECT_LIBRARY_CALL_ERROR:
9394
return sourceReferenceToSolidityCallsite(stackTraceEntry.sourceReference);
9495

@@ -265,6 +266,7 @@ function getMessageFromLastStackTraceEntry(
265266
return `VM Exception while processing transaction: ${panicMessage}`;
266267

267268
case StackTraceEntryType.CUSTOM_ERROR:
269+
case StackTraceEntryType.CHEATCODE_ERROR:
268270
return `VM Exception while processing transaction: ${stackTraceEntry.message}`;
269271

270272
case StackTraceEntryType.OTHER_EXECUTION_ERROR:

v-next/hardhat/src/internal/builtin-plugins/solidity-test/stack-trace-solidity-errors.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ export function getMessageFromLastStackTraceEntry(
6363
case StackTraceEntryType.CUSTOM_ERROR:
6464
return stackTraceEntry.message;
6565

66+
case StackTraceEntryType.CHEATCODE_ERROR:
67+
return stackTraceEntry.message;
68+
6669
case StackTraceEntryType.CONTRACT_TOO_LARGE_ERROR:
6770
return "Trying to deploy a contract whose code is too large";
6871

v-next/hardhat/test/internal/builtin-plugins/network-manager/edr/stack-traces/stack-trace-solidity-errors.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import type {
2+
SolidityStackTraceEntry,
3+
StackTraceEntryType,
4+
} from "../../../../../../src/internal/builtin-plugins/network-manager/edr/stack-traces/solidity-stack-trace.js";
5+
16
import assert from "node:assert/strict";
27
import { describe, it } from "node:test";
38

@@ -37,5 +42,19 @@ describe("SolidityCallSite", function () {
3742

3843
assert.equal(callSite.toString(), "Contract.functionName (Source.sol:1)");
3944
});
45+
46+
it("exhaustive stack trace entries", async () => {
47+
// This is a type-only test to ensure that the SolidityStackTraceEntry union type
48+
// includes all the expected variants.
49+
const hhEntryType = (_entryType: SolidityStackTraceEntry["type"]) => {};
50+
const edrEntryType = (_entryType: StackTraceEntryType) => {};
51+
52+
const _test1 = (entryType: SolidityStackTraceEntry["type"]) => {
53+
edrEntryType(entryType);
54+
};
55+
const _test2 = (entryType: StackTraceEntryType) => {
56+
hhEntryType(entryType);
57+
};
58+
});
4059
});
4160
});

0 commit comments

Comments
 (0)