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

Commit

Permalink
chore: updates foundry docs to reflect latest v2 version (#1016)
Browse files Browse the repository at this point in the history
  • Loading branch information
dutterbutter authored Apr 9, 2024
1 parent dbdb344 commit 0e0f1ae
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 81 deletions.
12 changes: 6 additions & 6 deletions docs/build/test-and-debug/foundry.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ For instructions on how to install `foundry-zksync` please refer to the [Getting

## Overview

`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.
`foundry-zksync`, a fork of Foundry, provides developers with a tailored testing framework designed specifically for zkSync environments. Utilizing `forge test --zksync`, 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:
To initiate your tests, use the `forge test --zksync` command with the `--zksync` flag, or incorporate `vm.zkVm(true)` within your tests. 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
forge test --zksync

Running 2 tests for test/Counter.t.sol:CounterTest
[PASS] testFuzz_SetNumber(uint256) (runs: 256, μ: 27553, ~: 28409)
Expand All @@ -35,22 +35,22 @@ Test result: ok. 2 passed; 0 failed; 0 skipped; finished in 96.80ms
You can run specific tests by filtering based on the contract or test names:

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

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
forge test --match-path test/Counter.t.sol --zksync
```

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.
To automatically re-run tests upon any file changes, use the `forge test --watch --run-all --zksync` command.

## Writing Tests

Expand Down
109 changes: 36 additions & 73 deletions docs/build/tooling/foundry/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ To integrate `foundry-zksync` into your projects, you have the flexibility to in
2. Navigate to the project directory and switch to the main branch:

```bash
cd foundry-zksync && git checkout main
cd foundry-zksync && git checkout dev
```

For component-specific installations:

- **zkForge**: To install, execute:
- **Forge**: To install, execute:

```bash
cargo install --path ./crates/zkforge --profile local --force --locked
cargo install --path ./crates/forge --profile local --force --locked
```

- **zkCast**: To install, run:
- **Cast**: To install, run:

```bash
cargo install --path ./crates/zkcast --profile local --force --locked
cargo install --path ./crates/cast --profile local --force --locked
```

For the entire suite:
Expand All @@ -55,7 +55,7 @@ Choose the installation that best fits your development needs.

### Initial Setup

After installation, initialize a new project with `zkforge init <project_name>`, which sets up the basic structure of a new Foundry project.
After installation, initialize a new project with `forge init <project_name>`, which sets up the basic structure of a new Foundry project.

### Project Configuration using `foundry.toml`

Expand All @@ -65,11 +65,11 @@ Configuration can be arbitrarily namespaced by profiles. The default profile is

You can select another profile using the `FOUNDRY_PROFILE` environment variable. You can also override parts of your configuration using `FOUNDRY_` or `DAPP_` prefixed environment variables, like `FOUNDRY_SRC`.

`zkforge init` creates a basic, extendable `foundry.toml` file.
`forge init` creates a basic, extendable `foundry.toml` file.

To see your current configuration, run `zkforge config`. To see only basic options (as set with `zkforge init`), run `zkforge config --basic`. This can be used to create a new `foundry.toml` file with `zkforge config --basic > foundry.toml`.
To see your current configuration, run `forge config`. To see only basic options (as set with `forge init`), run `forge config --basic`. This can be used to create a new `foundry.toml` file with `forge config --basic > foundry.toml`.

By default `zkforge config` shows the currently selected foundry profile and its values. It also accepts the same arguments as `zkforge build`. An example `foundry.toml` for zkSync with zksolc configurations may look like:
By default `forge config` shows the currently selected foundry profile and its values. It also accepts the same arguments as `forge build`. An example `foundry.toml` for zkSync with zksolc configurations may look like:

```
[profile.default]
Expand All @@ -81,26 +81,26 @@ libs = ['lib']
src = 'src'
libs = ['lib']
fallback_oz = true
is_system = true
is_system = false
mode = "3"
```

## Basic Usage

### Running Tests

Use `zkforge test` to run tests written for your smart contracts. For an overview of how to write tests using `Foundry-zksync` please refer to Foundry testing [here](../../test-and-debug/foundry.md).
Use `forge test --zksync` to run tests written for your smart contracts. For an overview of how to write tests using `foundry-zksync` please refer to Foundry testing [here](../../test-and-debug/foundry.md).

## Deploying Smart Contracts with `zkforge`
## Deploying Smart Contracts with `forge`

### Compilation with `zkforge zk-build`
### Compilation with `forge build --zksync`

`zkforge zkbuild` (also accessible via aliases like `zkforge zk-build`, `zkforge zk-compile`, `zkforge zkb`) is used for compiling smart contracts into zkEVM bytecode. The compiled files are stored in a structured directory at `<PROJECT-ROOT>/zkout/`.
`forge build --zksync` is used for compiling smart contracts into zkEVM bytecode. The compiled files are stored in a structured directory at `<PROJECT-ROOT>/zkout/`.

**Usage:**

```sh
zkforge zkbuild [OPTIONS]
forge build [OPTIONS] --zksync
```

**Key Compiler Options:**
Expand All @@ -117,20 +117,17 @@ zkforge zkbuild [OPTIONS]
Compile with default settings or specify `zksolc` version:

```sh
zkforge zkbuild

# specifying zksolc version
zkforge zkbuild --use-zksolc v1.3.19
forge build --zksync
```

### Deployment with `zkforge zk-create`
### Deployment with `forge create --zksync`

`zkforge zkcreate` (and its aliases `zkforge zk-create`, `zkforge zk-deploy`, `zkforge zkc`) deploys smart contracts to zkSync.
`forge create --zksync` deploys smart contracts to zkSync.

**Usage:**

```sh
zkforge zkcreate <CONTRACT> [OPTIONS] --rpc-url <RPC-URL> --chain <CHAIN-ID> --private-key <PRIVATE-KEY>
forge create <CONTRACT> [OPTIONS] --rpc-url <RPC-URL> --chain <CHAIN-ID> --private-key <PRIVATE-KEY> --zksync
```

**Options:**
Expand Down Expand Up @@ -170,7 +167,7 @@ contract Greeter {
</details>

```bash
zkforge zkcreate src/Greeter.sol:Greeter --constructor-args "Hello zkSync" --private-key <PRIVATE_KEY> --rpc-url https://sepolia.era.zksync.dev --chain 300
forge create src/Greeter.sol:Greeter --constructor-args "Hello zkSync" --private-key <PRIVATE_KEY> --rpc-url https://sepolia.era.zksync.dev --chain 300 --zksync
```

### Deploying Factory Contracts
Expand Down Expand Up @@ -209,25 +206,25 @@ contract Factory {
**Compile `GreeterFactory.sol`:**

```bash
zkforge zkbuild --is-system=true
forge build --is-system=true --zksync
```

**Deploy `GreeterFactory.sol`:**

```sh
zkforge zkcreate src/GreeterFactory.sol:Factory --factory-deps src/Greeter.sol:Greeter --private-key <PRIVATE_KEY> --rpc-url https://sepolia.era.zksync.dev --chain 300
forge create src/GreeterFactory.sol:Factory --factory-deps src/Greeter.sol:Greeter --private-key <PRIVATE_KEY> --rpc-url https://sepolia.era.zksync.dev --chain 300 --zksync
```

**Deploy `Greeter.sol` via `GreeterFactory.sol`:**

```sh
zkcast zk-send <FACTORY_ADDRESS> "CreateNewGreeter(string)" "zkSync Rules" --private-key <PRIVATE_KEY> --rpc-url https://sepolia.era.zksync.dev --chain 300
cast send <FACTORY_ADDRESS> "CreateNewGreeter(string)" "zkSync Rules" --private-key <PRIVATE_KEY> --rpc-url https://sepolia.era.zksync.dev --chain 300
```

**Interact with `Greeter.sol`**

```sh
zkcast call <CONTRACT_ADDRESS> "greet()(string)" --rpc-url https://sepolia.era.zksync.dev --chain 300
cast call <CONTRACT_ADDRESS> "greet()(string)" --rpc-url https://sepolia.era.zksync.dev --chain 300
```

**Output:**
Expand All @@ -239,7 +236,7 @@ zkcast call <CONTRACT_ADDRESS> "greet()(string)" --rpc-url https://sepolia.era.z
**To decode the output to a readable string:**

```sh
zkcast to-ascii 0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000c7a6b53796e632052756c65730000000000000000000000000000000000000000
cast to-ascii 0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000c7a6b53796e632052756c65730000000000000000000000000000000000000000
```

**Output:**
Expand All @@ -248,11 +245,11 @@ zkcast to-ascii 0x0000000000000000000000000000000000000000000000000000000000000
zkSync Rules
```

## Basic zkSync Chain Interactions with `zkcast`
## Basic zkSync Chain Interactions with `cast`

### Introduction

This guide introduces you to fundamental interactions within the zkSync chain using `zkcast`, a component of the `foundry-zksync` toolkit. Learn how to query chain IDs, retrieve client versions, check L2 ETH balances, obtain gas prices, and more.
This guide introduces you to fundamental interactions within the zkSync chain using `cast`, a component of the `foundry-zksync` toolkit. Learn how to query chain IDs, retrieve client versions, check L2 ETH balances, obtain gas prices, and more.

### Chain ID Retrieval

Expand All @@ -261,7 +258,7 @@ This guide introduces you to fundamental interactions within the zkSync chain us
Retrieve the Chain ID for a local zkSync node with:

```sh
zkcast chain-id --rpc-url http://localhost:3050
cast chain-id --rpc-url http://localhost:3050
```

Expected Output: `270`, indicating the Chain ID of your local zkSync node.
Expand All @@ -271,7 +268,7 @@ This guide introduces you to fundamental interactions within the zkSync chain us
For the zkSync Sepolia Testnet, use:

```sh
zkcast chain-id --rpc-url https://sepolia.era.zksync.dev
cast chain-id --rpc-url https://sepolia.era.zksync.dev
```

Expected Output: `300`, the Chain ID for the zkSync Sepolia Testnet.
Expand All @@ -281,7 +278,7 @@ This guide introduces you to fundamental interactions within the zkSync chain us
Knowing the client version is vital for compatibility checks and debugging:

```sh
zkcast client --rpc-url https://sepolia.era.zksync.dev
cast client --rpc-url https://sepolia.era.zksync.dev
```

Expected Output: `zkSync/v2.0`, denoting the client version.
Expand All @@ -291,7 +288,7 @@ Expected Output: `zkSync/v2.0`, denoting the client version.
Verify the Layer 2 (L2) balance of an account:

```sh
zkcast balance 0x8b1d48a69ACEbC6eb201e2F4d162A002203Bfe8E --rpc-url https://sepolia.era.zksync.dev
cast balance 0x8b1d48a69ACEbC6eb201e2F4d162A002203Bfe8E --rpc-url https://sepolia.era.zksync.dev
```

Expected Output: A numerical value, e.g., `774909739323110932`, representing the account's L2 balance.
Expand All @@ -301,7 +298,7 @@ Expected Output: A numerical value, e.g., `774909739323110932`, representing the
Fetch the current gas price on the network for transaction cost estimations:

```sh
zkcast gas-price --rpc-url https://sepolia.era.zksync.dev
cast gas-price --rpc-url https://sepolia.era.zksync.dev
```

Expected Output: A value such as `100000000`, indicating the current gas price.
Expand All @@ -311,57 +308,23 @@ Expected Output: A value such as `100000000`, indicating the current gas price.
Gain insights into the latest block on the zkSync chain:

```sh
zkcast block latest --rpc-url https://sepolia.era.zksync.dev
cast block latest --rpc-url https://sepolia.era.zksync.dev
```

Expected Output: Detailed information about the latest block, including base fee per gas, gas limit, block hash, and more.

### Sending Transactions

Initiate transactions, such as contract function calls, using `zkcast`:
Initiate transactions, such as contract function calls, using `cast`:

```sh
zkcast zk-send <CONTRACT_ADDRESS> <FUNCTION_SIGNATURE> <ARGUMENTS> --rpc-url <RPC-URL> --private-key <PRIVATE-KEY> --chain <CHAIN-ID>
cast send <CONTRACT_ADDRESS> <FUNCTION_SIGNATURE> <ARGUMENTS> --rpc-url <RPC-URL> --private-key <PRIVATE-KEY> --chain <CHAIN-ID>
```

Example:

```sh
zkcast zk-send 0x97b985951fd3e0c1d996421cc783d46c12d00082 "setGreeting(string)" "Hello, zkSync!" --rpc-url http://localhost:3050 --private-key <PRIVATE-KEY> --chain 270
cast send 0xe34E488C1B0Fb372Cc4a5d39219261A5a6fc7996 "setGreeting(string)" "Hello, zkSync!" --rpc-url https://sepolia.era.zksync.dev --private-key <PRIVATE-KEY> --chain 300
```

This command calls the `setGreeting` function of a contract, updating the greeting to "Hello, zkSync!". Replace `<PRIVATE-KEY>` with your actual private key.

### Bridging Assets Between L1 and L2

#### L1 to L2 Deposits

Deposit assets from Layer 1 (Ethereum) to Layer 2 (zkSync):

```sh
zkcast zk-deposit <RECIPIENT_ADDRESS> <AMOUNT> <TOKEN> --l1-rpc-url <L1-RPC-URL> --l2-url <L2-RPC-URL> --chain <CHAIN-ID> --private-key <PRIVATE-KEY>
```

Note: For ETH deposits, leave the `<TOKEN>` parameter empty.

Example (Depositing ETH):

```sh
zkcast zk-deposit 0x36615Cf349d7F6344891B1e7CA7C72883F5dc049 1 ether --l1-rpc-url http://localhost:8545 --l2-url http://localhost:3050 --private-key <PRIVATE-KEY> --chain 270
```

#### L2 to L1 Withdrawals

Withdraw assets from Layer 2 back to Layer 1:

```sh
zkcast zk-send --withdraw <RECIPIENT_ADDRESS> --amount <AMOUNT> <TOKEN> --rpc-url <L2-RPC-URL> --private-key <PRIVATE-KEY> --chain <CHAIN-ID>
```

Example (Withdrawing ETH):

```sh
zkcast zk-send --withdraw 0x36615Cf349d7F6344891B1e7CA7C728

83F5dc049 --amount 1 ether --rpc-url http://localhost:3050 --private-key <PRIVATE-KEY> --chain 270
```
3 changes: 1 addition & 2 deletions docs/build/tooling/foundry/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ head:

## Overview

`foundry-zksync` is a specialized fork of [Foundry](https://github.com/foundry-rs/foundry), tailored for zkSync. It extends Foundry's capabilities for Ethereum app development to support zkSync, allowing for the compilation, deployment, testing, and interaction with smart contracts on zkSync. `foundry-zksync` introduces `zkforge` and `zkcast` extensions of Foundry's existing `forge` and `cast` tools but tailored for zkSync usage.
`foundry-zksync` is a specialized fork of [Foundry](https://github.com/foundry-rs/foundry), tailored for zkSync. It extends Foundry's capabilities for Ethereum app development to support zkSync, allowing for the compilation, deployment, testing, and interaction with smart contracts on zkSync. `foundry-zksync` introduces `--zksync` flag, or the use of `vm.zkVm(true)` to target the zkSync VM.

### Status and Contribution

Expand All @@ -36,7 +36,6 @@ head:

While `foundry-zksync` is **alpha stage**, there are some limitations to be aware of, but not limited to:

- **Cheat Codes Support**: Not all cheat codes are fully supported. [View the list of supported cheat codes](https://github.com/matter-labs/foundry-zksync/blob/main/SUPPORTED_CHEATCODES.md).
- **Compile Time**: Some users may experience slow compiling.
- **Specific Foundry Features**: Currently features such as `coverage`, `--gas-report` or `--verify` may not work as intended. We are actively working on providing support for these feature types.
- **Compiling Libraries**: Compiling non-inlinable libraries requires deployment and adding to configuration. For more information please refer to [official docs](https://era.zksync.io/docs/tools/hardhat/compiling-libraries.html).
Expand Down

0 comments on commit 0e0f1ae

Please sign in to comment.