diff --git a/packages/protocol/contracts-0.8/common/ScoreManager.sol b/packages/protocol/contracts-0.8/common/ScoreManager.sol index 1f4e695a21b..58b07e6292f 100644 --- a/packages/protocol/contracts-0.8/common/ScoreManager.sol +++ b/packages/protocol/contracts-0.8/common/ScoreManager.sol @@ -68,10 +68,7 @@ contract ScoreManager is * @dev Set value to `ZERO_SCORE` to set score to zero. */ function setGroupScore(address group, uint256 score) external onlyAuthorizedToUpdateScore { - require(score > 0, "Score must be greater than ZERO."); - require(score <= ZERO_SCORE, "Score must be less than or equal to 1e24 or ZERO_SCORE."); - groupScores[group] = score; - + groupScores[group] = checkScore(score); emit GroupScoreSet(group, score); } @@ -85,10 +82,7 @@ contract ScoreManager is address validator, uint256 score ) external onlyAuthorizedToUpdateScore { - require(score > 0, "Score must be greater than ZERO."); - require(score <= ZERO_SCORE, "Score must be less than or equal to 1e24 or ZERO_SCORE."); - validatorScores[validator] = score; - + validatorScores[validator] = checkScore(score); emit ValidatorScoreSet(validator, score); } @@ -150,4 +144,13 @@ contract ScoreManager is } return score; } + + function checkScore(uint256 score) internal pure returns (uint256) { + if (score == 0) { + return ZERO_SCORE; + } + + require(score <= FIXED1_UINT, "Score must be less than or equal to 1e24."); + return score; + } } diff --git a/packages/protocol/test-sol/unit/common/ScoreManager.t.sol b/packages/protocol/test-sol/unit/common/ScoreManager.t.sol index 4bac827aa63..eccba616e3b 100644 --- a/packages/protocol/test-sol/unit/common/ScoreManager.t.sol +++ b/packages/protocol/test-sol/unit/common/ScoreManager.t.sol @@ -61,8 +61,8 @@ contract ScoreManagerTest_setGroupScore is ScoreManagerTest { } function test_Reverts_WhenSetToMoreThan1e24Plus1() public { - vm.expectRevert("Score must be less than or equal to 1e24 or ZERO_SCORE."); - scoreManager.setGroupScore(owner, 1e24 + 2); + vm.expectRevert("Score must be less than or equal to 1e24."); + scoreManager.setGroupScore(owner, 1e24 + 1); } function test_Returns1FixidityWhenGroupScoreDoesNotExist() public { @@ -70,13 +70,8 @@ contract ScoreManagerTest_setGroupScore is ScoreManagerTest { } function test_Returns0WhenGroupScoreIsZERO_SCORE() public { - scoreManager.setGroupScore(owner, ZERO_SCORE); - assert(scoreManager.getGroupScore(owner) == 0); - } - - function test_Reverts_WhenSettingScoreToZero() public { - vm.expectRevert("Score must be greater than ZERO."); scoreManager.setGroupScore(owner, 0); + assert(scoreManager.getGroupScore(owner) == 0); } function test_EmitsGroupScoreSet() public { @@ -107,20 +102,15 @@ contract ScoreManagerTest_setValidatorScore is ScoreManagerTest { } function test_Reverts_WhenSetToMoreThan1e24() public { - vm.expectRevert("Score must be less than or equal to 1e24 or ZERO_SCORE."); - scoreManager.setValidatorScore(owner, 1e24 + 2); + vm.expectRevert("Score must be less than or equal to 1e24."); + scoreManager.setValidatorScore(owner, 1e24 + 1); } function test_Returns0WhenValidatorScoreIsZero() public { - scoreManager.setValidatorScore(owner, ZERO_SCORE); + scoreManager.setValidatorScore(owner, 0); assert(scoreManager.getValidatorScore(owner) == 0); } - function test_Reverts_WhenSettingScoreToZero() public { - vm.expectRevert("Score must be greater than ZERO."); - scoreManager.setGroupScore(owner, 0); - } - function test_EmitsValidatorScoreSet() public { vm.expectEmit(false, false, false, true); emit ValidatorScoreSet(owner, 42);