Skip to content

Commit dc28ac9

Browse files
committed
feat: Port solidity-stack-trace.ts
1 parent 137cfb3 commit dc28ac9

File tree

3 files changed

+70
-188
lines changed

3 files changed

+70
-188
lines changed

packages/hardhat-core/src/internal/hardhat-network/stack-traces/debug.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { bytesToHex as bufferToHex } from "@nomicfoundation/ethereumjs-util";
22
import chalk from "chalk";
33

4+
import { stackTraceEntryTypeToString } from "@nomicfoundation/edr";
45
import {
56
CallMessageTrace,
67
CreateMessageTrace,
@@ -202,7 +203,7 @@ export function printStackTrace(trace: SolidityStackTrace) {
202203

203204
const withTextualType = withHexAddress.map((entry) => ({
204205
...entry,
205-
type: StackTraceEntryType[entry.type],
206+
type: stackTraceEntryTypeToString(entry.type),
206207
}));
207208

208209
const withFlattenedSourceReferences = withTextualType.map((entry) => ({

packages/hardhat-core/src/internal/hardhat-network/stack-traces/solidity-stack-trace.ts

+66-186
Original file line numberDiff line numberDiff line change
@@ -1,189 +1,69 @@
1-
import { ReturnData } from "../provider/return-data";
2-
3-
import { ContractFunctionType } from "./model";
4-
5-
export enum StackTraceEntryType {
6-
CALLSTACK_ENTRY,
7-
UNRECOGNIZED_CREATE_CALLSTACK_ENTRY,
8-
UNRECOGNIZED_CONTRACT_CALLSTACK_ENTRY,
9-
PRECOMPILE_ERROR,
10-
REVERT_ERROR,
11-
PANIC_ERROR,
12-
CUSTOM_ERROR,
13-
FUNCTION_NOT_PAYABLE_ERROR,
14-
INVALID_PARAMS_ERROR,
15-
FALLBACK_NOT_PAYABLE_ERROR,
16-
FALLBACK_NOT_PAYABLE_AND_NO_RECEIVE_ERROR,
17-
UNRECOGNIZED_FUNCTION_WITHOUT_FALLBACK_ERROR, // TODO: Should trying to call a private/internal be a special case of this?
18-
MISSING_FALLBACK_OR_RECEIVE_ERROR,
19-
RETURNDATA_SIZE_ERROR,
20-
NONCONTRACT_ACCOUNT_CALLED_ERROR,
21-
CALL_FAILED_ERROR,
22-
DIRECT_LIBRARY_CALL_ERROR,
23-
UNRECOGNIZED_CREATE_ERROR,
24-
UNRECOGNIZED_CONTRACT_ERROR,
25-
OTHER_EXECUTION_ERROR,
26-
// This is a special case to handle a regression introduced in solc 0.6.3
27-
// For more info: https://github.com/ethereum/solidity/issues/9006
28-
UNMAPPED_SOLC_0_6_3_REVERT_ERROR,
29-
CONTRACT_TOO_LARGE_ERROR,
30-
INTERNAL_FUNCTION_CALLSTACK_ENTRY,
31-
CONTRACT_CALL_RUN_OUT_OF_GAS_ERROR,
32-
}
33-
34-
export const FALLBACK_FUNCTION_NAME = "<fallback>";
35-
export const RECEIVE_FUNCTION_NAME = "<receive>";
36-
export const CONSTRUCTOR_FUNCTION_NAME = "constructor";
37-
export const UNRECOGNIZED_FUNCTION_NAME = "<unrecognized-selector>";
38-
export const UNKNOWN_FUNCTION_NAME = "<unknown>";
39-
export const PRECOMPILE_FUNCTION_NAME = "<precompile>";
40-
export const UNRECOGNIZED_CONTRACT_NAME = "<UnrecognizedContract>";
41-
42-
export interface SourceReference {
43-
sourceName: string;
44-
sourceContent: string;
45-
contract?: string;
46-
function?: string;
47-
line: number;
48-
range: [number, number];
49-
}
50-
51-
export interface CallstackEntryStackTraceEntry {
52-
type: StackTraceEntryType.CALLSTACK_ENTRY;
53-
sourceReference: SourceReference;
54-
functionType: ContractFunctionType;
55-
}
56-
57-
export interface UnrecognizedCreateCallstackEntryStackTraceEntry {
58-
type: StackTraceEntryType.UNRECOGNIZED_CREATE_CALLSTACK_ENTRY;
59-
sourceReference?: undefined;
60-
}
61-
62-
export interface UnrecognizedContractCallstackEntryStackTraceEntry {
63-
type: StackTraceEntryType.UNRECOGNIZED_CONTRACT_CALLSTACK_ENTRY;
64-
address: Uint8Array;
65-
sourceReference?: undefined;
66-
}
67-
68-
export interface PrecompileErrorStackTraceEntry {
69-
type: StackTraceEntryType.PRECOMPILE_ERROR;
70-
precompile: number;
71-
sourceReference?: undefined;
72-
}
73-
74-
export interface RevertErrorStackTraceEntry {
75-
type: StackTraceEntryType.REVERT_ERROR;
76-
message: ReturnData;
77-
sourceReference: SourceReference;
78-
isInvalidOpcodeError: boolean;
79-
}
80-
81-
export interface PanicErrorStackTraceEntry {
82-
type: StackTraceEntryType.PANIC_ERROR;
83-
errorCode: bigint;
84-
sourceReference?: SourceReference;
85-
}
86-
87-
export interface CustomErrorStackTraceEntry {
88-
type: StackTraceEntryType.CUSTOM_ERROR;
89-
// unlike RevertErrorStackTraceEntry, this includes the message already parsed
90-
message: string;
91-
sourceReference: SourceReference;
92-
}
93-
94-
export interface UnmappedSolc063RevertErrorStackTraceEntry {
95-
type: StackTraceEntryType.UNMAPPED_SOLC_0_6_3_REVERT_ERROR;
96-
sourceReference?: SourceReference;
97-
}
98-
99-
export interface FunctionNotPayableErrorStackTraceEntry {
100-
type: StackTraceEntryType.FUNCTION_NOT_PAYABLE_ERROR;
101-
value: bigint;
102-
sourceReference: SourceReference;
103-
}
104-
105-
export interface InvalidParamsErrorStackTraceEntry {
106-
type: StackTraceEntryType.INVALID_PARAMS_ERROR;
107-
sourceReference: SourceReference;
108-
}
109-
110-
export interface FallbackNotPayableErrorStackTraceEntry {
111-
type: StackTraceEntryType.FALLBACK_NOT_PAYABLE_ERROR;
112-
value: bigint;
113-
sourceReference: SourceReference;
114-
}
115-
116-
export interface FallbackNotPayableAndNoReceiveErrorStackTraceEntry {
117-
type: StackTraceEntryType.FALLBACK_NOT_PAYABLE_AND_NO_RECEIVE_ERROR;
118-
value: bigint;
119-
sourceReference: SourceReference;
120-
}
121-
122-
export interface UnrecognizedFunctionWithoutFallbackErrorStackTraceEntry {
123-
type: StackTraceEntryType.UNRECOGNIZED_FUNCTION_WITHOUT_FALLBACK_ERROR;
124-
sourceReference: SourceReference;
125-
}
126-
127-
export interface MissingFallbackOrReceiveErrorStackTraceEntry {
128-
type: StackTraceEntryType.MISSING_FALLBACK_OR_RECEIVE_ERROR;
129-
sourceReference: SourceReference;
130-
}
131-
132-
export interface ReturndataSizeErrorStackTraceEntry {
133-
type: StackTraceEntryType.RETURNDATA_SIZE_ERROR;
134-
sourceReference: SourceReference;
135-
}
136-
137-
export interface NonContractAccountCalledErrorStackTraceEntry {
138-
type: StackTraceEntryType.NONCONTRACT_ACCOUNT_CALLED_ERROR;
139-
sourceReference: SourceReference;
140-
}
141-
142-
export interface CallFailedErrorStackTraceEntry {
143-
type: StackTraceEntryType.CALL_FAILED_ERROR;
144-
sourceReference: SourceReference;
145-
}
146-
147-
export interface DirectLibraryCallErrorStackTraceEntry {
148-
type: StackTraceEntryType.DIRECT_LIBRARY_CALL_ERROR;
149-
sourceReference: SourceReference;
150-
}
151-
152-
export interface UnrecognizedCreateErrorStackTraceEntry {
153-
type: StackTraceEntryType.UNRECOGNIZED_CREATE_ERROR;
154-
message: ReturnData;
155-
sourceReference?: undefined;
156-
isInvalidOpcodeError: boolean;
157-
}
158-
159-
export interface UnrecognizedContractErrorStackTraceEntry {
160-
type: StackTraceEntryType.UNRECOGNIZED_CONTRACT_ERROR;
161-
address: Uint8Array;
162-
message: ReturnData;
163-
sourceReference?: undefined;
164-
isInvalidOpcodeError: boolean;
165-
}
166-
167-
export interface OtherExecutionErrorStackTraceEntry {
168-
type: StackTraceEntryType.OTHER_EXECUTION_ERROR;
169-
sourceReference?: SourceReference;
170-
}
171-
172-
export interface ContractTooLargeErrorStackTraceEntry {
173-
type: StackTraceEntryType.CONTRACT_TOO_LARGE_ERROR;
174-
sourceReference?: SourceReference;
175-
}
176-
177-
export interface InternalFunctionCallStackEntry {
178-
type: StackTraceEntryType.INTERNAL_FUNCTION_CALLSTACK_ENTRY;
179-
pc: number;
180-
sourceReference: SourceReference;
181-
}
182-
183-
export interface ContractCallRunOutOfGasError {
184-
type: StackTraceEntryType.CONTRACT_CALL_RUN_OUT_OF_GAS_ERROR;
185-
sourceReference?: SourceReference;
186-
}
1+
import type {
2+
CallstackEntryStackTraceEntry,
3+
UnrecognizedCreateCallstackEntryStackTraceEntry,
4+
UnrecognizedContractCallstackEntryStackTraceEntry,
5+
PrecompileErrorStackTraceEntry,
6+
RevertErrorStackTraceEntry,
7+
PanicErrorStackTraceEntry,
8+
CustomErrorStackTraceEntry,
9+
FunctionNotPayableErrorStackTraceEntry,
10+
InvalidParamsErrorStackTraceEntry,
11+
FallbackNotPayableErrorStackTraceEntry,
12+
FallbackNotPayableAndNoReceiveErrorStackTraceEntry,
13+
UnrecognizedFunctionWithoutFallbackErrorStackTraceEntry,
14+
MissingFallbackOrReceiveErrorStackTraceEntry,
15+
ReturndataSizeErrorStackTraceEntry,
16+
NonContractAccountCalledErrorStackTraceEntry,
17+
CallFailedErrorStackTraceEntry,
18+
DirectLibraryCallErrorStackTraceEntry,
19+
UnrecognizedCreateErrorStackTraceEntry,
20+
UnrecognizedContractErrorStackTraceEntry,
21+
OtherExecutionErrorStackTraceEntry,
22+
UnmappedSolc063RevertErrorStackTraceEntry,
23+
ContractTooLargeErrorStackTraceEntry,
24+
InternalFunctionCallStackEntry,
25+
ContractCallRunOutOfGasError,
26+
} from "@nomicfoundation/edr";
27+
28+
export {
29+
SourceReference,
30+
StackTraceEntryType,
31+
stackTraceEntryTypeToString,
32+
FALLBACK_FUNCTION_NAME,
33+
RECEIVE_FUNCTION_NAME,
34+
CONSTRUCTOR_FUNCTION_NAME,
35+
UNRECOGNIZED_FUNCTION_NAME,
36+
UNKNOWN_FUNCTION_NAME,
37+
PRECOMPILE_FUNCTION_NAME,
38+
UNRECOGNIZED_CONTRACT_NAME,
39+
} from "@nomicfoundation/edr";
40+
41+
export type {
42+
CallstackEntryStackTraceEntry,
43+
UnrecognizedCreateCallstackEntryStackTraceEntry,
44+
UnrecognizedContractCallstackEntryStackTraceEntry,
45+
PrecompileErrorStackTraceEntry,
46+
RevertErrorStackTraceEntry,
47+
PanicErrorStackTraceEntry,
48+
CustomErrorStackTraceEntry,
49+
FunctionNotPayableErrorStackTraceEntry,
50+
InvalidParamsErrorStackTraceEntry,
51+
FallbackNotPayableErrorStackTraceEntry,
52+
FallbackNotPayableAndNoReceiveErrorStackTraceEntry,
53+
UnrecognizedFunctionWithoutFallbackErrorStackTraceEntry,
54+
MissingFallbackOrReceiveErrorStackTraceEntry,
55+
ReturndataSizeErrorStackTraceEntry,
56+
NonContractAccountCalledErrorStackTraceEntry,
57+
CallFailedErrorStackTraceEntry,
58+
DirectLibraryCallErrorStackTraceEntry,
59+
UnrecognizedCreateErrorStackTraceEntry,
60+
UnrecognizedContractErrorStackTraceEntry,
61+
OtherExecutionErrorStackTraceEntry,
62+
UnmappedSolc063RevertErrorStackTraceEntry,
63+
ContractTooLargeErrorStackTraceEntry,
64+
InternalFunctionCallStackEntry,
65+
ContractCallRunOutOfGasError,
66+
};
18767

18868
export type SolidityStackTraceEntry =
18969
| CallstackEntryStackTraceEntry

packages/hardhat-core/test/internal/hardhat-network/stack-traces/test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import fsExtra from "fs-extra";
55
import path from "path";
66
import semver from "semver";
77

8+
import { stackTraceEntryTypeToString } from "@nomicfoundation/edr";
89
import { EdrProviderWrapper } from "../../../../src/internal/hardhat-network/provider/provider";
910
import { ReturnData } from "../../../../src/internal/hardhat-network/provider/return-data";
1011
import {
@@ -316,7 +317,7 @@ function compareStackTraces(
316317
const actual = trace[i];
317318
const expected = description[i];
318319

319-
const actualErrorType = StackTraceEntryType[actual.type];
320+
const actualErrorType = stackTraceEntryTypeToString(actual.type);
320321
const expectedErrorType = expected.type;
321322

322323
if (

0 commit comments

Comments
 (0)