Skip to content

Files

Latest commit

3b87318 · Mar 8, 2024

History

History
This branch is 203 commits behind foundry-rs/book:master.

forge-std

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Sep 6, 2022
Jul 8, 2022
Feb 3, 2023
Sep 16, 2022
Sep 16, 2022
Sep 21, 2022
May 19, 2022
Apr 23, 2022
Aug 8, 2023
May 28, 2023
Jul 8, 2022
Mar 8, 2024
Jul 13, 2023
Sep 6, 2022
Aug 23, 2023
Apr 23, 2022
Jul 8, 2022
Jun 25, 2023
Jul 28, 2023
Jul 8, 2022
Mar 28, 2023
Apr 23, 2022
Apr 23, 2022
Apr 23, 2022
Jul 8, 2022
Jul 8, 2022
Apr 23, 2022
Apr 23, 2022
Aug 6, 2022
Aug 6, 2022
Apr 23, 2022
Dec 4, 2022
Feb 3, 2023
Apr 23, 2022
Jul 8, 2022
Apr 23, 2022
Sep 6, 2022
Jul 8, 2022
Apr 23, 2022
Oct 26, 2022
May 19, 2022
Jun 25, 2023
Apr 23, 2022
Jul 8, 2022
Jul 8, 2022
Dec 24, 2023
Jul 8, 2022
Jul 8, 2022
Apr 23, 2022

Forge Standard Library Reference

Forge Standard Library (Forge Std for short) is a collection of helpful contracts that make writing tests easier, faster, and more user-friendly.

Using Forge Std is the preferred way of writing tests with Foundry.

What's included:

  • Vm.sol: Up-to-date cheatcodes interface

    import "forge-std/Vm.sol";
  • console.sol and console2.sol: Hardhat-style logging functionality

    import "forge-std/console.sol";

    Note: console2.sol contains patches to console.sol that allow Forge to decode traces for calls to the console, but it is not compatible with Hardhat.

    import "forge-std/console2.sol";
  • Script.sol: Basic utilities for Solidity scripting

    import "forge-std/Script.sol";
  • Test.sol: The complete Forge Std experience (more details below)

    import "forge-std/Test.sol";

Forge Std's Test

The Test contract in Test.sol provides all the essential functionality you need to get started writing tests.

Simply import Test.sol and inherit from Test in your test contract:

import "forge-std/Test.sol";

contract ContractTest is Test { ...

What's included:

  • Std Libraries

    • Std Logs: Expand upon the logging events from the DSTest library.
    • Std Assertions: Expand upon the assertion functions from the DSTest library.
    • Std Cheats: Wrappers around Forge cheatcodes for improved safety and DX.
    • Std Errors: Wrappers around common internal Solidity errors and reverts.
    • Std Storage: Utilities for storage manipulation.
    • Std Math: Useful mathematical functions.
    • Script Utils: Utility functions which can be accessed in tests and scripts.
    • Console Logging: Console logging functions.
  • A cheatcodes instance vm, from which you invoke Forge cheatcodes (see Cheatcodes Reference)

    vm.startPrank(alice);
  • All Hardhat console functions for logging (see Console Logging)

    console.log(alice.balance); // or `console2`
  • All Dappsys Test functions for asserting and logging (see Dappsys Test reference)

    assertEq(dai.balanceOf(alice), 10000e18);
  • Utility functions also included in Script.sol (see Script Utils)

    // Compute the address a contract will be deployed at for a given deployer address and nonce
    address futureContract = computeCreateAddress(alice, 1);