hardhat icon indicating copy to clipboard operation
hardhat copied to clipboard

test hangs after entering keystore password (using configVariable + viem + Node)

Open kanej opened this issue 6 months ago • 1 comments

If you connect to a network that leverages a config variable in its config, the test will hang after requesting the password.

This is based on the following discussion:

Discussed in https://github.com/NomicFoundation/hardhat/discussions/6833

Originally posted by Henri-Guillet June 9, 2025 Hi, I'm using Hardhat v3 alpha with Viem and Node.js.

I'm using the integrated keystore feature in Hardhat 3 to protect my RPC URL. I resolve it in my config using:

configVariable("BASE_URL")

When I run a script, everything works as expected:

I'm prompted for the keystore password,

I enter it in the terminal,

the script runs and deploys successfully.

However, when I run a test, I also get prompted for the password, I enter it — but then the test hangs, stuck right after this line:

const { viem, ignition, networkHelpers } = await network.connect("baseFork");

If I hardcode the RPC URL directly in my config instead of using the keystore + configVariable, the test works fine.

Thanks in advance for your help!

kanej avatar Jun 10 '25 08:06 kanej

I have been able to reproduce this issue locally.

In hardhat.config.ts:

networks: {
    // ...
    sepolia: {
      type: "http",
      chainType: "l1",
      url: configVariable("SEPOLIA_RPC_URL"),
      accounts: [configVariable("SEPOLIA_PRIVATE_KEY")],
    },
    // ...
  },

Then in your node test runner test:

  // ...
  it("should not stall", async () => {
    // trigger the keystore interruption
    await network.connect("sepolia");

    // pass the test
    assert.equal(1, 1);
  });

Running the test:

> npx hardhat test node
Compiling your Solidity contracts
Compiled 1 Solidity file with solc 0.8.28 (evm target: cancun)

Running node:test tests

  Counter
    ✔ The sum of the Increment events should match the current value
[hardhat-keystore] Enter the password: My Password

Note: My password is appearing in the clear, which also an issue

kanej avatar Jun 10 '25 08:06 kanej

We have added a development keystore to allow storing config variables without needing a password. If you try and use a config variable when in tests (e.g. connecting to a network that uses a config variable for the url), you will get an error if it is not present in the development keystore. We stop you accessing the production encrypted keystore from tests.

kanej avatar Aug 07 '25 11:08 kanej