Skip to content

Commit 17656a2

Browse files
ZeroEkkusuPaulRBergmds1DrakeEvanspcaversaccio
authored
feat: forge-std v1.0.0 (#184)
* Modularize forge-std (#126) * refactor: unbundle cheats from assertions refactor: new category StdUtils refactor: unbundle Test from Script * Rename "vm" to "vm_cheats" in "Cheats.sol" Mark "vm_cheats" as "private" Instantiate a "vm" in "Test.sol" * refactor: remove deprecated "lowLevelError" refactor: rename "vm_cheats" to just "vm" refactor: rename "vm_std_store" to just "vm" refactor: delete "INT256_MAX" and "UINT256_MAX" revert: redeclare "stdstore" in "Test" * refactor: move "stdErrors" to "Errors.sol" refactor: move "stdMath" to "Math.sol" * Add note about versions in "Errors.sol| Co-authored-by: Zero Ekkusu <[email protected]> * chore: delete stale delineators in Errors and Math chore: delete stale "using stdStorage for StdStorage" * refactor: modularize assertions and utils docs: add NatSpec tag @dev in "console2" refactor: delete log from "bound" function refactor: move "addressFromLast20Bytes" to "Utils.sol" refactor: move "bound" to "Utils.sol" refactor: move "computeCreateAddress" to "Utils.sol" style: move brackets on same line with "if" and "else" in "bound" * Log bound result with static call to `console.log` Co-authored-by: Zero Ekkusu <[email protected]> * fix: reintroduce "vm" in "Script.sol" chore: silence compiler warning in "bound" refactor: define console2.log address as constant in "Utils.sol" * test: move "testGenerateCorrectAddress" to "StdUtils.t.sol" * Nit: remove unnecessary "bytes20" casts * style: add white-spaces in "deal" * fix: readd "deployCode" functions with "val" * Add "computeCreate2Address" utility Rename "testGenerateCorrectAddress" to "testGenerateCreateAddress" * refactor: use "console2" in "Utils.sol" * style: end lines and white spaces * test: drop pragma to ">=0.8.0" in "StdError.t.sol" chore: remove comment about "v0.8.10" in "Errors.sol" * refactor: define "vm" and "stdStorage" in "TestBase" feat: add "Components.sol" file which re-exports everything * fix: inherit from DSTest in Test * feat: ScriptBase refactor: delete "TestBase.sol" refactor: move TestBase in "Test.sol" * ♻️ Make assertions virtual * ♻️ Make deployCode virtual * ✨ (Components) Export consoles * ♻️ (Script) Import Vm * ♻️ Import from Components * ♻️ Make bound view Co-authored-by: Zero Ekkusu <[email protected]> * feat: make `Script` safer (#147) * feat: add `stdStorageSafe` * test(cheats): fix tests `deployCode` tests started failing after 01c60f9 * refactor: make components `abstract` * feat: add `CheatsSafe` * feat: add `VmSafe` * refactor: update `Script` * docs: add license info (#156) * feat: rebrand components (#157) * feat: rebrand components Rename to Std<Component> * fix: StdErrors -> StdError * chore: remove `.DS_Store` * fix: use `ABIEncoderV2` * test: correct test name * fix: add `CommonBase` * refactor: move test dir to root * Revert "refactor: move test dir to root" This reverts commit f21ef1a. * refactor: move test dir to root, update ci accordingly * style: configure and run forge fmt * ci: split into jobs and add fmt job * ci: update name and triggers * ci: remove name field * feat: better bound, ref #188 * fix: bound logs + remove unneeded line * fix: update require strings * refactor: clean up `Test` and `Script` - do not forge fmt Components import - do not import Safe Components in `Test` * fix: udpate bound to match forge's uint edge bias strategy * feat: add interfaces (#193) * chore: update function visibility * feat: add interfaces * fix: fix import * style: consistent spec style * chore: fix find/replace issue Co-authored-by: Zero Ekkusu <[email protected]> * chore: update comments Co-authored-by: Zero Ekkusu <[email protected]> Co-authored-by: Zero Ekkusu <[email protected]> * feat: reimplement `bound` w/ even distribution * build: rename step * Add memory-safe notation so that compiling via-ir can optimize effectively (#196) * test(bound): add even distribution test (#197) * feat: add `assumeNoPrecompiles` (#195) * refactor: use fully-qualified paths instead of relative paths * chore: fix typo * feat: start adding StdChains * feat: start adding assumeNoPrecompiles * feat: add chains * feat: add precompiles/predeploys * Revert "refactor: use fully-qualified paths instead of relative paths" This reverts commit bb2579e. * refactor: use relative paths for compatibility with solc <0.6.9 (no --base-path flag) * refactor: make assumeNoPrecompiles virtual * refactor: no more constructor warning from StdChains * fix: move stdChains into StdCheats, fix constructor initalization order, move cheats into VmSafe that can be safely used * ♻️ update ds-test (#200) * ♻️ update ds-test Signed-off-by: Pascal Marco Caversaccio <[email protected]> * ♻️ use relative path for ds-test imports Signed-off-by: Pascal Marco Caversaccio <[email protected]> Signed-off-by: Pascal Marco Caversaccio <[email protected]> * refactor: move `UINT256_MAX` to `CommonBase` Signed-off-by: Pascal Marco Caversaccio <[email protected]> Co-authored-by: Paul Razvan Berg <[email protected]> Co-authored-by: Matt Solomon <[email protected]> Co-authored-by: Drake Evans <[email protected]> Co-authored-by: Pascal Marco Caversaccio <[email protected]>
1 parent 2a2ce36 commit 17656a2

36 files changed

+2553
-1870
lines changed

.github/workflows/ci.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: CI
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- master
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Install Foundry
17+
uses: onbjerg/foundry-toolchain@v1
18+
with:
19+
version: nightly
20+
21+
- name: Install dependencies
22+
run: forge install
23+
24+
- name: Check backward compatibility
25+
run: |
26+
forge build --skip test --use solc:0.8.0
27+
forge build --skip test --use solc:0.7.6
28+
forge build --skip test --use solc:0.7.0
29+
forge build --skip test --use solc:0.6.2
30+
31+
test:
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v3
35+
36+
- name: Install Foundry
37+
uses: onbjerg/foundry-toolchain@v1
38+
with:
39+
version: nightly
40+
41+
- name: Install dependencies
42+
run: forge install
43+
44+
- name: Run tests
45+
run: forge test -vvv
46+
47+
fmt:
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v3
51+
52+
- name: Install Foundry
53+
uses: onbjerg/foundry-toolchain@v1
54+
with:
55+
version: nightly
56+
57+
- name: Check formatting
58+
run: forge fmt --check

.github/workflows/tests.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
cache/
22
out/
33
.vscode
4-
.idea
4+
.idea

LICENSE-APACHE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright Contributors to forge-std
1+
Copyright Contributors to Forge Standard Library
22

33
Apache License
44
Version 2.0, January 2004

LICENSE-MIT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright Contributors to forge-std
1+
Copyright Contributors to Forge Standard Library
22

33
Permission is hereby granted, free of charge, to any
44
person obtaining a copy of this software and associated

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Forge Standard Library • [![tests](https://github.com/brockelmore/forge-std/actions/workflows/tests.yml/badge.svg)](https://github.com/brockelmore/forge-std/actions/workflows/tests.yml)
22

3-
Forge Standard Library is a collection of helpful contracts 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.
3+
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.
44

5-
**Learn how to use Forge Std with the [📖 Foundry Book (Forge Std Guide)](https://book.getfoundry.sh/forge/forge-std.html).**
5+
**Learn how to use Forge-Std with the [📖 Foundry Book (Forge-Std Guide)](https://book.getfoundry.sh/forge/forge-std.html).**
66

77
## Install
88

@@ -13,7 +13,7 @@ forge install foundry-rs/forge-std
1313
## Contracts
1414
### stdError
1515

16-
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 builtin errors.
16+
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 builtin errors.
1717

1818
See the contract itself for all error codes.
1919

@@ -244,3 +244,7 @@ import "forge-std/console.sol";
244244
...
245245
console.log(someValue);
246246
```
247+
248+
## License
249+
250+
Forge Standard Library is offered under either [MIT](LICENSE-MIT) or [Apache 2.0](LICENSE-APACHE) license.

foundry.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,21 @@
11
[profile.default]
22
fs_permissions = [{ access = "read-write", path = "./"}]
3+
4+
[rpc_endpoints]
5+
# We intentionally use both dashes and underscores in the key names to ensure both are supported.
6+
# The RPC URLs below match the StdChains URLs but append a trailing slash for testing.
7+
mainnet = "https://api.mycryptoapi.com/eth/"
8+
optimism_goerli = "https://goerli.optimism.io/"
9+
arbitrum-one-goerli = "https://goerli-rollup.arbitrum.io/rpc/"
10+
11+
[fmt]
12+
# These are all the `forge fmt` defaults.
13+
line_length = 120
14+
tab_width = 4
15+
bracket_spacing = false
16+
int_types = 'long'
17+
multiline_func_header = 'attributes_first'
18+
quote_style = 'double'
19+
number_underscore = 'preserve'
20+
single_line_statement_blocks = 'preserve'
21+
ignore = ["src/console.sol", "src/console2.sol"]

lib/ds-test

Submodule ds-test updated 1 file

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "forge-std",
3-
"version": "0.1.0",
4-
"description": "Forge Standard Library is a collection of helpful contracts for use with forge and foundry",
3+
"version": "1.0.0",
4+
"description": "Forge Standard Library is a collection of helpful contracts and libraries for use with Forge and Foundry.",
55
"homepage": "https://book.getfoundry.sh/forge/forge-std",
66
"bugs": "https://github.com/foundry-rs/forge-std/issues",
77
"license": "(Apache-2.0 OR MIT)",
8-
"author": "Contributors to forge-std",
8+
"author": "Contributors to Forge Standard Library",
99
"files": [
1010
"src/*"
1111
],

src/Common.sol

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.6.2 <0.9.0;
3+
4+
import {StdStorage, Vm} from "./Components.sol";
5+
6+
abstract contract CommonBase {
7+
address internal constant VM_ADDRESS = address(uint160(uint256(keccak256("hevm cheat code"))));
8+
uint256 internal constant UINT256_MAX =
9+
115792089237316195423570985008687907853269984665640564039457584007913129639935;
10+
11+
StdStorage internal stdstore;
12+
Vm internal constant vm = Vm(VM_ADDRESS);
13+
}

0 commit comments

Comments
 (0)