-
Notifications
You must be signed in to change notification settings - Fork 434
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
1 parent
083d21a
commit 0042e7d
Showing
3 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
packages/nouns-contracts/test/foundry/governance/ExcessETH.t.sol
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,103 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity ^0.8.19; | ||
|
||
import 'forge-std/Test.sol'; | ||
import { DeployUtilsExcessETH } from '../helpers/DeployUtilsExcessETH.sol'; | ||
import { NounsDAOExecutorV3 } from '../../../contracts/governance/NounsDAOExecutorV3.sol'; | ||
import { INounsAuctionHouse } from '../../../contracts/interfaces/INounsAuctionHouse.sol'; | ||
import { ExcessETH, INounsAuctionHouseV2, INounsDAOV3 } from '../../../contracts/governance/ExcessETH.sol'; | ||
|
||
contract DAOMock { | ||
uint256 adjustedSupply; | ||
|
||
function setAdjustedTotalSupply(uint256 adjustedSupply_) external { | ||
adjustedSupply = adjustedSupply_; | ||
} | ||
|
||
function adjustedTotalSupply() external view returns (uint256) { | ||
return adjustedSupply; | ||
} | ||
} | ||
|
||
contract AuctionMock is INounsAuctionHouseV2 { | ||
uint256[] pricesHistory; | ||
|
||
function setPrices(uint256[] memory pricesHistory_) external { | ||
// priceHistory.length = priceHistory_.length; | ||
// for (uint256 i = 0; i < priceHistory_.length; i++) { | ||
// priceHistory[i] = priceHistory_[i]; | ||
// } | ||
pricesHistory = pricesHistory_; | ||
} | ||
|
||
function prices(uint256 auctionCount) | ||
external | ||
view | ||
override | ||
returns (INounsAuctionHouse.Settlement[] memory priceHistory_) | ||
{ | ||
priceHistory_ = new INounsAuctionHouse.Settlement[](pricesHistory.length); | ||
for (uint256 i; i < pricesHistory.length; ++i) { | ||
priceHistory_[i].amount = pricesHistory[i]; | ||
} | ||
} | ||
|
||
function settleAuction() external {} | ||
|
||
function settleCurrentAndCreateNewAuction() external {} | ||
|
||
function createBid(uint256 nounId) external payable {} | ||
|
||
function pause() external {} | ||
|
||
function unpause() external {} | ||
|
||
function setTimeBuffer(uint256 timeBuffer) external {} | ||
|
||
function setReservePrice(uint256 reservePrice) external {} | ||
|
||
function setMinBidIncrementPercentage(uint8 minBidIncrementPercentage) external {} | ||
} | ||
|
||
contract ExcessETHTest is DeployUtilsExcessETH { | ||
DAOMock dao = new DAOMock(); | ||
AuctionMock auction = new AuctionMock(); | ||
NounsDAOExecutorV3 treasury; | ||
ExcessETH excessETH; | ||
|
||
uint256 waitingPeriodEnd; | ||
uint16 pastAuctionCount; | ||
|
||
function setUp() public { | ||
waitingPeriodEnd = block.timestamp + 90 days; | ||
pastAuctionCount = 90; | ||
|
||
treasury = _deployExecutorV3(address(dao)); | ||
excessETH = _deployExcessETH(treasury, auction, waitingPeriodEnd, pastAuctionCount); | ||
} | ||
|
||
function test_excessETH_beforeWaitingEnds_returnsZero() public { | ||
vm.deal(address(treasury), 100 ether); | ||
dao.setAdjustedTotalSupply(1); | ||
setMeanPrice(1 ether); | ||
|
||
assertEq(excessETH.excessETH(), 0); | ||
} | ||
|
||
function test_excessETH_afterWaitingEnds_justETHInTreasury_works() public { | ||
vm.deal(address(treasury), 100 ether); | ||
dao.setAdjustedTotalSupply(1); | ||
setMeanPrice(1 ether); | ||
vm.warp(waitingPeriodEnd + 1); | ||
|
||
assertEq(excessETH.excessETH(), 99 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); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
packages/nouns-contracts/test/foundry/helpers/DeployUtilsExcessETH.sol
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,43 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity ^0.8.19; | ||
|
||
import 'forge-std/Test.sol'; | ||
import { DeployUtilsV3 } from './DeployUtilsV3.sol'; | ||
import { NounsDAOExecutorV3 } from '../../../contracts/governance/NounsDAOExecutorV3.sol'; | ||
import { ExcessETH, INounsAuctionHouseV2, INounsDAOV3 } from '../../../contracts/governance/ExcessETH.sol'; | ||
import { WETH } from '../../../contracts/test/WETH.sol'; | ||
import { ERC20Mock, RocketETHMock } from './ERC20Mock.sol'; | ||
import { ERC1967Proxy } from '@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol'; | ||
import { IERC20 } from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; | ||
|
||
abstract contract DeployUtilsExcessETH is DeployUtilsV3 { | ||
function _deployExecutorV3(address dao) internal returns (NounsDAOExecutorV3) { | ||
NounsDAOExecutorV3 executor = NounsDAOExecutorV3( | ||
payable(address(new ERC1967Proxy(address(new NounsDAOExecutorV3()), ''))) | ||
); | ||
executor.initialize(dao, TIMELOCK_DELAY); | ||
return executor; | ||
} | ||
|
||
function _deployExcessETH( | ||
NounsDAOExecutorV3 owner, | ||
INounsAuctionHouseV2 auction, | ||
uint256 waitingPeriodEnd, | ||
uint16 pastAuctionCount | ||
) internal returns (ExcessETH excessETH) { | ||
WETH weth = new WETH(); | ||
ERC20Mock stETH = new ERC20Mock(); | ||
RocketETHMock rETH = new RocketETHMock(); | ||
|
||
excessETH = new ExcessETH( | ||
address(owner), | ||
INounsDAOV3(owner.admin()), | ||
auction, | ||
IERC20(address(weth)), | ||
stETH, | ||
rETH, | ||
waitingPeriodEnd, | ||
pastAuctionCount | ||
); | ||
} | ||
} |
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