Open fvictorio opened 3 years ago
It also doesn't work in hardhat-ethers. Both node and in-process. Tests just hang until a timeout of 20sec is reached. Here is the code:
const { expect } = require("chai");
const { ethers } = require("hardhat");
describe("Greeter", function () {
it("Should return the new greeting once it's changed", async function () {
ethers.provider.send("evm_setAutomine", [false]);
ethers.provider.send("evm_setIntervalMining", [0]);
ethers.provider.send("evm_increaseTime", [60]);
ethers.provider.send("evm_mine");
const Greeter = await ethers.getContractFactory("Greeter");
const greeter = await Greeter.deploy("Hello, world!");
await greeter.deployed();
expect(await greeter.greet()).to.equal("Hello, world!");
const setGreetingTx = await greeter.setGreeting("Hola, mundo!");
// wait until the transaction is mined
await setGreetingTx.wait();
expect(await greeter.greet()).to.equal("Hola, mundo!");
ethers.provider.send("evm_increaseTime", [60]);
ethers.provider.send("evm_mine");
});
});
@Lopol2010 it's because you are doing await greeter.deployed();
after deploying the contract. That will wait until the deploy transaction is mined, but since you call evm_mine
after that, the test will hang forever.
@fvictorio thank you very much!
I also noticed that the same rule applies to wait()
function.
Given this script:
If you run
hh run script.js
, the output is1 1 0
, instead of the expected2 0 0
.If you start a node in another terminal and then do
hh run script.js --network localhost
, you do get the expected output.