From 5b0c5961562a9645ea5e80c768e08c8735ddae8a Mon Sep 17 00:00:00 2001 From: zoeyTM Date: Tue, 12 Dec 2023 21:44:51 -0500 Subject: [PATCH 1/5] use readline in place of process.stdout --- packages/hardhat-plugin/src/ui/pretty-event-handler.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/hardhat-plugin/src/ui/pretty-event-handler.ts b/packages/hardhat-plugin/src/ui/pretty-event-handler.ts index 6def3977b..f3f98ffea 100644 --- a/packages/hardhat-plugin/src/ui/pretty-event-handler.ts +++ b/packages/hardhat-plugin/src/ui/pretty-event-handler.ts @@ -33,6 +33,7 @@ import { TransactionSendEvent, WipeApplyEvent, } from "@nomicfoundation/ignition-core"; +import readline from "readline"; import { calculateBatchDisplay } from "./helpers/calculate-batch-display"; import { calculateDeployingModulePanel } from "./helpers/calculate-deploying-module-panel"; @@ -452,12 +453,12 @@ export class PrettyEventHandler implements ExecutionEventListener { } private _clearCurrentLine(): void { - process.stdout.clearLine(0); - process.stdout.cursorTo(0); + readline.clearLine(process.stdout, 0); + readline.cursorTo(process.stdout, 0); } private _clearUpToHeight(height: number) { - process.stdout.moveCursor(0, -height); - process.stdout.clearScreenDown(); + readline.moveCursor(process.stdout, 0, -height); + readline.clearScreenDown(process.stdout); } } From 1a9d5eba13fc7fe72fb8d945d371452e183d9c82 Mon Sep 17 00:00:00 2001 From: zoeyTM Date: Tue, 12 Dec 2023 23:21:08 -0500 Subject: [PATCH 2/5] add test for CI deployment --- .../ci-success/contracts/Lock.sol | 34 +++++++++++++++++++ .../ci-success/hardhat.config.js | 14 ++++++++ .../ci-success/ignition/modules/LockModule.js | 18 ++++++++++ .../new-api/ci/basic-success.ts | 22 ++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 packages/core/test-integrations/fixture-projects/ci-success/contracts/Lock.sol create mode 100644 packages/core/test-integrations/fixture-projects/ci-success/hardhat.config.js create mode 100644 packages/core/test-integrations/fixture-projects/ci-success/ignition/modules/LockModule.js create mode 100644 packages/core/test-integrations/new-api/ci/basic-success.ts diff --git a/packages/core/test-integrations/fixture-projects/ci-success/contracts/Lock.sol b/packages/core/test-integrations/fixture-projects/ci-success/contracts/Lock.sol new file mode 100644 index 000000000..9e0e189d9 --- /dev/null +++ b/packages/core/test-integrations/fixture-projects/ci-success/contracts/Lock.sol @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.9; + +// Uncomment this line to use console.log +// import "hardhat/console.sol"; + +contract Lock { + uint public unlockTime; + address payable public owner; + + event Withdrawal(uint amount, uint when); + + constructor(uint _unlockTime) payable { + require( + block.timestamp < _unlockTime, + "Unlock time should be in the future" + ); + + unlockTime = _unlockTime; + owner = payable(msg.sender); + } + + function withdraw() public { + // Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal + // console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp); + + require(block.timestamp >= unlockTime, "You can't withdraw yet"); + require(msg.sender == owner, "You aren't the owner"); + + emit Withdrawal(address(this).balance, block.timestamp); + + owner.transfer(address(this).balance); + } +} diff --git a/packages/core/test-integrations/fixture-projects/ci-success/hardhat.config.js b/packages/core/test-integrations/fixture-projects/ci-success/hardhat.config.js new file mode 100644 index 000000000..c76e2c9b8 --- /dev/null +++ b/packages/core/test-integrations/fixture-projects/ci-success/hardhat.config.js @@ -0,0 +1,14 @@ +require("@nomicfoundation/hardhat-ignition"); + +/** @type import('hardhat/config').HardhatUserConfig */ +module.exports = { + solidity: { + version: "0.8.19", + settings: { + metadata: { + // We disable the metadata to keep the fixtures more stables + appendCBOR: false, + }, + }, + }, +}; diff --git a/packages/core/test-integrations/fixture-projects/ci-success/ignition/modules/LockModule.js b/packages/core/test-integrations/fixture-projects/ci-success/ignition/modules/LockModule.js new file mode 100644 index 000000000..fca85a0ce --- /dev/null +++ b/packages/core/test-integrations/fixture-projects/ci-success/ignition/modules/LockModule.js @@ -0,0 +1,18 @@ +const { buildModule } = require("@nomicfoundation/hardhat-ignition/modules"); + +const currentTimestampInSeconds = Math.round(new Date(2023, 0, 1) / 1000); +const TEN_YEAR_IN_SECS = 10 * 365 * 24 * 60 * 60; +const TEN_YEARS_IN_FUTURE = currentTimestampInSeconds + TEN_YEAR_IN_SECS; + +const ONE_GWEI = 1_000_000_000n; + +module.exports = buildModule("LockModule", (m) => { + const unlockTime = m.getParameter("unlockTime", TEN_YEARS_IN_FUTURE); + const lockedAmount = m.getParameter("lockedAmount", ONE_GWEI); + + const lock = m.contract("Lock", [unlockTime], { + value: lockedAmount, + }); + + return { lock }; +}); diff --git a/packages/core/test-integrations/new-api/ci/basic-success.ts b/packages/core/test-integrations/new-api/ci/basic-success.ts new file mode 100644 index 000000000..7f4db9366 --- /dev/null +++ b/packages/core/test-integrations/new-api/ci/basic-success.ts @@ -0,0 +1,22 @@ +import { assert } from "chai"; + +import { useHardhatProject } from "../../helpers/hardhat-projects"; + +// This test exists to ensure Ignition succeeds in a CI environment. +// It should always pass locally. +describe("CI - basic success case", function () { + this.timeout(60000); + + useHardhatProject("ci-success"); + + it("should succeed in a CI environment", async function () { + await assert.isFulfilled( + this.hre.run( + { scope: "ignition", task: "deploy" }, + { + modulePath: "./ignition/modules/LockModule.js", + } + ) + ); + }); +}); From b03e0e660d5936a49b30242d4ca829a1be67df2d Mon Sep 17 00:00:00 2001 From: zoeyTM Date: Tue, 12 Dec 2023 23:28:35 -0500 Subject: [PATCH 3/5] remove redundant CI task --- .github/workflows/ci.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab5d8db55..760e09edc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,9 +23,6 @@ jobs: run: npm run build - name: Run tests run: npm run test - - name: Run integration tests - working-directory: packages/core - run: npm run test:integrations - name: Run tests in examples run: npm run test:examples @@ -44,9 +41,6 @@ jobs: run: npm run build - name: Run tests run: npm run test - - name: Run integration tests - working-directory: packages/core - run: npm run test:integrations - name: Run tests in examples run: npm run test:examples @@ -68,9 +62,6 @@ jobs: run: npm run build - name: Run tests run: npm run test - - name: Run integration tests - working-directory: packages/core - run: npm run test:integrations - name: Run tests in examples run: npm run test:examples From 9c6a4596fad6c1d99294010ea946d7ad52881cbd Mon Sep 17 00:00:00 2001 From: John Kane Date: Fri, 15 Dec 2023 15:51:40 +0000 Subject: [PATCH 4/5] test: bring back skipped test Bring back the default sender test that previously failed due to tty issues. --- packages/hardhat-plugin/test/deploy/default-sender.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/hardhat-plugin/test/deploy/default-sender.ts b/packages/hardhat-plugin/test/deploy/default-sender.ts index b623afb3c..6247eb7e7 100644 --- a/packages/hardhat-plugin/test/deploy/default-sender.ts +++ b/packages/hardhat-plugin/test/deploy/default-sender.ts @@ -20,7 +20,7 @@ describe("default sender", function () { ); }); - it.skip("should allow setting default sender via cli", async function () { + it("should allow setting default sender via cli", async function () { const secondAccountAddress = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8"; await this.hre.run( From d7ebcba854437e3b7749c86fdd92face21adddf5 Mon Sep 17 00:00:00 2001 From: John Kane Date: Fri, 15 Dec 2023 16:25:19 +0000 Subject: [PATCH 5/5] test: update test text --- packages/core/test-integrations/new-api/ci/basic-success.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/core/test-integrations/new-api/ci/basic-success.ts b/packages/core/test-integrations/new-api/ci/basic-success.ts index 7f4db9366..245fb2a52 100644 --- a/packages/core/test-integrations/new-api/ci/basic-success.ts +++ b/packages/core/test-integrations/new-api/ci/basic-success.ts @@ -3,13 +3,14 @@ import { assert } from "chai"; import { useHardhatProject } from "../../helpers/hardhat-projects"; // This test exists to ensure Ignition succeeds in a CI environment. +// This is a test that the UI, runs even in constrained terminal environments. // It should always pass locally. -describe("CI - basic success case", function () { +describe("Running deployment in CI environment", function () { this.timeout(60000); useHardhatProject("ci-success"); - it("should succeed in a CI environment", async function () { + it("should succeed with UI in a CI environment", async function () { await assert.isFulfilled( this.hre.run( { scope: "ignition", task: "deploy" },