Skip to content

Commit

Permalink
add support for global module parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
zoeyTM committed Sep 30, 2024
1 parent 7be2762 commit 898572c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/internal/utils/resolve-module-parameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export function resolveModuleParameter(
}

const moduleParameters =
context.deploymentParameters[moduleParamRuntimeValue.moduleId];
context.deploymentParameters[moduleParamRuntimeValue.moduleId] ??
context.deploymentParameters.$global;

if (moduleParameters === undefined) {
assertIgnitionInvariant(
Expand Down
37 changes: 36 additions & 1 deletion packages/hardhat-plugin/test/module-parameters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable import/no-unused-modules */

import { buildModule } from "@nomicfoundation/ignition-core";
import { assert } from "chai";

import { useEphemeralIgnitionProject } from "./test-helpers/use-ignition-project";
Expand Down Expand Up @@ -93,5 +93,40 @@ describe("module parameters", () => {
/Parameter "unlockTime" exceeds maximum safe integer size. Encode the value as a string using bigint notation: `\${value}n`/
);
});

it("should use a global parameter", async function () {
const ignitionModule = buildModule("Test", (m) => {
const unlockTime = m.getParameter("unlockTime", 100);

const lock = m.contract("Lock", [unlockTime]);

return { lock };
});

const result = await this.hre.ignition.deploy(ignitionModule, {
parameters: { $global: { unlockTime: 1893499200000 } },
});

assert.equal(await result.lock.read.unlockTime(), 1893499200000);
});

it("should use a module parameter instead of a global parameter if both are present", async function () {
const ignitionModule = buildModule("Test", (m) => {
const unlockTime = m.getParameter("unlockTime", 100);

const lock = m.contract("Lock", [unlockTime]);

return { lock };
});

const result = await this.hre.ignition.deploy(ignitionModule, {
parameters: {
$global: { unlockTime: 1893499200000 },
Test: { unlockTime: 9876543210000 },
},
});

assert.equal(await result.lock.read.unlockTime(), 9876543210000);
});
});
});

0 comments on commit 898572c

Please sign in to comment.