Skip to main content

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
95 views

Mastering Foundry Basics

I'm interested in learning Foundry. What are the most effective resources and strategies you recommend for getting started with Foundry?
serpent0x's user avatar
0 votes
0 answers
14 views

Can you Fuzz test with random parameters in the setUp() function in Forge?

Context After looking at this documentation about fuzz testing, I tried to apply it to the setUp() function in my test. However, that throws an error. I would like to test that the random stuff that I ...
a.t.'s user avatar
  • 79
0 votes
0 answers
30 views

I have a problem with calling a function from another contract. I don't know why it is not working

I'm trying to solve a CTF challenge and can't seems to call the claim function from the vuln contract. I must use my "EOA" address to solve task to mark it solved, because my "EOA" ...
jose celis's user avatar
1 vote
1 answer
33 views

Foundry error on CLI command

forge create --rpc-url $QUICKNODE_RPC_URL --private-key $PRIVATE_KEY --etherscan-api-key $ETHERSCAN_API_KEY --verify src/Token.sol:Token [⠒] Compiling... No files changed, compilation skipped The ...
Flegi's user avatar
  • 13
0 votes
1 answer
17 views

How to set custom header using foundry?

On etherjs you can send a custom header as follows. import { ethers } from "ethers"; const connection = { url: "https://custom.rpc.url.com", headers: [ "Authorization&...
Irshad's user avatar
  • 1
1 vote
0 answers
37 views

Unable to update forge on windows

I am trying to run foundryup on windows to update foundry. Tried with git bash, it gives me this error : foundryup: installing foundry (version nightly, tag nightly) foundryup: downloading latest ...
RajaSolidity's user avatar
1 vote
0 answers
21 views

How to predeploy and verify a linked library?

There are 40 zeros as padding in the bytecode compiled with the library. And when deploying a contract that uses linked libraries, the contract's bytecode contains the libraries addresses. There is a ...
Sia's user avatar
  • 11
0 votes
1 answer
13 views

Simulating the passing of time in forge test for a timelocked contract?

Context I wrote a contract that aims to raise uint256 investmentTarget funds, within a time period of uint32 private _raisePeriod; after the constructor has been initialised at _startTime = block....
a.t.'s user avatar
  • 79
1 vote
1 answer
46 views

Foundry script: balance mismatch of tx caller

Found a balance mismatch (between actual & shown) for the caller's address when used as vm.startBroadcast(caller) in foundry script: You can reproduce the error using this foundry script: contract ...
abhi3700's user avatar
  • 219
0 votes
1 answer
17 views

Displaying terminal logs while calling a function from a specific wallet in Forge test?

Context As part of a test I would like to assert the funds from wallet investorWallet are reduced with the investmentAmount after an investment is made (by calling the receiveInvestment function in ...
a.t.'s user avatar
  • 79
0 votes
1 answer
17 views

Compiler run failed

So a bit of a N00b problem, Error (6275): Source "/root/solidity-course/src/SimpleStorage.sol" not found: File not found. Searched the following locations: "/root/solidity-course"....
neo_maredi's user avatar
0 votes
0 answers
31 views

Unable to transfer contract ether using call

Hi I am running a forge script against local Anvil and Im not sure why but my contract will not transfer ether. Contract does hold an eth balance, even when testing with very small amounts it fails (...
chr's user avatar
  • 56
2 votes
1 answer
68 views

Foundry interact with deployed contract

I have my Contract A which creates an ERC20 in the constructor. In the ContractA.t.sol I want to get the ERC20 to interact with it (I have a public method inside Contract A to get the ERC20 address). ...
Facundo Moreno's user avatar
0 votes
0 answers
32 views

How to set different etherscan api for different networks in foundry

I'm in the process of deploying the same contract across two different blockchains, with the intention of verifying them once deployed. I have obtained the API keys from Etherscan for both networks. ...
Emrah's user avatar
  • 1,664
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
2 votes
1 answer
80 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
52 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
64 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
1 vote
1 answer
47 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
2 votes
1 answer
225 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
  • 73
0 votes
0 answers
8 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
2 answers
398 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,484
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
1 vote
1 answer
371 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,484
0 votes
0 answers
150 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
61 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
91 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
  • 61
1 vote
1 answer
38 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
2 votes
1 answer
80 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
  • 463
1 vote
1 answer
31 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
  • 463
0 votes
1 answer
363 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
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
1 vote
1 answer
568 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
434 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
  • 785
2 votes
3 answers
528 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
  • 109
0 votes
1 answer
492 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
  • 109
4 votes
1 answer
2k 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,617
1 vote
1 answer
221 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
4 votes
1 answer
1k 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,733
2 votes
1 answer
445 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,733
0 votes
1 answer
476 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
420 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,733
1 vote
0 answers
157 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
567 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
  • 519
0 votes
1 answer
650 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
2 votes
0 answers
148 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
4 votes
2 answers
4k 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
524 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
  • 463
0 votes
1 answer
141 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
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