Skip to content

Commit

Permalink
WIP: Benchmark with patched Hardhat to use new EDR internals
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanewok committed Aug 26, 2024
1 parent 272b4c7 commit ac2e012
Show file tree
Hide file tree
Showing 3 changed files with 10,233 additions and 34 deletions.
36 changes: 16 additions & 20 deletions hardhat-tests/test/internal/hardhat-network/stack-traces/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import {
SolidityStackTraceEntry,
StackTraceEntryType,
stackTraceEntryTypeToString,
} from "hardhat/internal/hardhat-network/stack-traces/solidity-stack-trace";
import { SolidityTracer } from "hardhat/internal/hardhat-network/stack-traces/solidityTracer";
import { VmTraceDecoder } from "hardhat/internal/hardhat-network/stack-traces/vm-trace-decoder";
Expand Down Expand Up @@ -303,7 +304,7 @@ function compareStackTraces(
const actual = trace[i];
const expected = description[i];

const actualErrorType = StackTraceEntryType[actual.type];
const actualErrorType = stackTraceEntryTypeToString(actual.type);
const expectedErrorType = expected.type;

if (
Expand All @@ -322,19 +323,15 @@ function compareStackTraces(
`Stack trace of tx ${txIndex} entry ${i} type is incorrect: expected ${expectedErrorType}, got ${actualErrorType}`
);

const actualMessage = "message" in actual ? actual.message : undefined;

// actual.message is a ReturnData in revert errors, but a string
// in custom errors
let decodedMessage = "";
if (typeof actualMessage === "string") {
decodedMessage = actualMessage;
} else if (
actualMessage instanceof ReturnData &&
actualMessage.isErrorReturnData()
) {
decodedMessage = actualMessage.decodeError();
}
// actual.message is a ReturnData in revert errors but in custom errors
// we need to decode it
const decodedMessage =
"message" in actual
? actual.message
: "returnData" in actual &&
new ReturnData(actual.returnData).isErrorReturnData()
? new ReturnData(actual.returnData).decodeError()
: "";

if (expected.message !== undefined) {
assert.equal(
Expand All @@ -351,7 +348,7 @@ function compareStackTraces(
}

if (expected.value !== undefined) {
const actualValue = "value" in actual ? actual.value : undefined;
const actualValue = (actual as any).value;

assert.isDefined(
actualValue,
Expand All @@ -361,8 +358,8 @@ function compareStackTraces(
const expectedValue = BigInt(expected.value);

assert.isTrue(
expectedValue === actualValue,
`Stack trace of tx ${txIndex} entry ${i} has value ${actualValue!.toString(
expectedValue === (actual as any).value,
`Stack trace of tx ${txIndex} entry ${i} has value ${actualValue.toString(
10
)} and should have ${expectedValue.toString(10)}`
);
Expand All @@ -374,15 +371,14 @@ function compareStackTraces(
}

if (expected.errorCode !== undefined) {
const actualErrorCode =
"errorCode" in actual ? actual.errorCode : undefined;
const actualErrorCode = (actual as any).errorCode;

assert.isDefined(
actualErrorCode,
`Stack trace of tx ${txIndex} entry ${i} should have an errorCode`
);

const actualErrorCodeHex = actualErrorCode!.toString(16);
const actualErrorCodeHex = actualErrorCode.toString(16);

assert.isTrue(
expected.errorCode === actualErrorCodeHex,
Expand Down
Loading

0 comments on commit ac2e012

Please sign in to comment.