Repository: NomicFoundation/hardhat-ignition (ts)

Issue:
Not displaying execution warnings
If a module is modified between deployments such that it no longer mentions a previously successful future, we generate a warning, but continue with the deployment.

That warning is not showing in the cli UI.

Pull request:
fix: reconciliation warnings (PR B)
Add the reconciliation warnings to the deploying panel.

Fixes #567

Patch:
diff --git a/packages/hardhat-plugin/src/ui/helpers/calculate-deploying-module-panel.ts b/packages/hardhat-plugin/src/ui/helpers/calculate-deploying-module-panel.ts
index 5066120a..84f03d8f 100644
--- a/packages/hardhat-plugin/src/ui/helpers/calculate-deploying-module-panel.ts
+++ b/packages/hardhat-plugin/src/ui/helpers/calculate-deploying-module-panel.ts
@@ -3,8 +3,22 @@ import chalk from "chalk";
 import { UiState } from "../types";
 
 export function calculateDeployingModulePanel(state: UiState): string {
-  return `Hardhat Ignition 🚀
+  let deployingMessage = `Hardhat Ignition 🚀
 
 ${chalk.bold(`Deploying [ ${state.moduleName ?? "unknown"} ]`)}
 `;
+
+  if (state.warnings.length > 0) {
+    deployingMessage += `\n${chalk.yellow(
+      "Warning - previously executed futures are not in the module:"
+    )}\n`;
+
+    deployingMessage += state.warnings
+      .map((futureId) => chalk.yellow(` - ${futureId}`))
+      .join("\n");
+
+    deployingMessage += "\n";
+  }
+
+  return deployingMessage;
 }


Test patch:
diff --git a/packages/hardhat-plugin/test/ui/helpers/calculate-batch-display.ts b/packages/hardhat-plugin/test/ui/helpers/calculate-batch-display.ts
index 289bc40d..7cd582cb 100644
--- a/packages/hardhat-plugin/test/ui/helpers/calculate-batch-display.ts
+++ b/packages/hardhat-plugin/test/ui/helpers/calculate-batch-display.ts
@@ -8,6 +8,8 @@ import {
   UiStateDeploymentStatus,
 } from "../../../src/ui/types";
 
+import { testFormat } from "./test-format";
+
 const exampleState: UiState = {
   status: UiStateDeploymentStatus.DEPLOYING,
   chainId: 31337,
@@ -21,10 +23,10 @@ const exampleState: UiState = {
 
 describe("ui - calculate batch display", () => {
   it("should render a batch with a single running future", () => {
-    const expectedText = testFormat`
+    const expectedText = testFormat(`
       Batch #1
         Executing ExampleModule#Token...
-    `;
+    `);
 
     assertBatchText(
       [
@@ -41,10 +43,10 @@ describe("ui - calculate batch display", () => {
   });
 
   it("should render a batch with a single completed future", () => {
-    const expectedText = testFormat`
+    const expectedText = testFormat(`
       Batch #1
         Executed ExampleModule#Token
-    `;
+    `);
 
     assertBatchText(
       [
@@ -61,10 +63,10 @@ describe("ui - calculate batch display", () => {
   });
 
   it("should render a batch with a single failed future", () => {
-    const expectedText = testFormat`
+    const expectedText = testFormat(`
       Batch #1
         Failed ExampleModule#Token
-    `;
+    `);
 
     assertBatchText(
       [
@@ -82,10 +84,10 @@ describe("ui - calculate batch display", () => {
   });
 
   it("should render a batch with a single held future", () => {
-    const expectedText = testFormat`
+    const expectedText = testFormat(`
       Batch #1
         Held ExampleModule#Token
-    `;
+    `);
 
     assertBatchText(
       [
@@ -104,13 +106,13 @@ describe("ui - calculate batch display", () => {
   });
 
   it("should render a complex batch in multiple states", () => {
-    const expectedText = testFormat`
+    const expectedText = testFormat(`
       Batch #1
         Failed ExampleModule#Dex
         Held ExampleModule#ENS
         Executed ExampleModule#Router
         Executing ExampleModule#Token...
-      `;
+      `);
 
     assertBatchText(
       [
@@ -161,12 +163,3 @@ function assertBatchText(
   assert.equal(height, expectedHeight);
   assert.equal(actualText, expectedText);
 }
-
-function testFormat(expected: TemplateStringsArray): string {
-  return expected
-    .toString()
-    .substring(1) // Remove the first newline
-    .split("\n")
-    .map((line) => line.substring(6)) // remove prefix whitespace
-    .join("\n");
-}
diff --git a/packages/hardhat-plugin/test/ui/helpers/calculate-deploying-module-panel-display.ts b/packages/hardhat-plugin/test/ui/helpers/calculate-deploying-module-panel-display.ts
new file mode 100644
index 00000000..a28b4c80
--- /dev/null
+++ b/packages/hardhat-plugin/test/ui/helpers/calculate-deploying-module-panel-display.ts
@@ -0,0 +1,58 @@
+import { assert } from "chai";
+import chalk from "chalk";
+
+import { calculateDeployingModulePanel } from "../../../src/ui/helpers/calculate-deploying-module-panel";
+import { UiState, UiStateDeploymentStatus } from "../../../src/ui/types";
+
+import { testFormat } from "./test-format";
+
+describe("ui - calculate starting message display", () => {
+  const exampleState: UiState = {
+    status: UiStateDeploymentStatus.UNSTARTED,
+    chainId: 31337,
+    moduleName: "ExampleModule",
+    deploymentDir: "/users/example",
+    batches: [],
+    currentBatch: 0,
+    result: null,
+    warnings: [],
+  };
+
+  it("should display the deploying module message", () => {
+    const expectedText = testFormat(`
+    Hardhat Ignition 🚀
+
+    ${chalk.bold(`Deploying [ ExampleModule ]`)}
+    `);
+
+    const actualText = calculateDeployingModulePanel(exampleState);
+
+    assert.equal(actualText, expectedText);
+  });
+
+  it("should display reconciliation warnings", () => {
+    const expectedText = testFormat(`
+    Hardhat Ignition 🚀
+
+    ${chalk.bold(`Deploying [ ExampleModule ]`)}
+
+    ${chalk.yellow(
+      "Warning - previously executed futures are not in the module:"
+    )}
+    ${chalk.yellow(" - MyModule#Contract1")}
+    ${chalk.yellow(" - MyModule#Contract1.call1")}
+    ${chalk.yellow(" - MyModule#Contract2")}
+    `);
+
+    const actualText = calculateDeployingModulePanel({
+      ...exampleState,
+      warnings: [
+        "MyModule#Contract1",
+        "MyModule#Contract1.call1",
+        "MyModule#Contract2",
+      ],
+    });
+
+    assert.equal(actualText, expectedText);
+  });
+});
diff --git a/packages/hardhat-plugin/test/ui/helpers/calculate-deployment-complete-display.ts b/packages/hardhat-plugin/test/ui/helpers/calculate-deployment-complete-display.ts
index 5109cb8b..38c5df8c 100644
--- a/packages/hardhat-plugin/test/ui/helpers/calculate-deployment-complete-display.ts
+++ b/packages/hardhat-plugin/test/ui/helpers/calculate-deployment-complete-display.ts
@@ -12,6 +12,8 @@ import chalk from "chalk";
 
 import { calculateDeploymentCompleteDisplay } from "../../../src/ui/helpers/calculate-deployment-complete-display";
 
+import { testFormat } from "./test-format";
+
 describe("ui - calculate deployment complete display", () => {
   const exampleAddress = "0x1F98431c8aD98523631AE4a59f267346ea31F984";
   const differentAddress = "0x0011223344556677889900112233445566778899";
@@ -256,12 +258,3 @@ describe("ui - calculate deployment complete display", () => {
     });
   });
 });
-
-function testFormat(expected: string): string {
-  return expected
-    .toString()
-    .substring(1) // Remove the first newline
-    .split("\n")
-    .map((line) => line.substring(8)) // remove prefix whitespace
-    .join("\n");
-}
diff --git a/packages/hardhat-plugin/test/ui/helpers/calculate-deployment-status-display.ts b/packages/hardhat-plugin/test/ui/helpers/calculate-deployment-status-display.ts
index e366de0e..259a8492 100644
--- a/packages/hardhat-plugin/test/ui/helpers/calculate-deployment-status-display.ts
+++ b/packages/hardhat-plugin/test/ui/helpers/calculate-deployment-status-display.ts
@@ -4,6 +4,8 @@ import chalk from "chalk";
 
 import { calculateDeploymentStatusDisplay } from "../../../src/ui/helpers/calculate-deployment-status-display";
 
+import { testFormat } from "./test-format";
+
 describe("ui - calculate deployment status display", () => {
   const exampleAddress = "0x1F98431c8aD98523631AE4a59f267346ea31F984";
   const differentAddress = "0x0011223344556677889900112233445566778899";
@@ -172,12 +174,3 @@ describe("ui - calculate deployment status display", () => {
     });
   });
 });
-
-function testFormat(expected: string): string {
-  return expected
-    .toString()
-    .substring(1) // Remove the first newline
-    .split("\n")
-    .map((line) => line.substring(8)) // remove prefix whitespace
-    .join("\n");
-}
diff --git a/packages/hardhat-plugin/test/ui/helpers/test-format.ts b/packages/hardhat-plugin/test/ui/helpers/test-format.ts
new file mode 100644
index 00000000..6bc238a4
--- /dev/null
+++ b/packages/hardhat-plugin/test/ui/helpers/test-format.ts
@@ -0,0 +1,18 @@
+/**
+ * Formats a multiline string to make appear closer to the command line
+ * when inside a test file. The first line is ignored, and the whitespace
+ * at the start of the line is removed.
+ */
+export function testFormat(expected: string): string {
+  const lines = expected
+    .toString()
+    .substring(1) // Remove the first newline
+    .split("\n");
+
+  // calcualte the length of the whitespace prefix based on the first line
+  const whitespacePrefixLength = lines[0].search(/\S/);
+
+  return lines
+    .map((line) => line.substring(whitespacePrefixLength)) // strip prefix whitespace
+    .join("\n");
+}