Skip to content
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

Complete testing suit #175

Merged
merged 4 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions test/forge/MarketTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ contract MarketTest is BaseTest {
vault.submitCap(marketParams, 0);
}

function testSubmitCapAlreadySet() public {
_setCap(allMarkets[0], CAP);

vm.prank(RISK_MANAGER);
vm.expectRevert(ErrorsLib.AlreadySet.selector);
vault.submitCap(allMarkets[0], CAP);
}

function testSetSupplyQueue() public {
_setCap(allMarkets[0], CAP);
_setCap(allMarkets[1], CAP);
Expand All @@ -57,6 +65,16 @@ contract MarketTest is BaseTest {
assertEq(Id.unwrap(vault.supplyQueue(1)), Id.unwrap(allMarkets[2].id()));
}

function testSetSupplyQueueUnauthorizedMarket() public {
Id[] memory supplyQueue = new Id[](2);
supplyQueue[0] = allMarkets[0].id();
supplyQueue[1] = allMarkets[1].id();
Jean-Grimal marked this conversation as resolved.
Show resolved Hide resolved

vm.prank(ALLOCATOR);
vm.expectRevert(abi.encodeWithSelector(ErrorsLib.UnauthorizedMarket.selector, allMarkets[0].id()));
vault.setSupplyQueue(supplyQueue);
}

function testSortWithdrawQueue() public {
_setCap(allMarkets[0], CAP);
_setCap(allMarkets[1], CAP);
Expand All @@ -79,6 +97,28 @@ contract MarketTest is BaseTest {
assertEq(Id.unwrap(vault.withdrawQueue(2)), Id.unwrap(allMarkets[0].id()));
}

function testSortWithdrawQueueRemovingDisabledMarket() public {
_setCap(allMarkets[0], CAP);
_setCap(allMarkets[1], CAP);
_setCap(allMarkets[2], CAP);
Jean-Grimal marked this conversation as resolved.
Show resolved Hide resolved

assertEq(Id.unwrap(vault.withdrawQueue(0)), Id.unwrap(allMarkets[0].id()));
assertEq(Id.unwrap(vault.withdrawQueue(1)), Id.unwrap(allMarkets[1].id()));
assertEq(Id.unwrap(vault.withdrawQueue(2)), Id.unwrap(allMarkets[2].id()));

_setCap(allMarkets[2], 0);

uint256[] memory indexes = new uint256[](2);
indexes[0] = 1;
indexes[1] = 0;

vm.prank(ALLOCATOR);
vault.sortWithdrawQueue(indexes);

assertEq(Id.unwrap(vault.withdrawQueue(0)), Id.unwrap(allMarkets[1].id()));
assertEq(Id.unwrap(vault.withdrawQueue(1)), Id.unwrap(allMarkets[0].id()));
MerlinEgalite marked this conversation as resolved.
Show resolved Hide resolved
}

function testSortWithdrawQueueInvalidIndex() public {
_setCap(allMarkets[0], CAP);
_setCap(allMarkets[1], CAP);
Expand Down
46 changes: 46 additions & 0 deletions test/forge/ReallocateWithdrawTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ contract ReallocateWithdrawTest is BaseTest {
assertEq(vault.idle(), INITIAL_DEPOSIT, "vault.idle() 1");
}

function testReallocateWithdrawMax() public {
withdrawn.push(MarketAllocation(allMarkets[0], 0, type(uint256).max));
withdrawn.push(MarketAllocation(allMarkets[1], 0, type(uint256).max));
withdrawn.push(MarketAllocation(allMarkets[2], 0, type(uint256).max));

vm.prank(ALLOCATOR);
vault.reallocate(withdrawn, supplied);

assertEq(morpho.supplyShares(allMarkets[0].id(), address(vault)), 0, "morpho.supplyShares(0)");
assertEq(morpho.supplyShares(allMarkets[1].id(), address(vault)), 0, "morpho.supplyShares(1)");
assertEq(morpho.supplyShares(allMarkets[2].id(), address(vault)), 0, "morpho.supplyShares(2)");
assertEq(vault.idle(), INITIAL_DEPOSIT, "vault.idle() 1");
}

function testReallocateWithdrawInconsistentAsset() public {
allMarkets[0].loanToken = address(1);

Expand Down Expand Up @@ -133,4 +147,36 @@ contract ReallocateWithdrawTest is BaseTest {
);
assertApproxEqAbs(vault.idle(), expectedIdle, 1, "vault.idle() 1");
}

function testReallocateSupplyCapExceeded() public {
withdrawn.push(MarketAllocation(allMarkets[0], 0, type(uint256).max));
withdrawn.push(MarketAllocation(allMarkets[1], 0, type(uint256).max));
withdrawn.push(MarketAllocation(allMarkets[2], 0, type(uint256).max));

supplied.push(MarketAllocation(allMarkets[0], CAP2 + 1, 0));

vm.prank(ALLOCATOR);
vm.expectRevert(abi.encodeWithSelector(ErrorsLib.SupplyCapExceeded.selector, allMarkets[0].id()));
vault.reallocate(withdrawn, supplied);
}

function testReallocateInsufficientIdle(uint256 rewards) public {
rewards = bound(rewards, 1, MAX_TEST_ASSETS);

address rewardDonator = _addrFromHashedString("reward donator");
loanToken.setBalance(rewardDonator, rewards);
vm.prank(rewardDonator);
loanToken.transfer(address(vault), rewards);

console2.log(rewards, "rewards");
console2.log(loanToken.balanceOf(address(vault)), "loanToken.balanceOf(address(vault))");
Jean-Grimal marked this conversation as resolved.
Show resolved Hide resolved

_setCap(allMarkets[0], type(uint192).max);

supplied.push(MarketAllocation(allMarkets[0], CAP2 + rewards, 0));
MerlinEgalite marked this conversation as resolved.
Show resolved Hide resolved

vm.prank(ALLOCATOR);
vm.expectRevert(ErrorsLib.InsufficientIdle.selector);
vault.reallocate(withdrawn, supplied);
}
}