Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: forge-std v1.0.0 #184

Merged
merged 30 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9d323e3
Modularize forge-std (#126)
PaulRBerg Jul 26, 2022
aa2e9a3
feat: make `Script` safer (#147)
ZeroEkkusu Aug 14, 2022
da9be77
docs: add license info (#156)
ZeroEkkusu Aug 23, 2022
faa7593
feat: rebrand components (#157)
ZeroEkkusu Sep 7, 2022
77ec2c8
Merge branch 'master' into v0.3
ZeroEkkusu Sep 22, 2022
8421aec
fix: use `ABIEncoderV2`
ZeroEkkusu Sep 22, 2022
d7de20b
test: correct test name
ZeroEkkusu Sep 22, 2022
8352f50
Merge branch 'master' into v0.3
ZeroEkkusu Sep 27, 2022
9aeffc0
fix: add `CommonBase`
ZeroEkkusu Oct 1, 2022
24f8c2b
Merge branch 'master' into v0.3
mds1 Oct 6, 2022
f21ef1a
refactor: move test dir to root
mds1 Oct 6, 2022
ece89a0
Revert "refactor: move test dir to root"
mds1 Oct 6, 2022
cc55404
refactor: move test dir to root, update ci accordingly
mds1 Oct 7, 2022
4206aa3
style: configure and run forge fmt
mds1 Oct 10, 2022
d24318d
ci: split into jobs and add fmt job
mds1 Oct 10, 2022
ffd9c8e
ci: update name and triggers
mds1 Oct 10, 2022
dc8d830
ci: remove name field
mds1 Oct 10, 2022
16f109d
feat: better bound, ref https://github.com/foundry-rs/forge-std/issue…
mds1 Oct 14, 2022
1959a93
fix: bound logs + remove unneeded line
mds1 Oct 14, 2022
5269c76
fix: update require strings
mds1 Oct 15, 2022
87c9ac8
refactor: clean up `Test` and `Script`
ZeroEkkusu Oct 15, 2022
4d2879e
fix: udpate bound to match forge's uint edge bias strategy
mds1 Oct 15, 2022
be7916c
feat: add interfaces (#193)
mds1 Oct 15, 2022
7d14c38
feat: reimplement `bound` w/ even distribution
ZeroEkkusu Oct 21, 2022
14d78ea
build: rename step
ZeroEkkusu Oct 21, 2022
6ca63a3
Add memory-safe notation so that compiling via-ir can optimize effect…
DrakeEvans Oct 26, 2022
d369d2a
test(bound): add even distribution test (#197)
ZeroEkkusu Oct 28, 2022
72cdd70
feat: add `assumeNoPrecompiles` (#195)
mds1 Oct 28, 2022
4fba2c4
♻️ update ds-test (#200)
pcaversaccio Oct 31, 2022
80b66ff
refactor: move `UINT256_MAX` to `CommonBase`
ZeroEkkusu Oct 31, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: CI

on:
workflow_dispatch:
pull_request:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Foundry
uses: onbjerg/foundry-toolchain@v1
with:
version: nightly

- name: Install dependencies
run: forge install

- name: Check backward compatibility
run: |
forge build --skip test --use solc:0.8.0
forge build --skip test --use solc:0.7.6
forge build --skip test --use solc:0.7.0
forge build --skip test --use solc:0.6.2

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Foundry
uses: onbjerg/foundry-toolchain@v1
with:
version: nightly

- name: Install dependencies
run: forge install

- name: Run tests
run: forge test -vvv

fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Foundry
uses: onbjerg/foundry-toolchain@v1
with:
version: nightly

- name: Check formatting
run: forge fmt --check
27 changes: 0 additions & 27 deletions .github/workflows/tests.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cache/
out/
.vscode
.idea
.idea
2 changes: 1 addition & 1 deletion LICENSE-APACHE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright Contributors to forge-std
Copyright Contributors to Forge Standard Library

Apache License
Version 2.0, January 2004
Expand Down
2 changes: 1 addition & 1 deletion LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright Contributors to forge-std
Copyright Contributors to Forge Standard Library

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# 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)

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.
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://book.getfoundry.sh/forge/forge-std.html).**
**Learn how to use Forge-Std with the [📖 Foundry Book (Forge-Std Guide)](https://book.getfoundry.sh/forge/forge-std.html).**

## Install

Expand All @@ -13,7 +13,7 @@ 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 builtin errors.
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.

See the contract itself for all error codes.

Expand Down Expand Up @@ -244,3 +244,7 @@ import "forge-std/console.sol";
...
console.log(someValue);
```

## License

Forge Standard Library is offered under either [MIT](LICENSE-MIT) or [Apache 2.0](LICENSE-APACHE) license.
19 changes: 19 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
[profile.default]
fs_permissions = [{ access = "read-write", path = "./"}]

[rpc_endpoints]
# We intentionally use both dashes and underscores in the key names to ensure both are supported.
# The RPC URLs below match the StdChains URLs but append a trailing slash for testing.
mainnet = "https://api.mycryptoapi.com/eth/"
optimism_goerli = "https://goerli.optimism.io/"
arbitrum-one-goerli = "https://goerli-rollup.arbitrum.io/rpc/"

[fmt]
# These are all the `forge fmt` defaults.
line_length = 120
tab_width = 4
bracket_spacing = false
int_types = 'long'
multiline_func_header = 'attributes_first'
quote_style = 'double'
number_underscore = 'preserve'
single_line_statement_blocks = 'preserve'
ignore = ["src/console.sol", "src/console2.sol"]
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "forge-std",
"version": "0.1.0",
"description": "Forge Standard Library is a collection of helpful contracts for use with forge and foundry",
"version": "1.0.0",
"description": "Forge Standard Library is a collection of helpful contracts and libraries for use with Forge and Foundry.",
"homepage": "https://book.getfoundry.sh/forge/forge-std",
"bugs": "https://github.com/foundry-rs/forge-std/issues",
"license": "(Apache-2.0 OR MIT)",
"author": "Contributors to forge-std",
"author": "Contributors to Forge Standard Library",
"files": [
"src/*"
],
Expand Down
11 changes: 11 additions & 0 deletions src/Common.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.9.0;

import {StdStorage, Vm} from "./Components.sol";

abstract contract CommonBase {
address internal constant VM_ADDRESS = address(uint160(uint256(keccak256("hevm cheat code"))));

StdStorage internal stdstore;
Vm internal constant vm = Vm(VM_ADDRESS);
}
13 changes: 13 additions & 0 deletions src/Components.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.9.0;

import "./console.sol";
ZeroEkkusu marked this conversation as resolved.
Show resolved Hide resolved
import "./console2.sol";
import "./StdAssertions.sol";
import "./StdCheats.sol";
import "./StdError.sol";
import "./StdJson.sol";
import "./StdMath.sol";
import "./StdStorage.sol";
import "./StdUtils.sol";
import "./Vm.sol";
48 changes: 9 additions & 39 deletions src/Script.sol
Original file line number Diff line number Diff line change
@@ -1,44 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.9.0;
pragma solidity >=0.6.2 <0.9.0;

import "./console.sol";
import "./console2.sol";
import "./StdJson.sol";
import {CommonBase} from "./Common.sol";
// forgefmt: disable-next-line
import {console, console2, StdCheatsSafe, stdJson, stdMath, StdStorage, stdStorageSafe, StdUtils, VmSafe} from "./Components.sol";

abstract contract Script {
bool public IS_SCRIPT = true;
address constant private VM_ADDRESS =
address(bytes20(uint160(uint256(keccak256('hevm cheat code')))));

Vm public constant vm = Vm(VM_ADDRESS);

/// @dev Compute the address a contract will be deployed at for a given deployer address and nonce
/// @notice adapated from Solmate implementation (https://github.com/transmissions11/solmate/blob/main/src/utils/LibRLP.sol)
function computeCreateAddress(address deployer, uint256 nonce) internal pure returns (address) {
// The integer zero is treated as an empty byte string, and as a result it only has a length prefix, 0x80, computed via 0x80 + 0.
// A one byte integer uses its own value as its length prefix, there is no additional "0x80 + length" prefix that comes before it.
if (nonce == 0x00) return addressFromLast20Bytes(keccak256(abi.encodePacked(bytes1(0xd6), bytes1(0x94), deployer, bytes1(0x80))));
if (nonce <= 0x7f) return addressFromLast20Bytes(keccak256(abi.encodePacked(bytes1(0xd6), bytes1(0x94), deployer, uint8(nonce))));

// Nonces greater than 1 byte all follow a consistent encoding scheme, where each value is preceded by a prefix of 0x80 + length.
if (nonce <= 2**8 - 1) return addressFromLast20Bytes(keccak256(abi.encodePacked(bytes1(0xd7), bytes1(0x94), deployer, bytes1(0x81), uint8(nonce))));
if (nonce <= 2**16 - 1) return addressFromLast20Bytes(keccak256(abi.encodePacked(bytes1(0xd8), bytes1(0x94), deployer, bytes1(0x82), uint16(nonce))));
if (nonce <= 2**24 - 1) return addressFromLast20Bytes(keccak256(abi.encodePacked(bytes1(0xd9), bytes1(0x94), deployer, bytes1(0x83), uint24(nonce))));

// More details about RLP encoding can be found here: https://eth.wiki/fundamentals/rlp
// 0xda = 0xc0 (short RLP prefix) + 0x16 (length of: 0x94 ++ proxy ++ 0x84 ++ nonce)
// 0x94 = 0x80 + 0x14 (0x14 = the length of an address, 20 bytes, in hex)
// 0x84 = 0x80 + 0x04 (0x04 = the bytes length of the nonce, 4 bytes, in hex)
// We assume nobody can have a nonce large enough to require more than 32 bytes.
return addressFromLast20Bytes(keccak256(abi.encodePacked(bytes1(0xda), bytes1(0x94), deployer, bytes1(0x84), uint32(nonce))));
}

function addressFromLast20Bytes(bytes32 bytesValue) internal pure returns (address) {
return address(uint160(uint256(bytesValue)));
}
abstract contract ScriptBase is CommonBase {
VmSafe internal constant vmSafe = VmSafe(VM_ADDRESS);
}

function deriveRememberKey(string memory mnemonic, uint32 index) internal returns (address who, uint256 privateKey) {
privateKey = vm.deriveKey(mnemonic, index);
who = vm.rememberKey(privateKey);
}
abstract contract Script is ScriptBase, StdCheatsSafe, StdUtils {
bool public IS_SCRIPT = true;
}
Loading