Skip to content

Commit

Permalink
Get a basic foundry test running (compound-finance#606)
Browse files Browse the repository at this point in the history
* Get a basic foundry test running

* Don't copy lib

* Attempt forge test workflow

* Document usage in the README
  • Loading branch information
jflatow authored Nov 1, 2022
1 parent 6fa6fd5 commit 8e3e454
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/run-forge-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Run Forge Tests
on:
workflow_dispatch:
pull_request:
jobs:
forge-tests:
name: Forge tests
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
submodules: recursive

- name: Install Foundry
uses: onbjerg/foundry-toolchain@v1
with:
version: nightly

- name: Install dependencies
run: forge install

- name: Run tests
run: forge test -vvv
env:
ETHERSCAN_KEY: ${{ secrets.ETHERSCAN_KEY }}
SNOWTRACE_KEY: ${{ secrets.SNOWTRACE_KEY }}
INFURA_KEY: ${{ secrets.INFURA_KEY }}
POLYGONSCAN_KEY: ${{ secrets.POLYGONSCAN_KEY }}

- name: Build Comet with older solc versions
run: |
forge build --contracts contracts/Comet.sol --use solc:0.8.15
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ dist/
deployments/*/.contracts
deployments/*/*/verify
deployments/*/*/aliases.json
forge/cache
forge/out

.env
coverage/
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "forge/lib/forge-std"]
path = forge/lib/forge-std
url = https://github.com/foundry-rs/forge-std
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ Set up the following env variables:
- `COINMARKETCAP_API_KEY=your_coinmarket_api_key`
optional, only if you want to see cost in USD

### Run forge tests

Experimental support for `foundry` has been added, so assuming `forge` is installed:

```
forge test
```

See the [GitHub workflow](.github/workflows/run-forge-tests.yaml) for an example.


### Deploy contracts

Deploys contracts to a specified chain using a deployment script.
Expand Down
1 change: 1 addition & 0 deletions forge/lib/forge-std
Submodule forge-std added at 2a2ce3
41 changes: 41 additions & 0 deletions forge/test/Comet.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "forge-std/Test.sol";
import "../../contracts/Comet.sol";
import "../../contracts/CometConfiguration.sol";

contract CometTest is Test {
Comet public comet;

function setUp() public {
// XXX
}

function testFailXXX() public {
CometConfiguration.AssetConfig[] memory assets = new CometConfiguration.AssetConfig[](0);
CometConfiguration.Configuration memory config =
CometConfiguration.Configuration(address(0),
address(0),
address(0),
address(0),
address(0),
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
assets);
comet = new Comet(config);
}
}
6 changes: 6 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[profile.default]
src = 'contracts'
out = 'forge/out'
libs = ['node_modules', 'forge/lib']
test = 'forge/test'
cache_path = 'forge/cache'

0 comments on commit 8e3e454

Please sign in to comment.