-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1765 from kleros/feat/foundry-tests
feat(KC): add foundry test file
- Loading branch information
Showing
18 changed files
with
2,878 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule forge-std
updated
43 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e # exit on error | ||
|
||
rm -rf coverage | ||
mkdir -p coverage | ||
|
||
# Generate the Forge coverage report | ||
forge clean | ||
if [ "$CI" != "true" ]; then | ||
forge coverage --report summary --report lcov --report-file coverage/lcov-forge.info | ||
else | ||
# FIXME: Temporarily workaround a CI issue | ||
touch coverage/lcov-forge.info | ||
fi | ||
|
||
# Generate the Hardhat coverage report | ||
yarn clean | ||
yarn hardhat coverage --solcoverjs ./.solcover.js --temp artifacts --show-stack-traces --testfiles "test/**/*.ts" | ||
mv coverage/lcov.info coverage/lcov-hardhat.info | ||
|
||
# Make the Hardhat report paths relative for consistency with Forge coverage report | ||
sed -i -e 's/\/.*\/kleros-v2\/contracts\///g' coverage/lcov-hardhat.info | ||
|
||
# Merge the two reports | ||
lcov \ | ||
--ignore-errors format \ | ||
--ignore-errors inconsistent \ | ||
--ignore-errors empty \ | ||
--rc max_message_count=3 \ | ||
--rc derive_function_end_line=0 \ | ||
--rc branch_coverage=1 \ | ||
--add-tracefile coverage/lcov-hardhat.info \ | ||
--add-tracefile coverage/lcov-forge.info \ | ||
--output-file coverage/merged-lcov.info | ||
|
||
# Filter out unnecessary contracts from the report | ||
lcov \ | ||
--ignore-errors format \ | ||
--ignore-errors inconsistent \ | ||
--ignore-errors empty \ | ||
--ignore-errors unused \ | ||
--rc max_message_count=3 \ | ||
--rc branch_coverage=1 \ | ||
--rc derive_function_end_line=0 \ | ||
--remove coverage/merged-lcov.info \ | ||
--output-file coverage/filtered-lcov.info \ | ||
"../node_modules" "src/test" "src/token" "src/kleros-v1" "src/proxy/mock" "src/gateway/mock" "src/rng/mock" | ||
|
||
# Open more granular breakdown in browser | ||
if [ "$CI" != "true" ]; then | ||
# Generate the HTML report | ||
genhtml coverage/filtered-lcov.info \ | ||
--ignore-errors format \ | ||
--ignore-errors inconsistent \ | ||
--ignore-errors empty \ | ||
--ignore-errors category \ | ||
--rc branch_coverage=1 \ | ||
--rc max_message_count=3 \ | ||
-o coverage | ||
open coverage/index.html | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
/// @custom:authors: [@unknownunknown1] | ||
/// @custom:reviewers: [] | ||
/// @custom:auditors: [] | ||
/// @custom:bounties: [] | ||
/// @custom:deployments: [] | ||
|
||
pragma solidity 0.8.24; | ||
|
||
import "../arbitration/KlerosCore.sol"; | ||
|
||
/// @title KlerosCoreMock | ||
/// KlerosCore with view functions to use in Foundry tests. | ||
contract KlerosCoreMock is KlerosCore { | ||
function getCourtChildren(uint256 _courtId) external view returns (uint256[] memory children) { | ||
children = courts[_courtId].children; | ||
} | ||
|
||
function extraDataToCourtIDMinJurorsDisputeKit( | ||
bytes memory _extraData | ||
) external view returns (uint96 courtID, uint256 minJurors, uint256 disputeKitID) { | ||
(courtID, minJurors, disputeKitID) = _extraDataToCourtIDMinJurorsDisputeKit(_extraData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
/** | ||
* @custom:authors: [unknownunknown1] | ||
* @custom:reviewers: [] | ||
* @custom:auditors: [] | ||
* @custom:bounties: [] | ||
* @custom:deployments: [] | ||
*/ | ||
|
||
pragma solidity 0.8.24; | ||
|
||
import "../arbitration/SortitionModule.sol"; | ||
|
||
/// @title SortitionModuleMock | ||
/// @dev Adds getter functions to sortition module for Foundry tests. | ||
contract SortitionModuleMock is SortitionModule { | ||
function getSortitionProperties(bytes32 _key) external view returns (uint256 K, uint256 nodeLength) { | ||
SortitionSumTree storage tree = sortitionSumTrees[_key]; | ||
K = tree.K; | ||
nodeLength = tree.nodes.length; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.