diff --git a/packages/core/src/internal/utils/resolve-module-parameter.ts b/packages/core/src/internal/utils/resolve-module-parameter.ts index 0ff3cbff3..5d4959c0e 100644 --- a/packages/core/src/internal/utils/resolve-module-parameter.ts +++ b/packages/core/src/internal/utils/resolve-module-parameter.ts @@ -23,7 +23,8 @@ export function resolveModuleParameter( } const moduleParameters = - context.deploymentParameters[moduleParamRuntimeValue.moduleId]; + context.deploymentParameters[moduleParamRuntimeValue.moduleId] ?? + context.deploymentParameters.$global; if (moduleParameters === undefined) { assertIgnitionInvariant( diff --git a/packages/hardhat-plugin/test/module-parameters.ts b/packages/hardhat-plugin/test/module-parameters.ts index 076573f94..4b548bf7c 100644 --- a/packages/hardhat-plugin/test/module-parameters.ts +++ b/packages/hardhat-plugin/test/module-parameters.ts @@ -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"; @@ -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); + }); }); });