Skip to content

Commit

Permalink
fixed AvlTree test coverage (#105)
Browse files Browse the repository at this point in the history
* fixed AvlTree test coverage

* fixed array out-of-bounds issue
  • Loading branch information
mllwchrry authored Jun 12, 2024
1 parent 676a5c7 commit 28a5ea1
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions contracts/mock/libs/data-structures/AvlTreeMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -178,27 +178,49 @@ contract AvlTreeMock {
}

function traverseAddress() external view returns (uint256[] memory, address[] memory) {
(uint256[] memory keys_, bytes32[] memory values_) = _traverseAll(
_addressTree.first(),
_addressTree.size(),
true
);
Traversal.Iterator memory iterator_ = _addressTree.first();

bytes32[] memory keys_ = new bytes32[](_addressTree.size());
bytes32[] memory values_ = new bytes32[](keys_.length);

if (keys_.length != 0) {
(keys_[0], values_[0]) = iterator_.value();
}

uint256 index_ = 1;

while (iterator_.hasNext()) {
(keys_[index_], values_[index_]) = iterator_.next();

index_++;
}

return (keys_, values_.asAddressArray());
return (keys_.asUint256Array(), values_.asAddressArray());
}

function backwardsTraversalAddress()
external
view
returns (uint256[] memory, address[] memory)
{
(uint256[] memory keys_, bytes32[] memory values_) = _traverseAll(
_addressTree.last(),
_addressTree.size(),
false
);
Traversal.Iterator memory iterator_ = _addressTree.last();

bytes32[] memory keys_ = new bytes32[](_addressTree.size());
bytes32[] memory values_ = new bytes32[](keys_.length);

if (keys_.length != 0) {
(keys_[0], values_[0]) = iterator_.value();
}

uint256 index_ = 1;

while (iterator_.hasPrev()) {
(keys_[index_], values_[index_]) = iterator_.prev();

index_++;
}

return (keys_, values_.asAddressArray());
return (keys_.asUint256Array(), values_.asAddressArray());
}

function nextOnLast() external view returns (uint256, uint256) {
Expand Down

0 comments on commit 28a5ea1

Please sign in to comment.