So as the title suggested i tested a smart contract (ERC721) but the the test wont pass. I am using hardhat environment for testing, that is hardhat-waffle and chai library. Here is the smart contract and the testing script

// SPDX-License-Identifier: MIT
    pragma solidity ^0.8.4;

    import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
    import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
    import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
    import "@openzeppelin/contracts/access/Ownable.sol";
    import "@openzeppelin/contracts/utils/Counters.sol";

contract Depression is ERC721, ERC721Enumerable, ERC721URIStorage, Ownable {
using Counters for Counters.Counter;

Counters.Counter private _tokenIdCounter;

constructor() ERC721("Depression", "DEP") {}

function safeMint(address to, string memory uri) public onlyOwner {
    uint256 tokenId = _tokenIdCounter.current();
    _safeMint(to, tokenId);
    _setTokenURI(tokenId, uri);

// The following functions are overrides required by Solidity.

function _beforeTokenTransfer(address from, address to, uint256 tokenId)
    override(ERC721, ERC721Enumerable)
    super._beforeTokenTransfer(from, to, tokenId);

function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) {

function tokenURI(uint256 tokenId)
    override(ERC721, ERC721URIStorage)
    returns (string memory)
    return super.tokenURI(tokenId);

function supportsInterface(bytes4 interfaceId)
    override(ERC721, ERC721Enumerable)
    returns (bool)
    return super.supportsInterface(interfaceId);

and here is the script for testing

import { ethers } from "hardhat";
import chai from "chai";
import { solidity } from "ethereum-waffle";
import { Depression__factory, Depression } from "../typechain";

const { expect } = chai;
tokenAddress: string = "0xb962471ea0ff5db1d775374f8af342267326fbdc";

describe("Unit Test", () => {
it("VotingNFTContract", async () => {
try {
  const [deployer] = await ethers.getSigners();

  const tokenInstance = new Depression__factory(deployer).attach(tokenAddress);
  // const toMint = ethers.utils.parseEther("1");
  const toAddress = await deployer.getAddress();
  const beforeAmount = await tokenInstance.balanceOf(toAddress);
  const beforeAmountNumber = beforeAmount.toNumber()
  const tx = await tokenInstance.safeMint(toAddress, "http://localhost/api/token/");
  await tx.wait();
  const afterAmount = await tokenInstance.balanceOf(toAddress);
  const afterAmountNumber = afterAmount.toNumber();
  console.log("zap test", beforeAmount.toNumber(), afterAmount.toNumber());
} catch (error) {
  console.log("Error VotingNFT Deploy", error);

Heres the result of the test

$ yarn test
yarn run v1.22.5
npx hardhat test
No need to generate any newer typings.

Unit Test
  zap test 29 30
  Error: connect ETIMEDOUT
  Error: connect ETIMEDOUT

1) VotingNFTContract
Done in 115.79s.

I already use async await for the asynchronous function like balanceOf, and even already got the values in the console.log that i put, but somehow the expect block wont accept the values and then the test timedout. Any idea what i did wrong here?

1 Answer 1


Turns out its because of the gas reporter package that i enabled, when i disable it, the test run successfully.

Your Answer

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

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