Files
nexus/wiki/entities/Foundry.md
2026-05-03 05:42:12 +08:00

36 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "Foundry"
type: entity
tags: []
last_updated: 2026-05-01
---
## Overview
Foundry 是最流行的 Solidity 开发框架之一(由 Paradigm 开发),提供 Forge测试、Cast合约交互、ChiselSolidity REPL等工具链。与 Hardhat 相比Foundry 以速度快Rust 实现)、内置 Fuzz 测试和 Invariant 测试著称。
## Key Tools
### Forge
- Solidity 测试框架,类比 Hardhat + Mocha
- 支持 `vm.prank()` / `vm.startPrank()` 模拟调用者
- 支持 `vm.expectRevert()` 验证 revert 行为
- 内置 `testFuzz_*` 模糊测试和 `testInvariant_*` 不变测试
- `forge snapshot` 生成 Gas 消耗快照
### Cast
- 命令行合约交互工具
- 发送交易、调用视图函数、解码事件
- 访问链上数据
### Anvil
- 本地 EVM 测试网络
- 可分叉主网进行集成测试
## 与 Solidity Smart Contract Engineer 的关系
- [[engineering-solidity-smart-contract-engineer]] 要求所有合约配备 Foundry 测试套件,分支覆盖率 >95%
- Foundry 的 Fuzz 测试是发现边界条件和算术漏洞的关键工具
- Gas 快照用于持续跟踪 Gas 优化效果
## Sources
- [[engineering-solidity-smart-contract-engineer]]