Skip to content

Commit

Permalink
embed cheatcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
zerosnacks committed Oct 3, 2024
1 parent 240ec61 commit 15da828
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 34 deletions.
3 changes: 2 additions & 1 deletion src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
- [Deploying and Verifying](./forge/deploying.md)
- [Gas Tracking](./forge/gas-tracking.md)
- [Gas Reports](./forge/gas-reports.md)
- [Gas Snapshots](./forge/gas-snapshots.md)
- [Gas Function Snapshots](./forge/gas-function-snapshots.md)
- [Gas Section Snapshots](./forge/gas-section-snapshots.md)
- [Debugger](./forge/debugger.md)

# Cast Overview
Expand Down
34 changes: 2 additions & 32 deletions src/forge/gas-section-snapshots.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,6 @@

Forge can capture gas snapshots over arbitrary sections inside of your test functions. This can be useful to get a granular measurement of how much gas your logic is consuming as both external calls and internal gas usage are measured.

To usage gas snapshots, use the following [`cheatcodes`](../cheatcodes/gas-snapshots.md) in your test functions:
To usage gas snapshots, use the following cheatcodes in your test functions:

```solidity
/// Start a snapshot capture of the current gas usage by name.
/// The group name is derived from the contract name.
function startSnapshotGas(string calldata name) external;
/// Start a snapshot capture of the current gas usage by name in a group.
function startSnapshotGas(string calldata group, string calldata name) external;
/// Stop the snapshot capture of the current gas by latest snapshot name, capturing the gas used since the start.
function stopSnapshotGas() external returns (uint256 gasUsed);
/// Stop the snapshot capture of the current gas usage by name, capturing the gas used since the start.
/// The group name is derived from the contract name.
function stopSnapshotGas(string calldata name) external returns (uint256 gasUsed);
/// Stop the snapshot capture of the current gas usage by name in a group, capturing the gas used since the start.
function stopSnapshotGas(string calldata group, string calldata name) external returns (uint256 gasUsed);
/// Snapshot capture an arbitrary numerical value by name.
/// The group name is derived from the contract name.
function snapshotValue(string calldata name, uint256 value) external;
/// Snapshot capture an arbitrary numerical value by name in a group.
function snapshotValue(string calldata group, string calldata name, uint256 value) external;
/// Snapshot capture the gas usage of the last call by name from the callee perspective.
function snapshotGasLastCall(string calldata name) external returns (uint256 gasUsed);
/// Snapshot capture the gas usage of the last call by name in a group from the callee perspective.
function snapshotGasLastCall(string calldata group, string calldata name) external returns (uint256 gasUsed);
```
{{#include ../cheatcodes/gas-snapshots.md}}
2 changes: 1 addition & 1 deletion src/forge/gas-tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Forge can help you estimate how much gas your contract will consume.

Currently, Forge ships with three different tools for this job, but they may be merged in the future:
Currently, Forge ships with three different tools for this job:

- [**Gas reports**](./gas-reports.md): Gas reports give you an overview of how much Forge thinks the
individual functions in your contracts will consume in gas.
Expand Down

0 comments on commit 15da828

Please sign in to comment.