Skip to content

Commit

Permalink
add forge tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wighawag committed Nov 28, 2023
1 parent 58a32d1 commit f208b5f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
11 changes: 10 additions & 1 deletion contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@ deployments/localhost
/coverage-data.json
cache
artifacts
docs
docs

# foundry
forge-cache/
forge-artifacts/

# Note: by default we ignore lib/forge-std as we do not use submodules
# install it via `git clone --recursive https://github.com/foundry-rs/forge-std.git lib/forge-std`
lib/forge-std

18 changes: 18 additions & 0 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,28 @@ pnpm compile

### Test your contracts

There is 2 flavors of test

1. Using hardhat

```bash
pnpm test
```

2. Using foundry

```bash
forge test
```

This assumes you have `forge` installed and that you added forge-std in via the following command

```bash
git clone --recursive https://github.com/foundry-rs/forge-std.git lib/forge-std
```

You can also add it as a submodule if you prefers

### watch for changes and rebuild automatically

```bash
Expand Down
12 changes: 12 additions & 0 deletions contracts/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[profile.default]
src = "src"
out = "forge-artifacts"
libs = ["node_modules", "lib"]
remappings = [
"hardhat/=node_modules/hardhat/",
"solidity-proxy/=node_modules/solidity-proxy/"
]
test = 'test/foundry'
cache_path = 'forge-cache'

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
2 changes: 2 additions & 0 deletions contracts/remappings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/
18 changes: 18 additions & 0 deletions contracts/test/foundry/GreetingsRegistry.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Test, console2} from "forge-std/Test.sol";
import {GreetingsRegistry} from "../../src/GreetingsRegistry.sol";

contract GreetingsRegistryTest is Test {
GreetingsRegistry public registry;

function setUp() public {
registry = new GreetingsRegistry("");
}

function test_setMessage() public {
registry.setMessage("hello", 0);
assertEq(registry.lastGreetingOf(address(this)), "hello");
}
}

0 comments on commit f208b5f

Please sign in to comment.