Skip to content

Commit

Permalink
Update scores from uint64 to uint (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangruber authored Nov 13, 2023
1 parent d608173 commit 52a8291
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
10 changes: 5 additions & 5 deletions src/ImpactEvaluator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract ImpactEvaluator is AccessControl, Balances {
uint public nextRoundLength = 10;
uint public roundReward = 100 ether;

uint64 public constant MAX_SCORE = 1e15;
uint public constant MAX_SCORE = 1e15;

event MeasurementsAdded(
string cid,
Expand Down Expand Up @@ -91,7 +91,7 @@ contract ImpactEvaluator is AccessControl, Balances {
function setScores(
uint roundIndex,
address payable[] calldata addresses,
uint64[] calldata scores
uint[] calldata scores
) public onlyEvaluator {
require(
addresses.length == scores.length,
Expand All @@ -108,8 +108,8 @@ contract ImpactEvaluator is AccessControl, Balances {
previousRoundTotalScores += sumOfScores;
}

function validateScores(uint64[] memory scores) public view returns (uint) {
uint64 sum = 0;
function validateScores(uint[] memory scores) public view returns (uint) {
uint sum = 0;
for (uint i = 0; i < scores.length; i++) {
sum += scores[i];
}
Expand All @@ -123,7 +123,7 @@ contract ImpactEvaluator is AccessControl, Balances {

function reward(
address payable[] memory addresses,
uint64[] memory scores
uint[] memory scores
) private {
for (uint i = 0; i < addresses.length; i++) {
address payable participant = addresses[i];
Expand Down
46 changes: 23 additions & 23 deletions test/ImpactEvaluator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ contract ImpactEvaluatorTest is Test {
function test_SetScoresNotEvaluator() public {
ImpactEvaluator impactEvaluator = new ImpactEvaluator(address(0x1));
vm.expectRevert("Not an evaluator");
impactEvaluator.setScores(0, new address payable[](0), new uint64[](0));
impactEvaluator.setScores(0, new address payable[](0), new uint[](0));
}

function test_SetScores() public {
Expand All @@ -83,11 +83,11 @@ contract ImpactEvaluatorTest is Test {
address(this)
);
vm.expectRevert("Addresses and scores length mismatch");
impactEvaluator.setScores(1, new address payable[](1), new uint64[](0));
impactEvaluator.setScores(1, new address payable[](1), new uint[](0));

address payable[] memory addresses = new address payable[](1);
addresses[0] = payable(vm.addr(1));
uint64[] memory scores = new uint64[](1);
uint[] memory scores = new uint[](1);
scores[0] = impactEvaluator.MAX_SCORE();
impactEvaluator.setScores(1, addresses, scores);
assertEq(
Expand All @@ -114,7 +114,7 @@ contract ImpactEvaluatorTest is Test {
addresses[1] = payable(vm.addr(2));
addresses[2] = payable(vm.addr(3));

uint64[] memory scores = new uint64[](3);
uint[] memory scores = new uint[](3);
scores[0] = 50e13;
scores[1] = 25e13;
scores[2] = 25e13;
Expand All @@ -137,7 +137,7 @@ contract ImpactEvaluatorTest is Test {
address payable[] memory addresses = new address payable[](2);
addresses[0] = payable(vm.addr(1));
addresses[1] = payable(vm.addr(2));
uint64[] memory scores = new uint64[](2);
uint[] memory scores = new uint[](2);
scores[0] = impactEvaluator.MAX_SCORE() - 1;
scores[1] = 1;
impactEvaluator.setScores(1, addresses, scores);
Expand All @@ -158,7 +158,7 @@ contract ImpactEvaluatorTest is Test {
impactEvaluator.adminAdvanceRound();

address payable[] memory addresses = new address payable[](0);
uint64[] memory scores = new uint64[](0);
uint[] memory scores = new uint[](0);
impactEvaluator.setScores(0, addresses, scores);
}

Expand All @@ -167,11 +167,11 @@ contract ImpactEvaluatorTest is Test {
vm.deal(payable(address(impactEvaluator)), 100 ether);
impactEvaluator.adminAdvanceRound();
impactEvaluator.adminAdvanceRound();
uint64 iterations = 10;
uint iterations = 10;
for (uint i = 0; i < iterations; i++) {
address payable[] memory addresses = new address payable[](1);
addresses[0] = payable(vm.addr(i + 1));
uint64[] memory scores = new uint64[](1);
uint[] memory scores = new uint[](1);
scores[0] = impactEvaluator.MAX_SCORE() / iterations;
impactEvaluator.setScores(1, addresses, scores);
}
Expand All @@ -190,7 +190,7 @@ contract ImpactEvaluatorTest is Test {

address payable[] memory addresses = new address payable[](1);
addresses[0] = payable(vm.addr(1));
uint64[] memory scores = new uint64[](1);
uint[] memory scores = new uint[](1);
scores[0] = impactEvaluator.MAX_SCORE() + 1;
vm.expectRevert("Sum of scores too big");
impactEvaluator.setScores(0, addresses, scores);
Expand All @@ -202,7 +202,7 @@ contract ImpactEvaluatorTest is Test {

address payable[] memory addresses = new address payable[](1);
addresses[0] = payable(vm.addr(1));
uint64[] memory scores = new uint64[](1);
uint[] memory scores = new uint[](1);
scores[0] = impactEvaluator.MAX_SCORE() - 1;
impactEvaluator.setScores(0, addresses, scores);

Expand All @@ -216,7 +216,7 @@ contract ImpactEvaluatorTest is Test {
impactEvaluator.adminAdvanceRound();

address payable[] memory addresses = new address payable[](2);
uint64[] memory scores = new uint64[](2);
uint[] memory scores = new uint[](2);
addresses[0] = payable(vm.addr(1));
addresses[1] = payable(vm.addr(1));
scores[0] = 2 ** 64 - 1;
Expand All @@ -228,7 +228,7 @@ contract ImpactEvaluatorTest is Test {
function test_SetScoresUnfinishedRound() public {
ImpactEvaluator impactEvaluator = new ImpactEvaluator(address(this));
address payable[] memory addresses = new address payable[](0);
uint64[] memory scores = new uint64[](0);
uint[] memory scores = new uint[](0);
vm.expectRevert("Can only score previous round");
impactEvaluator.setScores(0, addresses, scores);
}
Expand All @@ -239,7 +239,7 @@ contract ImpactEvaluatorTest is Test {
impactEvaluator.adminAdvanceRound();

address payable[] memory addresses = new address payable[](1);
uint64[] memory scores = new uint64[](1);
uint[] memory scores = new uint[](1);
addresses[0] = payable(vm.addr(1));
scores[0] = impactEvaluator.MAX_SCORE();
impactEvaluator.setScores(0, addresses, scores);
Expand All @@ -261,7 +261,7 @@ contract ImpactEvaluatorTest is Test {

address payable[] memory addresses = new address payable[](1);
addresses[0] = payable(address(this));
uint64[] memory scores = new uint64[](1);
uint[] memory scores = new uint[](1);
scores[0] = impactEvaluator.MAX_SCORE();
impactEvaluator.setScores(1, addresses, scores);

Expand All @@ -280,7 +280,7 @@ contract ImpactEvaluatorTest is Test {

address payable[] memory addresses = new address payable[](1);
addresses[0] = payable(vm.addr(1));
uint64[] memory scores = new uint64[](1);
uint[] memory scores = new uint[](1);
scores[0] = impactEvaluator.MAX_SCORE();

impactEvaluator.setScores(1, addresses, scores);
Expand Down Expand Up @@ -318,7 +318,7 @@ contract ImpactEvaluatorTest is Test {

address payable[] memory addresses = new address payable[](1);
addresses[0] = payable(0x000000000000000000000000000000000000dEaD);
uint64[] memory scores = new uint64[](1);
uint[] memory scores = new uint[](1);
scores[0] = impactEvaluator.MAX_SCORE();

impactEvaluator.setScores(1, addresses, scores);
Expand Down Expand Up @@ -349,7 +349,7 @@ contract ImpactEvaluatorTest is Test {

address payable[] memory addresses = new address payable[](1);
addresses[0] = payable(vm.addr(1));
uint64[] memory scores = new uint64[](1);
uint[] memory scores = new uint[](1);
scores[0] = impactEvaluator.MAX_SCORE();
impactEvaluator.setScores(1, addresses, scores);
assertEq(vm.addr(1).balance, 0);
Expand All @@ -372,11 +372,11 @@ contract ImpactEvaluatorTest is Test {
impactEvaluator.adminAdvanceRound();
impactEvaluator.adminAdvanceRound();

uint64 participants = 10;
uint participants = 10;
address payable[] memory addresses = new address payable[](
participants
);
uint64[] memory scores = new uint64[](participants);
uint[] memory scores = new uint[](participants);
for (uint i = 0; i < participants; i++) {
addresses[i] = payable(vm.addr(i + 1));
scores[i] = impactEvaluator.MAX_SCORE() / participants;
Expand Down Expand Up @@ -467,7 +467,7 @@ contract ImpactEvaluatorTest is Test {
impactEvaluator.adminAdvanceRound();
address payable[] memory addresses = new address payable[](1);
addresses[0] = payable(vm.addr(1));
uint64[] memory scores = new uint64[](1);
uint[] memory scores = new uint[](1);
scores[0] = impactEvaluator.MAX_SCORE();
impactEvaluator.setScores(1, addresses, scores);
assertEq(impactEvaluator.availableBalance(), 100 ether);
Expand All @@ -491,7 +491,7 @@ contract ImpactEvaluatorTest is Test {

address payable[] memory addresses = new address payable[](1);
addresses[0] = payable(vm.addr(1));
uint64[] memory scores = new uint64[](1);
uint[] memory scores = new uint[](1);
scores[0] = impactEvaluator.MAX_SCORE();
impactEvaluator.setScores(1, addresses, scores);

Expand All @@ -513,7 +513,7 @@ contract ImpactEvaluatorTest is Test {

address payable[] memory addresses = new address payable[](1);
addresses[0] = payable(vm.addr(1));
uint64[] memory scores = new uint64[](1);
uint[] memory scores = new uint[](1);
scores[0] = 1;

for (uint i = 0; i < 1000; i++) {
Expand All @@ -528,7 +528,7 @@ contract ImpactEvaluatorTest is Test {

uint participants = 1000;
address payable[] memory addresses = new address payable[](participants);
uint64[] memory scores = new uint64[](participants);
uint[] memory scores = new uint[](participants);
for (uint i = 0; i < participants; i++) {
addresses[i] = payable(vm.addr(i + 1));
scores[i] = 1;
Expand Down

0 comments on commit 52a8291

Please sign in to comment.