foundry-rs / book Goto Github PK
View Code? Open in Web Editor NEWA book on all things Foundry, available at https://book.getfoundry.sh.
Home Page: https://book.getfoundry.sh
License: Apache License 2.0
A book on all things Foundry, available at https://book.getfoundry.sh.
Home Page: https://book.getfoundry.sh
License: Apache License 2.0
I want to restructure the book a bit by including section headers, draft chapters and removing some chapters that just take up space.
Draft SUMMARY.md
:
# Summary
[Introduction](./README.md)
# Getting Started
- [Installation](./getting-started/installation.md)
- [First Steps with Foundry](./getting-started/first-steps.md)
# Forge Overview
- [What is Forge?](./forge/README.md)
- [Projects]()
- [Creating a New Project](./forge/creating-a-new-project.md)
- [Working on an Existing Project](./forge/working-on-an-existing-project.md)
- [Dependencies](./forge/dependencies.md)
- [Project Layout](./forge/project-layout.md)
- [Configuring with `foundry.toml`](./forge/config.md)
- [Tests](./forge/tests.md)
- [Writing Tests](./forge/writing-tests.md)
- [Cheatcodes](./forge/cheatcodes.md)
- [Understanding Traces](./forge/traces.md)
- [Forking Mode](./forge/forking-mode.md)
- [Coverage Reports]()
- [Advanced Testing](./forge/advanced-testing.md)
- [Fuzz Testing](./forge/fuzz-testing.md)
- [Invariant Testing]()
- [Symbolic Testing]()
- [Table Testing]()
- [Mutation Testing]()
- [Linting and Formatting]()
- [Generating Documentation]()
- [Deploying and Verifying](./forge/deploying.md)
- [Gas Tracking](./forge/gas-tracking.md)
- [Gas Reports]()
- [Gas Snapshots]()
- [Debugger](./forge/debugger.md)
# Cast Overview
- [What is Cast?](./cast/cast-overview.md)
# Additional Configuration
- [Integrating with VSCode](./guides/vscode.md)
- [Shell Autocompletion](./guides/shell-autocompletion.md)
- [Continuous Integration](./forge/continous-integration.md)
# Tutorials
- [Creating an NFT with Solmate and Foundry](./tutorials/solmate-nft.md)
- [Incremental Adoption]()
# References
- [`forge` Reference]()
- [`cast` Reference](./reference/cast.md)
- [`foundry.toml` Reference](./reference/config.md)
- [`ds-test` Reference](./reference/ds-test.md)
- [Cheatcodes Reference](./reference/cheatcodes.md)
While reading the Writing Tests chapter, I stumbled upon the following code snippet:
function testCannotSubtract43() public {
cheats.expectRevert(abi.encodeWithSignature("Panic(uint256)", 0x11));
testNumber -= 43;
}
I tried to run it but I got the following error:
Error:
0: Compiler run failed
DeclarationError: Undeclared identifier.
--> /Users/paulrberg/workspace/templates/foundry-template/test/Contract.t.sol:22:9:
|
22 | cheats.expectRevert(abi.encodeWithSignature("Panic(uint256)", 0x11));
| ^^^^^^
It looks like the docs are not showing how to import and initialize the cheats
when first mentioning them.
See here
It would be nice to automate some parts of the documentation, such as the overall reference for cast
, forge
and the output of specific commands. This will require some scripts, and it might be possible to use the output of forge --help
/cast --help
or rustdoc in some way.
We still want to retain examples and so on, so it will require some thinking. If this can be pulled off, it would mean that some documentation is essentially written by improving the output of the help commands on the relevant commands upstream in Foundry, which will increase the quality of those
PR: foundry-rs/foundry#862
Issue: foundry-rs/foundry#861
Error in guide: https://onbjerg.github.io/foundry-book/tutorials/solmate-nft.html
Withdraw function uses OpenZeppelin PullPayment but mint function doesn't transfer funds to escrow
Funds would be locked in contract.
Guide should include test to check funds can be withdrawn.
Guide doesn't compile as Nft used for both contract and test contract.
The book should probably be deployed to Netlify or Vercel so we can have previews in pull requests
See the docs and PRs foundry-rs/foundry#795 / foundry-rs/foundry#678
Enable link preview for the Foundry Book (https://onbjerg.github.io/foundry-book/) to be show on social media
I will make a thumbnail - lmk!
It is now possible to also just pass raw calldata directly to cast send
and cast call
, see foundry-rs/foundry#742
We should add a guide on how to convert an existing codebase from Hardhat to Foundry over time.
This is the original PR, but it might have changed a bit since then - most notably the debugger is accessible only through this command for the time being.
New cheatcode landed: foundry-rs/foundry#725
The output of foundry test
in particular has changed
Awesome Foundry has a list of projects, tools, and libraries that use Foundry, that can be used as learning material for people wanting to see code.
Meta
Getting started
Forge
forge remove
and forge update
forge create
)Additional guides
Reference
ds-test
Referencefoundry.toml
ReferenceIt is a pretty barebones opinionated formatter with write and diff capabilities, but it is not configurable. Regardless, we should document it (and also add it to the GHA example)
It is possible to configure what is put in the contract artifacts (e.g. metadata, source maps, wasm bytecode and so on).
See this diff (including the tests) and the PR: foundry-rs/foundry#762
I think we should consider restructuring the command references to be more in line with something like Cargo's book. Their documentation is really good.
If you mock a call on an address with no code the call might fail regardless because Solidity does an extcodesize
check before calls under normal circumstances. Can be fixed by using vm.etch
in tandem
Should be updated in the places where it is referenced, e.g. the foundry.toml
Reference
Should contain:
Encountered error
> forge test
compiling...
Compiling 1 files with 0.8.12
Compilation finished successfully
Error:
0: Compiler run failed
TypeError: Member "expectRevert" not found or not visible after argument-dependent lookup in contract CheatCodes.
--> /Users/rootulp/git/rootulp/hello_foundry/src/Contract.sol:43:5:
|
43 | cheats.expectRevert(
| ^^^^^^^^^^^^^^^^^^^
while trying to reproduce and update the output for https://github.com/onbjerg/foundry-book/blame/master/src/forge/cheatcodes.md#L124
Both forge build
and forge test
have a watch mode now.
Relevant PRs:
Relevant issues:
Not sure what to put here yet.
Forge can now cache data from forked endpoints, see foundry-rs/foundry#1006
Should also include an update on how to persist the cache in CI
File: ds-test.md
Issue: The docs might be incorrect
Getting TypeError: No unique declaration found after argument-dependent lookup.
when an int_const
is passed to an assertion function.
// function assertEq(uint a, uint b) internal;
assertEq(1 ether, 1e18 wei);
Meanwhile, logging works fine:
// event log_uint(uint);
emit log_uint(1 ether);
Solution: I will fix the docs if others are getting the same error.
Test contracts are deployed to 0xb4c79dab8f259c7aee6e5b2aa729821864227e84
, but this address is not listed in the config.md
reference.
A quick test confirms this is the deploy address.
//SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0 <0.9.0;
import "ds-test/test.sol";
contract JustChecking is DSTest{
function testDeployer() public {
emit log_named_address("msg.sender", msg.sender);
emit log_named_address("tx.origin", tx.origin);
emit log_named_address("this", address(this));
}
}
Output
Logs:
msg.sender: 0x00a329c0648769a73afac7f9381e08fb43dbea72
tx.origin: 0x00a329c0648769a73afac7f9381e08fb43dbea72
this: 0xb4c79dab8f259c7aee6e5b2aa729821864227e84
I do not know if there is an environment variable in Forge to control the test deploy address. In DS-Test this environment variable is called DAPP_TEST_ADDRESS
(see here).
It is useful to have this address somewhere in the documentation because this contract is the default owner of contracts deployed by the test.
Any small inconsistencies I've noticed, which anyone can fix:
getCode
cheatcodeffi
cheatcodeprank
cheatcode example and add ##### Example
headingexpectCall
cheatcode exampleds-test.md
writing-tests.md
consistentcheatcodes.md
to be cleaner and easier to read and navigateds-test.md
Which one?
See these PRs:
And this issue: foundry-rs/foundry#859
cracks knuckles
The relevant file this should be updated in is ./src/forge/tests.md
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.