The most comprehensive Foundry testing toolkit featuring:
- Standard test patterns
- Advanced invariant & fuzzing tests
- Handler-based differential testing
- A massive collection of test ideas grouped into categories like Staking, Bridge, and Yield
- Full VM cheatcode documentation
- Ready-to-use code snippets
Below is the directory structure of the project:
contract/
├── Foundry Test Cheatcode/
│ ├── foundryTestCheat.sol // Solidity file containing cheatcode examples
│ └── foundryTestCheat.json // JSON file for VS Code snippet integration
│
└── Vulnerability Idea/
├── securityIdea.sol // Solidity file containing test idea examples
└── securityIdea.json // JSON file for VS Code snippet integration
- foundryTestCheat.sol: Contains practical examples of Foundry cheatcodes for smart contract testing.
- foundryTestCheat.json: JSON file used to integrate Foundry cheatcodes into VS Code for autocomplete support.
- securityIdea.sol: Contains example function signatures for testing vulnerabilities based on real-world audits.
- securityIdea.json: JSON file used to integrate vulnerability test ideas into VS Code for autocomplete support.
✅ Smart Contract Test Ideas Collection
A curated list of 600+ test ideas that you can use as inspiration during smart contract audits or development. These ideas are grouped into categories such as Staking, Bridge, and Yield. Each idea is represented as a function signature, ready for implementation:
function test_third_party_redeem_burns_shares_from_owner_even_when_allowance_used() public;
function test_third_party_redeem_only_spends_approved_allowance_and_not_more() public;
function test_requestWithdrawal_allows_anyone_to_initiate_with_valid_parameters() public;
function test_rescueTokens_function_cannot_be_called_by_authorized_addresses() public;
function test_position_cannot_be_unwound_after_transfer_to_new_owner() public; These test ideas were extracted and refined from over 30 public and private security reviews conducted on protocols such as:
- YieldFi, Euler, Surge, Optimism, FyD May, Beanstalk
- Notional Leverage Vault, Sigma Prime, Rocketpool, Archimedes
- Tadle, PoolTogether, Lyra Finance, Biconomy, Axelar Network
- WooFiSwap, BaderDAO, Astaria, Ethene Labs, Velodrome Finance
Big thanks to platforms like Solodit for aggregating findings from these audits, making it easier to compile this extensive list of test ideas. Special thanks to:
- Cantina, Spearbit, Code4rena, Sherlock, Halborn, CyfrinAudit
- MixBytes, Lonelyslot, milotruck, oxdeadbeef, and others who made their findings public.
You can generate this list of test ideas by simply typing:
ideaTo scaffold a new test file based on the securityIdeas.json template.
✅ Foundry Cheatcode Snippets
Access a wide range of cheatcodes to streamline your smart contract testing. Activate cheatcodes by typing:
ftThis will leverage the cheatCode.json template for quick insertion of Foundry cheatcodes.
-
Clone the repository:
git clone https://github.com/Sir-Shaedy/Ultimate-Foundry-CheatCode.git cd Ultimate-Foundry-CheatCode -
Ensure you have both
foundryTestCheat.jsonandsecurityIdeas.jsonfiles available in the repository. These files are essential for activating cheatcodes (ft) and generating test ideas (idea).
[Step One]
Open the foundryTestCheat.json file in VS Code.
[Step Two]
Copy the entire content from the file.
[Step Three]
Press CTRL + SHIFT + P on your keyboard.
[Step Four]
Search for "snippet" and choose "Configure User Snippets."
[Step Five]
Select solidity and paste the copied content into the file:
{
// Paste the entire foundryTestCheat.json content here
}[Step Six]
Save the file (CTRL+S). Now you can use cheatcodes via autocomplete.
[Step Seven]
Repeat the process for securityIdeas.json.
function testTransfer() public {
// Setup
deal(alice, 1 ether);
vm.prank(alice);
// Execute
token.transfer(bob, 1 ether);
// Verify
assertEq(token.balanceOf(bob), 1 ether);
}contract InvariantTest is Test {
function invariant_balance_sum() public view {
assertEq(
token.balanceOf(alice) + token.balanceOf(bob),
token.totalSupply()
);
}
}contract TokenHandler is Test {
uint256 internal ghost_totalSupply;
function deposit(uint256 amount) public {
amount = bound(amount, 1, 100 ether);
token.deposit{value: amount}(user);
ghost_totalSupply += amount;
}
}vm.warp(block.timestamp + 1 days); // Fast forward time
vm.roll(block.number + 100); // Jump block numbervm.prank(alice); // Next call as alice
vm.startPrank(alice); // All subsequent calls as alice
deal(alice, 100 ether); // Fund user accountuint256 forkId = vm.createFork("mainnet");
vm.selectFork(forkId);vm.mockCall(
address(token),
abi.encodeWithSelector(token.balanceOf.selector, alice),
abi.encode(100 ether)
);uint256 gasBefore = gasleft();
token.swap();
console.log("Gas used:", gasBefore - gasleft());function testFuzz_Transfer(uint256 amount) public {
amount = bound(amount, 1, 1000 ether);
deal(alice, amount);
vm.prank(alice);
token.transfer(bob, amount);
}vm.recordLogs();
myContract.action();
Vm.Log[] memory logs = vm.getRecordedLogs();vm.expectRevert(abi.encodeWithSelector(CustomError.selector));interface VmSafe {
function readFile(string calldata) external view returns (string memory);
function envUint(string calldata) external view returns (uint256);
}interface Vm {
function etch(address, bytes calldata) external;
function broadcast() external;
function makePersistent(address) external;
}- 🔄 Always clean up with
vm.stopPrank()orvm.clearMockedCalls() - 🏷️ Use
vm.label(address, "Name")for better traceability - 📊 Generate detailed gas reports using
forge test --gas-report - 🧹 Keep test files modular – separate unit, invariant, handler tests
This project would not have been possible without the hard work of the following contributors and platforms:
- Cantina, Spearbit, Code4rena, Sherlock, Halborn, CyfrinAudit
- MixBytes, Lonelyslot, milotruck, oxdeadbeef, and many others who made their audit findings public.
- Special thanks to Solodit for aggregating these findings and making them easily accessible.
The test ideas in this repository were extracted and refined from over 30 audits, including those of YieldFi, Euler, Surge, Optimism, FyD May, Beanstalk, Notional Leverage Vault, Sigma Prime, Rocketpool, Archimedes, Tadle, PoolTogether, Lyra Finance, Biconomy, Axelar Network, WooFiSwap, BaderDAO, Astaria, Ethene Labs, Velodrome Finance, and more.
Thank you all for your contributions to the blockchain security community!
MIT – Feel free to use in your projects with proper attribution.