Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
feat: adds foundry-zksync docs (#890)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicolas Villanueva <[email protected]>
  • Loading branch information
dutterbutter and MexicanAce authored Feb 8, 2024
1 parent 1a90563 commit a442e6d
Show file tree
Hide file tree
Showing 5 changed files with 484 additions and 4 deletions.
3 changes: 3 additions & 0 deletions cspell-zksync.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ IPFS
Nuxt
viem
Wagmi
zkbuild
zkout
zkcreate

// docs restructure
NVME
Expand Down
14 changes: 14 additions & 0 deletions docs/.vuepress/sidebar/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,20 @@ export const enSidebar = sidebar({
"/build/tooling/hardhat/other-plugins.md",
]
},
{
text: "Foundry",
collapsible: true,
children: [
{
text: "Overview",
link: "/build/tooling/foundry/overview.md",
},
{
text: "Getting Started",
link: "/build/tooling/foundry/getting-started.md",
},
]
},
{
text: "Ecosystem",
collapsible: true,
Expand Down
83 changes: 79 additions & 4 deletions docs/build/test-and-debug/foundry.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,85 @@ head:
content: Foundry | zkSync Docs
---

# Foundry
# zkSync Foundry Testing

Support for testing with Foundry is currently **in development** and not yet available. We are actively working on it. You can stay updated on the progress by visiting the repository at:
For instructions on how to install `foundry-zksync` please refer to the [Getting Started](../tooling/foundry/getting-started.md) page.

[https://github.com/matter-labs/foundry-zksync](https://github.com/matter-labs/foundry-zksync)
## Overview

If you're interested in contributing to the development of testing support, please feel free to open a pull request (PR) and collaborate with us!
`foundry-zksync`, a fork of Foundry, provides developers with a tailored testing framework designed specifically for zkSync environments. Utilizing `zkforge test`, you can execute your smart contract tests efficiently. Tests are written in Solidity, and the framework is designed to recognize any contract function prefixed with `test` as a test case. By convention, tests are typically stored within the `test/` directory and have a `.t.sol` extension.

:::info
For more detailed documentation related to Foundry testing please refer to the official upstream Foundry documentation [here](https://book.getfoundry.sh/forge/tests).
:::

## Running Tests

To initiate your tests, use the `zkforge test` command. This command automatically locates and executes tests across your source directory. Here's an example of executing tests in a standard project setup:

```bash
zkforge test

Running 2 tests for test/Counter.t.sol:CounterTest
[PASS] testFuzz_SetNumber(uint256) (runs: 256, μ: 27553, ~: 28409)
[PASS] test_Increment() (gas: 28379)
Test result: ok. 2 passed; 0 failed; 0 skipped; finished in 96.80ms
```

### Filtering Tests

You can run specific tests by filtering based on the contract or test names:

```bash
zkforge test --match-contract CounterTest --match-test test_Increment
```

This command will execute only the tests within `CounterTest` that include `test_Increment` in their name.

Similarly, you can use `--match-path` to run tests in files that match a specific glob pattern:

```bash
zkforge test --match-path Counter.t.sol
```

Inverse filters are available through `--no-match-contract`, `--no-match-test`, and `--no-match-path` flags.

## Watch Mode

To automatically re-run tests upon any file changes, use the `zkforge test --watch --run-all` command.

## Writing Tests

Tests are structured as Solidity contracts, often inheriting from the Forge Standard Library's `Test` contract for enhanced functionality, including basic assertions and logging:

```solidity
pragma solidity 0.8.10;
import "forge-std/Test.sol";
contract ContractBTest is Test {
uint256 testNumber;
function setUp() public {
testNumber = 42;
}
function test_NumberIs42() public {
assertEq(testNumber, 42);
}
function testFail_Subtract43() public {
testNumber -= 43;
}
}
```

### Key Concepts

- **`setUp`:** An optional function that runs before each test, used for initializing test conditions.
- **`test`:** Prefix for functions that are recognized as tests. These functions must either pass or revert to indicate success or failure, respectively.
- **`testFail`:** A prefix for test functions expected to revert. If such a function does not revert, the test is considered failed.

### Cheatcodes

Cheatcodes allow you to change the block number, your identity, and more. `foundry-zksync` supports the most common cheatcodes. For an exhaustive list of supported cheatcodes refer to the supported table [here](https://github.com/matter-labs/foundry-zksync/blob/main/SUPPORTED_CHEATCODES.md).
Loading

0 comments on commit a442e6d

Please sign in to comment.