Skip to main content
18 votes
Accepted

Foundry not outputting console.log

You need to increase the verbosity of forge test That is, try forge test -vv for the log output. or forge test -vvvv for a full trace of every function call. https://book.getfoundry.sh/reference/...
Bob Baxley's user avatar
15 votes
Accepted

Hardhat vs foundry, which to use for testing?

When it comes to testing, Foundry excels compare to Hardhat, the speed difference is incredible. In my test with 1k queries and transactions on-chain the difference is from 15 min with hardhat to 1 ...
donoso.eth's user avatar
  • 1,503
14 votes
Accepted

Failed to get EIP-1559 fees error when deploying to ZkEVM polygon using Foundry

try to add suffix --legacy in forge script Note The solution works for zkSync as well.
TIROGEN's user avatar
  • 156
11 votes
Accepted

What's the difference between invariant and fuzz testing?

Summary Fuzz testing, also known as fuzzing, involves providing random data as inputs during testing. Invariant tests are tests that focus on verifying the conditions that must always hold in a system....
Patrick Collins's user avatar
10 votes
Accepted

How to send array of structs using Foundry cast

Figured it out! cast send CONTRACT_ADDRESS "updatePrices((address,uint256,uint256)[])" "[(ADDR,100,200),(ADDR,300,400)]" --rpc-url RPC_URL --private-key=P_KEY
Simon Liu's user avatar
  • 261
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
8 votes

How to spoof accounts using Foundry?

There is even a simpler solution than suggested by adijo. address someUser = vm.addr(somePrivateKey); To get the private key either use an integer > 0, or do it more properly like this string ...
Yves Boutellier's user avatar
8 votes
Accepted

How do I access an event in a foundry script?

You can use vm.recordLogs() and then just get the logs and access them. Also please note that vm.getRecordedLogs() function will consume the recorded logs when called. vm.recordLogs(); emit LogTopic1(...
Josep Bové'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
Accepted

Foundry skip compilation on test

We recently added forge build --skip <...>. So you can do forge build --skip test link and that will only compile src/. We also recently trimmed down forge-std for v1.2 so compilation times with ...
Georgios Konstantopoulos'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
7 votes
Accepted

Foundry pranking different in test contract vs contract

Your understanding is correct. The prank cheatcode only applies to calls made from your tests; you cannot use the prank cheatcodes to change the msg.sender of the test functions themselves. To quote ...
Paul Razvan Berg's user avatar
6 votes
Accepted

How to fund an address in foundry test

For most such cases you need to find a vm function that does what you want. I recommend you check out this link. In this case it's vm.deal where you pass in the address as well as the amount of ether ...
Yves Boutellier's user avatar
6 votes

Hardhat vs foundry, which to use for testing?

I agree with other answers about foundry's speed, it is incredible, as is its reandomization testing and its debugging options. So, if you need fast tests or are stuck on an error, quickly (and easily)...
kuco 23's user avatar
  • 278
6 votes
Accepted

How to configure multiple solidity compiler versions in foundry?

So it doesn't seem like Foundry allows you to manually configure multiple solc versions however Foundry does automatically detect and configure the required compilers for your project, you'll need to ...
MShakeG's user avatar
  • 1,733
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

vm.prank is not chaging the msg.sender

The prank() cheat code in Foundry pranks the sender of the next call (and only the next call), all your subsequent calls (ownerOf, approve) are back to the original context, including msg.sender. You ...
DrGorilla.eth's user avatar
5 votes

Hardhat vs foundry, which to use for testing?

Here is my experience with Hardhat - for us, Hardhat works very well. We use it as the Test Node, I think in the Foundry ecosystem this is equivalent to the Anvil. So here are the points why Hardhat ...
tenbits's user avatar
  • 2,428
5 votes
Accepted

How to configure custom ethereum node in foundry project?

Yes, Foundry allows users to configure custom Ethereum nodes. RPC-Endpoints settings Custom RPC endpoints can be defined in the foundry.toml under [rpc_endpoints] as follows: # foundry.toml [...
MShakeG's user avatar
  • 1,733
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,617
4 votes

Importing openzeppelin contracts in foundry

You need to add remapping to a separate remappings.txt file instead of foundry.toml. (Seems like the instructions in video is a bit outdated). Try to follow the instructions in https://w.mirror.xyz/...
Edvard's user avatar
  • 71
4 votes
Accepted

To run vm.expectEmit() in my foundry test, do I need to put the events in the testing contract or can they be inherited?

It is the way it's been done in the docs. See: https://book.getfoundry.sh/cheatcodes/expect-emit You will have to declare locally in your tests the events and do event Transfer(address indexed from, ...
Olivier Demeaux's user avatar
4 votes

To run vm.expectEmit() in my foundry test, do I need to put the events in the testing contract or can they be inherited?

I documented this in an article here if you're interested. An approach I've been taking to have it be a bit cleaner is to inherit an interface of events only. The downside to this approach is that you ...
JasonGarcia.eth'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

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

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
4 votes

Hardhat vs foundry, which to use for testing?

I personally use Foundry. You can test whatever you want in either, so won’t (and shouldn’t) have to use both in a given project. The biggest difference is that Foundry lets your write tests in ...
Alex Otsu's user avatar
  • 478
4 votes

Hardhat vs foundry, which to use for testing?

Go with Foundry - it's faster and more ergonomic than anything else on the market right now. Solidity code should be tested in Solidity itself. It doesn't matter if you are coming from the JavaScript ...
Paul Razvan Berg's user avatar
4 votes
Accepted

Truffle vs Hardhat vs Foundry and web3js vs ethersjs

For me it's just foundry. You have the telegram chat for support with the developers of it, it's faster than all the competitors and you can write your own tests/scripts with solidity itself. This ...
Josep Bové's user avatar

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