-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
278 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
pragma solidity ^0.8.17; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
import {console2 as console} from "forge-std/console2.sol"; | ||
|
||
import {QuadraticIncreasingEscrow, IVotingEscrow, IEscrowCurve} from "src/escrow/increasing/QuadraticIncreasingEscrow.sol"; | ||
import {IVotingEscrowIncreasing, ILockedBalanceIncreasing} from "src/escrow/increasing/interfaces/IVotingEscrowIncreasing.sol"; | ||
|
||
contract MockEscrow { | ||
address public token; | ||
QuadraticIncreasingEscrow public curve; | ||
|
||
function setCurve(QuadraticIncreasingEscrow _curve) external { | ||
curve = _curve; | ||
} | ||
|
||
function checkpoint( | ||
uint256 _tokenId, | ||
IVotingEscrow.LockedBalance memory _oldLocked, | ||
IVotingEscrow.LockedBalance memory _newLocked | ||
) external { | ||
return curve.checkpoint(_tokenId, _oldLocked, _newLocked); | ||
} | ||
} | ||
|
||
contract QuadraticCurveBase is Test, ILockedBalanceIncreasing { | ||
QuadraticIncreasingEscrow internal curve; | ||
MockEscrow internal escrow; | ||
|
||
function setUp() public { | ||
escrow = new MockEscrow(); | ||
curve = new QuadraticIncreasingEscrow(address(escrow)); | ||
escrow.setCurve(curve); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
pragma solidity ^0.8.17; | ||
|
||
import {console2 as console} from "forge-std/console2.sol"; | ||
|
||
import {QuadraticIncreasingEscrow, IVotingEscrow, IEscrowCurve} from "src/escrow/increasing/QuadraticIncreasingEscrow.sol"; | ||
import {IVotingEscrowIncreasing, ILockedBalanceIncreasing} from "src/escrow/increasing/interfaces/IVotingEscrowIncreasing.sol"; | ||
import {QuadraticCurveBase, MockEscrow} from "./QuadraticCurveBase.t.sol"; | ||
|
||
contract TestQuadraticIncreasingCurve is QuadraticCurveBase { | ||
// check that our constants are initialized correctly | ||
// check the escrow is set | ||
function testEscrowInitializesCorrectly() public { | ||
MockEscrow escrow = new MockEscrow(); | ||
QuadraticIncreasingEscrow curve_ = new QuadraticIncreasingEscrow(address(escrow)); | ||
assertEq(address(curve_.escrow()), address(escrow)); | ||
} | ||
// validate the bias bounding works | ||
// warmup: TODO - how do we ensure the warmup doesn't add to an epoch that snaps | ||
// in the future | ||
// warmup: variable warmup perid (create a setter) | ||
// warmup: empty warmup period returns fase | ||
// supplyAt reverts | ||
// same block checkpointing overwrite user point history | ||
// updating checkpoint with a lower balance | ||
// updating checkpoint with a higher balance | ||
// updating with the same balance | ||
// only the escrow can call checkpoint | ||
// point index with large number of points | ||
// - if userepoch 0 return 0 | ||
// - if latest user epoch before ts, return the latest user epoch | ||
// - implicit zero balance | ||
// understand at what boundary the curve starts to break down by doing a very small and very large | ||
// deposit | ||
// test the bound bias caps at the boundary | ||
// test that the cooldown correcty calculates | ||
// test a checkpoint correctly saves the user point | ||
// test that the cooldown is respected for the NFT balance | ||
// test the fetched NFT balance from a point in timeFirst | ||
// TODO: check aero tests for other ideas | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
pragma solidity ^0.8.17; | ||
|
||
import "forge-std/Test.sol"; // Assuming you're using Foundry for testing | ||
import "@libs/EpochDurationLib.sol"; | ||
|
||
contract EpochDurationLibTest is Test { | ||
using EpochDurationLib for uint256; | ||
|
||
// Helper function to warp time for fuzzing | ||
function _warpTo(uint64 _warp) internal { | ||
vm.warp(_warp); | ||
} | ||
|
||
function testEpochStart(uint64 _warp) public { | ||
_warpTo(_warp); // Warp to fuzzed timestamp | ||
uint256 timestamp = block.timestamp; | ||
uint256 epochStart = EpochDurationLib.epochStart(timestamp); | ||
|
||
// The epoch start should be aligned to the start of the period | ||
assertEq(epochStart, timestamp - (timestamp % EpochDurationLib.EPOCH_DURATION)); | ||
} | ||
|
||
function testEpochNext(uint64 _warp) public { | ||
_warpTo(_warp); // Warp to fuzzed timestamp | ||
uint256 timestamp = block.timestamp; | ||
uint256 nextEpoch = EpochDurationLib.epochNext(timestamp); | ||
|
||
// Next epoch should start at the current epoch start + 2 weeks | ||
uint256 expectedNextEpoch = EpochDurationLib.epochStart(timestamp) + EpochDurationLib.EPOCH_DURATION; | ||
assertEq(nextEpoch, expectedNextEpoch); | ||
} | ||
|
||
function testEpochVoteStart(uint64 _warp) public { | ||
_warpTo(_warp); // Warp to fuzzed timestamp | ||
uint256 timestamp = block.timestamp; | ||
uint256 voteStart = EpochDurationLib.epochVoteStart(timestamp); | ||
|
||
// Vote start should be the start of the epoch + 1 hour | ||
uint256 expectedVoteStart = EpochDurationLib.epochStart(timestamp) + 1 hours; | ||
assertEq(voteStart, expectedVoteStart); | ||
} | ||
|
||
function testEpochVoteEnd(uint64 _warp) public { | ||
_warpTo(_warp); // Warp to fuzzed timestamp | ||
uint256 timestamp = block.timestamp; | ||
uint256 voteEnd = EpochDurationLib.epochVoteEnd(timestamp); | ||
|
||
// Vote end should be the start of the epoch + half the epoch duration - 1 hour | ||
uint256 expectedVoteEnd = EpochDurationLib.epochStart(timestamp) + | ||
(EpochDurationLib.EPOCH_DURATION / 2) - | ||
1 hours; | ||
assertEq(voteEnd, expectedVoteEnd); | ||
} | ||
|
||
function testVotingActiveDuringVotePeriod(uint64 _warp, uint32 _voting) public { | ||
vm.assume(_voting < 1 weeks - 1 hours); // Ensure voting period is less than a week | ||
_warpTo(_warp); // Warp to fuzzed timestamp | ||
uint256 timestamp = block.timestamp; | ||
uint256 voteStart = EpochDurationLib.epochVoteStart(timestamp); | ||
|
||
// Simulate a time during the voting period | ||
uint256 voteActiveTimestamp = voteStart + _voting; | ||
bool isVotingActive = EpochDurationLib.votingActive(voteActiveTimestamp); | ||
|
||
assertTrue(isVotingActive); | ||
} | ||
|
||
function testVotingActiveOutsideVotePeriod(uint64 _warp) public { | ||
_warpTo(_warp); // Warp to fuzzed timestamp | ||
uint256 timestamp = block.timestamp; | ||
uint256 voteEnd = EpochDurationLib.epochVoteEnd(timestamp); | ||
|
||
// Simulate a time after the voting period has ended | ||
uint256 afterVoteTimestamp = voteEnd + 1 hours; | ||
bool isVotingActive = EpochDurationLib.votingActive(afterVoteTimestamp); | ||
|
||
assertFalse(isVotingActive); | ||
} | ||
|
||
function testVotingNotActiveBeforeVoteStart(uint64 _warp) public { | ||
_warpTo(_warp); // Warp to fuzzed timestamp | ||
uint256 timestamp = block.timestamp; | ||
uint256 voteStart = EpochDurationLib.epochVoteStart(timestamp); | ||
|
||
// Simulate a time before the voting period starts | ||
uint256 beforeVoteStartTimestamp = voteStart - 1 hours; | ||
bool isVotingActive = EpochDurationLib.votingActive(beforeVoteStartTimestamp); | ||
|
||
assertFalse(isVotingActive); | ||
} | ||
} |
Oops, something went wrong.