Skip to content

Commit

Permalink
Merge pull request #18 from ionicprotocol/test/vote-gauges-reset
Browse files Browse the repository at this point in the history
Test voting on gauges reset on burn
  • Loading branch information
vminkov authored Aug 30, 2023
2 parents 35e6bfe + 15ee10e commit 77748ce
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
4 changes: 2 additions & 2 deletions contracts/Voter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ contract Voter is IVoter, OwnableUpgradeable, ReentrancyGuardUpgradeable {

function _vote(uint _tokenId, address[] memory _targetVote, uint256[] memory _weights) internal {
_reset(_tokenId);
uint _targetCnt = _targetVote.length;
uint256 _targetCnt = _targetVote.length;
uint256 _weight = IVoteEscrow(_ve).balanceOfNFT(_tokenId);
uint256 _totalVoteWeight = 0;
uint256 _totalWeight = 0;
Expand Down Expand Up @@ -296,7 +296,7 @@ contract Voter is IVoter, OwnableUpgradeable, ReentrancyGuardUpgradeable {
}
if (_usedWeight > 0) IVoteEscrow(_ve).voting(_tokenId);
totWeightsPerEpoch[_time] += _totalWeight;
usedWeights[_tokenId] = (_usedWeight);
usedWeights[_tokenId] = _usedWeight;
}

/// @notice claim LP gauge rewards
Expand Down
16 changes: 16 additions & 0 deletions contracts/test/BaseTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,29 @@ contract BaseTest is Test {
return array;
}

function asArray(address value0, address value1, address value2) public pure returns (address[] memory) {
address[] memory array = new address[](3);
array[0] = value0;
array[1] = value1;
array[2] = value2;
return array;
}

function asArray(uint256 value0, uint256 value1) public pure returns (uint256[] memory) {
uint256[] memory array = new uint256[](2);
array[0] = value0;
array[1] = value1;
return array;
}

function asArray(uint256 value0, uint256 value1, uint256 value2) public pure returns (uint256[] memory) {
uint256[] memory array = new uint256[](3);
array[0] = value0;
array[1] = value1;
array[2] = value2;
return array;
}

function asArray(uint256 value) public pure returns (uint256[] memory) {
uint256[] memory array = new uint256[](1);
array[0] = value;
Expand Down
40 changes: 34 additions & 6 deletions contracts/test/VoteEscrowFuzzTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ pragma solidity 0.8.19;

import { Voter } from "../Voter.sol";
import { VoteEscrow } from "../VoteEscrow.sol";
import { BaseTest } from "./BaseTest.sol";
import { BaseTest, IonicFlywheel } from "./BaseTest.sol";

contract VoteEscrowFuzzTest is BaseTest {
address alice = address(1);
address bob = address(255);
address charlie = address(768);

address[] markets;
address[] gauges;

function testLocksFixed() public {
testLocksFuzz(21);
}
Expand All @@ -26,6 +29,16 @@ contract VoteEscrowFuzzTest is BaseTest {
uint256 bridgedTokenId;
bytes memory bridgingMetadata;

for (uint160 i = 0; i < runs / 10; i++) {
address _rewardsContract = address(i);
address _market = address(i + 1023);
IonicFlywheel _flywheel = new IonicFlywheel(_rewardsContract);
address _gauge = voter.createMarketGauge(_market, address(_flywheel));

gauges.push(_gauge);
markets.push(_market);
}

for (uint256 i = 0; i < runs; i++) {
address minter;
if (i % 3 == 0) {
Expand Down Expand Up @@ -63,6 +76,8 @@ contract VoteEscrowFuzzTest is BaseTest {
bridgingMetadata = ve.burn(bridgedTokenId);
bridgingUser = minter;
emit log_named_uint("bridge burning", bridgedTokenId);

checkReset(bridgedTokenId);
}
vm.stopPrank();
vm.startPrank(minter);
Expand All @@ -75,9 +90,10 @@ contract VoteEscrowFuzzTest is BaseTest {
uint256 half0 = nft2Balance / 2;
uint256 half1 = nft2Balance - half0;
ve.split(asArray(half0, half1), nft2);

checkReset(nft2);
}
}
if (i > 10 && randi % 5 == 0) {
} else if (i > 10 && randi % 5 == 0) {
uint256 nft0 = ve.tokenOfOwnerByIndex(minter, 0);
uint256 nft1 = ve.tokenOfOwnerByIndex(minter, 1);
uint256 nft2 = ve.tokenOfOwnerByIndex(minter, 2);
Expand All @@ -87,15 +103,23 @@ contract VoteEscrowFuzzTest is BaseTest {
emit log_named_uint("merging", nft2);
ve.merge(nft0, nft1);
ve.merge(nft1, nft2);

checkReset(nft0);
checkReset(nft1);
}
}
if (i > 14 && randi % 7 == 0) {
} else if (i > 14 && randi % 7 == 0) {
uint256 nft1 = ve.tokenOfOwnerByIndex(minter, 1);
if (nft1 != 0 && block.timestamp > ve.locked__end(nft1)) {
emit log_named_uint("withdrawing", nft1);
ve.withdraw(nft1);

checkReset(nft1);
}
}
if (i > 5 && randi % 2 == 0) {
uint256 nft1 = ve.tokenOfOwnerByIndex(minter, 1);
voter.vote(nft1, asArray(gauges[0], gauges[1], gauges[2]), asArray(1, 2, 3));
}
}
}
emit log("");
Expand All @@ -110,6 +134,10 @@ contract VoteEscrowFuzzTest is BaseTest {
(int128 amount, uint256 end) = ve.locked(_tokenId);
assertEq(amount, 0, "am");
assertEq(end, 0, "end");
// TODO voting on gauges

for (uint256 i = 0; i < markets.length; i++) {
uint256 votes = voter.votes(_tokenId, markets[i]);
assertEq(votes, 0, "!votes reset");
}
}
}

0 comments on commit 77748ce

Please sign in to comment.