Skip to content

Commit

Permalink
Merge pull request #5741 from NomicFoundation/feat/hre-artifacts
Browse files Browse the repository at this point in the history
add mock artifacts plugins
  • Loading branch information
kanej committed Sep 17, 2024
2 parents 1500c66 + 9fc2bd0 commit 198612d
Show file tree
Hide file tree
Showing 11 changed files with 559 additions and 1 deletion.
9 changes: 9 additions & 0 deletions v-next/hardhat-errors/src/descriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ Please add the property "type" with the value "module" in your package.json to e
websiteTitle: "Invariant violation",
websiteDescription: `An internal invariant was violated. This is probably caused by a programming error in Hardhat or in one of the used plugins.
Please [report it](https://github.com/nomiclabs/hardhat/issues/new) to help us improve Hardhat.`,
shouldBeReported: true,
},
NOT_IMPLEMENTED_ERROR: {
number: 101,
messageTemplate: "Not implemented: {message}",
websiteTitle: "Not implemented",
websiteDescription: `A code path that has not been implemented was unexpectedly triggered.
Please [report it](https://github.com/nomiclabs/hardhat/issues/new) to help us improve Hardhat.`,
shouldBeReported: true,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import type {
Artifact,
ArtifactsManager,
BuildInfo,
CompilerInput,
CompilerOutput,
} from "../../../types/artifacts.js";

import { HardhatError } from "@ignored/hardhat-vnext-errors";

export class ArtifactsManagerImplementation implements ArtifactsManager {
public readArtifact(
_contractNameOrFullyQualifiedName: string,
): Promise<Artifact> {
throw new HardhatError(HardhatError.ERRORS.INTERNAL.NOT_IMPLEMENTED_ERROR, {
message: "Not implemented in fake artifacts manager",
});
}

public artifactExists(
_contractNameOrFullyQualifiedName: string,
): Promise<boolean> {
throw new HardhatError(HardhatError.ERRORS.INTERNAL.NOT_IMPLEMENTED_ERROR, {
message: "Not implemented in fake artifacts manager",
});
}

public getAllFullyQualifiedNames(): Promise<string[]> {
throw new HardhatError(HardhatError.ERRORS.INTERNAL.NOT_IMPLEMENTED_ERROR, {
message: "Not implemented in fake artifacts manager",
});
}

public getBuildInfo(
_fullyQualifiedName: string,
): Promise<BuildInfo | undefined> {
throw new HardhatError(HardhatError.ERRORS.INTERNAL.NOT_IMPLEMENTED_ERROR, {
message: "Not implemented in fake artifacts manager",
});
}

public getArtifactPaths(): Promise<string[]> {
throw new HardhatError(HardhatError.ERRORS.INTERNAL.NOT_IMPLEMENTED_ERROR, {
message: "Not implemented in fake artifacts manager",
});
}

public getBuildInfoPaths(): Promise<string[]> {
throw new HardhatError(HardhatError.ERRORS.INTERNAL.NOT_IMPLEMENTED_ERROR, {
message: "Not implemented in fake artifacts manager",
});
}

public saveArtifact(_artifact: Artifact): Promise<void> {
throw new HardhatError(HardhatError.ERRORS.INTERNAL.NOT_IMPLEMENTED_ERROR, {
message: "Not implemented in fake artifacts manager",
});
}

public saveBuildInfo(
_solcVersion: string,
_solcLongVersion: string,
_input: CompilerInput,
_output: CompilerOutput,
): Promise<string> {
throw new HardhatError(HardhatError.ERRORS.INTERNAL.NOT_IMPLEMENTED_ERROR, {
message: "Not implemented in fake artifacts manager",
});
}

public getArtifactPath(_fullyQualifiedName: string): Promise<string> {
throw new HardhatError(HardhatError.ERRORS.INTERNAL.NOT_IMPLEMENTED_ERROR, {
message: "Not implemented in fake artifacts manager",
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { HardhatRuntimeEnvironmentHooks } from "../../../../types/hooks.js";

export default async (): Promise<Partial<HardhatRuntimeEnvironmentHooks>> => {
const handlers: Partial<HardhatRuntimeEnvironmentHooks> = {
created: async (_context, hre): Promise<void> => {
const { ArtifactsManagerImplementation } = await import(
"../artifacts-manager.js"
);

hre.artifacts = new ArtifactsManagerImplementation();
},
};

return handlers;
};
11 changes: 11 additions & 0 deletions v-next/hardhat/src/internal/builtin-plugins/artifacts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { HardhatPlugin } from "../../../types/plugins.js";
import "./type-extensions.js";

const hardhatPlugin: HardhatPlugin = {
id: "artifacts",
hookHandlers: {
hre: import.meta.resolve("./hook-handlers/hre.js"),
},
};

export default hardhatPlugin;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { ArtifactsManager } from "../../../types/artifacts.js";

declare module "../../../types/hre.js" {
interface HardhatRuntimeEnvironment {
artifacts: ArtifactsManager;
}
}
4 changes: 3 additions & 1 deletion v-next/hardhat/src/internal/builtin-plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { HardhatPlugin } from "../../types/plugins.js";

import artifacts from "./artifacts/index.js";
import clean from "./clean/index.js";
import console from "./console/index.js";
import networkManager from "./network-manager/index.js";
Expand All @@ -8,14 +9,15 @@ import solidity from "./solidity/index.js";

// Note: When importing a plugin, you have to export its types, so that its
// type extensions, if any, also get loaded.
export type * from "./artifacts/index.js";
export type * from "./solidity/index.js";
export type * from "./network-manager/index.js";
export type * from "./clean/index.js";
export type * from "./console/index.js";
export type * from "./network-manager/index.js";
export type * from "./run/index.js";

export const builtinPlugins: HardhatPlugin[] = [
artifacts,
solidity,
networkManager,
clean,
Expand Down
2 changes: 2 additions & 0 deletions v-next/hardhat/src/internal/core/hre.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { UnsafeHardhatRuntimeEnvironmentOptions } from "./types.js";
import type { ArtifactsManager } from "../../types/artifacts.js";
import type {
HardhatUserConfig,
HardhatConfig,
Expand Down Expand Up @@ -40,6 +41,7 @@ export class HardhatRuntimeEnvironmentImplementation
// here, because it's added by a plugin. But as that plugin is builtin, its
// type extensions also affect this module.
public network!: NetworkManager;
public artifacts!: ArtifactsManager;

public static async create(
inputUserConfig: HardhatUserConfig,
Expand Down
Loading

0 comments on commit 198612d

Please sign in to comment.