Skip to content

Commit

Permalink
Merge branch 'master' into evalir/v1-expect-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Evalir committed Jul 5, 2023
2 parents 4ae9069 + 936df1a commit f2fac43
Show file tree
Hide file tree
Showing 25 changed files with 593 additions and 23 deletions.
4 changes: 4 additions & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
- [cast run](./reference/cast/cast-run.md)
- [cast estimate](./reference/cast/cast-estimate.md)
- [cast access-list](./reference/cast/cast-access-list.md)
- [cast logs](./reference/cast/cast-logs.md)
- [Block Commands](./reference/cast/block-commands.md)
- [cast find-block](./reference/cast/cast-find-block.md)
- [cast gas-price](./reference/cast/cast-gas-price.md)
Expand All @@ -144,6 +145,7 @@
- [cast proof](./reference/cast/cast-proof.md)
- [cast nonce](./reference/cast/cast-nonce.md)
- [cast code](./reference/cast/cast-code.md)
- [cast codesize](./reference/cast/cast-codesize.md)
- [ENS Commands](./reference/cast/ens-commands.md)
- [cast lookup-address](./reference/cast/cast-lookup-address.md)
- [cast resolve-name](./reference/cast/cast-resolve-name.md)
Expand Down Expand Up @@ -279,6 +281,7 @@
- [Utilities](./cheatcodes/utilities.md)
- [`addr`](./cheatcodes/addr.md)
- [`sign`](./cheatcodes/sign.md)
- [`skip`](./cheatcodes/skip.md)
- [`label`](./cheatcodes/label.md)
- [`deriveKey`](./cheatcodes/derive-key.md)
- [`parseBytes`](./cheatcodes/parse-bytes.md)
Expand Down Expand Up @@ -308,6 +311,7 @@
- [`startHoax`](./reference/forge-std/startHoax.md)
- [`deal`](./reference/forge-std/deal.md)
- [`deployCode`](./reference/forge-std/deployCode.md)
- [`deployCodeTo`](./reference/forge-std/deployCodeTo.md)
- [`bound`](./reference/forge-std/bound.md)
- [`changePrank`](./reference/forge-std/change-prank.md)
- [`makeAddr`](./reference/forge-std/make-addr.md)
Expand Down
3 changes: 3 additions & 0 deletions src/cheatcodes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ interface CheatCodes {
// Sets an address' code
function etch(address who, bytes calldata code) external;
// Marks a test as skipped. Must be called at the top of the test.
function skip(bool skip) external;
// Expects an error on next call
function expectRevert() external;
function expectRevert(bytes calldata) external;
Expand Down
3 changes: 2 additions & 1 deletion src/cheatcodes/etch.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ log_bytes(address(targetAddr).code); // 0x6080604052348015610010...

Forge Standard Library

[`deployCode`](../reference/forge-std/deployCode.md)
- [`deployCode`](../reference/forge-std/deployCode.md)
- [`deployCodeTo`](../reference/forge-std/deployCodeTo.md)
10 changes: 5 additions & 5 deletions src/cheatcodes/expect-revert.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ There are 3 signatures:
>
> The Solidity compiler will insert checks that ensures that the call succeeded, and revert if it did not.
>
> The `expectRevert` cheatcode works by inverting this, so the next call after this cheatcode returns `true` if it reverts, and `false` otherwise.
> On low level calls, the `expectRevert` cheatcode works by making the `status` boolean returned by the low level call correspond to whether the `expectRevert` succeeded or not, NOT whether or not the low-level call succeeds. Therefore, `status` being false corresponds to the cheatcode failing.
>
> The implication here is that to use this cheatcode with low-level calls, you must manually assert on the call's status since Solidity is not doing it for you.
> Apart from this, `expectRevert` also mangles return data on low level calls, and is not usable.
>
> For example:
> See the following example. For clarity, `status` has been renamed to `revertsAsExpected`:
>
> ```solidity
> function testLowLevelCallRevert() public {
> vm.expectRevert(bytes("error message"));
> (bool status, ) = address(myContract).call(myCalldata);
> assertTrue(status, "expectRevert: call did not revert");
> (bool revertsAsExpected, ) = address(myContract).call(myCalldata);
> assertTrue(revertsAsExpected, "expectRevert: call did not revert");
> }
> ```
Expand Down
6 changes: 4 additions & 2 deletions src/cheatcodes/get-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ vm.etch(targetAddr, deployed.code);

### SEE ALSO

[`getDeployedCode`](./get-deployed-code.md)
[`eth`](./etch.md)

Forge Standard Library

[`deployCode`](../reference/forge-std/deployCode.md)
[`getDeployedCode`](./get-deployed-code.md)
[`eth`](./etch.md)
[`deployCodeTo`](../reference/forge-std/deployCodeTo.md)

[forge-std]: ../reference/forge-std
32 changes: 32 additions & 0 deletions src/cheatcodes/skip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## `skip`

## Signature

```solidity
function skip(bool skip) external;
```

## Description

Marks a test as skipped, conditionally. It must be called at the top of the test to ensure it is skipped without any execution.

If `skip` is called with a false boolean, it will not skip the test.

Tests marked as skipped will appear with a `[SKIPPED]` label on the test runner and on the summary, to easily identify skipped tests.

### Examples

```solidity
function testSkip() public {
cheats.skip(true);
/// This revert will not be reached as this test will be skipped.
revert("Should not reach this revert");
}
function testNotSkip() public {
cheats.skip(false);
/// This revert will be reached as this test will not be skipped, and the test will fail.
revert("Should reach this revert");
}
```
2 changes: 1 addition & 1 deletion src/misc/precompile-registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Note that, while some chains like Optimism have bytecode deployed at a predeterm
| 433114, 43113 | `0x0200000000000000000000000000000000000001` | ContractNativeMinterAddress |
| 433114, 43113 | `0x0200000000000000000000000000000000000002` | TxAllowListAddress |
| 433114, 43113 | `0x0200000000000000000000000000000000000003` | FeeConfigManagerAddress |
| ALL | `0x04E59B44847b37957858892cA78fBf26C0b4956C` | (Foundry) Create2Deployer |
| ALL | `0x4e59b44847b379578588920cA78FbF26c0B4956C` | (Foundry) Create2Deployer |
| ALL | `0x7109709ECfa91a80626fF3989D68f67F5b1DD12D` | (Foundry) VM |
| ALL | `0x000000000000000000636F6e736F6c652e6c6f67` | (Foundry) Console |

Expand Down
2 changes: 1 addition & 1 deletion src/projects/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ remappings = [
Now we can import any of the contracts in `src/utils` of the solmate repository like so:

```solidity
import "solmate-utils/Contract.sol";
import "solmate-utils/LibString.sol";
```

### Updating dependencies
Expand Down
2 changes: 1 addition & 1 deletion src/reference/anvil/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ Returns the details of all transactions currently pending for inclusion in the n
     The base fee in a block

`--chain-id <CHAIN_ID>`
&nbsp;&nbsp;&nbsp;&nbsp; The chain ID
&nbsp;&nbsp;&nbsp;&nbsp; The chain ID [default: 31337]

`--code-size-limit <CODE_SIZE>`
&nbsp;&nbsp;&nbsp;&nbsp; EIP-170: Contract code size limit in bytes. Useful to increase this because of tests.
Expand Down
1 change: 1 addition & 0 deletions src/reference/cast/account-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
- [cast proof](./cast-proof.md)
- [cast nonce](./cast-nonce.md)
- [cast code](./cast-code.md)
- [cast codesize](./cast-codesize.md)
8 changes: 4 additions & 4 deletions src/reference/cast/cast-basefee.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

### NAME

cast-basefee - Get the basefee of a block.
cast-base-fee - Get the basefee of a block.

### SYNOPSIS

``cast basefee`` [*options*] [*block*]
``cast base-fee`` [*options*] [*block*]

### DESCRIPTION

Expand All @@ -26,12 +26,12 @@ The specified *block* can be a block number, or any of the tags: `earliest`, `fi

1. Get the basefee of the latest block:
```sh
cast basefee
cast base-fee
```

2. Get the basefee of the genesis block:
```sh
cast basefee 1
cast base-fee 1
```

### SEE ALSO
Expand Down
42 changes: 42 additions & 0 deletions src/reference/cast/cast-codesize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## cast codesize

### NAME

cast-codesize - Get the runtime bytecode size of a contract.

### SYNOPSIS

``cast codesize`` [*options*] *address*

### DESCRIPTION

Get the runtime bytecode size of a contract.

The contract (*address*) can be an ENS name or an address.

### OPTIONS

#### Query Options

`-B` *block*
`--block` *block*
&nbsp;&nbsp;&nbsp;&nbsp;The block height you want to query at.

&nbsp;&nbsp;&nbsp;&nbsp;Can be a block number, or any of the tags: `earliest`, `finalized`, `safe`, `latest` or `pending`.

#### RPC Options

{{#include ../common/rpc-url-option.md}}

{{#include common-options.md}}

### EXAMPLES

1. Get the runtime bytecode size of the WETH contract.
```sh
cast codesize 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
```

### SEE ALSO

[cast](./cast.md), [cast code](./cast-code.md)
56 changes: 56 additions & 0 deletions src/reference/cast/cast-logs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
## cast logs

### NAME

cast logs - Get logs by signature or topic.

### SYNOPSIS

``cast logs`` [*options*] *sig_or_topic* [*topics_or_args...*]


### DESCRIPTION

Get logs by signature or topic.

The (*sig_or_topic*) may either be the event signature or its hashed topic (located at topics[0]).

If using a signature, remaining arguments must be in their ordinary form. If using a topic, the arguments must be as they themselves appear as topics.

### OPTIONS

### Query Options

`--from-block` *from_block*
&nbsp;&nbsp;&nbsp;&nbsp;The block height to start query at.

&nbsp;&nbsp;&nbsp;&nbsp;Can also be the tags: `earlies`t, `finalized`, `safe`, `latest`, or `pending`.

`--to-block` *to_block*
&nbsp;&nbsp;&nbsp;&nbsp;The block height to stop query at.

&nbsp;&nbsp;&nbsp;&nbsp;Can also be the tags: `earlies`t, `finalized`, `safe`, `latest`, or `pending`.

`--address` *address*
&nbsp;&nbsp;&nbsp;&nbsp;The contract address to filter on

{{#include ../common/wallet-options.md}}

{{#include ../common/rpc-options.md}}

{{#include ../common/etherscan-options.md}}

### EXAMPLES

1. Get logs using a signature:
```sh
cast logs --from-block 15537393 --to-block latest 'Transfer (address indexed from, address indexed to, uint256 value)' 0x2e8ABfE042886E4938201101A63730D04F160A82
```
2. Get logs using a topic:
```sh
cast logs --from-block 15537393 --to-block latest 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef 0x0000000000000000000000002e8abfe042886e4938201101a63730d04f160a82
```

### SEE ALSO

[cast](./cast.md)
12 changes: 9 additions & 3 deletions src/reference/cast/cast-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### NAME

cast-storage - Get the raw value of a contract's storage slot.
cast-storage - Get the raw value of a contract's storage slot or its full storage layout.

### SYNOPSIS

Expand All @@ -12,14 +12,16 @@ cast-storage - Get the raw value of a contract's storage slot.

Get the raw value of a contract's storage slot. (Slot locations greater than 18446744073709551615 (u64::MAX) should be given as hex. Use `cast index` to compute mapping slots.)

Emit the slot number to get the full storage layout (requires contract to be verified on Etherscan with a Solidity version > 0.6.5 or you must be in a Forge project with a local contract matching the deployed bytecode).

The address (*address*) can be an ENS name or an address.

### OPTIONS

#### Query Options

`-B` *block*
`--block` *block*
`-B` *block*
`--block` *block*
&nbsp;&nbsp;&nbsp;&nbsp;The block height you want to query at.

&nbsp;&nbsp;&nbsp;&nbsp;Can be a block number, or any of the tags: `earliest`, `finalized`, `safe`, `latest` or `pending`.
Expand All @@ -37,6 +39,10 @@ The address (*address*) can be an ENS name or an address.
cast storage 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 0
```

2. Get the full storage layout of the Milady contract.
```sh
cast storage 0x5Af0D9827E0c53E4799BB226655A1de152A425a5
```
### SEE ALSO

[cast](./cast.md), [cast proof](./cast-proof.md)
6 changes: 6 additions & 0 deletions src/reference/cast/cast.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ This program is a set of tools to interact with Ethereum and perform conversions
[cast access-list](./cast-access-list.md)
&nbsp;&nbsp;&nbsp;&nbsp;Create an access list for a transaction.

[cast logs](./cast-logs.md)
&nbsp;&nbsp;&nbsp;&nbsp;Get logs by signature or topic

#### Block Commands

[cast find-block](./cast-find-block.md)
Expand Down Expand Up @@ -101,6 +104,9 @@ This program is a set of tools to interact with Ethereum and perform conversions
[cast code](./cast-code.md)
&nbsp;&nbsp;&nbsp;&nbsp;Get the bytecode of a contract.

[cast codesize](./cast-codesize.md)
&nbsp;&nbsp;&nbsp;&nbsp;Get the runtime bytecode size of a contract.

#### ENS Commands

[cast lookup-address](./cast-lookup-address.md)
Expand Down
1 change: 1 addition & 0 deletions src/reference/cast/transaction-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
- [cast run](./cast-run.md)
- [cast estimate](./cast-estimate.md)
- [cast access-list](./cast-access-list.md)
- [cast logs](./cast-logs.md)
1 change: 1 addition & 0 deletions src/reference/cast/utility-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- [cast sig-event](./cast-sig-event.md)
- [cast keccak](./cast-keccak.md)
- [cast compute-address](./cast-compute-address.md)
- [cast create2](./cast-create2.md)
- [cast interface](./cast-interface.md)
- [cast index](./cast-index.md)
- [cast --concat-hex](./cast--concat-hex.md)
Expand Down
2 changes: 1 addition & 1 deletion src/reference/config/solidity-compiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ Valid values are:
- Default: false
- Environment: `FOUNDRY_SPARSE_MODE` or `DAPP_SPARSE_MODE`

Enables [sparse mode](./forge/forge-build.md#sparse-mode-experimental) for builds.
Enables [sparse mode](../forge/forge-build.md#sparse-mode-experimental) for builds.

### Optimizer

Expand Down
8 changes: 7 additions & 1 deletion src/reference/forge-std/deployCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ Deploys a contract by fetching the contract bytecode from the artifacts director

The calldata parameter can either be in the form `ContractFile.sol` (if the filename and contract name are the same), `ContractFile.sol:ContractName`, or the path to an artifact, relative to the root of your project.

Values can also be passed by using the `val` parameter. This is necessary if you need to send ETH on the constructor.
Values can also be passed by using the `val` parameter. This is necessary if you need to send ETH on construction.

### Examples

```solidity
address deployment = deployCode("MyContract.sol", abi.encode(arg1, arg2));
```

### SEE ALSO

Forge Standard Library

- [`deployCodeTo`](./deployCodeTo.md)
Loading

0 comments on commit f2fac43

Please sign in to comment.