-
Notifications
You must be signed in to change notification settings - Fork 49
feat(KC): add foundry test file #1765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6b24daa
feat(KC): add foundry test file
unknownunknown1 7d8e858
fix(SortitionModule): delayed stake frontrun bug
unknownunknown1 236f9e1
Merge branch 'dev' into feat/foundry-tests
jaybuidl 917b82e
docs: license pragma
jaybuidl 6437726
fix: typos
jaybuidl 889cf63
chore: github actions workflow to run the foundry tests
jaybuidl b9810b2
test: combined test coverage reports from Hardhat and Foundry
jaybuidl 9025a05
test: fix
jaybuidl 2b62297
chore: temporarily disabling foundry tests in Github CI due to a stra…
jaybuidl b4fcc4e
test: attempt to fix randomly failing tx due to duplicate nounce
jaybuidl f281135
test: coverage script
jaybuidl 229ed9c
Merge branch 'dev' into feat/foundry-tests
jaybuidl 8e916d0
Merge branch 'dev' into feat/foundry-tests
jaybuidl fed3d93
chore: testing workflow debugging
jaybuidl 0220cc2
chore: testing workflow debugging
jaybuidl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||
jaybuidl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# 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 hidden or 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 |
---|---|---|
|
@@ -113,7 +113,7 @@ abstract contract KlerosCoreBase is IArbitratorV2 { | |
event AppealDecision(uint256 indexed _disputeID, IArbitrableV2 indexed _arbitrable); | ||
event Draw(address indexed _address, uint256 indexed _disputeID, uint256 _roundID, uint256 _voteID); | ||
event CourtCreated( | ||
uint256 indexed _courtID, | ||
uint96 indexed _courtID, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
uint96 indexed _parent, | ||
bool _hiddenVotes, | ||
uint256 _minStake, | ||
|
@@ -237,16 +237,18 @@ abstract contract KlerosCoreBase is IArbitratorV2 { | |
|
||
sortitionModule.createTree(bytes32(uint256(GENERAL_COURT)), _sortitionExtraData); | ||
|
||
uint256[] memory supportedDisputeKits = new uint256[](1); | ||
supportedDisputeKits[0] = DISPUTE_KIT_CLASSIC; | ||
emit CourtCreated( | ||
1, | ||
GENERAL_COURT, | ||
court.parent, | ||
_hiddenVotes, | ||
_courtParameters[0], | ||
_courtParameters[1], | ||
_courtParameters[2], | ||
_courtParameters[3], | ||
_timesPerPeriod, | ||
new uint256[](0) | ||
supportedDisputeKits | ||
); | ||
_enableDisputeKit(GENERAL_COURT, DISPUTE_KIT_CLASSIC, true); | ||
} | ||
|
@@ -351,7 +353,7 @@ abstract contract KlerosCoreBase is IArbitratorV2 { | |
if (_supportedDisputeKits[i] == 0 || _supportedDisputeKits[i] >= disputeKits.length) { | ||
revert WrongDisputeKitIndex(); | ||
} | ||
court.supportedDisputeKits[_supportedDisputeKits[i]] = true; | ||
_enableDisputeKit(uint96(courtID), _supportedDisputeKits[i], true); | ||
} | ||
// Check that Classic DK support was added. | ||
if (!court.supportedDisputeKits[DISPUTE_KIT_CLASSIC]) revert MustSupportDisputeKitClassic(); | ||
|
@@ -370,7 +372,7 @@ abstract contract KlerosCoreBase is IArbitratorV2 { | |
// Update the parent. | ||
courts[_parent].children.push(courtID); | ||
emit CourtCreated( | ||
courtID, | ||
uint96(courtID), | ||
_parent, | ||
_hiddenVotes, | ||
_minStake, | ||
|
@@ -1061,7 +1063,7 @@ abstract contract KlerosCoreBase is IArbitratorV2 { | |
bool _alreadyTransferred, | ||
OnError _onError | ||
) internal returns (bool) { | ||
if (_courtID == FORKING_COURT || _courtID > courts.length) { | ||
if (_courtID == FORKING_COURT || _courtID >= courts.length) { | ||
_stakingFailed(_onError, StakingResult.CannotStakeInThisCourt); // Staking directly into the forking court is not allowed. | ||
return false; | ||
} | ||
|
@@ -1102,6 +1104,7 @@ abstract contract KlerosCoreBase is IArbitratorV2 { | |
if (_result == StakingResult.CannotStakeInMoreCourts) revert StakingInTooManyCourts(); | ||
if (_result == StakingResult.CannotStakeInThisCourt) revert StakingNotPossibeInThisCourt(); | ||
if (_result == StakingResult.CannotStakeLessThanMinStake) revert StakingLessThanCourtMinStake(); | ||
if (_result == StakingResult.CannotStakeZeroWhenNoStake) revert StakingZeroWhenNoStake(); | ||
} | ||
|
||
/// @dev Gets a court ID, the minimum number of jurors and an ID of a dispute kit from a specified extra data bytes array. | ||
|
@@ -1147,13 +1150,11 @@ abstract contract KlerosCoreBase is IArbitratorV2 { | |
error SortitionModuleOnly(); | ||
error UnsuccessfulCall(); | ||
error InvalidDisputKitParent(); | ||
error DepthLevelMax(); | ||
error MinStakeLowerThanParentCourt(); | ||
error UnsupportedDisputeKit(); | ||
error InvalidForkingCourtAsParent(); | ||
error WrongDisputeKitIndex(); | ||
error CannotDisableClassicDK(); | ||
error ArraysLengthMismatch(); | ||
error StakingInTooManyCourts(); | ||
error StakingNotPossibeInThisCourt(); | ||
error StakingLessThanCourtMinStake(); | ||
|
@@ -1177,4 +1178,5 @@ abstract contract KlerosCoreBase is IArbitratorV2 { | |
error TransferFailed(); | ||
error WhenNotPausedOnly(); | ||
error WhenPausedOnly(); | ||
error StakingZeroWhenNoStake(); | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.