Skip to content

Commit 2c68008

Browse files
committed
regression test
1 parent 1716838 commit 2c68008

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/test/unit/EmissionsControllerUnit.t.sol

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,57 @@ contract EmissionsControllerUnitTests_updateDistribution is EmissionsControllerU
467467
})
468468
);
469469
}
470+
471+
// Regression test for bug where _checkDistribution was called after updating totalWeight,
472+
// causing valid weight updates to incorrectly revert due to double-counting the new weight
473+
function test_updateDistribution_DoesNotDoubleCountNewWeight() public {
474+
// Add first distribution with weight 6000
475+
cheats.prank(incentiveCouncil);
476+
uint distributionId1 = emissionsController.addDistribution(
477+
Distribution({
478+
weight: 6000,
479+
startEpoch: 0,
480+
stopEpoch: 0,
481+
distributionType: DistributionType.RewardsForAllEarners,
482+
operatorSet: emptyOperatorSet(),
483+
strategiesAndMultipliers: defaultStrategiesAndMultipliers()
484+
})
485+
);
486+
487+
// Add second distribution with weight 1000 (total = 7000)
488+
cheats.prank(incentiveCouncil);
489+
uint distributionId2 = emissionsController.addDistribution(
490+
Distribution({
491+
weight: 1000,
492+
startEpoch: 0,
493+
stopEpoch: 0,
494+
distributionType: DistributionType.RewardsForAllEarners,
495+
operatorSet: emptyOperatorSet(),
496+
strategiesAndMultipliers: defaultStrategiesAndMultipliers()
497+
})
498+
);
499+
500+
// Update second distribution to weight 4000 (total should be 10000, which is valid)
501+
// Without the fix, this would incorrectly check: 4000 + (7000 - 1000 + 4000) = 14000 > 10000
502+
// With the fix, this correctly checks: 4000 + (7000 - 1000) = 10000 <= 10000
503+
cheats.prank(incentiveCouncil);
504+
emissionsController.updateDistribution(
505+
distributionId2,
506+
Distribution({
507+
weight: 4000,
508+
startEpoch: 0,
509+
stopEpoch: 0,
510+
distributionType: DistributionType.RewardsForAllEarners,
511+
operatorSet: emptyOperatorSet(),
512+
strategiesAndMultipliers: defaultStrategiesAndMultipliers()
513+
})
514+
);
515+
516+
// Verify the update succeeded
517+
Distribution memory updated = emissionsController.getDistribution(distributionId2);
518+
assertEq(updated.weight, 4000);
519+
assertEq(emissionsController.totalWeight(), 10_000);
520+
}
470521
}
471522

472523
contract EmissionsControllerUnitTests_disableDistribution is EmissionsControllerUnitTests {

0 commit comments

Comments
 (0)