-
Notifications
You must be signed in to change notification settings - Fork 1
/
shared.ts
33 lines (26 loc) · 1.07 KB
/
shared.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Importing app code from the test helpers breaks hardhat environment fixtures for some reason,
// Likely due to requiring the hre before the tests start running.
import { existsSync, readFileSync } from "fs";
import { join } from "path";
import { HardhatPluginError } from "hardhat/plugins";
import { Artifact } from "hardhat/types";
export const PLUGIN_NAME = "upgrade-manager";
// Helpers useful in both tests and plugin task code should live here and be imported from each
export function getErrorMessageAndStack(error: unknown): {
message: string;
stack?: string;
} {
if (error instanceof Error) return error;
return { message: String(error), stack: new Error().stack };
}
export function readArtifactFromPlugin(artifactName: string): Artifact {
let path = join(__dirname, `./${artifactName}.sol.json`);
if (!existsSync(path)) {
throw new HardhatPluginError(
PLUGIN_NAME,
`Could not locate compiled artifact ${artifactName} at ${path}, run yarn compile`
);
}
let artifact: Artifact = JSON.parse(readFileSync(path, "utf-8"));
return artifact;
}