Skip to content

Commit

Permalink
Merge pull request #121 from liquity/stale-check
Browse files Browse the repository at this point in the history
refactor: remove stale and redundant check
  • Loading branch information
danielattilasimon authored Dec 27, 2024
2 parents b5ade69 + 7cf3b1f commit ffbf480
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/Governance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,10 @@ contract Governance is MultiDelegateCall, UserProxyFactory, ReentrancyGuard, Own
int256[] calldata _absoluteLQTYVotes,
int256[] calldata _absoluteLQTYVetos
) external nonReentrant {
require(_initiatives.length == _absoluteLQTYVotes.length, "Length");
require(_absoluteLQTYVetos.length == _absoluteLQTYVotes.length, "Length");
require(
_initiatives.length == _absoluteLQTYVotes.length && _absoluteLQTYVotes.length == _absoluteLQTYVetos.length,
"Governance: array-length-mismatch"
);

// To ensure the change is safe, enforce uniqueness
_requireNoDuplicates(_initiativesToReset);
Expand Down Expand Up @@ -669,20 +671,16 @@ contract Governance is MultiDelegateCall, UserProxyFactory, ReentrancyGuard, Own
}

/// @dev For each given initiative applies relative changes to the allocation
/// NOTE: Given the current usage the function either: Resets the value to 0, or sets the value to a new value
/// Review the flows as the function could be used in many ways, but it ends up being used in just those 2 ways
/// @dev Assumes that all the input arrays are of equal length
/// @dev NOTE: Given the current usage the function either: Resets the value to 0, or sets the value to a new value
/// Review the flows as the function could be used in many ways, but it ends up being used in just those 2 ways
function _allocateLQTY(
address[] memory _initiatives,
int256[] memory _deltaLQTYVotes,
int256[] memory _deltaLQTYVetos,
int256[] memory _deltaOffsetVotes,
int256[] memory _deltaOffsetVetos
) internal {
require(
_initiatives.length == _deltaLQTYVotes.length && _initiatives.length == _deltaLQTYVetos.length,
"Governance: array-length-mismatch"
);

AllocateLQTYMemory memory vars;
(vars.votesSnapshot_, vars.state) = _snapshotVotes();
vars.currentEpoch = epoch();
Expand Down
18 changes: 18 additions & 0 deletions test/Governance.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,24 @@ abstract contract GovernanceTest is Test {
/// Ensure that at the end you remove 100%
function test_fuzz_canRemoveExtact() public {}

function test_allocateLQTY_revertsWhenInputArraysAreOfDifferentLengths() external {
address[] memory initiativesToReset = new address[](0);
address[][2] memory initiatives = [new address[](2), new address[](3)];
int256[][2] memory votes = [new int256[](2), new int256[](3)];
int256[][2] memory vetos = [new int256[](2), new int256[](3)];

for (uint256 i = 0; i < 2; ++i) {
for (uint256 j = 0; j < 2; ++j) {
for (uint256 k = 0; k < 2; ++k) {
if (i == j && j == k) continue;

vm.expectRevert("Governance: array-length-mismatch");
governance.allocateLQTY(initiativesToReset, initiatives[i], votes[j], vetos[k]);
}
}
}
}

function test_allocateLQTY_single() public {
vm.startPrank(user);

Expand Down

0 comments on commit ffbf480

Please sign in to comment.