Questions tagged [forge]

Questions related to Forge, the contract formatting, testing and build tool of the Foundry toolchain.

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

Foundry Logging no longer working for contracts in lib folder?

My fuzz tests are calling Smart Contracts in my lib/ folder. In these tests, I'm trying to log variables, but nothing is logged. Yes, I'm using -vv. I even increased verbosity (all the way up to -...
António Gonçalves's user avatar
0 votes
1 answer
33 views

Calling function from an onlyOwner smart contract

I have two separate contract files. One is the source contract to test and the other is a foundry test contract. Source Contract // SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.13; ...
Joel Deleep's user avatar
2 votes
0 answers
49 views

How to Statefully Fuzz in Foundry without Invariants?

I want to Statefully (not Statelessly) Fuzz my Protocol. However, I don't have any Invariants to check. I just want to call all of my Protocol's functions, and see if anything breaks. This is my ...
António Gonçalves's user avatar
0 votes
0 answers
5 views

Facing File Import error in Foundry

I am trying to run a forge test. I see the file is in place. But still facing this error. Compiler run failed: Error (6275): Source "src/oracles/reserve/EthxReserveOracle.sol" not found: ...
k engineering's user avatar
1 vote
1 answer
50 views

Why the signature is different when using ethers v6 and foundry?

I'm using ethers v6 and foundry to test message signing. Though having the same hashed message and the signer private key, I can't find out why the signature is different. The following is my script. ...
Johnson's user avatar
  • 43
0 votes
0 answers
7 views

forge build: respect original directory structure in output

For forge build, when compiling smart contracts, is it possible to tell forge to respect the original directory layout in output? If src contracts with .sol files has directories, those same ...
Mikko Ohtamaa's user avatar
4 votes
1 answer
135 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
  • 3,169
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
2 votes
1 answer
106 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
  • 3,169
0 votes
0 answers
41 views

Failed to extract foundry config:

I am currently creating a new project using foundry(used hardhat before this) and I am currently getting this error when I run forge build: failed to extract foundry config: foundry config error: ...
EGstacking's user avatar
0 votes
1 answer
24 views

Failure to return contract in deployment script using Foundry

I have a contract Lottery.sol which deploys a contract PriceFeed. In Lottery.sol : contract PriceFeed { ..... } contract Lottery { PriceFeed public price_feed = new PriceFeed(); } In my Foundry ...
nostonksafrica's user avatar
0 votes
0 answers
48 views

Segmentation fault when running forge init

I got the "Segmentation fault" when I tried to run the command "forge init".chatgpt answer is "A Segmentation fault is a specific kind of error caused by accessing memory that ...
kumar's user avatar
  • 41
0 votes
1 answer
24 views

revert: No run-latest.json file found for specified chain

here is my integration script. // SPDX-License-Identifier: MIT pragma solidity ^0.8.18; import {Script, console} from "forge-std/Script.sol"; import {DevOpsTools} from "lib/foundry-...
Ibrahim Umar's user avatar
0 votes
0 answers
31 views

Using Forge, how can I output the contract content in the output metadata?

I want to get the source code sent to the compiler when using forge build. The output files currently have only the urls and not the content: "sources": { "contracts/MyContract....
Milk's user avatar
  • 411
0 votes
0 answers
20 views

Set forge fuzz.runs in github CI tests

I have a test using forge like so: /** * Reduce fuzz runs. * forge-config: default.fuzz.runs=10 */ function testMyThing(uint256 rng) external { // ... } When I run ...
Milk's user avatar
  • 411
0 votes
1 answer
148 views

trying to create contract on anvil/forge get error intrinsic gas too high

exact message: message: intrinsic gas too high -- CallGasCostMoreThanGasLimit, data: None generic counter contract from how to. googling around got me some old error somewhat related but not sure ...
Pavel Zaitsev's user avatar
2 votes
1 answer
150 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
1 vote
1 answer
270 views

How can I test in Foundry with multiple addresses?

Is there any way to test with multiple addresses using forge like you can in Truffle or Hardhat? Like Truffle gives you an array of addresses you can call and that changes the msg.sender calling the ...
Wes's user avatar
  • 55
1 vote
1 answer
176 views

How to customize forge formatter in vscode

I'm using Foundry toolchain and vscode for my smart contracts development. As suggested by the Foundry documentation I applied the vscode integration tweaks and I'm using forge formatter to format my ...
forhas's user avatar
  • 775
0 votes
1 answer
213 views

How to use anvil accounts in the Foundry Test

How can i use anvil accounts into the foundry tests? Like in hardhat node i can getNamedAccounts() but how can I use the anvil accounts into my forge Tests?
Saad Suri's user avatar
0 votes
1 answer
284 views

vm.startPrank doesn't change the msg.sender in foundry

While I'm performing the testing in foundry. I'm facing an issue of vm.startPrank doesn't change the msg.sender. CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D); address ...
Saad Suri's user avatar
3 votes
1 answer
1k views

How to deploy a contract in Foundry?

I want to deploy a smart contract using Foundry, but I don't want to pass my variables every time I run forge create inside of the terminal and I don't want to have to follow up every deployment with ...
Rohan Nero's user avatar
  • 1,492
1 vote
1 answer
160 views

foundry forge vm.rollFork not working as expected

I'm using vm.rollFork feature in foundry to get _token.totalSupply() at two different blocks but test failing because its returning same totalSupply number for two different blocks. I have checked and ...
Doe's user avatar
  • 23
3 votes
1 answer
613 views

How to Resolve Compiler Version Conflicts in Foundry Test Contracts?

I'm working on a Foundry project, and I'm encountering issues with compiler versions when trying to deploy Uniswap V3 core and periphery contracts in a test contract(i.e. UniswapTest shown below). The ...
MShakeG's user avatar
  • 1,593
1 vote
1 answer
238 views

How can I install multiple versions of a dependency in foundry?

In hardhat multiple versions of a dependency can be installed as follows in the package.json(assuming yarn is being used): "@openzeppelin/contracts": "^4.3.2", "openzeppelin-...
MShakeG's user avatar
  • 1,593
0 votes
1 answer
278 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
2 votes
1 answer
258 views

Does Foundry Support Dynamical Library Linking in Solidity?

I would like to deploy a contract that has external library dependencies that need to be dynamically linked. This is typically done in hardhat ethers as follows: const MyLibrary = await ethers....
MShakeG's user avatar
  • 1,593
1 vote
0 answers
134 views

How to test Chainlink Operator.sol in Foundry and find cause of revert?

I am trying to rewrite this test from Truffle/Javascript to Foundry/Solidity. This is the specific part I am stuck on: it("should not fulfill from unauthorized job", async function () { ...
palmcivet's user avatar
0 votes
1 answer
287 views

Encountering error when trying to run `forge create`

I am in the process of switching to foundry for contract development and testing. I have written some basic contracts, and am trying to use the alchemy RPC URL to deploy the contracts onto the testnet ...
immaxkent's user avatar
  • 499
0 votes
1 answer
453 views

Why do I get "Nothing to compile" everytime I run forge test -m *testname* on my foundry project?

I always get "Nothing to compile" everytime I run forge test -m testname on my foundry project and I don't know why
joe17ar's user avatar
  • 15
1 vote
0 answers
111 views

Is there any natural source of entropy when running `forge test`?

I'm looking for a pseudo-random value that is different each time the command is run. Either forge test or forge script.
Paul Razvan Berg's user avatar
3 votes
2 answers
2k views

How to use foundry cast call when the method returns a struct?

In a deployed contract (in sepolia) there is a method readTimelock(address,uint256) that returns a TimeLock, which is a struct like the following: struct TimeLock{ uint160 amount, uint64 ...
Jacobo Lansac's user avatar
0 votes
1 answer
353 views

Alter deploy address for contract created with `new` keyword

I have a forge test that contains new MyContract();. However the address that MyContract is deployed to just so happens to be in use by another contract, so the test fails. Is there a way to alter the ...
Milk's user avatar
  • 411
0 votes
0 answers
40 views

How to provide liquidity to PancakeSwapV3 farming?

I try to provide liquidity to PancakeSwapV3 farming. To do it I call safeTransferFrom method of NonfungiblePositionManager (https://bscscan.com/address/0x46a15b0b27311cedf172ab29e4f4766fbe7f4364). ...
Dmitriy's user avatar
  • 101
0 votes
1 answer
112 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
  • 665
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
1 vote
1 answer
655 views

Foundry is not able to install solc

Hi I just installed ubuntu 22 lts and then installed foundry. forge init works fine, but on forge test or forge buildit gets stuck on installing solc i have tried to cancel the operation and redo it, ...
Ren's user avatar
  • 27
2 votes
1 answer
754 views

How to sign message using Foundry?

The current documentation includes a way to sign messages; however, it returns (v, r, s) values. How to construct a signature from these values?
Emrah's user avatar
  • 1,624
1 vote
1 answer
377 views

How to move funds around using foundry in forked mainnet?

In mainnet forking, I am trying to move some fund, say from one LP token contract to address I control so that I can test functionality. Is there any cheatcode that enables me to do this?
Emrah's user avatar
  • 1,624
3 votes
1 answer
440 views

In forge tests, how can I import events?

In forge tests I've been redeclaring events within the test file so that I can use vm.assertEmit. Is there a way to import events from the contract I am testing instead? e.g. // SPDX-License-...
Milk's user avatar
  • 411
0 votes
1 answer
788 views

Why does my code not compile under Foundry when I use remappings with overlapping paths?

I want the following import in src: // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.16; pragma abicoder v2; import "@openzeppelin/contracts/utils/Address.sol"; import "@...
azvast's user avatar
  • 131
0 votes
0 answers
70 views

Problem with delegatecall

I want to change owner of USDT smart contract in arbitrum chain (EVM) with foundry forge but it dont changed with delegatecall. How can I change with delegatecall? Here is my code. // SPDX-License-...
K. Khurshudyan's user avatar
0 votes
1 answer
577 views

Fuzz Testing in Foundry: expectRevert Not Working (Call reverted as expected, but without data)

I am trying to check for a custom error with expectRevert in my Foundry test. Everything works however, after converting the following test to a fuzz test, it no longer works. How can I resolve this? ...
currenthandle's user avatar
3 votes
0 answers
207 views

Can't Access Properties Off of Struct In Foundry / Forge: Possibly Due to Nested Mapping

I am unable to get attributes off a struct in my contract from my Foundry test file. How can I get a property off an instance of a struct in my contract from my Foundry test file. In DAO.sol contract (...
currenthandle's user avatar
0 votes
0 answers
231 views

Continue to execute Foundry Script after error

I'm running a foundry script and wondered if it was possible to continue to execute the script after an error ? The program does not run as soon as it encounters an error. Currently I am debugging ...
0xheartcode's user avatar
0 votes
1 answer
695 views

Deploy to Sepolia Infura Foundry: Solidity Scripting

I'm trying to deploy my contract with Foundry Solidity Scripting to Infura on the Seoplia test net. But Im getting this weird issue that appears to be related to the Infura API Key (formerly Project ...
currenthandle's user avatar
3 votes
2 answers
2k views

Foundry expectRevert on Custom Error with Multiple Errors

I am attempting to expectRevert on a custom error with MULTIPLE parameters by following the example in the office Foundry. I am able to get it to work with a single parameter. But as soon as I add a ...
currenthandle's user avatar
1 vote
2 answers
785 views

Why is my foundry test contract not deploying to the 0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84 address?

I was reading in the docs that the test address is deployed to 0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84 yet when I try to console.log(address(this)) inside of my test, I get returned a different ...
Rohan Nero's user avatar
  • 1,492
1 vote
1 answer
433 views

How to use fix `forge update` error

When I originally type forge update I get returned this: Error: fatal: Needed a single revision Unable to find current origin/v1.3.0 revision in submodule path 'lib/forge-std' After following steps ...
Rohan Nero's user avatar
  • 1,492
0 votes
1 answer
63 views

Why contract owner suddenly has bunch of zeros as prefix?

I am making upgradeable erc20 smart contract using chugsplash as upgrader and foundry as framework. It's name is FractionToken.sol and has it test contract FractionToken.t.sol. It went well(The ...
zubeir muhammad arhesta's user avatar