Skip to content

Commit

Permalink
remove console logs, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dvpublic committed Dec 19, 2023
1 parent 1bce3f1 commit d6447f0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 42 deletions.
18 changes: 2 additions & 16 deletions contracts/ve/TetuVoterSimplified.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@ import "../proxy/ControllableV3.sol";
import "../interfaces/ITetuLiquidator.sol";
import "../interfaces/ITetuVaultV2.sol";
import "../interfaces/IERC4626.sol";
import "hardhat/console.sol";

interface ITest {
function _notifyRewardAmount(
uint amount,
uint tvlSum,
uint[] memory tvlInTokenValues,
address[] memory vaults_,
address _token,
address _gauge
) external;
}

/// @title Voter for veTETU.
/// Based on Solidly contract.
Expand Down Expand Up @@ -163,12 +151,10 @@ contract TetuVoterSimplified is ReentrancyGuard, ControllableV3, IVoter {
// gauge is able to revert if reward amount is too small
// in this case let's rollback transferring rewards to all vaults,
// and keep rewards on balance up to the next attempt
try TetuVoterSimplified(address(this))._notifyRewardAmount(c, _token, _gauge, amount) {
} catch {
console.log("revert");
}
try TetuVoterSimplified(address(this))._notifyRewardAmount(c, _token, _gauge, amount) {} catch {}
}

/// @notice Try to send all available rewards to vaults
/// @dev We need this external function to be able to call it inside try/catch
/// and revert transferring of rewards to all vaults simultaneously if transferring to any vault reverts
function _notifyRewardAmount(IController c, address _token, address _gauge, uint amount) external {
Expand Down
66 changes: 40 additions & 26 deletions test/ve/TetuVoterSimplifiedTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,32 +120,46 @@ describe("Tetu voter simplified tests", function () {
});

// *** NOTIFY

it("notify test", async function () {
await tetu.approve(voter.address, Misc.MAX_UINT);
await voter.notifyRewardAmount(parseUnits('100'), {gasLimit: 9_000_000});
});

it("notify zero amount revert test", async function () {
await tetu.approve(voter.address, Misc.MAX_UINT);
await expect(voter.notifyRewardAmount(0)).revertedWith("zero amount");
});

it("notify with little amount should not revert test", async function () {
await tetu.approve(voter.address, Misc.MAX_UINT);

// set StakelessMultiPoolBase.periodFinish
await voter.notifyRewardAmount(100, {gasLimit: 9_000_000});

// prepare total assets. Sum TVL will be 1+10_000
// ratio will be 1/10_000 and 9999/10_000
await underlying2.mint(strategy1, parseUnits("1"));
await underlying2.mint(strategy2, parseUnits("100"));
await liquidator.setPrice(1);
await liquidator.setUseTokensToCalculatePrice(true);

// Amount should be higher than remaining rewards
await voter.notifyRewardAmount(200, {gasLimit: 9_000_000});
describe("notifyRewardAmount", () => {
it("notify zero amount revert test", async function () {
await tetu.approve(voter.address, Misc.MAX_UINT);

await expect(voter.notifyRewardAmount(0)).revertedWith("zero amount");
});

it("should send all rewards to vaults", async function () {
await tetu.approve(voter.address, Misc.MAX_UINT);

const balanceBefore = await tetu.balanceOf(voter.address);
await voter.notifyRewardAmount(parseUnits('100'), {gasLimit: 9_000_000});
const balanceAfter = await tetu.balanceOf(voter.address);

expect(balanceBefore).eq(0);
expect(balanceAfter).eq(0);
});

it("should try to send all rewards to vaults but keep them on balance", async function () {
await tetu.approve(voter.address, Misc.MAX_UINT);

// set StakelessMultiPoolBase.periodFinish
await voter.notifyRewardAmount(100, {gasLimit: 9_000_000});

// prepare total assets. Sum TVL will be 1+100
// ratio will be 1/100 and 99/100
// as result, it should produce exception "Amount should be higher than remaining rewards"
// inside StakelessMultiPoolBase
await underlying2.mint(strategy1, parseUnits("1"));
await underlying2.mint(strategy2, parseUnits("100"));
await liquidator.setPrice(1);
await liquidator.setUseTokensToCalculatePrice(true);

// The app should try to transfer rewards to vaults, revert the transferring and keep the rewards on balance
const balanceBefore = await tetu.balanceOf(voter.address);
await voter.notifyRewardAmount(200, {gasLimit: 9_000_000});
const balanceAfter = await tetu.balanceOf(voter.address);

expect(balanceAfter).gt(balanceBefore);
});
});

// *** UPDATE
Expand Down

0 comments on commit d6447f0

Please sign in to comment.