Questions tagged [chai]
The chai tag has no usage guidance.
27
questions
0
votes
1
answer
20
views
Test if a smart contract function has been called
In my hardhat project I'm testing my smart contracts using chai.
For the sake of simplicity let's assume my contract is:
contract MyContract {
function a() external {
b();
}
function b() ...
2
votes
4
answers
60
views
unit testing with chai : is there a way to simulate or force a failed transaction?
Using hardhat and chai, is there a way to simulate/force a transaction failure so the error code will execute?
e.g. with the following, I want it to throw the error because the transaction didn't ...
0
votes
1
answer
109
views
how to use a library with testcases using hardhat
I'm using a library for managing Events. Now when I'm running the test case script then I'm getting an error.
ERROR
If I don't mention the library when I'm deploying the Users.sol contract.
...
0
votes
0
answers
41
views
Unit test in hardhat of SushiToken function delegatebySig
I'm playing around with contracts and trying to get the hang of it.
My problem is I'm stuck with a singe function I like to unit test.
I have absolutely no idea how to create an signatory in the ...
1
vote
1
answer
130
views
Comparing ethers BigNumber does not work
I'm testing the value of a BigNumber returned from a function call to a contract and its not working as expected.
I have this
const { BigNumber } = require('ethers');
...
const totalSupply = await ...
0
votes
1
answer
60
views
solidity function functionCall from openzeppelin-contracts-accounts reverted
I was calling flashLoan function using following parameters for hardhat testing
expect(
await this.pool.flashLoan(100, attacker.address, this.token.address, 0x00)
).to.be.not.reverted;
This is ...
0
votes
0
answers
128
views
Error using Merkle Tree proof in smart contract parameter in Chai
I'm trying to generate a proof from a merkle tree and enter it into the parameters of a function in a smart contract in chai.
But I'm getting the follwoing error:
Error: invalid arrayify value (...
1
vote
2
answers
105
views
Truffle Chai Assertion Error with Truffle Unit Cases
Problem: facing an issue with the below Truffle test case while trying to Implement the ERC20 token in my contract.
contract("Token Test", async(accounts) => {
const[deployerAccount, ...
0
votes
1
answer
58
views
Unable to call the OZ PaymentSplitter release method from my tests
I'm using hardhat, chai to write my tests for an nft sample project im working on.
Have set up the PaymentSplitter like so ...
contract MyNft is ERC721A, Ownable, MerkleWhitelist, PaymentSplitter {
...
0
votes
0
answers
11
views
Issue with contract redeployment while testing
I need to test a contract with hardhat.
This issue is that some functions need to wait some time in order to be effective.
Is there a way to tell hardhat to wait before running some functions of the ...
0
votes
0
answers
24
views
Check if a function does not exist in chai
I'm using chai to test my contracts.
I have a test that calls a function that does not exist in that contract.
This is the contract:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import &...
0
votes
0
answers
15
views
cosloe log multiple variables returned from Solidity functions
So I have a Solidity function which returns multiple values:
function getReserves() external returns (uint112, uint112) {
require(UniswapPair!= address(0), "Create Pair first");
...
0
votes
1
answer
313
views
Hardhat/Waffle/Chai : Display Revert Reason?
I'm testing a simple call and expect it to not revert
await expect(swapCall).to.not.be.reverted
The test fails currently and I get a
AssertionError: Expected transaction NOT to be reverted
How do I ...
0
votes
1
answer
412
views
Convert big number to number on hardhat tests
Sorry for the newbie question. There are a lot of solutions but non of them worked for me. I am getting an account's balance with
const balance_before = await ethers.provider.getBalance(redeemer....
0
votes
1
answer
71
views
Smart Contract test wont passed event though the value that needed to pass to the expect block already exist
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 ...
0
votes
0
answers
147
views
Hardhat/waffle: ether transfer with no effect
I'm going through the fantastic ethernaut challenges to learn solidity. In order to test and deploy my solutions I'm using hardhat/waffle/ethers. When running my contracts locally on the hardhat ...
0
votes
0
answers
278
views
npm throw errors when installing dependencies of hardhat
when installing those dependencies:
npm install ethers hardhat @nomiclabs/hardhat-waffle ethereum-waffle
chai @nomiclabs/hardhat-ethers
Those errors occurred:
npm WARN deprecated ganache-core@2.13.2: ...
0
votes
2
answers
376
views
How to test if msg.value is 1 ether in test
I have a function which mints when 1 eth is send to it. The function is
function _mint() public payable{
require(msg.value == 1 ether , "Send more ethers: 1 ether is required"...
1
vote
2
answers
648
views
Property 'revertedWith' does not exist on type 'Assertion'
I'm running a test using waffle in hardhat.
import { assert, expect } from "chai"
.
.
.
it("can only be changed through governance", async () => {
await expect(box.store(...
0
votes
1
answer
75
views
How to write Test case for NFT buy functionaity?
Function for buying NFT
function buy(address nftContract, uint256 itemId)
public
payable
nonReentrant
{
uint256 price = idToMarketItem[itemId].price;
uint256 tokenId = ...
1
vote
1
answer
30
views
How test uint from smartcontract with chai?
In my solidity smartcontract, I have a function to return a uint value :
function getUserBalance(address userAddress, address tokenAddress)
public
view
returns (uint256)
{
...
1
vote
7
answers
1k
views
I am running my tests in the hardhat environment but it gives me 0 passing all the time
I am facing rather unusual behavior from hardhat. I have written my test cases in a file inside test folder when i run yarn teston the terminal it gives me 0 passing. Don't have any idea as to why it ...
1
vote
2
answers
232
views
How to test a function which calls another contract from inside the function?
newToken.sol
import "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
contract newToken is ERC1155 {
using Counters for Counters.Counter;
Counters.Counter private ...
0
votes
2
answers
541
views
Invalid Chai property when testing smart contract
In a hardhat project I'm using smock to mock an ERC20 contract and chai's calledOnce to assert:
const {expect} = require("chai")
const {artifacts, ethers} = require("hardhat&...
0
votes
1
answer
347
views
Smart Contract Testing - ethereum-waffle expect function
Can someone please explain the significance of the location of the "await" keyword in the "expect" function from the waffle testing framework?
for example:
this passes (assume its ...
0
votes
0
answers
177
views
Error in testing contract with javascript on truffle
I'm trying to test a contract multiple times on truffle using javascript. The first test runs just fine, but the second gives me error no matter what's inside of it.
Here is my full testing code:
...
3
votes
1
answer
102
views
Chai closeTo on Ethereum Events
I know that we can use closeTo chai matcher like this:
expect(BigNumber.from(100)).to.be.closeTo(BigNumber.from(101), 10);
And we can test whether a transaction emits an event with specific arguments ...