-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix exisiting unit tests #54
Changes from 7 commits
44eca76
ed1e49d
3753572
a9d6939
11a9740
92f348e
3498f74
d194fe8
e56aba1
2639471
d0491cf
f985eb1
af6bfed
f081366
35e910a
94cf5b9
aee7b5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,10 @@ import {MockUSDC} from "./mocks/MockUSDC.sol"; | |
import {Setup, ERC20, IStrategyInterface} from "./utils/Setup.sol"; | ||
import {Strategy} from "../Strategy.sol"; | ||
|
||
import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol"; | ||
import {TermDiscountRateAdapter} from "../TermDiscountRateAdapter.sol"; | ||
|
||
|
||
contract TestUSDCIntegration is Setup { | ||
uint256 internal constant TEST_REPO_TOKEN_RATE = 0.05e18; | ||
uint256 public constant THREESIXTY_DAYCOUNT_SECONDS = 360 days; | ||
|
@@ -150,6 +154,98 @@ contract TestUSDCIntegration is Setup { | |
assertTrue(offers[0] == offerId1 ? address(repoToken1WeekAuction) <= address(repoToken1MonthAuction) : address(repoToken1MonthAuction) <= address(repoToken1WeekAuction)); | ||
} | ||
|
||
function testRemovingMaturedTokensWithRedemptionAttempt() public { | ||
address testUser = vm.addr(0x11111); | ||
mockUSDC.mint(testUser, 1e18); | ||
repoToken1Month.mint(testUser, 1000e18); | ||
|
||
vm.startPrank(testUser); | ||
mockUSDC.approve(address(mockYearnVault), type(uint256).max); | ||
mockYearnVault.deposit(1e18, testUser); | ||
repoToken1Month.approve(address(strategy), type(uint256).max); | ||
termStrategy.sellRepoToken(address(repoToken1Month), 1e6); | ||
vm.stopPrank(); | ||
|
||
address[] memory holdings = termStrategy.repoTokenHoldings(); | ||
assertEq(holdings.length, 1); | ||
|
||
|
||
vm.warp(block.timestamp + 5 weeks); | ||
termStrategy.auctionClosed(); | ||
|
||
holdings = termStrategy.repoTokenHoldings(); | ||
assertEq(holdings.length, 0); | ||
assertEq(repoToken1Month.balanceOf(address(strategy)), 0); | ||
} | ||
|
||
function testRepoTokenBlacklist() public { | ||
address testUser = vm.addr(0x11111); | ||
vm.prank(testUser); | ||
vm.expectRevert("!management"); | ||
termStrategy.setRepoTokenBlacklist(address(repoToken1Week), true); | ||
vm.stopPrank(); | ||
|
||
vm.prank(management); | ||
termStrategy.setRepoTokenBlacklist(address(repoToken1Week), true); | ||
vm.stopPrank(); | ||
|
||
vm.prank(testUser); | ||
vm.expectRevert(abi.encodeWithSelector(Strategy.RepoTokenBlacklisted.selector, address(repoToken1Week))); | ||
termStrategy.sellRepoToken(address(repoToken1Week), 1e6); | ||
} | ||
|
||
function testPauses() public { | ||
address testUser = vm.addr(0x11111); | ||
mockUSDC.mint(testUser, 1e18); | ||
vm.prank(testUser); | ||
vm.expectRevert("!management"); | ||
termStrategy.pauseDeposit(); | ||
vm.expectRevert("!management"); | ||
termStrategy.unpauseDeposit(); | ||
vm.stopPrank(); | ||
|
||
vm.prank(management); | ||
termStrategy.pauseDeposit(); | ||
vm.stopPrank(); | ||
|
||
vm.prank(testUser); | ||
mockUSDC.approve(address(termStrategy), 1e6); | ||
|
||
vm.prank(testUser); | ||
vm.expectRevert(abi.encodeWithSelector(Strategy.DepositPaused.selector)); | ||
IERC4626(address(termStrategy)).deposit(1e6, testUser); | ||
vm.stopPrank(); | ||
|
||
vm.prank(management); | ||
termStrategy.unpauseDeposit(); | ||
vm.stopPrank(); | ||
|
||
vm.prank(testUser); | ||
IERC4626(address(termStrategy)).deposit(1e6, testUser); | ||
vm.stopPrank(); | ||
} | ||
|
||
function testSetDiscountRateAdapter() public { | ||
address testUser = vm.addr(0x11111); | ||
|
||
TermDiscountRateAdapter invalid = new TermDiscountRateAdapter(address(0), adminWallet); | ||
TermDiscountRateAdapter valid = new TermDiscountRateAdapter(address(termController), adminWallet); | ||
|
||
vm.prank(testUser); | ||
vm.expectRevert("!management"); | ||
termStrategy.setDiscountRateAdapter(address(valid)); | ||
|
||
vm.prank(management); | ||
vm.expectRevert(); | ||
termStrategy.setDiscountRateAdapter(address(invalid)); | ||
Comment on lines
+361
to
+362
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specify expected revert reason in In the test Apply this diff to specify the expected revert reason: vm.prank(management);
-vm.expectRevert();
+vm.expectRevert("InvalidTermAdapter(address)");
termStrategy.setDiscountRateAdapter(address(invalid)); Replace
|
||
|
||
vm.prank(management); | ||
termStrategy.setDiscountRateAdapter(address(valid)); | ||
vm.stopPrank(); | ||
|
||
assertEq(address(valid), address(termStrategy.discountRateAdapter())); | ||
} | ||
|
||
function _getRepoTokenAmountGivenPurchaseTokenAmount( | ||
uint256 purchaseTokenAmount, | ||
MockTermRepoToken termRepoToken, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-License-Identifier: AGPL-3.0 | ||
pragma solidity ^0.8.18; | ||
|
||
import {MockFactory} from "@tokenized-strategy/test/mocks/MockFactory.sol"; | ||
|
||
contract MockFeesFactory is MockFactory { | ||
address public governance; | ||
|
||
constructor(uint16 bps, address treasury) MockFactory(bps, treasury) { | ||
governance = msg.sender; | ||
} | ||
Comment on lines
+9
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider adding parameter validation and review governance initialization. The constructor implementation is generally correct, but consider the following suggestions:
Here's a potential refactor to address these points: constructor(uint16 bps, address treasury, address _governance) MockFactory(bps, treasury) {
require(bps > 0 && bps <= 10000, "Invalid bps value");
require(treasury != address(0), "Invalid treasury address");
require(_governance != address(0), "Invalid governance address");
governance = _governance;
} This refactor adds basic validation and allows for explicit setting of the governance address. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
pragma solidity ^0.8.18; | ||
|
||
import {ITermAuction} from "../../interfaces/term/ITermAuction.sol"; | ||
import {ITermAuctionOfferLocker} from "../../interfaces/term/ITermAuctionOfferLocker.sol"; | ||
import {ITermRepoToken} from "../../interfaces/term/ITermRepoToken.sol"; | ||
import {ITermRepoServicer} from "../../interfaces/term/ITermRepoServicer.sol"; | ||
import {MockTermAuctionOfferLocker} from "./MockTermAuctionOfferLocker.sol"; | ||
|
@@ -45,7 +46,24 @@ contract MockTermAuction is ITermAuction { | |
} | ||
} | ||
|
||
function auctionCanceled() external { | ||
function auctionCancelForWithdrawal() external { | ||
auctionCancelledForWithdrawal = true; | ||
} | ||
Comment on lines
+49
to
51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add access control to The |
||
|
||
function auctionCancel(bytes32[] calldata offerIds) external { | ||
|
||
uint256 i = 0; | ||
// Return revealed offer funds. | ||
for (i = 0; i < offerIds.length; ++i) { | ||
ITermAuctionOfferLocker.TermAuctionOffer memory offer = MockTermAuctionOfferLocker(termAuctionOfferLocker).lockedOffer(offerIds[i]); | ||
|
||
MockTermAuctionOfferLocker(termAuctionOfferLocker).unlockOfferPartial( | ||
offer.id, | ||
offer.offeror, | ||
offer.amount | ||
); | ||
} | ||
|
||
|
||
} | ||
Comment on lines
+53
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add access control to The |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add redemption attempt to match the test function name
The test function
testRemovingMaturedTokensWithRedemptionAttempt
does not include an attempt to redeem the matured tokens, despite the implication in its name. Consider adding logic to attempt redemption and verify the outcome to fully cover the intended scenario.Apply this diff to include the redemption attempt:
Replace
expectedRedeemedAmount
with the expected amount after redemption.