Skip to content

Commit 9a44c10

Browse files
authored
Merge pull request #10 from datachainlab/install-unit-test
ci: run Forge unit tests on GitHub Actions
2 parents 29e2ab5 + 3447aec commit 9a44c10

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Forge Unit Tests
2+
3+
on:
4+
pull_request: {}
5+
push:
6+
branches: [ main ]
7+
8+
jobs:
9+
unit-tests:
10+
runs-on: ubuntu-latest
11+
env:
12+
CI: true
13+
14+
steps:
15+
- name: Setup Node.js
16+
uses: actions/setup-node@v3
17+
with:
18+
node-version: "25"
19+
20+
- name: Checkout
21+
uses: actions/checkout@v3
22+
23+
- name: Install deps
24+
run: |
25+
npm ci
26+
27+
- name: Run unit tests
28+
run: npm test

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"deploy": "forge script script/DeployAll.s.sol --rpc-url anvil --broadcast",
66
"compile": "forge build",
77
"postinstall": "forge build",
8-
"clean": "rm -rf build"
8+
"clean": "rm -rf build",
9+
"test": "forge test -vvv"
910
},
1011
"dependencies": {
1112
"@hyperledger-labs/yui-ibc-solidity": "git+https://github.com/hyperledger-labs/yui-ibc-solidity.git#v0.3.40",

test/IBCKeeper.t.sol

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.20;
3+
4+
import "forge-std/src/Test.sol";
5+
import "../src/core/IBCKeeper.sol";
6+
7+
contract DummyHandler {}
8+
9+
contract TestableIBCKeeper is IBCKeeper {
10+
constructor(IIBCHandler h) IBCKeeper(h) {}
11+
12+
function handlerAddr() external view returns (address) {
13+
return address(getIBCHandler());
14+
}
15+
}
16+
17+
contract IBCKeeperTest is Test {
18+
DummyHandler dummy;
19+
TestableIBCKeeper keeper;
20+
21+
function setUp() public {
22+
dummy = new DummyHandler();
23+
keeper = new TestableIBCKeeper(IIBCHandler(address(dummy)));
24+
}
25+
26+
function test_GetIBCHandler_GetIBCHandlerReturnsSameAddress() public view {
27+
address h = keeper.handlerAddr();
28+
assertEq(h, address(dummy));
29+
}
30+
31+
function test_Constructor_AllowsZeroAddress() public {
32+
TestableIBCKeeper k = new TestableIBCKeeper(IIBCHandler(address(0)));
33+
assertEq(k.handlerAddr(), address(0));
34+
}
35+
}

0 commit comments

Comments
 (0)