-
Notifications
You must be signed in to change notification settings - Fork 433
fix: updates coding example and minor spelling/grammar fixes #24
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
Merged
brockelmore
merged 1 commit into
foundry-rs:master
from
devtooligan:fix/readme-code-example
Mar 8, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ forge install brockelmore/forge-std | |
| ## Contracts | ||
| ### stdError | ||
|
|
||
| This is a helper contract for errors and reverts in solidity. 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. | ||
|
|
||
|
|
@@ -23,7 +23,7 @@ import "ds-test/test.sol"; | |
| import "forge-std/stdlib.sol"; | ||
| import "forge-std/Vm.sol"; | ||
|
|
||
| contract TestContract is DSTest, stdError { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the main change |
||
| contract TestContract is DSTest { | ||
| Vm public constant vm = Vm(HEVM_ADDRESS); | ||
|
|
||
| ErrorsTest test; | ||
|
|
@@ -47,7 +47,7 @@ contract ErrorsTest { | |
|
|
||
| ### stdStorage | ||
|
|
||
| This is a rather large contract due to all of the overloading to make the UX decent. Primarly, 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. The one _major_ caveat to this is while a slot can be found for packed storage variables, we can't write to that variable safely. If a user tries to write to a packed slot, the execution throws an error, unless it is uninitialized (`bytes32(0)`). | ||
| 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. The one _major_ caveat to this is while a slot can be found for packed storage variables, we can't write to that variable safely. If a user tries to write to a packed slot, the execution throws an error, unless it is uninitialized (`bytes32(0)`). | ||
|
|
||
| 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. | ||
|
|
||
|
|
@@ -99,14 +99,14 @@ contract TestContract is DSTest { | |
|
|
||
| // It supports arbitrary storage layouts, like assembly based storage locations | ||
| function testFindHidden() public { | ||
| // hidden is a random hash of a bytes, iteration through slots would | ||
| // `hidden` is a random hash of a bytes, iteration through slots would | ||
| // not find it. Our mechanism does | ||
| // Also, you can use the selector instead of string | ||
| // Also, you can use the selector instead of a string | ||
| uint256 slot = stdstore.target(address(test)).sig(test.hidden.selector).find(); | ||
| assertEq(slot, keccak256("my.random.var")); | ||
| } | ||
|
|
||
| // if targeting a mapping, you have to pass in the keys necessary to perform the find | ||
| // If targeting a mapping, you have to pass in the keys necessary to perform the find | ||
| // i.e.: | ||
| function testFindMapping() public { | ||
| uint256 slot = stdstore | ||
|
|
@@ -183,7 +183,7 @@ With these 4 functions, you can find any slot (or write to it with their counter | |
|
|
||
| ### stdCheats | ||
|
|
||
| This is a wrapper over miscellaneous cheatcodes that need wrappers to be more dev friendly. Currently there are only function related to `prank`. In general, users may expect ETH to be put into an address on `prank`, but this is not the case for safety reasons. Explicitly this `hoax` function should only be used for address that have expected balances as it will get overwritten. If an address already has Eth, you should just use `prank`. If you want to change that balance explicitly, just use `deal`. If you want to do both, `hoax` is also right for you. | ||
| This is a wrapper over miscellaneous cheatcodes that need wrappers to be more dev friendly. Currently there are only functions related to `prank`. In general, users may expect ETH to be put into an address on `prank`, but this is not the case for safety reasons. Explicitly this `hoax` function should only be used for address that have expected balances as it will get overwritten. If an address already has ETH, you should just use `prank`. If you want to change that balance explicitly, just use `deal`. If you want to do both, `hoax` is also right for you. | ||
|
|
||
|
|
||
| #### Example usage: | ||
|
|
@@ -206,22 +206,22 @@ contract StdCheatsTest is DSTest, stdCheats { | |
| } | ||
|
|
||
| function testHoax() public { | ||
| // we call the hoax, which gives the target address | ||
| // we call `hoax`, which gives the target address | ||
| // eth and then calls `prank` | ||
| hoax(address(1337)); | ||
| test.bar{value: 100}(address(1337)); | ||
|
|
||
| // overloaded to allow you to specify how much eth to | ||
| // initialize the addres with | ||
| // initialize the address with | ||
| hoax(address(1337), 1); | ||
| test.bar{value: 1}(address(1337)); | ||
| } | ||
|
|
||
| function testStartHoax() public { | ||
| // we call the startHoax, which gives the target address | ||
| // we call `startHoax`, which gives the target address | ||
| // eth and then calls `startPrank` | ||
| // | ||
| // it is also overloaded so that you can specify eth amount | ||
| // it is also overloaded so that you can specify an eth amount | ||
| startHoax(address(1337)); | ||
| test.bar{value: 100}(address(1337)); | ||
| test.bar{value: 100}(address(1337)); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was gonna capitalize Solidity but then thought maybe its better just to delete it...