Skip to content

Commit

Permalink
refactor: Only import ported runtime JS via requireNapiRs
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanewok committed Aug 20, 2024
1 parent 1900e08 commit 92b9ba0
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import type {
import type {
EdrContext,
Provider as EdrProviderT,
VmTraceDecoder as VmTraceDecoderT,
VMTracer as VMTracerT,
RawTrace,
Response,
SubscriptionEvent,
Expand Down Expand Up @@ -168,15 +170,15 @@ export class EdrProviderWrapper
private _callOverrideCallback?: CallOverrideCallback;

/** Used for internal stack trace tests. */
private _vmTracer?: VMTracer;
private _vmTracer?: VMTracerT;

private constructor(
private readonly _provider: EdrProviderT,
// we add this for backwards-compatibility with plugins like solidity-coverage
private readonly _node: {
_vm: MinimalEthereumJsVm;
},
private readonly _vmTraceDecoder: VmTraceDecoder,
private readonly _vmTraceDecoder: VmTraceDecoderT,
// The common configuration for EthereumJS VM is not used by EDR, but tests expect it as part of the provider.
private readonly _common: Common,
tracingConfig?: TracingConfig
Expand Down Expand Up @@ -465,7 +467,7 @@ export class EdrProviderWrapper
*
* Used for internal stack traces integration tests.
*/
public setVmTracer(vmTracer?: VMTracer) {
public setVmTracer(vmTracer?: VMTracerT) {
this._vmTracer = vmTracer;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
export { ReturnData } from "@nomicfoundation/edr";
import { requireNapiRsModule } from "../../../common/napi-rs";

const { ReturnData } = requireNapiRsModule(
"@nomicfoundation/edr"
) as typeof import("@nomicfoundation/edr");

export { ReturnData };
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
import { ExitCode } from "@nomicfoundation/edr";
import { requireNapiRsModule } from "../../../../common/napi-rs";

const { ExitCode } = requireNapiRsModule(
"@nomicfoundation/edr"
) as typeof import("@nomicfoundation/edr");

export { ExitCode };
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
export { createModelsAndDecodeBytecodes } from "@nomicfoundation/edr";
import { requireNapiRsModule } from "../../../common/napi-rs";

const { createModelsAndDecodeBytecodes } = requireNapiRsModule(
"@nomicfoundation/edr"
) as typeof import("@nomicfoundation/edr");

export { createModelsAndDecodeBytecodes };
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
export { printMessageTrace, printStackTrace } from "@nomicfoundation/edr";
import { requireNapiRsModule } from "../../../common/napi-rs";

const { printMessageTrace, printStackTrace } = requireNapiRsModule(
"@nomicfoundation/edr"
) as typeof import("@nomicfoundation/edr");

export { printMessageTrace, printStackTrace };
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { linkHexStringBytecode } from "@nomicfoundation/edr";
import { requireNapiRsModule } from "../../../common/napi-rs";

const { linkHexStringBytecode } = requireNapiRsModule(
"@nomicfoundation/edr"
) as typeof import("@nomicfoundation/edr");

export { linkHexStringBytecode };
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
SourceReference,
CallstackEntryStackTraceEntry,
UnrecognizedCreateCallstackEntryStackTraceEntry,
UnrecognizedContractCallstackEntryStackTraceEntry,
Expand All @@ -25,6 +26,22 @@ import type {
ContractCallRunOutOfGasError,
} from "@nomicfoundation/edr";

import { requireNapiRsModule } from "../../../common/napi-rs";

const {
StackTraceEntryType,
stackTraceEntryTypeToString,
FALLBACK_FUNCTION_NAME,
RECEIVE_FUNCTION_NAME,
CONSTRUCTOR_FUNCTION_NAME,
UNRECOGNIZED_FUNCTION_NAME,
UNKNOWN_FUNCTION_NAME,
PRECOMPILE_FUNCTION_NAME,
UNRECOGNIZED_CONTRACT_NAME,
} = requireNapiRsModule(
"@nomicfoundation/edr"
) as typeof import("@nomicfoundation/edr");

export {
SourceReference,
StackTraceEntryType,
Expand All @@ -36,7 +53,7 @@ export {
UNKNOWN_FUNCTION_NAME,
PRECOMPILE_FUNCTION_NAME,
UNRECOGNIZED_CONTRACT_NAME,
} from "@nomicfoundation/edr";
};

export type {
CallstackEntryStackTraceEntry,
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
export { SolidityTracer } from "@nomicfoundation/edr";
import { requireNapiRsModule } from "../../../common/napi-rs";

const { SolidityTracer } = requireNapiRsModule(
"@nomicfoundation/edr"
) as typeof import("@nomicfoundation/edr");

export { SolidityTracer };
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import type { VmTraceDecoder as VmTraceDecoderT } from "@nomicfoundation/edr";
import chalk from "chalk";
import debug from "debug";
import { VmTraceDecoder, initializeVmTraceDecoder } from "@nomicfoundation/edr";
import { Reporter } from "../../sentry/reporter";
import { TracingConfig } from "../provider/node-types";
import { requireNapiRsModule } from "../../../common/napi-rs";

const log = debug("hardhat:core:hardhat-network:node");

const { VmTraceDecoder, initializeVmTraceDecoder } = requireNapiRsModule(
"@nomicfoundation/edr"
) as typeof import("@nomicfoundation/edr");

function initializeVmTraceDecoderWrapper(
vmTraceDecoder: VmTraceDecoder,
vmTraceDecoder: VmTraceDecoderT,
tracingConfig: TracingConfig
) {
try {
Expand All @@ -33,5 +38,6 @@ function initializeVmTraceDecoderWrapper(

export {
VmTraceDecoder,
VmTraceDecoderT,
initializeVmTraceDecoderWrapper as initializeVmTraceDecoder,
};
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
import { VmTracer as VMTracer } from "@nomicfoundation/edr";
export { VMTracer };
import { requireNapiRsModule } from "../../../common/napi-rs";

const { VmTracer } = requireNapiRsModule(
"@nomicfoundation/edr"
) as typeof import("@nomicfoundation/edr");

export { VmTracer as VMTracer };
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import fsExtra from "fs-extra";
import path from "path";
import semver from "semver";

import { stackTraceEntryTypeToString } from "@nomicfoundation/edr";
import { EdrProviderWrapper } from "../../../../src/internal/hardhat-network/provider/provider";
import { ReturnData } from "../../../../src/internal/hardhat-network/provider/return-data";
import {
Expand All @@ -27,7 +26,7 @@ import {
StackTraceEntryType,
} from "../../../../src/internal/hardhat-network/stack-traces/solidity-stack-trace";
import { SolidityTracer } from "../../../../src/internal/hardhat-network/stack-traces/solidityTracer";
import { VmTraceDecoder } from "../../../../src/internal/hardhat-network/stack-traces/vm-trace-decoder";
import { VmTraceDecoderT } from "../../../../src/internal/hardhat-network/stack-traces/vm-trace-decoder";
import {
BuildInfo,
CompilerInput,
Expand All @@ -40,6 +39,7 @@ import { SUPPORTED_SOLIDITY_VERSION_RANGE } from "../../../../src/internal/hardh
import { TracingConfig } from "../../../../src/internal/hardhat-network/provider/node-types";
import { BUILD_INFO_FORMAT_VERSION } from "../../../../src/internal/constants";
import { FakeModulesLogger } from "../helpers/fakeLogger";
import { requireNapiRsModule } from "../../../../src/common/napi-rs";
import {
compileFiles,
COMPILER_DOWNLOAD_TIMEOUT,
Expand All @@ -58,6 +58,10 @@ import {
traceTransaction,
} from "./execution";

const { stackTraceEntryTypeToString } = requireNapiRsModule(
"@nomicfoundation/edr"
) as typeof import("@nomicfoundation/edr");

interface StackFrameDescription {
type: string;
sourceReference?: {
Expand Down Expand Up @@ -540,7 +544,7 @@ async function runTest(

compareConsoleLogs(logger.lines, tx.consoleLogs);

const vmTraceDecoder = (provider as any)._vmTraceDecoder as VmTraceDecoder;
const vmTraceDecoder = (provider as any)._vmTraceDecoder as VmTraceDecoderT;
const decodedTrace = vmTraceDecoder.tryToDecodeMessageTrace(trace);

try {
Expand Down

0 comments on commit 92b9ba0

Please sign in to comment.