Skip to main content
Share Your Experience: Take the 2024 Developer Survey
10 votes
Accepted

Forge-std/Test.sol imported and working but VSCode marks an error

remappings.txt is used by VSCode to remap the imports (Forge might use the remappings declared in foundry.toml, remappings.txt or lookup in ./lib/ without the need to manually declare them, which is ...
DrGorilla.eth's user avatar
7 votes
Accepted

Catching custom error

SOLUTION 1: Best solution is using expectRevert cheat code from forge-std: vm.expectRevert(ExampleBridgeContract.InvalidCaller.selector); exampleBridge.convert(empty, empty, empty, empty, 0, 0, 0, ...
Jan Beneš's user avatar
7 votes

Foundry: skip specifics tests

In addition to the @Olivier Demeaux answer. If I needed to skip some tests I would do Make tests internal/private. Forge will run only public or external tests Remove the "test" word to ...
AGJoYy's user avatar
  • 426
6 votes

How to use anvil accounts in the Foundry Test

When you run the anvil command, you can use the exact same mnemonic (secret phrase) to generate the keys & addresses. anvil -m 'test test test test test test test test test test test junk' When ...
Patrick Collins's user avatar
5 votes
Accepted

Transaction gas cost in Foundry `forge` unit tests

It is not currently possible to create custom spans for gas reporting in Forge - or rather, Forge does not have a built-in mechanism for this. The only way you can achieve something similar, is to ...
onbjerg's user avatar
  • 398
5 votes
Accepted

How to deploy a contract in Foundry?

There are multiple different ways to deploy contracts in Foundry. The most basic ones use forge create and require you to pass some OPTIONS in-line when you run the command. Here is an example of ...
Rohan Nero's user avatar
  • 1,607
4 votes
Accepted

Foundry expectRevert on Custom Error with Multiple Errors

I had to remove the space between uint256 and uint256 on this line: bytes4 selector = bytes4(keccak256("MaximumContributionExceeded(uint256,uint256)"));
currenthandle's user avatar
4 votes

Foundry: skip specifics tests

For any forge test, we support filtering via matches. ➜ ~ forge t --help Run the project's tests. Usage: forge test [OPTIONS] Options: -h, --help Print help information (use `-h` for a ...
Georgios Konstantopoulos's user avatar
4 votes

Foundry: skip specifics tests

Yes you can! You just have to add "no_match_test" to your foundry.toml file, then the name of the test. I ran my tests, then added the line no_match_test = "testClaimTreasure" to ...
Olivier Demeaux's user avatar
4 votes
Accepted

How to Resolve Compiler Version Conflicts in Foundry Test Contracts?

Instead of trying to import contracts that are incompatible with your test contract's version and then attempting to deploy those contracts using the new keyword, you can instead use the StdCheats#...
MShakeG's user avatar
  • 1,703
3 votes

Exclusive tests in forge

For individual tests i use: forge test --match-path test/functional/**/$(TEST_NAME)\* This runs TEST_NAME in any subfolder after the the path test/functional
FreddyC's user avatar
  • 301
3 votes

Exclusive tests in forge

Yes you can! You can use forge test --match-contract $YourContractName or even forge test --match where, for exemple, if you use --match mint, forge will execute all tests that have 'mint' in their ...
Olivier Demeaux's user avatar
3 votes

How to solve incompatible solidity versions error in Foundry/forge

Those contracts define conflicting Solidity compiler versions, so they cannot be imported and built in the same contract as you are trying to do in your Pancake.sol file. You need to separate the ...
Giuseppe Bertone's user avatar
3 votes
Accepted

Withdraw fails in Foundry Test

When you want to withdraw and the signing account is the deployer and test contract itself (it's the same), like you have, then you need to give the contract TestContract is Test the ability to ...
Yves Boutellier's user avatar
3 votes
Accepted

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

Doing it this way would be a more accurate test: // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract address_test { function retSender() external view returns(address, address) { ...
Alexey Smirnov's user avatar
3 votes

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

I discovered that the signMessage function in ethers v6 follows EIP-191 , utilizing the string "\x19Ethereum Signed Message: + length of the message + message". For instance, if the message ...
Johnson's user avatar
  • 73
2 votes
Accepted

How does console.logging work (e.g. Foundry's Console.sol)?

The 0x000000000000000000636F6e736F6c652e6c6f67 address is for hardhat local blockchain that we use for testing our contracts locally, in the dev invironment. So, under the hoods, hardhat is sending ...
Jeremy Then's user avatar
  • 4,609
2 votes

Forge-std/Test.sol imported and working but VSCode marks an error

You need to edit .vscode/setting.json remove the following lines if you have them "solidity.packageDefaultDependenciesContractsDirectory": "src", "solidity....
erdaltuncberk's user avatar
2 votes

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

@xana Sorry address 0x7FA9385bE102ac3EAc297483Dd6233D62b3e1496 is consistent as for myself as well the same deployment address pops up
Capt Python's user avatar
2 votes

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

Your test contract is deployed to a different address than the one mentioned in the docs because each test contract has its own unique address. The address mentioned in the docs is just an example to ...
xana's user avatar
  • 51
2 votes

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

can it be that you have other 'forge' cli installed?, my help looks different: javiermac@Donosos-MacBook-Pro spool-foundry % forge help Build, test, fuzz, debug and deploy Solidity contracts. Usage: ...
donoso.eth's user avatar
  • 1,493
2 votes

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

SOLVED. My apologies, it turns out that the syntax call in the question was actually correct. I misspelled the function readTimeLock() which should have been instead of readTimelock(). I guess the ...
Jacobo Lansac's user avatar
2 votes

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

It seems to be a bug in Foundry. Or at least an incompatibility with how the Solidity compiler processes remappings. For solc your remappings are perfectly fine. This will compile just fine (assuming ...
cameel's user avatar
  • 2,241
2 votes
Accepted

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

If you want to install say the 2 versions of @openzeppelin/contracts stated in the question, they can be installed as follows: # notice show openzeppelin-contracts-solc-0.7= is prepended to the ...
MShakeG's user avatar
  • 1,703
2 votes

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

As long as your constructor is marked payable, you can modify your test like this: function setUp() public { test = new testContract{value: 777}( Owner; ); } You can ...
Rohan Nero's user avatar
  • 1,607
2 votes

Foundry script: balance mismatch of tx caller

Remove --private-key flag to view the original balance. Balance: 25476025062017363181 Actually, by default when the same caller is used with private key, foundry somehow adds more gas coin to the ...
abhi3700's user avatar
  • 219
2 votes

Mastering Foundry Basics

I recommend starting with the Cyfrin Foundry Fundamentals course. https://updraft.cyfrin.io/courses/foundry
Ougi's user avatar
  • 90
1 vote
Accepted

Encountering error when trying to run `forge create`

You should include your Alchemy's API key into your RPC url, like stated in Alchemy's docs: https://eth-goerli.g.alchemy.com/v2/[YOUR-API-KEY] However they do state that Goerli will be deprecated by ...
ChefAharoni's user avatar
1 vote

Forge-std/Test.sol imported and working but VSCode marks an error

Step 1: Identify the Missing Source file When you encounter the Source not found error, take note of the missing source file. In your case, it's forge-std/Test.sol. Step 2: Resolve the Issue To ...
Mujahid Ali's user avatar
1 vote

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

You can see an example of working with a struct or custom type here in the foundry abi-encode method. Example: cast abi-encode "someFunc((string,uint256))" "(myString,1)" For your ...
Patrick Collins's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible