forge-std
1,064
Stars
0
Forks
0
Watchers
0
Open Issues
未知
许可证
Solidity
语言
创建时间
最近更新
项目能做什么
配合 Forge 和 Foundry 使用的智能合约与实用函数库集合。
来源:AI 基于仓库事实生成
· 内容以仓库实际 README 为准
使用说明 查看原始 README 原仓库文档
中文使用说明暂未生成。下面保留原仓库 README 摘录,命令与配置均以原文为准。
原始 README 摘录(英文原文,节选前 3000 字符)
# Forge Standard Library • [](https://github.com/foundry-rs/forge-std/actions/workflows/ci.yml)
Forge Standard Library is a collection of helpful contracts and libraries for use with [Forge and Foundry](https://github.com/foundry-rs/foundry). It leverages Forge's cheatcodes to make writing tests easier and faster, while improving the UX of cheatcodes.
**Learn how to use Forge-Std with the [📖 Foundry Book (Forge-Std Guide)](https://getfoundry.sh/reference/forge-std/overview/).**
## Install
```bash
forge install foundry-rs/forge-std
```
## Contracts
### stdError
This is a helper contract for errors and reverts. In Forge, this contract is particularly helpful for the `expectRevert` cheatcode, as it provides all compiler built-in errors.
See the contract itself for all error codes.
#### Example usage
```solidity
import "forge-std/Test.sol";
contract TestContract is Test {
ErrorsTest test;
function setUp() public {
test = new ErrorsTest();
}
function testExpectArithmetic() public {
vm.expectRevert(stdError.arithmeticError);
test.arithmeticError(10);
}
}
contract ErrorsTest {
function arithmeticError(uint256 a) public {
a = a - 100;
}
}
```
### stdStorage
This is a rather large contract due to all of the overloading to make the UX decent. Primarily, it is a wrapper around the `record` and `accesses` cheatcodes. It can _always_ find and write the storage slot(s) associated with a particular variable without knowing the storage layout. By default, writing to packed storage variables is not supported and will throw an error. However, you can enable packed slot support by calling `enable_packed_slots()` before using `find()` or `checked_write()`.
This works by recording all `SLOAD`s and `SSTORE`s during a function call. If there is a single slot read or written to, it immediately returns the slot. Otherwise, behind the scenes, we iterate through and check each one (assuming the user passed in a `depth` parameter). If the variable is a struct, you can pass in a `depth` parameter which is basically the field depth.
I.e.:
```solidity
struct T {
// depth 0
uint256 a;
// depth 1
uint256 b;
}
```
#### Example usage
```solidity
import "forge-std/Test.sol";
contract TestContract is Test {
using stdStorage for StdStorage;
Storage test;
function setUp() public {
test = new Storage();
}
function testFindExists() public {
// Let's say we want to find the slot for the public
// variable `exists`. We just pass in the function selector
// to the `find` command
uint256 slot = stdstore.target(address(test)).sig("exists()").find();
assertEq(slot, 0);
}
function testWriteExists() public {
// Let's say we want to write to the slot for the public
// variable `exists`. We just pass in the function se
阅读完整原文
商业机会分析 AI 生成
高级 DeFi 测试场景与 Mock 数据资产包(订阅制/买断)
| 产品构想 | 基于 forge-std 开发开箱即用的复杂 DeFi 协议交互与高保真 Mock/Fork 测试脚手架(如 Uniswap V3/V4, Aave, Compound 等深度集成的测试套件和预置 Cheatcodes 扩展)。 |
| 核心功能 | 一键本地 Fork 环境重现复杂交互;常见协议的接口 Mock 与状态速查库;预置套利、清算等边缘场景测试用例模板。 |
| 目标用户 | 独立 DeFi 开发者、中小型 Web3 协议开发团队 |
| 难度/周期 | 中等 · 1-2 个月 · 成本:极低(主要为开发和维护时间成本) |
| 收费模式 | 开源基础版,专业级复杂协议测试套件采用付费 License 或 GitHub Sponsors / Gumroad 售卖。 |
| 竞争风险 | DeFi 协议接口升级需频繁维护;开发者偏好自行编写简易 Mock。 |
| 依据 | 已验证事实 |
基于 Foundry 的安全审计辅助与断言规则库 (SaaS / CLI 工具)
| 产品构想 | 结合 forge-std 的 cheatcodes,构建自动化不变性测试(Invariant Testing)与模糊测试(Fuzzing)模板生成器,生成可用于安全审计报告的回归验证脚本。 |
| 核心功能 | 常见漏洞(重入、溢出、访问控制)的不变性断言规则库;一键导出覆盖率与攻击模拟结果;与 CI 深度集成的自动化审计检查脚本。 |
| 目标用户 | 智能合约安全审计师、协议安全工程师 |
| 难度/周期 | 高 · 2-3 个月 · 成本:低(云端测试运行节点或本地 CLI 分发) |
| 收费模式 | SaaS 订阅制(按月收取 CI 分析费用)或针对审计团队的席位授权许可。 |
| 竞争风险 | 安全工具市场竞争激烈(已有 Slither、Echidna、Certora 等成熟竞品)。 |
| 依据 | 数据支持的判断 |
企业级智能合约 CI/CD 测试加速与云端沙盒服务
| 产品构想 | 提供围绕 Foundry/forge-std 的测试监控平台,提供主网状态快照缓存、测试用例并行化加速、覆盖率可视化报告展示。 |
| 核心功能 | 私有 RPC 快照缓存加速 fork 测试;GitHub Actions / GitLab CI 无缝集成插件;详细的 Gas 消耗与回归性能对比面板。 |
| 目标用户 | 中大型 Web3 项目团队、去中心化自治组织 (DAO) 核心开发组 |
| 难度/周期 | 高 · 3-4 个月 · 成本:中等(RPC 节点成本、云服务器算力) |
| 收费模式 | 按测试构建时长与 RPC 流量阶梯计费(Usage-based SaaS)。 |
| 竞争风险 | 需要维护稳定的 RPC 基础设施,运维成本相对较高。 |
| 依据 | AI推测 |
AI 基于仓库公开数据分析生成,含推测成分,不构成收益承诺。
报告会保存到 个人中心
竞品与相似项目 GitHub Search 真实检索
| 项目 | 中文简介 | Stars | 语言 |
|---|---|---|---|
| libretro/libretro-database | 中文介绍暂未生成 Repository containing cheatcode files, content data files, e |
1,476 | Python |
| radixdevs/neo | 中文介绍暂未生成 A plugin that enables usage of cheatcodes in Break The Code |
138 | SCSS |
| a16z/halmos-cheatcodes | 中文介绍暂未生成 | 72 | Solidity |
| devtooligan/Huffpoint | 中文介绍暂未生成 Create breakpoints for use with Foundry debugger -- https:// |
32 | Solidity |
| codepo8/web-cheatcodes | 中文介绍暂未生成 Demo sites to explain non-developer how they can use browser |
29 | - |
| NiV-L-A/CLPS2C-Compiler | 中文介绍暂未生成 CLPS2C-Compiler is a compiler for CLPS2C, a domain-specific |
18 | C# |
以上为通过 GitHub 官方 Search API 检索的相似项目,功能差异与优劣势需进一步人工确认,配置 AI 后可生成对比分析。
项目优势与风险
| 技术成熟度 | 创建于 ,最近推送 ,发布过 44 个 Release |
| 社区活跃 | Star 1,064 / Fork 0 / Issue 0(数据支持,可自行核实) |
| 许可证 | 未检测到(需人工确认) |
| 主要风险 | 上游项目方向可能变化;同赛道竞争者较多(见竞品表);热度与需求不完全等价 |
安装与使用
快速开始(以仓库 README 为准)
git clone https://github.com/foundry-rs/forge-std.git cd forge-std # 请阅读仓库 README 获取确切安装步骤(依赖、配置、启动命令)
术语说明:Docker=应用容器(把程序和依赖打包运行);API Key=调用外部服务的密钥;Git Clone=把仓库代码下载到本地。常见错误:API Key 未配置 / 端口占用 / 数据库连接失败,多数项目在 README 的 Troubleshooting 章节有说明。