Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mock artifacts plugins #5741

Merged
merged 4 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: {
kanej marked this conversation as resolved.
Show resolved Hide resolved
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
76 changes: 76 additions & 0 deletions v-next/hardhat/src/internal/artifacts/artifacts-manager.ts
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,13 @@
import type { HardhatRuntimeEnvironmentHooks } from "../../../../types/hooks.js";

import { ArtifactsManagerImplementation } from "../../../artifacts/artifacts-manager.js";
kanej marked this conversation as resolved.
Show resolved Hide resolved

export default async (): Promise<Partial<HardhatRuntimeEnvironmentHooks>> => {
const handlers: Partial<HardhatRuntimeEnvironmentHooks> = {
created: async (_context, hre): Promise<void> => {
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("./hookHandlers/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