Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use readline in place of process.stdout #654

Merged
merged 5 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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,
},
},
},
};
Original file line number Diff line number Diff line change
@@ -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 };
});
23 changes: 23 additions & 0 deletions packages/core/test-integrations/new-api/ci/basic-success.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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("Running deployment in CI environment", function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done on the test.

this.timeout(60000);

useHardhatProject("ci-success");

it("should succeed with UI in a CI environment", async function () {
await assert.isFulfilled(
this.hre.run(
{ scope: "ignition", task: "deploy" },
{
modulePath: "./ignition/modules/LockModule.js",
}
)
);
});
});
9 changes: 5 additions & 4 deletions packages/hardhat-plugin/src/ui/pretty-event-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion packages/hardhat-plugin/test/deploy/default-sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading