0

I want to check if the ether balance of an account decreased after the transaction using changeEtherBalance I tried to follow the waffle docs but couldn't do it either.

        await token.connect(addr1).mint(1, {value: ethers.utils.parseEther("0.1")}))
        .to.changeEtherBalance(addr1, -(ethers.utils.parseEther("0.1"))
        );

Error:

Error: overflow (fault="overflow", operation="BigNumber.from", value=-100000000000000000, code=NUMERIC_FAULT, version=bignumber/5.5.0)

2 Answers 2

0

You can see more information here. Basically you should send the recipient and the amount:

await expect(() => wallet.sendTransaction({to: walletTo.address, value: 200}))
  .to.changeEtherBalance(walletTo, 200);
3
  • But I want to check the new balance of the wallet that sent the value, so the result is going to be less than the original one.
    – n3n3
    Nov 28, 2021 at 20:54
  • Then I dont think changeEtherBalance is what you need to use, you need another validation thats checks the new balance and compares it with the previous one
    – Julissa DC
    Nov 29, 2021 at 1:45
  • I know I can do it by simply using ethers.provider.getBalance(address), but really wanted to try using this method. Thanks anyway :)
    – n3n3
    Nov 29, 2021 at 9:10
0

I just found what I should have done, it's pretty simple:

await token.connect(addr1).mint(1, {value: ethers.utils.parseEther("0.1")}))
        .to.changeEtherBalance(addr1, ethers.utils.parseEther("-0.1"));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.