CHEATCODES:-
------------------------------------------------------------------------------

 ๐Ÿงช Testing

* `forge test` โ†’ Run tests (fast + parallelized).
* `setUp()` โ†’ Runs before every test (fresh state).
* `beforeTest()/beforeTestSetup()` โ†’ Setup code for specific tests.
* `assertEq`, `assertTrue`, etc. โ†’ Assertions.
* `vm.expectRevert` โ†’ Catch reverts.
* `vm.expectEmit` โ†’ Check for emitted events.
* **Fuzz Testing** โ†’ Auto-generate random inputs.
* **Invariant Testing** โ†’ Ensure rules always hold (`assert` properties across fuzz loops).

---

โšก Cheatcodes (vm.)

* `vm.warp` โ†’ Change block timestamp.
* `vm.roll` โ†’ Change block number.
* `vm.prank` / `vm.startPrank` / `vm.stopPrank` โ†’ Impersonate accounts.
* `vm.deal` โ†’ Give ETH to any address.
* `vm.mockCall` / `vm.expectCall` โ†’ Mock/verify contract calls.
* `vm.snapshot` / `vm.revertTo` โ†’ Save/restore EVM state.
* `vm.fee` / `vm.txGasPrice` โ†’ Manipulate gas-related values.
* `vm.env*` โ†’ Load env vars (like private keys).

---

๐Ÿ–ฅ๏ธ Scripts & Deployments

* `forge script` โ†’ Run Solidity deployment scripts.
* `--broadcast` โ†’ Actually send transactions.
* `--verify` โ†’ Auto-verify contracts on Etherscan.
* Multi-chain ready โ†’ Just switch `--rpc-url`.

---

 ๐ŸŒ Forking

* `vm.createFork`, `vm.selectFork` โ†’ Fork mainnet/testnet.
* `vm.makePersistent` โ†’ Keep state between forks.
* Common use: Test Uniswap, Aave, Compound logic on **real blockchain state**.

---

 ๐Ÿ” Debugging

* `forge test -vvvv` โ†’ Detailed logs (tx traces, storage, logs).
* `console.log` / `console2.log` โ†’ Print variables while testing.
* `cast` โ†’ Inspect chain state (`cast call`, `cast send`, `cast block`, etc.).

---

 ๐Ÿ› ๏ธ Developer Utilities

* **Gas Snapshots** โ†’ `forge snapshot` compares gas usage across commits.
* **CI Friendly** โ†’ Works fast in GitHub Actions / pipelines.
* **FFI (Foreign Function Interface)** โ†’ Run external scripts from Solidity (advanced).
* **Configurable via foundry.toml** โ†’ Networks, remappings, compiler settings.

---

 ๐Ÿงพ TL;DR โ€“ Most Used Daily

1. `forge test` (with fuzz + invariants).
2. `vm.prank`, `vm.warp`, `vm.expectRevert`.
3. Forking with `vm.createFork` for DeFi contracts.
4. Scripts: `forge script ... --broadcast`.
5. Debugging: `forge test -vvvv`, `console.log`.
6. Deploy + Verify in one command.
7. Gas snapshots for optimizations.

๐ŸŽฎ Cheatcodes in Foundry โ€” ๐ŸŽฎ

Cheatcodes are special functions provided by Foundryโ€™s vm (Virtual Machine) object that allow you to manipulate the testing environment in ways that are impossible on a real blockchain. They are your "superpowers" for writing powerful, flexible, and realistic tests.

โš ๏ธ Important Note: Cheatcodes are only available in tests and scripts. They are disabled on real networks. They are not "cheating" in a bad sense โ€” they are essential tools for robust testing.


๐Ÿ“š 1. What are Cheatcodes?

Cheatcodes are functions from the Vm interface (usually accessed via the global vm variable in your test contracts) that let you:

You get access to vm by inheriting from the Test contract in your test file:

import "forge-std/Test.sol";

contract MyTest is Test {
    // You can now use vm.<cheatcodeName>()
}


๐Ÿ•ฐ๏ธ 2. Environment Manipulation Cheatcodes

These cheatcodes let you control the blockchain's "state" during your tests.

A. vm.warp(uint256 timestamp)