Skip to main content

Questions tagged [test]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer
52 views

TESTS FOR MY ERC20 TOKEN IS NOT WORKING

// SPDX-License-Identifier: SEE LICENSE IN LICENSE pragma solidity ^0.8.24; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/token/ERC20/...
Kwesili Okafor's user avatar
0 votes
1 answer
20 views

Error: Timeout of 2400000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves

When I try run my unit test ("hh test" or "yarn hardhat test") in ethersV6, for some reason it doesn't enter in my Promise's test because even doesn't appear the console.log(). The ...
Tucan's user avatar
  • 3
0 votes
1 answer
62 views

Foundry Solidity Error: panic: array out-of-bounds access (0x32) while testing a batch mint function

I'm writing foundry tests for a function which batch mints erc1155 tokens for the users, but I'm getting a panic revert. The function I'm testing: function mintBatch( address to_, ...
DevABDee's user avatar
  • 473
0 votes
1 answer
16 views

Debugging when catching a custom error

Example Based on this answer, I was able to write the following custom error: error ReachedInvestmentCeiling(uint256 providedVal, string errorMessage); if (hasReachedInvestmentCeiling(...
a.t.'s user avatar
  • 79
0 votes
0 answers
17 views

Forge test estimates less gas than the real transaction

I noticed that using forge test, the estimated gas used tends to be much less than the real gas used. Taking for example this transaction in Ethereum mainnet: https://etherscan.io/tx/...
quantoor's user avatar
0 votes
1 answer
290 views

NotImplementedError: Method 'HardhatEthersProvider.resolveName' is not implemented

I'm trying to implement meta transactions for my web app. I'm currently testing the smart contracts using hardhat but keep running into this error in my NodeManager.ts file. The error below 1) ...
Zhi's user avatar
  • 11
1 vote
0 answers
22 views

Foundry Access denied error

I get this access denied error when I run forge test in my VS Code terminal.
EGstacking's user avatar
0 votes
0 answers
37 views

Gas reporter does not report gas usage for low level calls

I am using npx hardhat test command to get the gas usages analysis. My configuration to get the report is like below. In my tests. I have tests for deployment, functions calls, but also some other ...
Ferda-Ozdemir-Sonmez's user avatar
2 votes
1 answer
293 views

How to assign and send ether value together with deployment of contract using Foundry

This is the simple function, how do I deploy the contract and send ether along with it? function setUp() public { test = new testContract( Owner; ); }
anonauditor's user avatar
0 votes
1 answer
33 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
2 answers
38 views

Does anyone know why this still reverts?

So, I'm trying to test an underflow of test ERC20 tokens, but even if I remove all the require checks of the EIP20 (ERC20) file, when I transfer 1 test token from the contract to an address (the ...
19216811's user avatar
0 votes
0 answers
381 views

"TypeError: (0 , ethers_1.getAddress) is not a function" when writing tests in hardhat with typescript

i get this error when i run this test: typescript import { expect } from "chai"; import { ethers } from "hardhat"; import { Ballot } from "../typechain-types"; const ...
robberdom's user avatar
0 votes
1 answer
1k views

Error: invalid contract address or ENS name (argument="addressOrName", value=undefined, code=INVALID_ARGUMENT, version=contracts/5.7.0)

I am trying to test the contract but getting error: Basic NFT Unit Tests Constructor 1) "before each" hook for "Initializes the NFT Correctly." 0 passing (2s) 1 ...
Sunny Kharwar's user avatar
0 votes
1 answer
85 views

Truffle test USDC transfer to contract + instantiate contracts

I'm writing my smart contract tests in JS and using Truffle. I want to test a specific function in my contract that requires a token address and contract address as parameters: address _asset, ...
Piji's user avatar
  • 1
3 votes
3 answers
2k views

Mining a new block in Foundry `forge test`

I have a contract with a function that uses blockhash(block.number -1), and I want to test that its value changes after a new block is mined. Is there a way to somehow mine a new block midway through ...
EmmanuelB's user avatar
  • 156
2 votes
1 answer
170 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
0 votes
2 answers
66 views

Enhancing testability of contracts with immutable state variables

I have been encountering challenges when testing contracts that utilize immutable state variables. As we know, immutable variables are assigned only once during contract deployment and cannot be ...
Ahmed Ihsan Tawfeeq's user avatar
5 votes
1 answer
491 views

Foundry pranking different in test contract vs contract

I have a test in foundry where I prank msg.sender as such: address USER = address(1); vm.startPrank(USER); myContract.doStuff(); console.log("msg.sender from test", msg.sender); vm.stopPrank(...
Patrick Collins's user avatar
1 vote
3 answers
521 views

"before each" hook for "sets the aggregator addresses correctly" TypeError: Cannot read properties of undefined (reading 'JsonpcProvider')

actual issue looks like that i had faced :( when i tried running yarn hardhat test it was always error outing like in above image. I have searched solution but could not find proper solution to it!
n-dcool's user avatar
  • 11
0 votes
1 answer
1k views

i experienced a "code=UNSUPPORTED_OPERATION"-error while learning how to code

Error: cannot override "wertgesendet" (operation="overrides", overrides=["wertgesendet"], code=UNSUPPORTED_OPERATION, version=contracts/5.5.0) guys i am receiving this ...
nazo beyli's user avatar
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
0 votes
1 answer
28 views

Query on connect()

Suppose i deployed a contract like this:const test = await ethers.getContractFactory("Test"); await test.deployed(); const [ signer, acc1, acc2 ] = await ethers.provider.listAccounts() So, ...
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
0 votes
1 answer
364 views

InvalidInputError: Received invalid block tag 642829559307850963015472508762062935916233390536. Latest block number is 1

After compiling the below dead-simple contract // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.9; contract SendWei { function sendWei(address payable recipient, uint256 amount) public ...
Sprint's user avatar
  • 3
0 votes
1 answer
467 views

Why do i always get this error whenever i use forge test?

I am trying to use foundry, whenever I use forge test on my mac(10.15.7 Catalina)it throws this error and doesn't install forge-std lib for me. please how do i resolve this?
Tom GE's user avatar
  • 1
1 vote
1 answer
467 views

Property 'revertedWithCustomError' does not exist on type 'Assertion'

Im updating my project from Javascript to Typescript. Up until now I had no issues using revertedWithCustomError. When trying to assert with revertedWithCustomError I get the following linter error ...
Potion's user avatar
  • 163
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
214 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
4 votes
5 answers
3k views

Foundry: skip specifics tests

In a foundry project, I have a few fuzzing tests that are failing but do not want to remove them from my file. For example, in mocha/chai you have a .skip keyword that will let you skip some tests. Is ...
maxime's user avatar
  • 106
0 votes
1 answer
31 views

Trying to test a simple contract but failing

I am currently following my first Ethereum course, and I am trying to test the a very simple contract, but it keeps failing. When I run the contract on Remix, everything seems to be working fine, so I'...
Yotam's user avatar
  • 103
1 vote
1 answer
62 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
1 vote
1 answer
177 views

Accessing data of struct in mapping externally

MultiSig Wallet contract: contract MultiSig { address[] public owners; uint256 requiredVoteCount; event Deposit(uint256 amount); event Approved(address approverOwner, uint256 approvedTransaction); ...
Kartal Karabulut's user avatar
0 votes
2 answers
180 views

How to get TEST ETH?

I'm learning how to develop on the ethereum network. I'm currently going thru a tutorial I found, and I need to get test eth. Every faucet/website I've tried ( even from the official ethereum.org/...
Mateusz Szumilo's user avatar
0 votes
1 answer
149 views

Contract not found when forking, but is present on remote network

I have forked polygon mumbai network in my local project so that I can solve the Ethernaut challenges by writing tests (to improve my understanding of ethers.js, testing, and solving the problems etc) ...
pho_pho's user avatar
  • 157
1 vote
1 answer
98 views

Test file in hardhat, hardhat tutorial, testing token

const { expect } = require("chai"); describe("Token contract", function () { it("Deployment should assign the total supply of tokens to the owner", async function () { ...
Whizzie's user avatar
  • 11
1 vote
1 answer
170 views

getContract from forked testnet

when I run hardhat on forked testnet and try to run test script that includes dai = await ethers.getContractAt("IERC20", DAI) I get this error: NomicLabsHardhatPluginError: ...
Mourad's user avatar
  • 123
2 votes
1 answer
688 views

error[9582]: TypeError: Member "expectRevert" not found or not visible after argument-dependent lookup in contract Vm

I'm having this error when i try to run the test testCannotDecrementLargerNumbers // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.13; import "forge-std/Test.sol"; import ".....
Sergio Sotelo's user avatar
1 vote
1 answer
71 views

Factory test - How to cast in TypeScript

I am new to solidity and am now facing a problem. I created a factory : pragma solidity ^0.8; import "./Offering.sol"; contract OfferFactory { Offering[] _offers; function ...
Bruno's user avatar
  • 23
0 votes
1 answer
37 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
  • 106
0 votes
0 answers
18 views

Truffle test won't return token name

I have been stuck on this part of my Bootcamp for two weeks now pouring over github and asked on stackoverflow. I have googled my error and found nothing as well as deleting my dependencies and ...
braun bushong's user avatar
1 vote
0 answers
234 views

hardhat-gas-reporter not to calculate(skip) gas tax in some transactions in the gas report

I use hardhat-gas-reporter package. I want the gas tax not to be calculated for part of the transactions in one test in the gas report. Can this be done? code example it("Should deployed test&...
dromey's user avatar
  • 61
0 votes
1 answer
458 views

HardhatError: HH700: Artifact for contract "UniswapV2Router02" not found

I wanna get UniswapV2Router02 deployed on Fantom network. UniswapRouter = await ethers.getContractAt( "UniswapV2Router02", "0xf491e7b69e4244ad4002bc14e878a34207e38c29" )...
bindle bisu's user avatar
0 votes
0 answers
231 views

Failure running tests using both hardhat in a foundry project

I want to run upgradeability test using hardhat in a foundry project. Following is my project directory details: ❯ tree -L 1 -a . ├── .env ├── .env.example ├── .eslintignore ├── .eslintrc.js ├── .gas-...
abhi3700's user avatar
  • 219
1 vote
2 answers
517 views

hardhat: want to test an emit event that is in a library

file Library library Events { error Mint(); } file Contract calling the event emit Event.Mint() Can't get Chai detect the event that is in the library Throw this error in both cases: ...
Tomis's user avatar
  • 11
1 vote
2 answers
2k views

Is there a way to reset ETH balance in hardhat test cases?

I have been trying to create a test case file in which I have multiple it statements and a few of them consist of functions that are payable in nature. When I run the test cases, with every case ...
Shubham Sharma's user avatar
0 votes
1 answer
111 views

Getting assertion error for unit test

Im getting the assertion error the test it("return false if enough time hasnt passed", async function(){ await expect(raffle.enterRaffle({value: raffleEntranceFee})) ...
Yash Dhumal's user avatar
0 votes
0 answers
548 views

Fail with error 'SafeMath: subtraction overflow'

I am trying to use the "create" function from an LSP smart contract from the UMA protocol but I can not use it it always returns the "Fail with error 'SafeMath: subtraction overflow'&...
Dimitri's user avatar
3 votes
4 answers
2k views

Run a single hardhat test file

I have a few test files: ./test/ContractA.test.js const { expect } = require("chai"); describe("ContractA tests", function () { it("does function one", async function (...
Jim's user avatar
  • 173
1 vote
1 answer
19 views

Passing an error testing suite in contract

hello how do i make a proper testing suite for error? the contract has this modifier for freeMint() fn modifier protectTier(uint256 _level) { require( _level != privateTier, &...
Dell Watson's user avatar