Skip to content

Commit

Permalink
Multiple updates (#26)
Browse files Browse the repository at this point in the history
* advance round before adding measurement

* allow any unevaluated round to be evaluated

* always call reward after setScores

* clean up
  • Loading branch information
juliangruber authored Sep 16, 2023
1 parent 2ead7c6 commit cd61ec2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 20 deletions.
7 changes: 2 additions & 5 deletions src/ImpactEvaluator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ contract ImpactEvaluator is AccessControl {
}

function addMeasurements(string memory cid) public returns (uint) {
maybeAdvanceRound();
uint roundIndex = currentRoundIndex();
rounds[roundIndex].measurementsCids.push(cid);
emit MeasurementsAdded(cid, roundIndex);
maybeAdvanceRound();
return roundIndex;
}

Expand All @@ -75,7 +75,6 @@ contract ImpactEvaluator is AccessControl {
string memory summaryText
) public {
require(hasRole(EVALUATE_ROLE, msg.sender), "Not an evaluator");
require(roundIndex <= rounds.length - 2, "Wrong round");
require(
addresses.length == scores.length,
"Addresses and scores length mismatch"
Expand All @@ -87,9 +86,7 @@ contract ImpactEvaluator is AccessControl {
}
round.summaryText = summaryText;
round.scoresSubmitted = true;
if (scores.length > 0) {
reward(addresses, scores);
}
reward(addresses, scores);
}

function reward(
Expand Down
16 changes: 1 addition & 15 deletions test/ImpactEvaluator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,10 @@ contract ImpactEvaluatorTest is Test {
function test_SetScores() public {
ImpactEvaluator impactEvaluator = new ImpactEvaluator(address(this));
impactEvaluator.adminAdvanceRound();
impactEvaluator.grantRole(
impactEvaluator.EVALUATE_ROLE(),
address(this)
);
impactEvaluator.revokeRole(
impactEvaluator.DEFAULT_ADMIN_ROLE(),
address(this)
);
vm.expectRevert("Wrong round");
impactEvaluator.setScores(
1,
new address payable[](0),
new uint64[](0),
"no measurements"
);
vm.expectRevert("Addresses and scores length mismatch");
impactEvaluator.setScores(
0,
Expand Down Expand Up @@ -110,17 +99,14 @@ contract ImpactEvaluatorTest is Test {
function test_SetScoresEmptyRound() public {
ImpactEvaluator impactEvaluator = new ImpactEvaluator(address(this));
impactEvaluator.adminAdvanceRound();
impactEvaluator.grantRole(
impactEvaluator.EVALUATE_ROLE(),
address(this)
);
impactEvaluator.revokeRole(
impactEvaluator.DEFAULT_ADMIN_ROLE(),
address(this)
);

address payable[] memory addresses = new address payable[](0);
uint64[] memory scores = new uint64[](0);
vm.deal(payable(address(impactEvaluator)), 100);
impactEvaluator.setScores(0, addresses, scores, "0 tasks performed");
}

Expand Down

0 comments on commit cd61ec2

Please sign in to comment.