Questions tagged [chai]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
0 answers
16 views

Hardhat doesn't recognize custom errors from inherited Contracts

I am trying to test TimelockController contract from Openzeppelin using their test. The timelockController imports Address.sol, which has a custom Error called FailedCall. Now for my case, I have ...
Zartaj Afser's user avatar
  • 3,709
0 votes
1 answer
23 views

I met an issue when I tried to test my smart contract, which is :AssertionError: expected undefined to equal 17

This is smart contract. // SPDX-License-Identifier: MIT pragma solidity ^0.8.7; contract SimpleStorage { uint256 favoriteNumber; Person public person = Person({favoriteNumber: 2, name: "...
rocco zha's user avatar
2 votes
1 answer
70 views

TypeError in Hardhat-Chai Matchers - isAddress not a function

I'm encountering a TypeError in my Hardhat test script that involves the isAddress function from the @nomicfoundation/hardhat-chai-matchers library. The error seems to be causing issues with my test ...
Aung's user avatar
  • 21
1 vote
0 answers
14 views

How can I call a function from another contract with it's reference | TypeError: contract.functionName is not a function

I've two smart contracts in my hardhat environment, really small. They are given below: contract Parent { Child[] public domainRegistries; function createChild() public returns (Child) { ...
Maifee Ul Asad's user avatar
0 votes
1 answer
40 views

How to advance blocks in a Hardhat test that uses block.timestamp?

I have this code for a Voting smart contract test: it("Should return true if end time is less than the current timestamp", async function () { const { votingSmartContract } = await ...
Falcon Stakepool's user avatar
0 votes
1 answer
120 views

ethers.utils.solidityKeccak256 in hardhat test file

Here is a test file. ethers.getSigners() works fine ethers.deployContract() works fine for some reason, ethers.utils.solidityKeccak256 keeps breaking the code with this error: ' TypeError: Cannot read ...
Jesse Jacob's user avatar
2 votes
1 answer
235 views

TypeError: Cannot read properties of undefined (reading 'checkUpkeep')

i'm getting this error while testing patrick collins smart-contract-lottery project, below is the part where the error coming from. describe("checkUpkeep", async function () { ...
Gautam's user avatar
  • 33
-1 votes
1 answer
16 views

All my Assert.isTrue testing seems to be passing, im a bit skeptical about how efficient it's to test with asert.isTrue and assert.isFalse [closed]

Is Assert.isTrue efficient for testing solidity functions, all my testing are passing and I'm a bit skeptical about its efficiency.
Santos's user avatar
  • 17
0 votes
1 answer
29 views

When I run the yarn hardhat test the console only shows 0passing(0ms) and the test didn't run

When I run the yarn hardhat test the console only shows 0passing(0ms), which means the test didn't run. const { assert, expect } = require("chai") const { ethers, deployments, ...
hugr kai's user avatar
0 votes
0 answers
22 views

logging events while testing

In Current Version of ethers v6 ., once the event is emitted how we should log them ., because the older method of logging from transaction receipt is not working " for example this is my ...
jeevan siddu's user avatar
1 vote
0 answers
350 views

Cannot solve Error: Invalid Chai property: revertedWith

I am trying to run a test on my contract using hardhat and chai. But I am running into this error. I have tried install ethereum-waffle. But it did not solve the problem. I also added ethereum-waffle ...
Samarth Bagga's user avatar
4 votes
4 answers
7k views

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

I follow the simple tutorial by hardhat here https://hardhat.org/hardhat-runner/docs/other-guides/waffle-testing by creating Greeter.sol and test/test.js. This leads to the following error: 1) ...
Justin Zhang's user avatar
0 votes
0 answers
27 views

Inheritance between contracts

I have a ZombieFactory contract which has a public array, I have another ZombieFeeding contract which inherits from ZombieFactory and I want to display the value of the zombies array defined and ...
VBO's user avatar
  • 1
1 vote
1 answer
321 views

Testing for success (no revert) in Hardhat

I'm using hardhat with mocha and chai to write tests for a contract. I'm trying to write a test that will expect a function call to be successful (not to revert); the function does not emit any events....
Origin's user avatar
  • 133
0 votes
1 answer
41 views

How to assert that a BigNumber is included in a list of numbers?

I am trying to assert a uint256 the following way: expect(tokenType).to.be.oneOf([1, 2, 3, 4]); I just want to check that its value is any of the ones on that list, as I am using a ...
Falcon Stakepool's user avatar
2 votes
0 answers
94 views

Can not sign transaction with signer get from mnemonic

I'm writing test for MAX_SUPPLY of this function // contract.sol function mintStandard() public payable whenNotPaused { require( _standardCounter.current() <= 2222, &...
dtnwen's user avatar
  • 33
0 votes
1 answer
52 views

How to you write tests for the transferFrom function for my ICO contract?

I want to write a test for the transferFrom(). I'm doing it by checking that the address balances change after the function is called. When I run the test, I get the error below. It's caused by the ...
kihiuFrank's user avatar
1 vote
1 answer
449 views

How can i pass constructor args to test solidity contracts in Hardhat?

I am using openzepplin with role based access control to create erc-20 token constructor(address minter, address burner) ERC20("ArtPlace Token", "ARTP") { _mint(msg.sender, ...
Ri dev's user avatar
  • 11
0 votes
2 answers
81 views

How do I test burning tokens in my ICO contract?

I'm writing tests for the burn func in ICO.sol The first two tests are passing, but when I come to test where the tokens are indeed burned, the state of the ICO seems to change. To burn tokens, the ...
kihiuFrank's user avatar
0 votes
0 answers
83 views

Mocha Tests unexpected error

My tests where running well but not when I run yarn hardhat test, I get the error below. Error An unexpected error occurred: TypeError: describe is not a function at Object.<anonymous> (/...
kihiuFrank's user avatar
2 votes
1 answer
207 views

AssertionError: expected BigNumber { value: "0" } to equal BigNumber { value: "0" }

I have created two basic ERC20 tokens (TokenA and TokenB) and a contract that swaps TokenA with TokenB. Everything seems working but I get the error above when I run the test file. How can BigNumber { ...
Claudio's user avatar
  • 35
0 votes
1 answer
112 views

Hardhat Chai expect to.be.reverted fails on reversion

I have a basic ERC contract with the user deployer that is owner and only has rights to mint. The mint function has an "onlyOwner" modifier with no message sent when reversion is triggered ...
Gnostication's user avatar
1 vote
1 answer
69 views

Hardhat deploys contract to 2 different contract addresses while deploying uniswap clone

I am learning about writing tests with Hard Hat and using fixtures, but I am having the strangest issue when deploying a uniswap clone. My deployWETH fixture consistently returns the same contract ...
Jared Hodgkins's user avatar
3 votes
1 answer
141 views

How to write test cases for custom errors?

I have a smart contract here that have mints NFTs and claim reward functions, and I have used custom errors instead of require error stakeNotOver(); function claimReward(uint256 stakeId) external ...
Talha Sajid Chaudhary's user avatar
1 vote
0 answers
168 views

What is the right typescript type for an event?

Not sure if this the right place thus my question involves more contract testing than solidity but here we go: I implemented a contract factory and spent a couple of hours figuring out how to check if ...
onizukaek's user avatar
  • 111
0 votes
2 answers
378 views

Error: Timeout of 40000ms exceeded

I'm running a test using hardhat and chai. I keep getting this error: Error: Timeout of 40000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure ...
Ololade's user avatar
  • 73
0 votes
2 answers
274 views

Testing contract selfdestruct in Hardhat - Chai matchers

I'm writing unit tests for a solidity contract in a Hardhat project and I can't seem to find a selfdestruct matcher. Solidity Chai Matchers are a set of helper functions that make testing solidity ...
Adham's user avatar
  • 181
0 votes
1 answer
11 views

How I can create a test function which reicive a specific ammount of ether in hardhat?

The function what I want to test is this function mint(uint256 tokenId) external payable { require(msg.value == 0.01 ether, 'Wrong price'); _safeMint(msg.sender, tokenId); } ...
Abel Gonzalez's user avatar
2 votes
0 answers
115 views

AssertionError: Expected event "RaffleEnter" to be emited, but it doesn't exist in the contract

I'm working on freeCodeCamp.org's Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course I have the following contract code: //SPDX-License-Identifier: MIT pragma ...
PSS's user avatar
  • 543
4 votes
2 answers
2k views

How to work with block timestamps in ethers and hardhat?

I have a time-dependent contract that has two require statements function launch(uint256 _goal, uint32 _startAt, uint32 _endAt) external { require(_startAt >= block.timestamp, "...
Kate Johnson's user avatar
1 vote
0 answers
90 views

Hardhat Staging test is getting errors

const { getNamedAccounts, ethers, network } = require("hardhat") const { assert, expect } = require("chai") const { developmentChains, networkConfig, } = require("../../...
Yana Gupta's user avatar
1 vote
1 answer
58 views

Hardhat Lottery test is failing

const { deployments, getNamedAccounts, ethers, network } = require("hardhat") const { assert, expect } = require("chai") const { developmentChains, networkConfig, } = require(&...
Yana Gupta's user avatar
0 votes
1 answer
160 views

Testing safeTransferFrom with onlyAllowedOperator using chai/hardhat

I am writing tests for an NFT using safeTransferFrom with onlyAllowedOperator and the tests are failing with and without onlyAllowedOperator. Here's the function: function safeTransferFrom(address ...
Jacek's user avatar
  • 135
0 votes
1 answer
459 views

Im trying to run a js script on the blockchain using hardhat ,it throws an error whenever I run it on the command line

This is the following error I get when running the command "npx hardhat --network localhost scripts/1_deploy.js" HeadersTimeoutError: Headers Timeout Error at Timeout.onParserTimeout [...
Alwin Tomy's user avatar
0 votes
1 answer
198 views

check balance before and after transaction with chai

I'm writing the test cases for a contract, and I have a problem trying to match the balance, because of the transaction gas. what is the correct way to do it? it("should allow the owner of the ...
Fede's user avatar
  • 105
0 votes
3 answers
1k views

Error: Transaction reverted: function selector was not recognized and there's no fallback nor receive function

I'm getting a console error in hardhat test case this is my solidity code /** * donateToCampaign - Allows a user to donate to a specific campaign. * * @param _id the ID of the campaign to donate to....
Fede's user avatar
  • 105
1 vote
2 answers
1k views

conflict peer dependencies: nomicfoundation & hardhat-deploy-ethers

I'm facing a blockage so any help will be appreciated: @nomiclabs/hardhat-ethers is an essential peer dependency to hardhat-deploy-ethers but that will prevent me from installing @nomicfoundation/chai-...
sasha's user avatar
  • 41
0 votes
3 answers
4k views

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

My smart contract is over 300 lines of code, complete with events, modifiers, internal functions, getters and setters. I'm trying to run tests using hardhat and chai. All I'm getting is this error: ...
Jean-François Beaulieu's user avatar
1 vote
1 answer
24 views

Unittest for excisting NFT

I have build a contract (not yet deployed) that allows to check if the msg.sender holds a certain NFT: pragma solidity ^0.8.17; import "@openzeppelin/contracts/interfaces/IERC721.sol"; ...
Casper Nybroe's user avatar
1 vote
0 answers
35 views

How can i bind log() to my runtime in my unit test file?

How can I make log() bind to my runtime in my chai unit-testing script? I have a hardhat solidity project. Included snippets and pseudocode. This framework is very new to me so if there are obvious ...
Viggos's user avatar
  • 131
1 vote
1 answer
1k views

AssertionError: expected Promise{…} to equal 1

Code: describe("uploading post", async () => { let result, postCounter const hash = "whatever" before(async () => { result = await ...
Sina Blank's user avatar
0 votes
2 answers
2k views

Error: VM Exception while processing transaction: reverted with reason string 'Didn't send enough!' on testing contract

Getting this error while testing one of functions functionality in the contract AssertionError: Expected transaction to be reverted with You need to spend more ETH!!, but other exception was thrown: ...
Aman's user avatar
  • 23
1 vote
1 answer
53 views

Principles of Testing Smart Contracts

Generally, when writing tests for smart contracts, how comprehensive do the tests have to be? Also, how does one know what to test (e.g., which line in the function in the original contract file the ...
Will-Up-Vote-If-Good's user avatar
4 votes
1 answer
192 views

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

Does anyone know how to get the gas costs of a reversed transaction when testing with Hardhat / Chai? I found out I can get the receipt object of a transaction, which holds the required data to ...
Rik Schoonbeek's user avatar
0 votes
0 answers
276 views

AssertionError: expected 0 to equal " ". The numerical values of the inputs were compared, and they differed

I'm pretty new to coding and solidiy - I'm testing a covered-call option smart contract in hardhat - specifically a function to check if the balance of the smart contract has been updated following ...
0xJI's user avatar
  • 11
1 vote
1 answer
157 views

Hardhat and Chai testing : How should I write the test?

I've digged through all the related question, but none of these worked for me. I used this repo, and replaced the contract and test file : https://github.com/NomicFoundation/hardhat-boilerplate EDIT ...
ISMAIL S.'s user avatar
1 vote
1 answer
337 views

TypeError: <FUNCTION_NAME>.owner / .connect() is not a function on hardhat unit testing

Plugin and tools used: hardhat-chai-matcher, chai, mocha Issue: Was wonder if its my environment setup wrong, so i ran other test but theyre passing just alright: This is my test script written ...
Senzel's user avatar
  • 13
1 vote
4 answers
2k views

Hardhat chai .revertWith() not catching reverted error from Smart Contract

I am using Hardhat and chai for my testing and attempting to trigger an error that gets reverted to make sure my contract is acting properly. Note: I'm running on a forked hardhat chain of mainnet. I ...
l1nkm4rine's user avatar
0 votes
1 answer
181 views

Getting error while testing transfer function using chai

I have a function that transfers the amount from owner to user. I'm getting success in the event emitted message and my test is failing every time. Here is my code. function investInMPay(uint256 ...
0xSavan's user avatar
  • 55
0 votes
1 answer
34 views

Event test failing because of address's casing

I am trying to test if the event is emitted with the correct arguments however my tests are failing because of some casing issue. What is the best away to overcome this issue?
maxime's user avatar
  • 96