Skip to content

Commit

Permalink
Merge pull request #816 from SebastienGllmt/writeLocalhostDeployment-…
Browse files Browse the repository at this point in the history
…flag

feat: add `writeLocalhostDeployment` option
  • Loading branch information
zoeyTM authored Sep 25, 2024
2 parents 739713b + f52cc2a commit f77041e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/hardhat-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ ignitionScope
.addOptionalParam("strategy", "Set the deployment strategy to use", "basic")
.addFlag("reset", "Wipes the existing deployment state before deploying")
.addFlag("verify", "Verify the deployment on Etherscan")
.addFlag(
"writeLocalhostDeployment",
"Write deployment information to disk when deploying to the in-memory network"
)
.setDescription("Deploy a module to the specified network")
.setAction(
async (
Expand All @@ -107,6 +111,7 @@ ignitionScope
reset,
verify,
strategy: strategyName,
writeLocalhostDeployment,
}: {
modulePath: string;
parameters?: string;
Expand All @@ -115,6 +120,7 @@ ignitionScope
reset: boolean;
verify: boolean;
strategy: string;
writeLocalhostDeployment: boolean;
},
hre
) => {
Expand Down Expand Up @@ -150,10 +156,9 @@ ignitionScope
const deploymentId = resolveDeploymentId(givenDeploymentId, chainId);

const deploymentDir =
hre.network.name === "hardhat"
hre.network.name === "hardhat" && !writeLocalhostDeployment
? undefined
: path.join(hre.config.paths.ignition, "deployments", deploymentId);

if (chainId !== 31337) {
if (process.env.HARDHAT_IGNITION_CONFIRM_DEPLOYMENT === undefined) {
const prompt = await Prompt({
Expand Down
55 changes: 55 additions & 0 deletions packages/hardhat-plugin/test/deploy/writeLocalhost.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { assert } from "chai";
import { pathExists, removeSync } from "fs-extra";
import path from "path";

import { useEphemeralIgnitionProject } from "../test-helpers/use-ignition-project";

const fixtureProjectName = "minimal";
const deploymentDir = path.join(
path.resolve(__dirname, `../fixture-projects/${fixtureProjectName}/ignition`),
"deployments",
"chain-31337"
);

describe("localhost deployment flag", function () {
useEphemeralIgnitionProject(fixtureProjectName);

beforeEach("clean filesystem", async function () {
// make sure nothing is left over from a previous test
removeSync(deploymentDir);
});
afterEach("clean filesystem", function () {
// cleanup
removeSync(deploymentDir);
});

it("true should write deployment to disk", async function () {
await this.hre.run(
{ scope: "ignition", task: "deploy" },
{
modulePath: "./ignition/modules/OwnModule.js",
writeLocalhostDeployment: true,
}
);

assert(
await pathExists(deploymentDir),
"Deployment was not written to disk"
);
});

it("false should not write deployment to disk", async function () {
await this.hre.run(
{ scope: "ignition", task: "deploy" },
{
modulePath: "./ignition/modules/OwnModule.js",
writeLocalhostDeployment: false,
}
);

assert(
!(await pathExists(deploymentDir)),
"Deployment was not written to disk"
);
});
});

0 comments on commit f77041e

Please sign in to comment.