Questions tagged [test]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
17 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
14 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
23 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
154 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
0 answers
21 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 ...
AndyCrypto's user avatar
0 votes
0 answers
363 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
0 answers
23 views

My Hardhat test are inconsistent

I'm stuck with an issue, where my tests runs yields different errors while the code doesn't change. I'm using hardhat + chai, with an archive node service like Alchemy which allows me to fork the ...
Yakitori's user avatar
  • 757
0 votes
1 answer
820 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
71 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
2 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
  • 131
2 votes
1 answer
150 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
55 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
377 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
457 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
786 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
23 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
  • 665
0 votes
1 answer
27 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
  • 665
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
  • 665
0 votes
1 answer
266 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
427 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
430 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
22 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
25 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
  • 328
1 vote
0 answers
169 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
  • 665
3 votes
4 answers
2k 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
  • 96
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
46 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
0 votes
1 answer
129 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
130 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
127 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
  • 155
1 vote
1 answer
86 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
162 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
1 vote
1 answer
540 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
61 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
32 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
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
214 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
394 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
222 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
  • 189
1 vote
2 answers
438 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
1k 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
97 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
409 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
17 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
3 votes
1 answer
205 views

Using modifiers in Foundry `test`

Is it a good practice to create modifiers in Foundry tests? When testing cases, that share significant number of steps, but not that much that you want to create a separate testContract for them, with ...
Sergey Kaunov's user avatar
0 votes
1 answer
151 views

How should I approach testing functions that call already deployed contracts? [ethers.js] [chai] [mocha]

Suppose my contract utilizes the WETH contract (address 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2) in some manner. I can write test cases with Chai/Mocha just fine for most cases (they're "...
greentriangles1's user avatar
2 votes
1 answer
130 views

Truffle contract factory test with Javascript

Here is my smart contract source code. // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.9; contract CampaignFactory { address[] public deployedCampaigns; function createCampaign(uint ...
enthusiastic's user avatar
0 votes
1 answer
1k views

Sending multiple transactions in a block using Hardhat test network

Hardhat's test network, defaultNetwork: "hardhat" in config, automatically mines a block every time a transaction is sent by default. This is problematic for situations where I want to test ...
Shiri's user avatar
  • 786