Skip to content

Commit

Permalink
Add tests for curve + withdrawals
Browse files Browse the repository at this point in the history
  • Loading branch information
xavikh committed Feb 10, 2025
1 parent 5c53046 commit b1a8fc4
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions test/escrow/curve/QuadraticCurveMath.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ pragma solidity ^0.8.17;

import {console2 as console} from "forge-std/console2.sol";

import {SafeCastUpgradeable as SafeCast} from "@openzeppelin/contracts-upgradeable/utils/math/SafeCastUpgradeable.sol";

import {IClock} from "src/clock/IClock.sol";
import {QuadraticIncreasingEscrow, IVotingEscrow, IEscrowCurve} from "src/escrow/increasing/QuadraticIncreasingEscrow.sol";
import {IVotingEscrowIncreasing, ILockedBalanceIncreasing} from "src/escrow/increasing/interfaces/IVotingEscrowIncreasing.sol";

import {QuadraticCurveBase} from "./QuadraticCurveBase.t.sol";

contract TestQuadraticIncreasingCurve is QuadraticCurveBase {
using SafeCast for uint256;

function test_votingPowerComputesCorrect() public {
/**
Period Result
Expand Down Expand Up @@ -283,5 +288,55 @@ contract TestQuadraticIncreasingCurve is QuadraticCurveBase {
depositSecond,
"Balance incorrect after season reset II"
);

vm.warp(block.timestamp + clock.epochDuration());

assertEq(
curve.votingPowerAt(tokenIdFirst, block.timestamp),
600985163959347101952,
"Balance incorrect after p1"
);

assertEq(
curve.votingPowerAt(tokenIdSecond, block.timestamp),
1428570120419660800000000000,
"Balance incorrect after p1"
);

vm.warp(block.timestamp + clock.epochDuration());

// Simulate a beginWithdrawal checkpoint
uint256 checkpointClearTime = IClock(clock).epochNextCheckpointTs();
escrow.checkpoint(
tokenIdFirst,
LockedBalance(0, 0),
LockedBalance(0, checkpointClearTime.toUint48())
);

assertEq(
curve.votingPowerAt(tokenIdFirst, block.timestamp),
901476370123561173504,
"Voting power should be the same after beginWithdrawal"
);

clock.newSeason();

escrow.checkpoint(
tokenIdSecond,
LockedBalance(0, 0),
LockedBalance(0, checkpointClearTime.toUint48())
);

assertEq(
curve.votingPowerAt(tokenIdSecond, block.timestamp),
2142851910251161600000000000,
"Voting power should be the same after beginWithdrawal II"
);

vm.warp(block.timestamp + clock.epochDuration());

assertEq(curve.votingPowerAt(tokenIdFirst, block.timestamp), 0, "Voting power should be after withdrawal");
assertEq(curve.votingPowerAt(tokenIdSecond, block.timestamp), 0, "Voting power should be after withdrawal II");

}
}

0 comments on commit b1a8fc4

Please sign in to comment.