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

changeEtherBalance() just passes the test with any value #5583

Closed
gkfyr opened this issue Aug 8, 2024 · 1 comment
Closed

changeEtherBalance() just passes the test with any value #5583

gkfyr opened this issue Aug 8, 2024 · 1 comment
Assignees

Comments

@gkfyr
Copy link

gkfyr commented Aug 8, 2024

Version of Hardhat

2.22.7, 2.12.5, 2.20.1

What happened?

Hi! I'm working out in my hardhat test codes, using hardhat-chai-matchers
but i found the test case just passes with any value if u use changeEtherBalance() even it is empty inside.
if u using changeEtherBalance(), it passes the it() case with any value or none in expect() too.

If u need more detail about this case, I'll gladly help!
Thanks :)

Minimal reproduction steps

make any test file in the test directory, and run it with npx hardhat test test/[filename].test.js

even it appear same in hardhat-boilerplate clone too! https://github.com/NomicFoundation/hardhat-boilerplate

u can see it even passes the test if u put anything or nothing both expect() and changeEtherBalance().

const { expect } = require("chai");

describe("changeEtherBalance check", function () {
  it("any value", async function () {
    expect().to.changeEtherBalance();
  });
});

Search terms

changeEtherBalance

@fvictorio fvictorio added this to Hardhat Aug 8, 2024
@github-project-automation github-project-automation bot moved this to Backlog in Hardhat Aug 8, 2024
@gkfyr gkfyr changed the title changeEtherBalance() just passes the test with any value changeEtherBalance() just passes the test with any value Aug 8, 2024
@ChristopherDedominici
Copy link
Contributor

Hi @gkfyr, I reviewed your code and noticed the issue:
the test is passing because the code isn't waiting for the execution to complete. The expect().to.changeEtherBalance() function is asynchronous, so it needs to be awaited.
If you modify the code to include await, like this:
await expect().to.changeEtherBalance()
the test will fail as expected.

Without await, the execution finishes before the changeEtherBalance function is executed, resulting in a false positive.

@github-project-automation github-project-automation bot moved this from Backlog to Done in Hardhat Aug 26, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests

2 participants