Foundry

Running Foundry Test Scripts

This documentation provides a step-by-step guide to setting up Foundry, configuring dependencies, and executing test scripts for integrations with Compound, Aave, and LayerBank protocols.


1. Install Foundry

Foundry is a Rust-based Ethereum development framework providing tools like forge, cast, and anvil for compiling, deploying, and testing smart contracts.

1. Install Foundry (Linux/Mac):

curl -L https://foundry.paradigm.xyz | bash

Reload your environment:

foundryup

Verify installation:

forge --version

2. For Windows users (WSL):

Option 1: Using Windows Subsystem for Linux (WSL)

  • Install WSL and Ubuntu from the Microsoft Store.

  • Follow the above Linux installation steps within WSL.

Option 2: Using PowerShell Run the following command in PowerShell:

Restart the terminal and run:

Verify installation:


Clone and Configure the Repository

Clone the repository and enter its directory:

Install Dependencies

Foundry requires external libraries (Compound, Aave, LayerBank). Install them using forge install:

This command ensures all dependencies are placed in the lib/ directory.

Configure foundry.toml

Set your foundry.toml configuration as follows:

This configuration:

  • Enables IR-based compilation (via_ir = true) for optimized bytecode.

  • Enables Solidity optimizer with 200 runs (optimizer = true).

  • Defines remappings for external dependencies.

  • Specifies src/ as the source directory and lib/ as the library directory.


Run Local Fork with Anvil

Anvil is a fast Ethereum RPC fork provider for running local blockchain simulations.

1. Start Local Anvil Node

Run Anvil for local blockchain development:

Replace:

  • https://your-rpc-url.com with your RPC provider.

  • YOUR_CHAIN_ID with your blockchain's Chain ID (e.g., 1 for Ethereum, 534352 for Scroll).

Example for Scroll Mainnet (using Alchemy):

What This Does:

  • Forks the mainnet, allowing contract interactions as if on mainnet.

  • Persists the blockchain state, so transactions behave realistically.

  • Runs a local RPC server (127.0.0.1:8545) for Foundry tests.

2. Run Foundry Tests

Navigate to the test directory:

Run specific tests:

Replace YOUR_TEST_SCRIPT.t.sol with the actual test file name. Example:

Explanation of Flags:

  • --fork-url http://127.0.0.1:8545→ Connects to the locally running Anvil fork.

  • --match-path test/YOUR_TEST_SCRIPT.t.sol → Runs a specific test script.

  • -vvv → Enables verbose mode (displays logs, transactions, and errors).


Log Successful Test Runs

Use the following command to log test results and store them in a file:

tee test-results.log → Saves all logs to test-results.log.

Review logs by opening the file:

Example Running Test Script for Combined Vault

If successful, the output will look like:

Additional Resources

Last updated