Skip to content

Commit 80f2e83

Browse files
committed
Start porting ErrorInferrer
1 parent 03fbf70 commit 80f2e83

File tree

1 file changed

+2
-64
lines changed

1 file changed

+2
-64
lines changed

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

+2-64
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { defaultAbiCoder as abi } from "@ethersproject/abi";
33
import { equalsBytes } from "@nomicfoundation/ethereumjs-util";
44
import semver from "semver";
55

6+
import { ErrorInferrer as ErrorInferrerRs } from "@nomicfoundation/edr";
67
import { assertHardhatInvariant } from "../../core/errors";
78
import { AbiHelpers } from "../../util/abi-helpers";
89
import { ReturnData } from "../provider/return-data";
@@ -178,70 +179,7 @@ export class ErrorInferrer {
178179
public filterRedundantFrames(
179180
stacktrace: SolidityStackTrace
180181
): SolidityStackTrace {
181-
return stacktrace.filter((frame, i) => {
182-
if (i + 1 === stacktrace.length) {
183-
return true;
184-
}
185-
186-
const nextFrame = stacktrace[i + 1];
187-
188-
// we can only filter frames if we know their sourceReference
189-
// and the one from the next frame
190-
if (
191-
frame.sourceReference === undefined ||
192-
nextFrame.sourceReference === undefined
193-
) {
194-
return true;
195-
}
196-
197-
// look TWO frames ahead to determine if this is a specific occurrence of
198-
// a redundant CALLSTACK_ENTRY frame observed when using Solidity 0.8.5:
199-
if (
200-
frame.type === StackTraceEntryType.CALLSTACK_ENTRY &&
201-
i + 2 < stacktrace.length &&
202-
stacktrace[i + 2].sourceReference !== undefined &&
203-
stacktrace[i + 2].type === StackTraceEntryType.RETURNDATA_SIZE_ERROR
204-
) {
205-
// ! below for tsc. we confirmed existence in the enclosing conditional.
206-
const thatSrcRef = stacktrace[i + 2].sourceReference;
207-
if (
208-
thatSrcRef !== undefined &&
209-
frame.sourceReference.range[0] === thatSrcRef.range[0] &&
210-
frame.sourceReference.range[1] === thatSrcRef.range[1] &&
211-
frame.sourceReference.line === thatSrcRef.line
212-
) {
213-
return false;
214-
}
215-
}
216-
217-
// constructors contain the whole contract, so we ignore them
218-
if (
219-
frame.sourceReference.function === "constructor" &&
220-
nextFrame.sourceReference.function !== "constructor"
221-
) {
222-
return true;
223-
}
224-
225-
// this is probably a recursive call
226-
if (
227-
i > 0 &&
228-
frame.type === nextFrame.type &&
229-
frame.sourceReference.range[0] === nextFrame.sourceReference.range[0] &&
230-
frame.sourceReference.range[1] === nextFrame.sourceReference.range[1] &&
231-
frame.sourceReference.line === nextFrame.sourceReference.line
232-
) {
233-
return true;
234-
}
235-
236-
if (
237-
frame.sourceReference.range[0] <= nextFrame.sourceReference.range[0] &&
238-
frame.sourceReference.range[1] >= nextFrame.sourceReference.range[1]
239-
) {
240-
return false;
241-
}
242-
243-
return true;
244-
});
182+
return ErrorInferrerRs.filterRedundantFrames(stacktrace);
245183
}
246184

247185
// Heuristics

0 commit comments

Comments
 (0)