Foundry
Fast build and testing of Solidity Smart Contracts in Rust.
Env Variables
NEVER use a .env file
Don't use VS Code but direct in terminal
cast wallet import defaultKey --interactive
Remove all history with any keys.
history -c
rm .bash_history
Resources
Testing
https://github.com/foundry-rs/forge-std
Tests are deployed to 0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84. If you deploy a contract within your test, then 0xb4c...7e84 will be its deployer. If the contract deployed within a test gives special permissions to its deployer, such as Ownable.sol's onlyOwner modifier, then the test contract 0xb4c...7e84 will have those permissions.
Use the getCode cheatcode to deploy contracts with incompatible Solidity versions.
Cheatcodes - IMPORTANT
Most of the time, simply testing your smart contracts outputs isn't enough. To manipulate the state of the blockchain, as well as test for specific reverts and events, Foundry is shipped with a set of cheatcodes.
Cheatcodes allow you to change the block number, your identity, and more. They are invoked by calling specific functions on a specially designated address: 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D.
You can access cheatcodes easily via the vm instance available in Forge Standard Library's Test contract. Forge Standard Library is explained in greater detail in the following section.
Forge Standard Library
Forge Standard Library (Forge Std for short) is a collection of helpful contracts that make writing tests easier, faster, and more user-friendly.
Using Forge Std is the preferred way of writing tests with Foundry.
It provides all the essential functionality you need to get started writing tests:
Vm.sol: Up-to-date cheatcodes interface console.sol and console2.sol: Hardhat-style logging functionality Test.sol: A superset of DSTest containing standard libraries, a cheatcodes instance (vm), and Hardhat console Simply import Test.sol and inherit from Test in your test contract:
Forking mode
Forking is especially useful when you need to interact with existing contracts, and you may choose to do integration testing this way, as if you were on an actual network.
Advanced Testing
One the main attractions of using Foundry.