---
marp: true
title: 03 Foundry workflow
---

# 03 Foundry workflow

---

## The tools
- `forge` build, test, fuzz, coverage, scripts
- `anvil` local EVM node (test accounts with fake ETH)
- `cast` call / send / decode from the shell
- `chisel` Solidity REPL

---

## Project layout
```
foundry.toml   # solc 0.8.24, evm_version = "cancun" for XDC mainnet
src/           # contracts
test/          # *.t.sol, contracts that inherit forge-std Test
script/        # *.s.sol deploy scripts
```

---

## Tests in Solidity
```solidity
function test_RevertWhen_Full() public {
    vm.prank(alice); seats.book();
    vm.prank(bob);   seats.book();
    vm.expectRevert(WorkshopSeats.Full.selector);
    seats.book();
}
function testFuzz_NeverOverbooked(uint8 n) public { ... }
```
Cheatcodes: `vm.prank`, `vm.warp`, `vm.expectRevert`, `makeAddr`, `vm.createSelectFork`

---

## Local deploy loop
```bash
anvil --port 18513
forge script script/Deploy.s.sol --rpc-url http://127.0.0.1:18513 \
  --broadcast --private-key <anvil test account #0>
cast call <addr> "seatsLeft()(uint256)" --rpc-url http://127.0.0.1:18513
```
Same commands target XDC/Apothem by changing `--rpc-url` (not in this workshop).

---

## Habits
- `forge fmt`, `forge test --gas-report`, `forge coverage`
- Keys: never in files or repos; use hardware/keystore (`cast wallet import`) for real deploys

→ Lab 1
