Skip to content
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

Fix balanceHeld #74

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/ImpactEvaluator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ contract ImpactEvaluator is AccessControl, Balances {
if (block.number >= currentRoundEndBlockNumber) {
advanceRound();
}
transferScheduled();
balanceHeld -= transferScheduled();
}

function addMeasurements(
Expand Down Expand Up @@ -151,7 +151,6 @@ contract ImpactEvaluator is AccessControl, Balances {

function releaseRewards() public onlyAdmin {
_releaseRewards();
balanceHeld -= transferScheduled();
}

function availableBalance() public view returns (uint) {
Expand Down
19 changes: 16 additions & 3 deletions test/ImpactEvaluator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ contract ImpactEvaluatorTest is Test {
impactEvaluator.setScores(1, addresses, scores);
assertEq(vm.addr(1).balance, 0);
impactEvaluator.releaseRewards();
assertEq(vm.addr(1).balance, 0);
impactEvaluator.tick();
assertEq(vm.addr(1).balance, 100 ether);

impactEvaluator.revokeRole(
Expand Down Expand Up @@ -390,6 +392,7 @@ contract ImpactEvaluatorTest is Test {
impactEvaluator.releaseRewards();
vm.expectRevert("Scheduled transfers still pending");
impactEvaluator.releaseRewards();
impactEvaluator.tick();

assertEq(impactEvaluator.participantCountReadyForTransfer(), 0);
for (uint i = 0; i < 10; i++) {
Expand Down Expand Up @@ -456,15 +459,18 @@ contract ImpactEvaluatorTest is Test {

function test_BalanceHeld() public {
ImpactEvaluator impactEvaluator = new ImpactEvaluator(address(this));
impactEvaluator.setMaxTransfersPerTx(1);
vm.deal(payable(address(impactEvaluator)), 100 ether);
assertEq(impactEvaluator.balanceHeld(), 0);

impactEvaluator.adminAdvanceRound();
impactEvaluator.adminAdvanceRound();
address payable[] memory addresses = new address payable[](1);
address payable[] memory addresses = new address payable[](2);
addresses[0] = payable(vm.addr(1));
uint[] memory scores = new uint[](1);
scores[0] = impactEvaluator.MAX_SCORE();
addresses[1] = payable(vm.addr(2));
uint[] memory scores = new uint[](2);
scores[0] = impactEvaluator.MAX_SCORE() / 2;
scores[1] = impactEvaluator.MAX_SCORE() / 2;
impactEvaluator.setScores(1, addresses, scores);
assertEq(
impactEvaluator.balanceHeld(),
Expand All @@ -480,6 +486,10 @@ contract ImpactEvaluatorTest is Test {
);

impactEvaluator.releaseRewards();
assertEq(impactEvaluator.balanceHeld(), 100 ether);
impactEvaluator.tick();
assertEq(impactEvaluator.balanceHeld(), 50 ether);
impactEvaluator.tick();
assertEq(impactEvaluator.balanceHeld(), 0);
}

Expand Down Expand Up @@ -532,6 +542,7 @@ contract ImpactEvaluatorTest is Test {
impactEvaluator.adminAdvanceRound();
impactEvaluator.setScores(2, addresses, scores);
impactEvaluator.releaseRewards();
impactEvaluator.tick();
assertEq(vm.addr(1).balance, 0.8 ether);

assertEq(impactEvaluator.minBalanceForTransfer(), 0.5 ether);
Expand All @@ -551,12 +562,14 @@ contract ImpactEvaluatorTest is Test {
scores[0] = impactEvaluator.MAX_SCORE() / 2;
impactEvaluator.setScores(1, addresses, scores);
impactEvaluator.releaseRewards();
impactEvaluator.tick();
assertEq(vm.addr(1).balance, 50 ether, "round 1");

impactEvaluator.adminAdvanceRound();

impactEvaluator.setScores(2, addresses, scores);
impactEvaluator.releaseRewards();
impactEvaluator.tick();
assertEq(vm.addr(1).balance, 100 ether, "round 2");
}

Expand Down
Loading