Skip to main content
10 votes
Accepted

I am running my tests in the hardhat environment but it gives me 0 passing all the time

This can happen if await ethers.getSigners() is executed in describe clause. Example that doesn't work (0 passing): describe("ContractName", async () => { await ethers.getSigners() ...
Kof's user avatar
  • 2,993
10 votes
Accepted

Followed hardhat test tutorial and got "TypeError: (0 , ethers_1.getAddress) is not a function" error

Nomic foundation released a new version of hardhat (2.15.0) Try: npm install -g yarn yarn add --dev hardhat @nomiclabs/hardhat-ethers@npm:hardhat-deploy-ethers ethers which will force update the ...
Szymon Ligas's user avatar
8 votes
Accepted

Transaction reverted: trying to deploy a contract whose code is too large

In this case, the problem was the mal-formed hardhat.config.js file. Here is what should solve the problem: module.exports = { solidity: { version: "0.8.9", settings: { ...
Jean-François Beaulieu's user avatar
6 votes
Accepted

Property 'revertedWith' does not exist on type 'Assertion'

Pre June 2022 You need to also add ethereum-waffle to your package, not just the nomiclabs one @nomiclabs/hardhat-waffle. you need both yarn add --dev ethereum-waffle you just only need to install ...
Patrick Collins's user avatar
5 votes
Accepted

unit testing with chai : is there a way to simulate or force a failed transaction?

minimal code to implement Lauri's suggestion Target.sol (contract being tested) pragma solidity ^0.8.10; contract Target { address payable owner; constructor () { owner = payable(...
sola24's user avatar
  • 1,248
5 votes
Accepted

Comparing ethers BigNumber does not work

Try like this : expect(totalSupply.eq(BigNumber.from("4")).to.equal(true); This is because to.equal internally uses the strict equality check === which on Objects only returns true if the ...
hroussille's user avatar
  • 7,841
4 votes

Smart Contract Testing - ethereum-waffle expect function

The await keyword blocks continuation of execution until a promise has been resolved (or rejected, which throws an Error). This is nothing specific to waffle, it's a feature of modern JavaScript and ...
patrickd's user avatar
4 votes

Property 'revertedWith' does not exist on type 'Assertion'

Hardhat has released a new package named hardhat-toolbox to replace hardhat-waffle. Install it with npm install --save-dev @nomicfoundation/hardhat-toolbox and then import it in your hardhat.config.js ...
Antonio U's user avatar
  • 649
3 votes

solidity function functionCall from openzeppelin-contracts-accounts reverted

i was able to solve this. the issue was functionCall requires a bytes String of an function. So here i was in need of approve function byte string. bytes memory data = abi.encodeWithSignature( ...
Tanjin Alam's user avatar
3 votes

Property 'revertedWith' does not exist on type 'Assertion'

I was experiencing this issue as well and most online help weren't addressing the underlying cause. You also have to add the following to your test files to use event emitters from chai matchers: ...
Damilola Fagoyinbo's user avatar
3 votes
Accepted

Why are there so many async and await in smart contract tests?

Not only on smart contract tests, but in Javascript and Nodejs, in general, is common to find many async/await function calls. The Javascript is single-threaded. So, how do you get this sense of ...
Jeremy Then's user avatar
  • 4,629
2 votes
Accepted

How to test a function which calls another contract from inside the function?

I'm assuming your question is "How do I interact with the deployed 'newToken' contract created in 'createContract.create'?". I haven't used truffle before, so the following code is untested. ...
phaze's user avatar
  • 1,625
2 votes

How test uint from smartcontract with chai?

Self answer : expect(parseInt(amountForSpenderBeforeWithdraw)).to.be.greaterThan(parseInt(amountForSpenderAfterWithdraw));
Xstahef's user avatar
  • 157
2 votes

I am running my tests in the hardhat environment but it gives me 0 passing all the time

once upon a time, i wrote this, it should be "it", but i wrote "if". no error, just tip "0 passing", describe("Token contract", function () { if("...
michael wang's user avatar
2 votes
Accepted

Convert big number to number on hardhat tests

You're getting an overflow error, because javascript can't represent this number with enough accuracy. Even if you were able to convert it to a number, comparing it with any other would not be ...
phaze's user avatar
  • 1,625
2 votes

npm throw errors when installing dependencies of hardhat

Hardhat migrated waffle plugin to the chai detailed info here https://hardhat.org/hardhat-runner/docs/guides/migrating-from-hardhat-waffle#migrating-away-from-hardhat-waffle
s3f4's user avatar
  • 21
2 votes

Hardhat test is not working

Your beforEach(async function () is missing an "e" at the end of before Should be beforeEach(async function ()
Maah's user avatar
  • 21
2 votes
Accepted

How to use variables set inside a beforeEach with hardhat testing

You have defined local constant called owner, but haven't assigned the global owner value. Just remove the const from beforeEach action and you should have access to globally defined owner: ...
OneThunder's user avatar
2 votes
Accepted

Encountering difficulties while writing tests with .connect(notDeployer)

You should connect to a signer, not an address. accounts = await ethers.getSigners() await LPR.connect(accounts[1]).gift(someAddress)
always_beta's user avatar
2 votes

revertedWith not matched error message

I ran into a very similar error as this, and after a lot of searching, this discussion proved helpful to me, specifically this comment here The important bit is that apparently BigNumbers matchers use ...
agrippa's user avatar
  • 121
2 votes

hardhat: want to test an emit event that is in a library

When you have a contract that emits an event in an underlying library instead of the contract itself, since the contract doesn't contain the ABI of the event you probably face this error: ...
Mahdi Darabi's user avatar
2 votes
Accepted

What is a good way to learn Solidity?

Solidity isn't really a hard language to learn if you know basic programming concepts. There are multiple places that are teaching solidity and it is hard to say which is the best place. So I will ...
Ad-h0c's user avatar
  • 978
2 votes

How to get the gas costs of a reversed transaction when testing (with Chai / ethers.js / Hardhat)?

I've figured out a way to do this, althought I wonder if there isn't an easier way. // Get latest transaction hash const latestBlock = await ethers.provider.getBlock("latest"); ...
Rik Schoonbeek's user avatar
2 votes

Transaction reverted: trying to deploy a contract whose code is too large

This one is hard to answer without the smart contract code. I guess the compiled bytecode is too large (e.g. 24kb limit in ETH), You may try to use optimizer when compiling: https://hardhat.org/...
minhhn2910's user avatar
  • 1,820
2 votes

Transaction reverted: trying to deploy a contract whose code is too large

Sometimes, it could also be that the contract costs more gas than the limit you set on it, I had a similar problem and I got over it by removing the gas limit and deploying on a local node checking ...
Leslie Douglas's user avatar
2 votes
Accepted

How to work with block timestamps in ethers and hardhat?

I think the first require statement fails, because you are passing the blockTimestamp value to the launch function as startAt. Try to test the condition where the campaign is too short by adding a few ...
timsntech's user avatar
  • 648
2 votes

How to write test cases for custom errors?

What error is it? I tried it by myself and see the error Invalid Chai property: revertedWithCustomError. Did you try to change revertedWithCustomError => revertedWith like below? it("Should ...
CT95's user avatar
  • 503
1 vote

Encountering difficulties while writing tests with .connect(notDeployer)

According to ethersjs docs: A Signer in ethers is an abstraction of an Ethereum Account, which can be used to sign messages and transactions and send signed transactions to the Ethereum Network to ...
0xAnon's user avatar
  • 174
1 vote

Encountering difficulties while writing tests with .connect(notDeployer)

well do this way here we are connecting addr1 and gifting to addr2 const connectacc2 = await LPR.connect(addr1.address).gift(addr2.address);
DereK's user avatar
  • 294
1 vote

How to Properly Unit Test onlyOwner

The await keyword is at the wrong place. Replace this part: await expect(token721 .connect(account1.address) .mint(account1.address, TEST_URI1)) .to.be.rejectedWith("...
Merunas Grincalaitis's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible