Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .c8rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"reporter": ["lcov", "text"]
}
96 changes: 55 additions & 41 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,13 @@ jobs:
run: npm ci

- name: Run Unit Tests
run: npm run test
run: npm run coverage

- name: Upload coverage report
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: lcov-${{ github.job }}
path: coverage/lcov.info

sol-tests-local-storage:
name: 'Forge tests w/storage emulation'
Expand Down Expand Up @@ -158,7 +164,13 @@ jobs:
run: forge build

- name: Run Forge tests using local storage emulation (without forking)
run: forge test -vvv
run: forge coverage --report summary --report lcov -vvv

- name: Upload coverage report
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: lcov-${{ github.job }}
path: lcov.info

sol-tests-ffi-mock:
name: 'Forge tests w/FFI curl process mock'
Expand Down Expand Up @@ -191,11 +203,17 @@ jobs:
run: echo "./test/scripts" >> "$GITHUB_PATH"

- name: Run Forge tests using JSON-RPC Mainnet and Testnet servers (with forking)
run: forge test -vvv --fork-url https://testnet.hashio.io/api --fork-block-number 13890397
run: forge coverage --report summary --report lcov -vvv --fork-url https://testnet.hashio.io/api --fork-block-number 13890397

- name: Show Mocked curl Requests
run: cat test/scripts/curl.log

- name: Upload coverage report
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: lcov-${{ github.job }}
path: lcov.info

sol-tests-json-rpc-mock:
name: 'Forge tests w/RPC mock server'
runs-on: smart-contracts-linux-medium
Expand Down Expand Up @@ -230,7 +248,40 @@ jobs:
run: node test/scripts/json-rpc-mock.js &

- name: Run Forge tests using JSON-RPC mock server for storage emulation (with forking)
run: forge test -vvv --fork-url http://localhost:7546 --no-storage-caching
run: forge coverage --report summary --report lcov -vvv --fork-url http://localhost:7546 --no-storage-caching

- name: Upload coverage report
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: lcov-${{ github.job }}
path: lcov.info

coverage-report:
name: Coverage Report
runs-on: smart-contracts-linux-medium
needs: [npm-test, sol-tests-local-storage, sol-tests-ffi-mock, sol-tests-json-rpc-mock]
steps:
- name: Harden Runner
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
with:
egress-policy: audit

- name: Checkout Code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
submodules: recursive

- name: Download coverage reports
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
with:
pattern: lcov-*

- name: Send the coverage results to Codecov and comment coverage changes
uses: codecov/codecov-action@5c47607acb93fed5485fdbf7232e8a31425f672a # v5.0.2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./lcov-npm-test/lcov.info,./lcov-sol-tests-local-storage/lcov.info,./lcov-sol-tests-ffi-mock/lcov.info,./lcov-sol-tests-json-rpc-mock/lcov.info
slug: hashgraph/hedera-forking

foundry-example-tests:
name: 'Foundry example tests w/mainnet'
Expand Down Expand Up @@ -298,43 +349,6 @@ jobs:
run: npm run test
working-directory: examples/hardhat-hts

sol-tests-coverage:
name: 'Solidity Coverage test'
runs-on: smart-contracts-linux-medium
steps:
- name: Harden Runner
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
with:
egress-policy: audit

- name: Checkout Code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
submodules: recursive

- name: Set up Node.js
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
with:
node-version: '20'

- name: Install Foundry
uses: step-security/foundry-toolchain@01e2d127ea061e2ce8fa34340de71ca8518f093e # v1.2.1
with:
version: stable

- name: Run Forge build
run: forge build

- name: Generate Coverage Report
run: forge coverage --report lcov -vvv

- name: Send the coverage results to Codecov and comment coverage changes
uses: codecov/codecov-action@5c47607acb93fed5485fdbf7232e8a31425f672a # v5.0.2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./lcov.info
slug: hashgraph/hedera-forking

e2e-test:
name: 'NPM e2e validation tests'
runs-on: smart-contracts-linux-medium
Expand Down
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
/cache/
/out/

.idea/

# Ignore `.env` that contains account details for the `create-token` script
/scripts/.env

Expand All @@ -15,3 +13,8 @@

# Contains Mirror Node request logs created when mocking `curl`
/test/scripts/curl.log

# Generated by `coverage` script using `c8`
# `reports-dir`: directory where coverage reports will be output to
# https://github.com/bcoe/c8?tab=readme-ov-file#cli-options--configuration
/coverage/
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,38 @@ Once Local Node is up and running, run the validation tests with
npm run test:e2e
```

## Coverage

Run NPM tests with coverage using

```console
npm run coverage
```

Similarly, Solidity test coverage can be obtained using the [`forge coverage`](https://book.getfoundry.sh/reference/forge/forge-coverage) command, for example

```console
forge coverage
```

The [§ _Tests_](#tests) describes different test execution settings depending on the contracts to be tested.

> [!IMPORTANT]
> To obtain accurate coverage reports remember to clean up any cache related data.
>
> Both Foundry and Hardhat cache successful JSON-RPC calls when running tests.
> This means that when RPC calls are cached, there are fewer calls made to the forking library.
> This in turn make coverage reports provide inaccurate results.
>
> Foundry's JSON-RPC cache can be displayed and cleaned up using the [`forge cache`](https://book.getfoundry.sh/reference/forge/forge-cache) command.
> Its cache it is usually located in `~/.foundry/cache/`.
>
> On the other hand, Hardhat cache is located under each plugin tests, _i.e_, `test/plugin/*/cache`.

Test coverage reports based on [_§ Tests_](#tests) are uploaded to [Codecov](https://codecov.io/gh/hashgraph/hedera-forking)

[![codecov Sunburst](https://codecov.io/gh/hashgraph/hedera-forking/graphs/sunburst.svg?token=NNW96R6VIE)](https://codecov.io/gh/hashgraph/hedera-forking)

## Support

If you have a question on how to use the product, please see our
Expand Down
Loading