From 52ce1d66fe9d878707c77ed23efad7ad312c0f17 Mon Sep 17 00:00:00 2001 From: Pierrick Turelier Date: Thu, 19 May 2022 14:31:41 -0500 Subject: [PATCH] fix(tests): fix GaugeController unit tests --- contracts/GaugeController.sol | 66 +++++-- contracts/GaugeReward.sol | 7 +- test/GaugeController.test.ts | 323 +++++++++++++++++++++------------- 3 files changed, 259 insertions(+), 137 deletions(-) diff --git a/contracts/GaugeController.sol b/contracts/GaugeController.sol index de6d6565..0bc02513 100644 --- a/contracts/GaugeController.sol +++ b/contracts/GaugeController.sol @@ -3,13 +3,14 @@ pragma solidity 0.8.6; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@pooltogether/owner-manager-contracts/contracts/Ownable.sol"; import "./interfaces/IGaugeController.sol"; import "./interfaces/IGaugeReward.sol"; import "./libraries/TwabLib.sol"; import "./libraries/ExtendedSafeCastLib.sol"; -contract GaugeController is IGaugeController { +contract GaugeController is IGaugeController, Ownable { using ExtendedSafeCastLib for uint256; struct GaugeInfo { @@ -43,11 +44,37 @@ contract GaugeController is IGaugeController { */ mapping(address => TwabLib.Account) internal gaugeScaleTwabs; - constructor(IERC20 _token, IGaugeReward _gaugeReward) { + /* ============ Events ============ */ + + /** + * @notice Event emitted when the GaugeReward contract address is set + * @param gaugeReward Address of the newly set GaugeReward contract + */ + event GaugeRewardSet(IGaugeReward gaugeReward); + + /** + * @notice Event emitted when the contract is deployed + * @param token Address of the token being staked in the gauge + */ + event Deployed(IERC20 token); + + /* ============ Constructor ============ */ + + /** + * @notice GaugeController constructor + * @param _token Address of the token being staked in the gauge + * @param _owner Address of the contract owner + */ + constructor(IERC20 _token, address _owner) Ownable(_owner) { + require(_owner != address(0), "GC/owner-not-zero-address"); + require(address(_token) != address(0), "GC/token-not-zero-address"); token = _token; - gaugeReward = _gaugeReward; + + emit Deployed(_token); } + /* ============ External Functions ============ */ + function deposit(address _to, uint256 _amount) public { balances[_to] += _amount; token.transferFrom(msg.sender, address(this), _amount); @@ -92,17 +119,11 @@ contract GaugeController is IGaugeController { } function addGauge(address _gauge) public { - addGaugeWithScale(_gauge, 1 ether); + _addGaugeWithScale(_gauge, 1 ether); } function addGaugeWithScale(address _gauge, uint256 _scale) public { - TwabLib.Account storage gaugeScaleTwab = gaugeScaleTwabs[_gauge]; - (TwabLib.AccountDetails memory twabDetails, , ) = TwabLib.increaseBalance( - gaugeScaleTwab, - _scale.toUint208(), - uint32(block.timestamp) - ); - gaugeScaleTwab.details = twabDetails; + _addGaugeWithScale(_gauge, _scale); } function removeGauge(address _gauge) public { @@ -117,6 +138,17 @@ contract GaugeController is IGaugeController { gaugeScaleTwab.details = twabDetails; } + /** + * @notice Set GaugeReward contract + * @param _gaugeReward Address of the GaugeReward contract + */ + function setGaugeReward(IGaugeReward _gaugeReward) external onlyOwner { + require(address(_gaugeReward) != address(0), "GC/GaugeReward-not-zero-address"); + gaugeReward = _gaugeReward; + + emit GaugeRewardSet(_gaugeReward); + } + function setGaugeScale(address _gauge, uint256 _scale) public { TwabLib.Account storage gaugeScaleTwab = gaugeScaleTwabs[_gauge]; TwabLib.AccountDetails memory twabDetails = gaugeScaleTwab.details; @@ -184,6 +216,18 @@ contract GaugeController is IGaugeController { return userGaugeBalance[_user][_gauge]; } + /* ============ Internal Functions ============ */ + + function _addGaugeWithScale(address _gauge, uint256 _scale) internal { + TwabLib.Account storage gaugeScaleTwab = gaugeScaleTwabs[_gauge]; + (TwabLib.AccountDetails memory twabDetails, , ) = TwabLib.increaseBalance( + gaugeScaleTwab, + _scale.toUint208(), + uint32(block.timestamp) + ); + gaugeScaleTwab.details = twabDetails; + } + function _getAverageGaugeBetween( address _gauge, uint256 _startTime, diff --git a/contracts/GaugeReward.sol b/contracts/GaugeReward.sol index 1f5e91bc..c41d0f10 100644 --- a/contracts/GaugeReward.sol +++ b/contracts/GaugeReward.sol @@ -10,8 +10,6 @@ import "./interfaces/IGaugeReward.sol"; import "./interfaces/IGaugeController.sol"; import "./interfaces/IPrizePoolLiquidatorListener.sol"; -import "hardhat/console.sol"; - /** * @title PoolTogether V4 GaugeReward * @author PoolTogether Inc Team @@ -78,7 +76,7 @@ contract GaugeReward is IGaugeReward, IPrizePoolLiquidatorListener, Multicall { /* ============ Events ============ */ /** - * @notice Emitted when the contract is initialized + * @notice Emitted when the contract is deployed * @param gaugeController Address of the GaugeController * @param vault Address of the Vault */ @@ -202,9 +200,11 @@ contract GaugeReward is IGaugeReward, IPrizePoolLiquidatorListener, Multicall { uint256 _oldStakeBalance ) external override onlyGaugeController { RewardToken memory _rewardToken = _claimPastRewards(_gauge, _user, _oldStakeBalance); + if (address(_rewardToken.token) != address(0)) { _claim(_gauge, _rewardToken.token, _user, _oldStakeBalance, false); } + userLastClaimedTimestamp[_user] = block.timestamp; } @@ -331,6 +331,7 @@ contract GaugeReward is IGaugeReward, IPrizePoolLiquidatorListener, Multicall { if (_gaugeRewardTokensLength > 0) { uint256 i = _gaugeRewardTokensLength; + while (i > 0) { i = i - 1; _rewardToken = gaugeRewardTokens[_gauge][i]; diff --git a/test/GaugeController.test.ts b/test/GaugeController.test.ts index 7c2b9026..215ddcc1 100644 --- a/test/GaugeController.test.ts +++ b/test/GaugeController.test.ts @@ -1,34 +1,44 @@ -import { ethers } from 'hardhat'; -import { expect } from 'chai'; import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; +import { expect } from 'chai'; import { Contract, ContractFactory } from 'ethers'; -import { utils } from 'ethereum-waffle/node_modules/ethers'; +import { deployMockContract, MockContract } from 'ethereum-waffle'; +import { artifacts, ethers } from 'hardhat'; +import { Artifact } from 'hardhat/types'; + import { increaseTime } from './helpers/increaseTime'; -const { getSigners } = ethers; +const { getSigners, utils } = ethers; +const { parseEther: toWei } = utils; describe('GaugeController', () => { - let wallet1: SignerWithAddress; + let owner: SignerWithAddress; let GaugeController: Contract; + let GaugeReward: MockContract; let Token: Contract; - + let GaugeControllerFactory: ContractFactory; + let GaugeRewardArtifact: Artifact; let TokenFactory: ContractFactory; + let VaultFactory: ContractFactory; + + const gaugeAddress = '0x0000000000000000000000000000000000000001'; before(async () => { - [wallet1] = await getSigners(); - GaugeControllerFactory = await ethers.getContractFactory( - 'GaugeController' - ); + [owner] = await getSigners(); + GaugeControllerFactory = await ethers.getContractFactory('GaugeController'); + GaugeRewardArtifact = await artifacts.readArtifact('GaugeReward'); TokenFactory = await ethers.getContractFactory('ERC20Mintable'); + VaultFactory = await ethers.getContractFactory('Vault'); }); beforeEach(async () => { - Token = await TokenFactory.deploy("GaugeToken", "GaugeToken"); - GaugeController = await GaugeControllerFactory.deploy( - Token.address, - "0x0000000000000000000000000000000000000000", - ); + Token = await TokenFactory.deploy('GaugeToken', 'GaugeToken'); + + GaugeController = await GaugeControllerFactory.deploy(Token.address, owner.address); + + GaugeReward = await deployMockContract(owner, GaugeRewardArtifact.abi); + + await GaugeController.setGaugeReward(GaugeReward.address); }); /** @@ -40,12 +50,12 @@ describe('GaugeController', () => { */ describe('deposit(address _to, uint256 _amount)', () => { it('should SUCCEED to deposit', async () => { - await Token.mint(wallet1.address, utils.parseEther('100')); - await Token.approve(GaugeController.address, utils.parseEther('100')); - const tx = await GaugeController.deposit(wallet1.address, utils.parseEther('100')) + await Token.mint(owner.address, toWei('100')); + await Token.approve(GaugeController.address, toWei('100')); + const tx = await GaugeController.deposit(owner.address, toWei('100')); expect(tx.confirmations).to.be.equal(1); }); - }) + }); /** * @description Test withdraw(uint256 _amount) function @@ -54,15 +64,15 @@ describe('GaugeController', () => { * 1. transfer `token` from `address(this)` to `msg.sender` * 3. emit a Withdraw event */ - describe('withdraw(uint256 _amount)', () => { + describe('withdraw(uint256 _amount)', () => { it('should SUCCEED to withdraw funds', async () => { - await Token.mint(wallet1.address, utils.parseEther('100')); - await Token.approve(GaugeController.address, utils.parseEther('100')); - await GaugeController.deposit(wallet1.address, utils.parseEther('100')) - const tx = await GaugeController.withdraw(utils.parseEther('100')) + await Token.mint(owner.address, toWei('100')); + await Token.approve(GaugeController.address, toWei('100')); + await GaugeController.deposit(owner.address, toWei('100')); + const tx = await GaugeController.withdraw(toWei('100')); expect(tx.confirmations).to.be.equal(1); }); - }) + }); /** * @description Test increaseGauge(address _gauge, uint256 _amount) function @@ -73,22 +83,35 @@ describe('GaugeController', () => { * 4. update the `gaugeTwab.details` with the updated `twabDetails` object * 4. emit a GaugeIncreased event */ - describe('increaseGauge(address _gauge, uint256 _amount)', () => { + describe('increaseGauge(address _gauge, uint256 _amount)', () => { it('should SUCCEED to increase gaugeBalance by decreasing staked balance.', async () => { - await GaugeController.addGauge("0x0000000000000000000000000000000000000001"); - expect(await GaugeController.getGauge("0x0000000000000000000000000000000000000001")).to.eq("0") - await Token.mint(wallet1.address, utils.parseEther('100')); - await Token.approve(GaugeController.address, utils.parseEther('100')); - await GaugeController.deposit(wallet1.address, utils.parseEther('100')) - const tx = await GaugeController.increaseGauge("0x0000000000000000000000000000000000000001", utils.parseEther('100')) - expect(tx.confirmations).to.be.equal(1); - expect(await GaugeController.getGauge("0x0000000000000000000000000000000000000001")).to.eq("100000000000000000000") + await GaugeController.addGauge(gaugeAddress); + + expect(await GaugeController.getGaugeBalance(gaugeAddress)).to.equal('0'); + + await Token.mint(owner.address, toWei('100')); + await Token.approve(GaugeController.address, toWei('100')); + + await GaugeController.deposit(owner.address, toWei('100')); + + await GaugeReward.mock.afterIncreaseGauge + .withArgs(gaugeAddress, owner.address, toWei('0')) + .returns(); + + const tx = await GaugeController.increaseGauge(gaugeAddress, toWei('100')); + + expect(tx.confirmations).to.equal(1); + + expect(await GaugeController.getGaugeBalance(gaugeAddress)).to.equal( + '100000000000000000000', + ); }); + it('should FAIL to increase gaugeBalance BECAUSE of insufficient balance', async () => { - await GaugeController.addGauge("0x0000000000000000000000000000000000000001"); - expect(GaugeController.increaseGauge("0x0000000000000000000000000000000000000001", utils.parseEther('100'))).to.be.reverted + await GaugeController.addGauge(gaugeAddress); + expect(GaugeController.increaseGauge(gaugeAddress, toWei('100'))).to.be.reverted; }); - }) + }); /** * @description Test decreaseGauge(address _gauge, uint256 _amount) function @@ -99,23 +122,41 @@ describe('GaugeController', () => { * 4. update the `gaugeTwab.details` with the updated `twabDetails` object * 5. emit a GaugeDecreased event */ - describe('decreaseGauge(address _gauge, uint256 _amount)', () => { + describe('decreaseGauge(address _gauge, uint256 _amount)', () => { it('should SUCCEED to increase staked balance by decreasing gaugeBalance .', async () => { - await GaugeController.addGauge("0x0000000000000000000000000000000000000001"); - expect(await GaugeController.getGauge("0x0000000000000000000000000000000000000001")).to.eq("0") - await Token.mint(wallet1.address, utils.parseEther('200')); - await Token.approve(GaugeController.address, utils.parseEther('200')); - await GaugeController.deposit(wallet1.address, utils.parseEther('200')) - await GaugeController.increaseGauge("0x0000000000000000000000000000000000000001", utils.parseEther('200')) - const tx = await GaugeController.decreaseGauge("0x0000000000000000000000000000000000000001", utils.parseEther('100')) + await GaugeController.addGauge(gaugeAddress); + + expect(await GaugeController.getGaugeBalance(gaugeAddress)).to.eq('0'); + + await Token.mint(owner.address, toWei('200')); + await Token.approve(GaugeController.address, toWei('200')); + + await GaugeController.deposit(owner.address, toWei('200')); + + await GaugeReward.mock.afterIncreaseGauge + .withArgs(gaugeAddress, owner.address, toWei('0')) + .returns(); + + await GaugeController.increaseGauge(gaugeAddress, toWei('200')); + + await GaugeReward.mock.afterDecreaseGauge + .withArgs(gaugeAddress, owner.address, toWei('200')) + .returns(); + + const tx = await GaugeController.decreaseGauge(gaugeAddress, toWei('100')); + expect(tx.confirmations).to.be.equal(1); - expect(await GaugeController.getGauge("0x0000000000000000000000000000000000000001")).to.eq("100000000000000000000") + + expect(await GaugeController.getGaugeBalance(gaugeAddress)).to.eq( + '100000000000000000000', + ); }); + it('should FAIL to increase staked balance BECAUSE of insufficient gaugeBalance.', async () => { - await GaugeController.addGauge("0x0000000000000000000000000000000000000001"); - expect(GaugeController.decreaseGauge("0x0000000000000000000000000000000000000001", utils.parseEther('100'))).to.be.reverted + await GaugeController.addGauge(gaugeAddress); + expect(GaugeController.decreaseGauge(gaugeAddress, toWei('100'))).to.be.reverted; }); - }) + }); /** * @description Test addGaugeWithScale(address _to, uint256 _scale) function @@ -126,12 +167,14 @@ describe('GaugeController', () => { * 4. update the `gaugeTwab.details` with the updated `twabDetails` object * 5. emit a AddGaugeWithScale event */ - describe('addGaugeWithScale(address _to, uint256 _scale)', () => { + describe('addGaugeWithScale(address _to, uint256 _scale)', () => { it('should SUCCEED to add gauge to the gaugeScaleTwabs mapping', async () => { - await GaugeController.addGaugeWithScale("0x0000000000000000000000000000000000000001", utils.parseEther('1')) - expect(await GaugeController.getGaugeScale("0x0000000000000000000000000000000000000001")).to.eq("1000000000000000000") + await GaugeController.addGaugeWithScale(gaugeAddress, toWei('1')); + expect(await GaugeController.getGaugeScaleBalance(gaugeAddress)).to.eq( + '1000000000000000000', + ); }); - }) + }); /** * @description Test removeGauge(address _gauge) function @@ -142,12 +185,12 @@ describe('GaugeController', () => { * 4. update the `gaugeTwab.details` with the updated `twabDetails` object * 5. emit a RemoveGauge event */ - describe('removeGauge(address _gauge)', () => { + describe('removeGauge(address _gauge)', () => { it('should SUCCEED to remove gauge from the gaugeScaleTwabs mapping', async () => { - await GaugeController.removeGauge("0x0000000000000000000000000000000000000001") - expect(await GaugeController.getGaugeScale("0x0000000000000000000000000000000000000001")).to.eq("0") + await GaugeController.removeGauge(gaugeAddress); + expect(await GaugeController.getGaugeScaleBalance(gaugeAddress)).to.eq('0'); }); - }) + }); /** * @description Test setGaugeScale(address _gauge, uint256 _scale function @@ -155,135 +198,169 @@ describe('GaugeController', () => { * 1. require the `msg.sender` to be authorized to remove a gauge * 2. require the `gauge` DOES exist. * 3. IF - * 3.1 - * 3.2 + * 3.1 + * 3.2 * 4. emit a RemoveGauge event */ - describe('setGaugeScale(address _gauge, uint256 _scale', () => { + describe('setGaugeScale(address _gauge, uint256 _scale', () => { it('should SUCCEED to INCREASE the scale on EXISTING gauge', async () => { - await GaugeController.addGauge("0x0000000000000000000000000000000000000001"); - await GaugeController.setGaugeScale("0x0000000000000000000000000000000000000001", utils.parseEther('2')) - expect(await GaugeController.getGaugeScale("0x0000000000000000000000000000000000000001")).to.eq("2000000000000000000") + await GaugeController.addGauge(gaugeAddress); + await GaugeController.setGaugeScale(gaugeAddress, toWei('2')); + expect(await GaugeController.getGaugeScaleBalance(gaugeAddress)).to.eq( + '2000000000000000000', + ); }); - + it('should SUCCEED to DECREASE the scale on EXISTING gauge', async () => { - await GaugeController.addGauge("0x0000000000000000000000000000000000000001"); - await GaugeController.setGaugeScale("0x0000000000000000000000000000000000000001", utils.parseEther('0.5')) - expect(await GaugeController.getGaugeScale("0x0000000000000000000000000000000000000001")).to.eq("500000000000000000") + await GaugeController.addGauge(gaugeAddress); + await GaugeController.setGaugeScale(gaugeAddress, toWei('0.5')); + expect(await GaugeController.getGaugeScaleBalance(gaugeAddress)).to.eq( + '500000000000000000', + ); }); - }) + }); /** - * @description Test getGauge(address _gauge) function + * @description Test getGaugeBalance(address _gauge) function * -= Expected Behavior =- * 1. read `GaugeTwabs.details.balance` */ - describe('getGauge(address _gauge)', () => { + describe('getGaugeBalance(address _gauge)', () => { it('should SUCCEED to READ the GaugeTwabs[gauge].details.balance from EMPTY mapping', async () => { - expect(await GaugeController.getGauge("0x0000000000000000000000000000000000000002")).to.eq("0") + expect( + await GaugeController.getGaugeBalance('0x0000000000000000000000000000000000000002'), + ).to.eq('0'); }); it('should SUCCEED to READ the GaugeTwabs[gauge].details.balance from INITIALIZED mapping', async () => { - await GaugeController.addGauge("0x0000000000000000000000000000000000000001"); - expect(await GaugeController.getGauge("0x0000000000000000000000000000000000000001")).to.eq("0") + await GaugeController.addGauge(gaugeAddress); + expect(await GaugeController.getGaugeBalance(gaugeAddress)).to.eq('0'); }); - }) - + }); + /** - * @description Test getGaugeScale(address _gauge) function + * @description Test getGaugeScaleBalance(address _gauge) function * -= Expected Behavior =- * 1. read `GaugeScaleTwabs.details.balance` */ - describe('getGaugeScale(address _gauge)', () => { + describe('getGaugeScaleBalance(address _gauge)', () => { it('should SUCCEED to READ the GaugeScaleTwabs[gauge].details.balance from EMPTY mapping', async () => { - expect(await GaugeController.getGauge("0x0000000000000000000000000000000000000002")).to.eq("0") + expect( + await GaugeController.getGaugeBalance('0x0000000000000000000000000000000000000002'), + ).to.eq('0'); }); it('should SUCCEED to READ the GaugeScaleTwabs[gauge].details.balance from INITIALIZED mapping', async () => { - await GaugeController.addGauge("0x0000000000000000000000000000000000000001"); - expect(await GaugeController.getGaugeScale("0x0000000000000000000000000000000000000001")).to.eq("1000000000000000000") + await GaugeController.addGauge(gaugeAddress); + expect(await GaugeController.getGaugeScaleBalance(gaugeAddress)).to.eq( + '1000000000000000000', + ); }); - }) + }); /** * @description Test getScaledAverageGaugeBetween(address _gauge, uint256 _startTime, uint256 _endTime) function * -= Expected Behavior =- * 1. read `Gauge` average balance between `_startTime` and `_endTime` - * 2. read `GaugeScale` average balance between `_startTime` and `_endTime` + * 2. read `GaugeScale` average balance between `_startTime` and `_endTime` * 3. compute average of `Gauge` and `GaugeScale` */ - describe('getScaledAverageGaugeBetween(address _gauge, uint256 _startTime, uint256 _endTime)', () => { + describe('getScaledAverageGaugeBetween(address _gauge, uint256 _startTime, uint256 _endTime)', () => { it('should SUCCEED to READ the scaled average of', async () => { // Add Gauge with Scale TWAB - await GaugeController.addGaugeWithScale("0x0000000000000000000000000000000000000001", utils.parseEther('1')); + await GaugeController.addGaugeWithScale(gaugeAddress, toWei('1')); // Increase Gauge TWAB - await Token.mint(wallet1.address, utils.parseEther('100')); - await Token.approve(GaugeController.address, utils.parseEther('100')); - await GaugeController.deposit(wallet1.address, utils.parseEther('100')) - await GaugeController.increaseGauge("0x0000000000000000000000000000000000000001", utils.parseEther('100')) - + await Token.mint(owner.address, toWei('100')); + await Token.approve(GaugeController.address, toWei('100')); + + await GaugeController.deposit(owner.address, toWei('100')); + + await GaugeReward.mock.afterIncreaseGauge + .withArgs(gaugeAddress, owner.address, toWei('0')) + .returns(); + + await GaugeController.increaseGauge(gaugeAddress, toWei('100')); + // Simulate Increase in Time by 1 Day (86400 seconds) - await increaseTime(ethers.provider, 86400) - const timestamp = (await ethers.provider.getBlock('latest')).timestamp - const startTime = timestamp - 86400 - const endTime = timestamp + await increaseTime(ethers.provider, 86400); + const timestamp = (await ethers.provider.getBlock('latest')).timestamp; + const startTime = timestamp - 86400; + const endTime = timestamp; // READ Scaled Gauge TWAB - const read = await GaugeController.getScaledAverageGaugeBetween("0x0000000000000000000000000000000000000001", startTime, endTime) - expect(read).to.eq("100000000000000000000") + const read = await GaugeController.getScaledAverageGaugeBetween( + gaugeAddress, + startTime, + endTime, + ); + + expect(read).to.eq('100000000000000000000'); }); - }) + }); /** * @description Test getAverageGaugeBetween(address _gauge, uint256 _startTime, uint256 _endTime) function * -= Expected Behavior =- * 1. read `Gauge` average balance between `_startTime` and `_endTime` */ - describe('getAverageGaugeBetween(address _gauge, uint256 _startTime, uint256 _endTime)', () => { + describe('getAverageGaugeBetween(address _gauge, uint256 _startTime, uint256 _endTime)', () => { it('should SUCCEED to READ the balance average of the gauge', async () => { // Add Gauge with Scale TWAB - await GaugeController.addGaugeWithScale("0x0000000000000000000000000000000000000001", utils.parseEther('1')); + await GaugeController.addGaugeWithScale(gaugeAddress, toWei('1')); // Increase Gauge TWAB - await Token.mint(wallet1.address, utils.parseEther('100')); - await Token.approve(GaugeController.address, utils.parseEther('100')); - await GaugeController.deposit(wallet1.address, utils.parseEther('100')) - await GaugeController.increaseGauge("0x0000000000000000000000000000000000000001", utils.parseEther('100')) - + await Token.mint(owner.address, toWei('100')); + await Token.approve(GaugeController.address, toWei('100')); + + await GaugeController.deposit(owner.address, toWei('100')); + + await GaugeReward.mock.afterIncreaseGauge + .withArgs(gaugeAddress, owner.address, toWei('0')) + .returns(); + + await GaugeController.increaseGauge(gaugeAddress, toWei('100')); + // Simulate Increase in Time by 1 Day (86400 seconds) - await increaseTime(ethers.provider, 86400) - const timestamp = (await ethers.provider.getBlock('latest')).timestamp - const startTime = timestamp - 86400 - const endTime = timestamp + await increaseTime(ethers.provider, 86400); + const timestamp = (await ethers.provider.getBlock('latest')).timestamp; + const startTime = timestamp - 86400; + const endTime = timestamp; // READ Gauge TWAB - const read = await GaugeController.getAverageGaugeBetween("0x0000000000000000000000000000000000000001", startTime, endTime) - expect(read).to.eq("100000000000000000000") + const read = await GaugeController.getAverageGaugeBetween( + gaugeAddress, + startTime, + endTime, + ); + + expect(read).to.eq('100000000000000000000'); }); - }) - + }); + /** * @description Test getAverageGaugeScaleBetween(address _gauge, uint256 _startTime, uint256 _endTime) function * -= Expected Behavior =- * 1. read `GaugeScale` average balance between `_startTime` and `_endTime` */ - describe('getAverageGaugeScaleBetween(address _gauge, uint256 _startTime, uint256 _endTime)', () => { + describe('getAverageGaugeScaleBetween(address _gauge, uint256 _startTime, uint256 _endTime)', () => { it('should SUCCEED to READ the scale TWAB of the gauge', async () => { // Add Gauge with Scale TWAB - await GaugeController.addGaugeWithScale("0x0000000000000000000000000000000000000001", utils.parseEther('1')); - + await GaugeController.addGaugeWithScale(gaugeAddress, toWei('1')); + // Simulate Increase in Time by 1 Day (86400 seconds) - await increaseTime(ethers.provider, 86400) - const timestamp = (await ethers.provider.getBlock('latest')).timestamp - const startTime = timestamp - 86400 - const endTime = timestamp + await increaseTime(ethers.provider, 86400); + const timestamp = (await ethers.provider.getBlock('latest')).timestamp; + const startTime = timestamp - 86400; + const endTime = timestamp; // READ Gauge TWAB - const read = await GaugeController.getAverageGaugeScaleBetween("0x0000000000000000000000000000000000000001", startTime, endTime) - expect(read).to.eq("1000000000000000000") + const read = await GaugeController.getAverageGaugeScaleBetween( + gaugeAddress, + startTime, + endTime, + ); + expect(read).to.eq('1000000000000000000'); }); - }) - - + }); });