diff --git a/README.md b/README.md index ecd3529..52e79ac 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,27 @@ - [LockstakeEngine multicall](https://etherscan.io/tx/0x4b049eef5530930673ed21c3c7b4c47daceb3ee492c1d8f2c86d0623965b43c5) - [LockstakeEngine getReward + lock](https://etherscan.io/tx/0x2b85425949094b36528c92ee6b913974f374a1a7399ed546036148783b460c6b) - [VoteDelegateFactory create](https://etherscan.io/tx/0x1cf5f9999f05343cc8d3e6afaa392bf8a00824b1d972bc3bca9371d212f6286c) -- [Sky buy back](https://etherscan.io/tx/0x7a1d70e7a0e989cdaca487cc5ff04dc8ae042dbf44f6f18b021ff54deb1f0f74) +## Running Tests -- TODO: update to sol 0.8.34 +Tests require a connection to Ethereum mainnet to fork and test against real state. + +### Setup + +1. Get an Ethereum RPC URL: + - [Alchemy](https://www.alchemy.com/) (recommended) + - [Infura](https://www.infura.io/) + - Local Anvil instance + +2. Configure the fork URL: +```bash +cd foundry +cp .env.sample .env +# Edit .env and add your RPC URL +``` + +3. Run tests: +```bash +forge test +``` + +All test contracts inherit from `BaseTest` which automatically handles fork setup when `FORK_URL` is configured. diff --git a/foundry/.env.sample b/foundry/.env.sample index ab7f712..a30ddc2 100644 --- a/foundry/.env.sample +++ b/foundry/.env.sample @@ -1 +1,3 @@ -FORK_URL= +# Ethereum mainnet RPC URL for test forking +# Required to run tests against mainnet state (Alchemy, Infura, etc.) +FORK_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY diff --git a/foundry/test/BaseTest.sol b/foundry/test/BaseTest.sol new file mode 100644 index 0000000..7f4c33a --- /dev/null +++ b/foundry/test/BaseTest.sol @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later +pragma solidity 0.8.33; + +import {Test} from "forge-std/Test.sol"; + +/// @notice Base test contract that handles mainnet fork setup +/// Automatically forks Ethereum mainnet if FORK_URL is set +contract BaseTest is Test { + function setUp() public virtual { + string memory forkUrl = vm.envString("FORK_URL"); + if (bytes(forkUrl).length > 0) { + vm.createSelectFork(forkUrl); + } + } +}