Questions tagged [chai]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
6 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
86 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
11 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
0 answers
18 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
18 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
196 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
3 votes
4 answers
5k 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
25 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
125 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
31 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
74 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
32 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
0 votes
1 answer
235 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
  • 1
0 votes
2 answers
59 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
77 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
141 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
57 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
56 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
84 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
118 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
283 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
  • 53
0 votes
2 answers
219 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
  • 81
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
106 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
  • 529
2 votes
2 answers
1k 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
76 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
52 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
136 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
  • 125
0 votes
1 answer
319 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
159 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
2 answers
876 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
898 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
3k 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
21 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
31 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
855 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
40 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
140 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
195 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
137 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
284 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
3 answers
1k 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
170 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
26 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
0 votes
0 answers
124 views

Hardhat tests failing when testing require statement

Hi I am trying to test a smart contract I wrote using hardhat, with chai and @nomicfoundation/hardhat-chai-matchers. I have followed the documentation however I am having no luck. Please see below the ...
Jo1234's user avatar
  • 21
1 vote
1 answer
514 views

Writing Solidity tests for array length & contents (chai)

tdlr; solution I had to await both of the values used in my assertions. For grabbing the length of the array, I needed to add a new method to my contract, as shown here. The reason for this is in the ...
Andy Hoffman's user avatar
0 votes
0 answers
381 views

to.be.reverted function showing invalid chai property

it("money",async()=>{ console.log(await instance.hasRole("0xc5d48d6799b0d7d7cdfebe6afd6fac6dff6746359d2e02d434f8172e9a93fe97",accounts[8])); console.log(await ...
Yakshesh Gupta's user avatar
2 votes
1 answer
41 views

How do you know when an operation should be performed synchronously or asynchronously in smart contract tests?

What operations are usually perform asynchronously in smart contract tests, and what operations are usually performed synchronously in smart contract tests? When are each of these usually used?
Will-Up-Vote-If-Good's user avatar
2 votes
1 answer
91 views

How do mocha and chai work?

I got this snippet from: https://hardhat.org/tutorial/testing-contracts In this test, what does const { expect } = require("chai") mean? Also, I thought describe() is from the Mocha ...
Will-Up-Vote-If-Good's user avatar