Skip to content

Commit a30b300

Browse files
jparklevodyslam
authored andcommitted
Merge rebranded master branch to PR in order to test packaging workflow
* fix(evm-adapters): initialize forked backend cache with local backend state * fix: appease linter * fix(solc): bump version tests for solc release seth: update optimism genesis blockhashes (foundry-rs#134) Optimism performed a regenesis which updated the genesis blockhashes for both mainnet and kovan. For `seth chain` and any other `seth` commands that rely on `seth chain` to work, the hardcoded genesis blockhashes need to be updated. The values were fetched using the following commands: ``` $ seth --rpc-url https://mainnet.optimism.io block 0 hash 0x7ca38a1916c42007829c55e69d3e9a73265554b586a499015373241b8a3fa48b $ seth --rpc-url https://kovan.optimism.io block 0 hash 0x02adc9b449ff5f2467b8c674ece7ff9b21319d76c4ad62a67a70d552655927e5 ``` Tested locally with the commands: ``` $ ./target/debug/seth chain --rpc-url https://mainnet.optimism.io optimism-mainnet $ ./target/debug/seth chain --rpc-url https://kovan.optimism.io optimism-kovan ``` fix provider caching (foundry-rs#135) Use new Solc compilation pipeline (foundry-rs#130) * chore: deprecate dapp_solc * chore: cargo lock * chore(evm-adapters): use sol 0.6.6 for tests without auto solc detection * fix(evm-adapters): adjust breaking changes COMPILED.get -> COMPILED.find bytecode -> bin * refactor(dapp): move sol contracts under testdata/ * chore(dapp): remove dapptools artifacts they will be available via the upstream compilation pipeline * fix(dapp): adjust breaking changes COMPILED.get -> COMPILED.find bytecode -> bin * feat(multi-runner): use new compilation pipeline We now provide a pre-configured Project to the builder, it'll proceed to compile it and use the artifacts accordingly. The addresses map is now part of the contracts map * test(multi-runner): adjust tests to match new compilation pipeline * feat(cli): set Project paths from the BuildOpts * feat(cli): use Project to compile files * chore(cli): remove unused funcs * fix(cli/etherscan): breaking api changes * chore: cargo fmt * tests: avoid race conditions during solc install We do that by using ethers-solc/tests feature which imposes a mutex on the solc downloading step. * test(evm-adapters): make LargeContract test more robust * fix(ethers-solc): update ethers-solc to fixed version bug chore: remove direct svm dep feat: allow specifying ETH_RPC_URL in forking mode fix(rpc): default to Latest block instead of the backend's if none is… (foundry-rs#136) * fix(rpc): default to Latest block instead of the backend's if none is provided * feat(cli): exit -1 if error in tests feat(cli): specify contracts with DAPP_SRC env var ref: foundry-rs#108 feat: expand env vars (foundry-rs#138) * feat(cli): add DAPP_TEST_TIMESTAMP and TEST_NUMBER * feat(dapp): allow specifying sender for all txs * feat(cli): allow specifying the sender for all calls * chore: cargo fmt feat(evm-adapters): make Executor work in already running tokio runtime (foundry-rs#140) * fix deps * feat(evm-adapters): make Executor work in already running tokio runtime fix(cli): wait for git submodule command to finish fix(cli/multi-runner): return errors before checking cache This is a footgun and we should have a helper function for it in ethers-solc chore: actualize seth commands in README.md (foundry-rs#142) * chore: actualize seth commands in README.md * update according to seth from dapptools-rs 0.1.0 feat: Update sputnik (foundry-rs#144) * temp: use patched evm for auto_impl & update lock rust-ethereum/evm#85 * fix sputnik breaking changes * fix(dapp): breaking changes * fix(cli): breaking changes * cli: default to london * chore: fmt fix: enable cheatcodes in the constructor (foundry-rs#145) * feat: override contract creation method Before, transact_create would delegate to the internal handler which does not use cheatcodes. We copy-paste transact_create so that we force it to route to our cheatcode handler. * fix(evm): use the externally exposed apis for create_inner * chore: remove dbg * test: add constructor cheatcode check feat(cli): allow specifying FORK_BLOCK via env var feat(cli): allow skipping automatic solc version detection feat(seth): improve piped input support (foundry-rs#149) Co-authored-by: Alexey Shekhirin <[email protected]> feat(seth): storage (foundry-rs#150) * feat(seth): storage * pad * fmt & clippy Co-authored-by: Alexey Shekhirin <[email protected]> fix(dapptools): explicitly set lib_paths as allowed paths (foundry-rs#139) * fix(dapptools): set lib_paths to libraries on paths config * fix(dapptools): add lib_paths as allowed paths rather than as 'libs' * chore(dapptools): undo unrelated fmt change * chore(dapptools): appease linter deal + prank cheat codes (foundry-rs#146) * deal + spoof cheat codes fixes fixes deal + prank * fixes * no change of origin * fmt * prank is payable * accurate readme * clippy lint fix chore: fmt Adds etch (setCode) cheatcode ref: foundry-rs#151 Rebrand to Foundry (foundry-rs#156) * wip: rebrand * update readme * add demo svg * more readme * benches * cleanup * add more context in readme * docs: some cleanup (foundry-rs#153) * docs: tagline fixes (foundry-rs#154) * docs: add CLI docs * chore typos * docs * modify forge readme * modify forge readme * add cheatcodes readme * cli readme * retab * retab * add minimal utils readme * evm adapters docs * fix: parse block as decimal not hex * chore: fmt Co-authored-by: Matt <[email protected]> Co-authored-by: t11s <[email protected]> more docs (foundry-rs#157) * update doc * update doc * update doc * fuzz docs * wrap evm adapters docs perf(evm-adapters): use existing runtime in SharedBackend if available (foundry-rs#158) * perf(evm-adapters): use existing runtime in SharedBackend if available * chore: box runtime to fix enum size lint Co-authored-by: Georgios Konstantopoulos <[email protected]> perf: clippy is a good servant but a bad master (foundry-rs#159) fix(cli): set root to curr dir correctly feat(cli): print counterexample if fuzztest fails feat(cli): forge init (foundry-rs#161) * feat(cli): forge init * chore: address review comments fix(cli): install with Command vs libgit2 (foundry-rs#162) evmodin: update and fix breaking changes (foundry-rs#163)
1 parent a7b9175 commit a30b300

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2609
-2491
lines changed

Diff for: Cargo.lock

+221-212
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
members = [
33
"evm-adapters",
44
"utils",
5-
"seth",
6-
"dapp",
7-
"dapptools",
8-
"solc",
5+
"cast",
6+
"forge",
7+
"cli",
98
]
109

1110
# Binary size optimizations
@@ -14,3 +13,6 @@ opt-level = "z"
1413
lto = true
1514
codegen-units = 1
1615
panic = "abort"
16+
17+
[patch."https://github.com/rust-blockchain/evm"]
18+
evm = { git = "https://github.com/gakonst/evm", branch = "feat/auto-impl" }

Diff for: README.md

+114-133
Original file line numberDiff line numberDiff line change
@@ -1,140 +1,103 @@
1-
# <h1 align="center"> dapptools.rs </h1>
1+
# <h1 align="center"> foundry </h1>
22

3-
_Rust port of DappTools_
4-
5-
![Github Actions](https://github.com/gakonst/dapptools-rs/workflows/Tests/badge.svg)
6-
[![Telegram Chat](https://img.shields.io/endpoint?color=neon&style=flat-square&url=https%3A%2F%2Ftg.sumanjay.workers.dev%2Fturbodapptools)](https://t.me/turbodapptools)
3+
![Github Actions](https://github.com/gakonst/foundry/workflows/Tests/badge.svg)
4+
[![Telegram Chat](https://img.shields.io/endpoint?color=neon&style=flat-square&url=https%3A%2F%2Ftg.sumanjay.workers.dev%2Ffoundry_rs)](https://t.me/foundry_rs)
75
[![Crates.io][crates-badge]][crates-url]
86

9-
[crates-badge]: https://img.shields.io/crates/v/turbodapp.svg
10-
[crates-url]: https://crates.io/crates/turbodapp
7+
[crates-badge]: https://img.shields.io/crates/v/foundry.svg
8+
[crates-url]: https://crates.io/crates/foundry-rs
9+
10+
**Foundry is a blazing fast, portable and modular toolkit for Ethereum
11+
application development written in Rust.**
12+
13+
Foundry consists of:
14+
15+
- [**Forge**](./forge): Ethereum testing framework (like Truffle, Hardhat and
16+
Dapptools).
17+
- [**Cast**](./cast): Swiss army knife for interacting with EVM smart contracts,
18+
sending transactions and getting chain data.
1119

12-
## Installing
20+
![demo](./assets/demo.svg)
21+
22+
## Forge
23+
24+
```
25+
cargo install --git https://github.com/gakonst/foundry --bin forge
26+
```
1327

14-
We have not published a release yet. Until we do, please use the command below.
15-
Because our dependencies may not be stable, do not forget the `--locked`
16-
parameter, which will force the installer to use the checked in `Cargo.lock`
17-
file.
28+
More documentation can be found in the [forge package](./forge/README.md) and in
29+
the [CLI README](./cli/README.md).
30+
31+
### Features
32+
33+
1. Fast & flexible compilation pipeline:
34+
1. Automatic Solidity compiler version detection & installation (under
35+
`~/.svm`)
36+
1. Incremental compilation & caching: Only changed files are re-compiled
37+
1. Parallel compilation
38+
1. Non-standard directory structures support (e.g. can build
39+
[Hardhat repos](https://twitter.com/gakonst/status/1461289225337421829))
40+
1. Tests are written in Solidity (like in DappTools)
41+
1. Fast fuzz Tests with shrinking of inputs & printing of counter-examples
42+
1. Fast remote RPC forking mode leveraging Rust's async infrastructure like
43+
tokio
44+
1. Flexible debug logging:
45+
1. Dapptools-style, using `DsTest`'s emitted logs
46+
1. Hardhat-style, using the popular `console.sol` contract
47+
1. Portable (5-10MB) & easy to install statically linked binary without
48+
requiring Nix or any other package manager
49+
1. Abstracted over EVM implementations (currently supported: Sputnik, EvmOdin)
50+
51+
### How Fast?
52+
53+
Forge is quite fast at both compiling (leveraging the
54+
[ethers-solc](https://github.com/gakonst/ethers-rs/tree/master/ethers-solc/)
55+
package) and testing.
56+
57+
Some benchmarks below:
58+
59+
| Project | Forge | DappTools | Speedup |
60+
| --------------------------------------------------- | ----- | --------- | ------- |
61+
| [guni-lev](https://github.com/hexonaut/guni-lev/) | 28.6s | 2m36s | 5.45x |
62+
| [solmate](https://github.com/Rari-Capital/solmate/) | 6s | 46s | 7.66x |
63+
| [geb](https://github.com/reflexer-labs/geb) | 11s | 40s | 3.63x |
64+
| [vaults](https://github.com/rari-capital/vaults) | 1.4s | 5.5s | 3.9x |
65+
66+
It also works with "non-standard" directory structures (i.e. contracts not in
67+
`src/`, libraries not in `lib/`). When
68+
[tested](https://twitter.com/gakonst/status/1461289225337421829) with
69+
[`openzeppelin-contracts`](https://github.com/OpenZeppelin/openzeppelin-contracts),
70+
Hardhat compilation took 15.244s, whereas Forge took 9.449 (~4s cached)
71+
72+
## Cast
73+
74+
Cast is a swiss army knife for interacting with Ethereum applications from the
75+
command line.
1876

1977
```
20-
cargo install --git https://github.com/gakonst/dapptools-rs --locked
78+
cargo install --git https://github.com/gakonst/foundry --bin cast
79+
// Get USDC's total supply
80+
cast call 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 "totalSupply()(uint256)" --rpc-url <..your node url>
2181
```
2282

23-
Alternatively, clone the repository and run: `cargo build --release`
24-
25-
## Why?! DappTools is great!
26-
27-
Developer experience is the #1 thing we should be optimizing for in development.
28-
Tests MUST be fast, non-trivial tests (e.g. proptests) MUST be easy to write,
29-
and compilation MUST be fast.
30-
31-
Before getting into technical reasons, my simple answer is: rewriting software
32-
in Rust is fun. I enjoy it, and that could be the end of the "why" section.
33-
34-
DappTools is REALLY great.
35-
[You should try it](https://github.com/dapphub/dapptools/), especially the
36-
symbolic execution and step debugger features.
37-
38-
But it has some shortcomings:
39-
40-
It's written in a mix of Bash, Javascript and Haskell. In my opinion, this makes
41-
it hard to contribute, you don't have a "standard" way to test things, and it
42-
happens to be that there are not that many Haskell developers in the Ethereum
43-
community.
44-
45-
It is also hard to distribute. It requires installing Nix, and that's a barrier
46-
to entry to many already because (for whatever reason) Nix doesn't always
47-
install properly the first time.
48-
49-
The more technical reasons I decided to use it are:
50-
51-
1. It is easier to write regression tests in Rust than in Bash.
52-
1. Rust binaries are cross-platform and easy to distribute.
53-
1. Compilation speed: We can use native bindings to the Solidity compiler
54-
(instead of calling out to solcjs or even to the compiled binary) for extra
55-
compilation speed.
56-
1. Testing speed: HEVM tests are really fast, but I believe we can go faster by
57-
leveraging Rust's high performance multithreading and resource allocation
58-
system.
59-
1. There seems to be an emerging community of Rust-Ethereum developers.
60-
61-
Benchmarks TBD in the future, but:
62-
63-
1. [Using a Rust EVM w/ forked RPC mode](https://github.com/brockelmore/rust-cevm/#compevm-rust-ethereum-virtual-machine-implementation-designed-for-smart-contract-composability-testing)
64-
was claimed to be as high as 10x faster than HEVM's forking mode.
65-
1. Native bindings to the Solidity compiler have been shown to be
66-
[10x](https://forum.openzeppelin.com/t/a-faster-solidity-compiler-cli-in-rust/2546)
67-
faster than the JS bindings or even just calling out to the native binary.
68-
1. `seth` and `dapp` are less than 7mb when built with `cargo build --release`.
69-
70-
## Features
71-
72-
- seth
73-
- [x] `--from-ascii` / `--from-utf8`
74-
- [x] `--to-hex`
75-
- [x] `--to-checksum-address`
76-
- [x] `--to-ascii`
77-
- [x] `--to-bytes32`
78-
- [x] `--to-dec`
79-
- [x] `--to-fix`
80-
- [x] `--to-uint256`
81-
- [x] `--to-wei`
82-
- [x] `block`
83-
- [x] `block-number`
84-
- [x] `chain-id`
85-
- [x] `age`
86-
- [x] `basefee`
87-
- [x] `gas-price`
88-
- [x] `call` (partial)
89-
- [x] `send` (partial)
90-
- [x] `balance`
91-
- [x] `ens`
92-
- abi encoding
93-
- 4byte resolution
94-
- dapp
95-
- [ ] test
96-
- [x] Simple unit tests
97-
- [x] Gas costs
98-
- [x] DappTools style test output
99-
- [x] JSON test output
100-
- [x] Matching on regex
101-
- [x] DSTest-style assertions support
102-
- [x] Fuzzing
103-
- [ ] Symbolic execution
104-
- [ ] Coverage
105-
- [ ] HEVM-style Solidity cheatcodes
106-
- [x] roll
107-
- [x] warp
108-
- [x] ffi
109-
- [x] store
110-
- [x] load
111-
- [ ] sign
112-
- [ ] addr
113-
- [ ] makeEOA
114-
- ...?
115-
- [ ] Structured tracing with abi decoding
116-
- [ ] Per-line gas profiling
117-
- [x] Forking mode
118-
- [x] Automatic solc selection
119-
- [x] build
120-
- [x] Can read DappTools-style .sol.json artifacts
121-
- [x] Manual remappings
122-
- [x] Automatic remappings
123-
- [x] Multiple compiler versions
124-
- [ ] Incremental compilation
125-
- [ ] Can read Hardhat-style artifacts
126-
- [ ] Can read Truffle-style artifacts
127-
- [x] install
128-
- [x] update
129-
- [ ] debug
130-
- [x] CLI Tracing with `RUST_LOG=dapp=trace`
131-
132-
## Tested Against
133-
134-
This repository has been tested against a few repositories which you can monitor
135-
[here](https://github.com/gakonst/dapptools-benchmarks)
136-
137-
## Development
83+
More documentation can be found in the [cast package](./cast/README.md).
84+
85+
## Contributing
86+
87+
### Directory structure
88+
89+
This repository contains several Rust crates:
90+
91+
- [`forge`](forge): Library for building and testing a Solidity repository.
92+
- [`cast`](cast): Library for interacting with a live Ethereum JSON-RPC
93+
compatible node, or for parsing data.
94+
- [`cli`](cli): Command line interfaces to `cast` and `forge`.
95+
- [`evm-adapters`](evm-adapters): Unified layer of abstraction over multiple EVM
96+
types. Currently supported EVMs:
97+
[Sputnik](https://github.com/rust-blockchain/evm/),
98+
[Evmodin](https://github.com/vorot93/evmodin).
99+
- [`utils`](utils): Utilities for parsing ABI data, will eventually be
100+
upstreamed to [ethers-rs](https://github.com/gakonst/ethers-rs/).
138101

139102
### Rust Toolchain
140103

@@ -156,16 +119,34 @@ cargo doc --open
156119

157120
### Formatting
158121

122+
We use the nightly toolchain for formatting and linting.
123+
159124
```
160125
cargo +nightly fmt
161-
cargo clippy
126+
cargo +nightly clippy --all-features -- -D warnings
162127
```
163128

164129
## Getting Help
165130

166131
First, see if the answer to your question can be found in the API documentation.
167132
If the answer is not there, try opening an
168-
[issue](https://github.com/gakonst/dapptools-rs/issues/new) with the question.
169-
170-
Join the [turbodapptools telegram](https://t.me/turbodapptools) to chat with the
171-
community!
133+
[issue](https://github.com/gakonst/foundry/issues/new) with the question.
134+
135+
Join the [foundry telegram](https://t.me/foundry_rs) to chat with the community!
136+
137+
## Acknowledgements
138+
139+
- Foundry is a clean-room rewrite of the testing framework
140+
[dapptools](https://github.com/dapphub/dapptools). None of this would have
141+
been possible without the DappHub team's work over the years.
142+
- [Matthias Seitz](https://twitter.com/mattsse_): Created
143+
[ethers-solc](https://github.com/gakonst/ethers-rs/tree/master/ethers-solc/)
144+
which is the backbone of our compilation pipeline, as well as countless
145+
contributions to ethers, in particular the `abigen` macros.
146+
- [Rohit Narunkar](https://twitter.com/rohitnarurkar): Created the Rust Solidity
147+
version manager [svm-rs](https://github.com/roynalnaruto/svm-rs) which we use
148+
to auto-detect and manage multiple Solidity versions.
149+
- All the other
150+
[contributors](https://github.com/gakonst/foundry/graphs/contributors) to the
151+
[ethers-rs](https://github.com/gakonst/ethers-rs) &
152+
[foundry](https://github.com/gakonst/foundry) repositories and chatrooms.

Diff for: assets/ContractTemplate.sol

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// SPDX-License-Identifier: Unlicense
2+
pragma solidity 0.8.10;
3+
4+
contract Contract {}

Diff for: assets/ContractTemplate.t.sol

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// SPDX-License-Identifier: Unlicense
2+
pragma solidity 0.8.10;
3+
4+
contract ContractTest {
5+
function setUp() public {}
6+
}

Diff for: assets/demo.svg

+1
Loading

Diff for: seth/Cargo.toml renamed to cast/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[package]
2-
name = "seth"
2+
name = "cast"
33
version = "0.1.0"
44
edition = "2018"
55
license = "MIT OR Apache-2.0"
66

77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10-
dapp-utils = { path = "../utils" }
10+
foundry-utils = { path = "../utils" }
1111
# ethers = "0.5"
1212
ethers-core = { git = "https://github.com/gakonst/ethers-rs", default-features = false }
1313
ethers-providers = { git = "https://github.com/gakonst/ethers-rs", default-features = false }

Diff for: cast/README.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# `cast`
2+
3+
## Features
4+
5+
- [ ] `--abi-decode`
6+
- [ ] `--calldata-decode`
7+
- [x] `--from-ascii` (with `--from-utf8` alias)
8+
- [ ] `--from-bin`
9+
- [ ] `--from-fix`
10+
- [ ] `--from-wei`
11+
- [ ] `--max-int`
12+
- [ ] `--max-uint`
13+
- [ ] `--min-int`
14+
- [x] `--to-checksum-address` (`--to-address` in dapptools)
15+
- [x] `--to-ascii`
16+
- [x] `--to-bytes32`
17+
- [x] `--to-dec`
18+
- [x] `--to-fix`
19+
- [x] `--to-hex`
20+
- [x] `--to-hexdata`
21+
- [ ] `--to-int256`
22+
- [x] `--to-uint256`
23+
- [x] `--to-wei`
24+
- [ ] `4byte`
25+
- [ ] `4byte-decode`
26+
- [ ] `4byte-event`
27+
- [ ] `abi-encode`
28+
- [x] `age`
29+
- [x] `balance`
30+
- [x] `basefee`
31+
- [x] `block`
32+
- [x] `block-number`
33+
- [ ] `bundle-source`
34+
- [x] `call` (partial)
35+
- [x] `calldata`
36+
- [x] `chain`
37+
- [x] `chain-id`
38+
- [ ] `code`
39+
- [ ] `debug`
40+
- [ ] `estimate`
41+
- [ ] `etherscan-source`
42+
- [ ] `events`
43+
- [x] `gas-price`
44+
- [ ] `index`
45+
- [x] `keccak`
46+
- [ ] `logs`
47+
- [x] `lookup-address`
48+
- [ ] `ls`
49+
- [ ] `mktx`
50+
- [x] `namehash`
51+
- [ ] `nonce`
52+
- [ ] `publish`
53+
- [ ] `receipt`
54+
- [x] `resolve-name`
55+
- [ ] `run-tx`
56+
- [x] `send` (partial)
57+
- [ ] `sign`
58+
- [x] `storage`
59+
- [ ] `tx`

0 commit comments

Comments
 (0)