Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eladmallel committed Sep 29, 2023
1 parent 6be9a90 commit e322863
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions packages/nouns-contracts/test/foundry/governance/ExcessETH.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { NounsDAOExecutorV3 } from '../../../contracts/governance/NounsDAOExecut
import { INounsAuctionHouse } from '../../../contracts/interfaces/INounsAuctionHouse.sol';
import { ExcessETH, INounsAuctionHouseV2, INounsDAOV3 } from '../../../contracts/governance/ExcessETH.sol';
import { ERC20Mock, RocketETHMock } from '../helpers/ERC20Mock.sol';
import { WETH } from '../../../contracts/test/WETH.sol';

contract DAOMock {
uint256 adjustedSupply;
Expand Down Expand Up @@ -104,11 +105,66 @@ contract ExcessETHTest is DeployUtilsExcessETH {
assertEq(excessETH.excessETH(), 1 ether);
}

function test_excessETH_givenBalancesInAllERC20s_takesThemIntoAccount() public {
// expected value = 10 ETH
dao.setAdjustedTotalSupply(10);
setMeanPrice(1 ether);
vm.warp(waitingPeriodEnd + 1);

// giving treasury 11 ETH -> Excess grows to 1 ETH
vm.deal(address(treasury), 11 ether);

// giving 1 stETH -> excess grows to 2 ETH
ERC20Mock(address(excessETH.stETH())).mint(address(treasury), 1 ether);

// giving 1 WETH -> excess grows to 3 ETH
WETH weth = WETH(payable(address(excessETH.wETH())));
weth.deposit{ value: 1 ether }();
weth.transfer(address(treasury), 1 ether);

// giving 1 rETH at a rate of 2 -> excess grows to 5 ETH
RocketETHMock reth = RocketETHMock(address(excessETH.rETH()));
reth.setRate(2);
reth.mint(address(treasury), 1 ether);

assertEq(excessETH.excessETH(), 5 ether);
}

function test_excessETH_givenRecentAuctionPriceChange_expectedTreasuryValueDropsAsExpected() public {
vm.warp(waitingPeriodEnd + 1);
vm.deal(address(treasury), 100 ether);

dao.setAdjustedTotalSupply(1);
setMeanPrice(100 ether);

assertEq(excessETH.excessETH(), 0);

// (100 * 88 + 10 * 2) / 90 = 98
// with 1 noun in supply, expected value is 98 ETH
uint256[] memory recentPrices = new uint256[](2);
recentPrices[0] = 10 ether;
recentPrices[1] = 10 ether;
setUniformPastAuctionsWithDifferentRecentPrices(100 ether, recentPrices);

assertEq(excessETH.excessETH(), 2 ether);
}

function setMeanPrice(uint256 meanPrice) internal {
uint256[] memory prices = new uint256[](pastAuctionCount);
for (uint256 i = 0; i < pastAuctionCount; i++) {
prices[i] = meanPrice;
}
auction.setPrices(prices);
}

function setUniformPastAuctionsWithDifferentRecentPrices(uint256 meanPrice, uint256[] memory recent) internal {
uint256[] memory prices = new uint256[](pastAuctionCount + recent.length);
for (uint256 i = 0; i < recent.length; i++) {
prices[i] = recent[i];
}
for (uint256 i = 0; i < pastAuctionCount; i++) {
prices[i + recent.length] = meanPrice;
}
auction.setPrices(prices);
}
}

0 comments on commit e322863

Please sign in to comment.