Skip to main content

Questions tagged [unittesting]

https://remix-ide.readthedocs.io/en/latest/unittesting.html

Filter by
Sorted by
Tagged with
0 votes
0 answers
26 views

Mock unit tests

For a "professional" project that's created to look for funding, are mocks from unit tests recommended to be the old fashion way by creating each mock from scratch or is it ok with just ...
dNyrM's user avatar
  • 938
0 votes
2 answers
36 views

Unit test error: "AccessManagedUnauthorized" when minting ERC-20 token in a DAO project

I'm relatively new to Solidity and currently working on building a DAO using the OpenZeppelin contract wizard. I've generated ERC-20 token and governor contracts using the wizard to kickstart my ...
Hessamedean Aghajanlou's user avatar
0 votes
1 answer
14 views

How to set Pool Extension for staking function?

Now I am trying to test stake and claimReward function following existing sample codes. StakingPool.sol contract StakingPool is Context, Ownable, ReentrancyGuard { //rest codes function stake(...
Apple-Tim's user avatar
0 votes
1 answer
36 views

How I can test smart contract which has logic based on chainId

Dear blockchain developers, I have a ERC20 with restriction of minting only on Polygon chain: // SPDX-License-Identifier: MIT pragma solidity 0.8.23; import "@openzeppelin/contracts/token/ERC20/...
Arkenstone's user avatar
1 vote
0 answers
20 views

Issues setting up a test case for when withdrawal fails in my Contract

Question Description: I created a contract that users can fund and only the owner of the Contract can withdraw the funds from the Contract. The Contract is below: // SPDX-License-Identifier: MIT ...
Eyang Daniel's user avatar
0 votes
1 answer
34 views

Does Integration-Testing can be done in local blockchain using Hardhat?

I'm currently working on a project where I need to perform integration testing involving a third-party contract. This contract is part of a library that I've included in my project as a git submodule ...
codekoriko's user avatar
3 votes
0 answers
258 views

How to mock smart contract with hardhat and ethers v6

I found here 2 ways to mock Smart contract but they all limited to ethers.js v5: @nomiclabs/hardhat-waffle @defi-wonderland/smock Today hardhat-toolbox is at version 4 and migrated away from hardhat-...
codekoriko's user avatar
4 votes
2 answers
477 views

How to use forge coverage effectively?

I am trying to get the test coverage for our Smart Contracts. Couple of questions I have. While running the coverage command, it doesn't include all the test cases in the folder, is it because we ...
Zartaj Afser's user avatar
  • 4,684
1 vote
1 answer
426 views

`vm.expectRevert` is not working as expected in Foundry

Here is the file I am working with SubscribeBySig.t.sol . You can replicate the scenario by cloning the above repo, switch to the 230-migrate-comm-unit-tests branch and run forge test. The problem is ...
Zartaj Afser's user avatar
  • 4,684
0 votes
1 answer
202 views

Extracting input data when writing Forge tests/POCs

I would like to write a test in Foundry but I need to be able to first read data from a previous transaction that was submitted in some point in the past. For example, the transaction I'm interested ...
SKA's user avatar
  • 47
0 votes
0 answers
18 views

Need help testing my smart contract. Error cannot read undefined

I am testing my smart contract and I am getting this Assertion Error. I do not know or understand what it means and after searching how to fix it online and making some adjustments to my code, I am ...
EGstacking's user avatar
2 votes
1 answer
946 views

Argument of type 'HardhatEthersSigner' is not assignable to parameter of type 'string | Signer | undefined'

I'm writing unit tests for an ERC20 token in TypeScript. I'm getting this error from TypeScript: Argument of type 'HardhatEthersSigner' is not assignable to parameter of type 'string | Signer | ...
stuckoverflow's user avatar
0 votes
1 answer
506 views

Foundry forge unit tests fail when use customERC20Token.balanceOf(msg.sender)

I have a raffle contract that required a custom ERC20 token as an entrance fee. In Raffle contract I have the enterRaffle function: function enterRaffle() public payable { uint256 ...
Claudiu Ungureanu's user avatar
0 votes
0 answers
246 views

TypeError: AbiCoder is not a constructor

I am working with patrick solidity course on youtube and have gotten to the point of carrying out unit testing. I am having this issue getting this error const { assert, expect } = require("...
eric Igbinosun's user avatar
0 votes
1 answer
391 views

Guidance on writing a Foundry Test for a deploy script! (Lesson 9: Raffle contract)

I am following the new foundry course by Patrick and was wondering if I could get tips on how to test the deploy script - https://github.com/Cyfrin/foundry-smart-contract-lottery-f23/blob/main/script/...
Philiplima's user avatar
0 votes
0 answers
57 views

Solidity Infinite Loop

I was creating a game of Casino Roulette using ChainLink's VRF Coordinator and Automation. I am stuck in "seemingly" an infinite loop in the following function: function ...
Brexela's user avatar
  • 11
1 vote
1 answer
172 views

Hardhat Errors: Invalid value null supplied to : QUANTITY

Getting this error some times while testing a Hardhat file. But when I cancel that script and run that same script again, it works. The complete error is here: "before each" hook: Before ...
Pankaj Jagtap's user avatar
1 vote
0 answers
322 views

how to write test for upgradeable smart contract in hardhat

I'm writing a Hardhat test for my contract. // SPDX-License-Identifier: MIT pragma solidity ^0.8.18; import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol"; import &...
Mehran Ra's user avatar
  • 590
1 vote
1 answer
78 views

runner object doesn't exist during an event emit testing

EDIT June 28 2023: When I removed import '@openzeppelin/hardhat-upgrades'; from hardhat.config.ts, then whether I use ethers.getContractFactory or ethers.deployContract there is always runner.provider ...
Téwa's user avatar
  • 141
0 votes
2 answers
90 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
1 answer
142 views

Why my test is failing here?

I am writing a test for checking a upgradable contract: function test_Proxy() public { vm.startPrank(address(user)); // checking is non-owner address can call the upgradeTo() or not ...
Hacek 's user avatar
  • 677
0 votes
2 answers
125 views

Trying to Run a unit test, but getting the following error: AssertionError: expected '0xCAEc8498aB11D596116B5175017B9Ab220b…' to equal undefined

I am trying to write a unit test for the simple condition of checking the owner's address once the contract is deployed. The unit test code for this is as follows: const { ethers } = require("...
Pratik Jussal's user avatar
1 vote
1 answer
97 views

Unit Testing Error - time related reverts

I am trying to unit test my smart contract and I am struggling to figure out why I am getting an error for invalid dates for a specific describe and if statement. I have been struggling all day to ...
OhItsPM's user avatar
  • 85
1 vote
1 answer
109 views

Should I interact with existing contract or create new instance for unit-testing

I'm trying to unit test my simple contract however, I don't know which way to do it. For unit-testing should I create a new contract on beforeEach(), so it runs before each it()? Using: new ethers....
IBeFrogs's user avatar
2 votes
1 answer
172 views

Test failing unexpectedly

This is code for my unit test scripts, I don't know where I am wrong. const { deployments, ethers, network } = require("hardhat") const { assert, expect } = require("chai") const { ...
Yana Gupta's user avatar
1 vote
1 answer
66 views

My unit tests fail with different error. What I'm I doing wrong?

I'm writing unit tests for my e-commerce smart contract and they keep failing. Wonder what I'm doing wrong. I want to check; that buyer pays exact price that seller cannot be the buyer that product ...
kihiuFrank's user avatar
1 vote
2 answers
79 views

Having issues with unit test failing hardhat FundeMe

When I run yarn hardhat test I get below error: 1) "before each" hook for "sets the aggregator addresses correctly" 0 passing (1m) 1 failing FundMe "before each" hook ...
Sameer's user avatar
  • 11
2 votes
1 answer
508 views

How to access address mapping to array struct in hardhat solidity?

I'm writing Unit Test using hardhat for a solidity contract. There is a public mapping variable which has a mapping of address to array of struct. struct ticket { uint16 looteryID; ...
Ashish Kumar Rena's user avatar
4 votes
1 answer
200 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
2 votes
0 answers
119 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
  • 553
1 vote
0 answers
39 views

Query on signature testing

I am taking nonce as input from users and while testing the signature i am giving the nonce = 1, i want my signatures which is calculated 2 times, first by users, and 2nd by my contract,with same data,...
Hacek 's user avatar
  • 677
1 vote
1 answer
223 views

Accessing mapping's data from test script

Suppose there is a mapping mapping (address => bool) submitted. How to access this mapping's data from test script??
Hacek 's user avatar
  • 677
1 vote
1 answer
24 views

testing confusion

I have addOwner() like this: function addOwner(address _owner) public onlyOwner { require(!owners[_owner]); owners[_owner] = true; } I was testing for function can not be called ...
Hacek 's user avatar
  • 677
1 vote
0 answers
34 views

How to get the address which verify() returns from test script?

my verify() looks like this: function verify( address _customer, address _to, uint256 _value, bytes32 _key, bytes memory _signature ) public ...
Hacek 's user avatar
  • 677
2 votes
1 answer
16 views

How to use a contract's mapping in test script?

Suppose there is a mapping mapping (address => bool) submitted. If want to save something (like submitted[address] = true) in this mapping from test script while testing how can I do it??
Hacek 's user avatar
  • 677
2 votes
2 answers
799 views

How to extract the ABI part from JSON file created in artifacts and create a separate file for it?

I have been using the Hardhat environment for a while now, and every time I have to provide the ABI to the front-end team, I need to copy-paste the ABI manually from the JSON file, since it contains ...
Shubham Sharma's user avatar
1 vote
1 answer
404 views

Solidity- How to test struct array in foundry

Here I have created one struct with different parameters such as address, uint, bool, uint and in this array I have pushed some values in submitTransaction function and it is working as expected: ...
raju raj kishore's user avatar
1 vote
0 answers
73 views

test transaction call brownie

in brownie, i have a function that calls another one in the same contract, and i want to test if it does it properly : The function : function onTokenTransfer( address _sender, uint256 _fee, ...
noro meb's user avatar
  • 368
1 vote
0 answers
37 views

i am getting error on running this this test but if i write "await expect(fundMe.fund()).to.be.reverted" only then this test passes

i am getting error in this unit test but if i write test with to.be.reverted only it passes ? await expect(fundMe.fund()).to.be.reverted describe("fund", async function() { it("...
haris rashid's user avatar
15 votes
5 answers
5k views

Hardhat vs foundry, which to use for testing?

I'm looking into smart contract testing and saw that Hardhat and Foundry are the main kits developers are using for testing. Are the two comparable when it comes to testing? Should I include both ...
Nal Luksic's user avatar
  • 1,197
1 vote
1 answer
70 views

Staging test errors: Error: No Contract deployed with name Raffle

const { assert, expect } = require("chai"); const { getNamedAccounts, ethers, network } = require("hardhat"); const { developmentChains } = require("../../helper-hardhat-...
Anooj Patnaik'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
1 answer
27 views

Live testing so annoying and time-consuming

After days of unit local testing i begin testing on testnet, and it turns that i have some errors that appear from nowhere, to fix those errors i need to redeploy all the contracts and arrange all the ...
noro meb's user avatar
  • 368
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
0 answers
217 views

Having issue in passing parameter while testing

I'm having an issue while passing parameters to constructor during test. My constructor looks like constructor(address _ethUsdPriceFeedAddress) { _owner = payable(msg.sender); ...
Hacek 's user avatar
  • 677
1 vote
1 answer
53 views

Unit test with msg.sender not the signer

Given the following two contracts contract Parent { mapping(uint32 => address) private Children; function AddChild(address _childAddress, uint32 _childID) public { require(...
ThomasS's user avatar
  • 13
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
4 answers
317 views

Confused about the function of these lines of test code

Test file: const {expect} = require("chai"); const {ethers} = require("hardhat"); describe("NFT Marketplace", function () { let NFTMarket; let nftMarket; let ...
Will-Up-Vote-If-Good's user avatar
1 vote
1 answer
77 views

What do these lines of test do?

Test file: const {expect} = require("chai"); const {ethers} = require("hardhat"); describe("NFT Marketplace", function () { let NFTMarket; let nftMarket; let ...
Will-Up-Vote-If-Good's user avatar
1 vote
0 answers
104 views

How to Test Solidity Struct in Args?

I have an event, where I forward a Struct when issuing it. But I'm not able to test this with chai + hardhat, I get the following error: Here is my getResult function, my struct, and my emitted event ...
THIAGO DE BONIS's user avatar