Skip to content

Increase test Coverage #105

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

Merged
merged 1 commit into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ test-invariants:
# Coverage
coverage:
@forge coverage --report lcov
@lcov --ignore-errors unused --remove ./lcov.info -o ./lcov.info.pruned "test/*" "script/*"

coverage-html:
@make coverage
Expand Down
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ runs = 256
depth = 500
shrink_run_limit = 5_000
show_metrics = true
fail_on_revert = true
fail_on_revert = false

[dependencies]
"@openzeppelin-contracts" = "5.0.2"
Expand Down
49 changes: 48 additions & 1 deletion test/unit/OriginARM/ClaimRedeem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ contract Unit_Concrete_OriginARM_ClaimRedeem_Test_ is Unit_Shared_Test {
originARM.claimRedeem(0);
}

function test_ClaimRedeem() public requestRedeemAll(alice) timejump(CLAIM_DELAY) {
function test_ClaimRedeem_WithoutActiveMarket() public requestRedeemAll(alice) timejump(CLAIM_DELAY) {
uint256 balanceBefore = weth.balanceOf(alice);
// Alice claims her redeem
vm.prank(alice);
Expand All @@ -71,5 +71,52 @@ contract Unit_Concrete_OriginARM_ClaimRedeem_Test_ is Unit_Shared_Test {
assertEq(claimed, true, "Claimed should be true");
assertEq(originARM.withdrawsClaimed(), DEFAULT_AMOUNT, "Claimed amount should be DEFAULT_AMOUNT");
assertEq(weth.balanceOf(alice), balanceBefore + DEFAULT_AMOUNT, "Alice should receive her WETH");
assertEq(originARM.claimable(), DEFAULT_AMOUNT + MIN_TOTAL_SUPPLY, "Claimable should be updated");
}

function test_ClaimRedeem_WithActiveMarket_EnoughLiquidity()
public
setARMBuffer(1e18)
addMarket(address(market))
setActiveMarket(address(market))
requestRedeemAll(alice)
timejump(CLAIM_DELAY)
{
uint256 balanceBefore = weth.balanceOf(alice);
// Alice claims her redeem
vm.prank(alice);
vm.expectEmit(address(originARM));
emit AbstractARM.RedeemClaimed(alice, 0, DEFAULT_AMOUNT);
originARM.claimRedeem(0);

(, bool claimed,,,) = originARM.withdrawalRequests(0);
// Assertions
assertEq(claimed, true, "Claimed should be true");
assertEq(originARM.withdrawsClaimed(), DEFAULT_AMOUNT, "Claimed amount should be DEFAULT_AMOUNT");
assertEq(weth.balanceOf(alice), balanceBefore + DEFAULT_AMOUNT, "Alice should receive her WETH");
assertEq(originARM.claimable(), DEFAULT_AMOUNT + MIN_TOTAL_SUPPLY, "Claimable should be updated");
}

function test_ClaimRedeem_WithActiveMarket_NotEnoughLiquidity()
public
setARMBuffer(0)
addMarket(address(market))
setActiveMarket(address(market))
requestRedeemAll(alice)
timejump(CLAIM_DELAY)
{
uint256 balanceBefore = weth.balanceOf(alice);
// Alice claims her redeem
vm.prank(alice);
vm.expectEmit(address(originARM));
emit AbstractARM.RedeemClaimed(alice, 0, DEFAULT_AMOUNT);
originARM.claimRedeem(0);

(, bool claimed,,,) = originARM.withdrawalRequests(0);
// Assertions
assertEq(claimed, true, "Claimed should be true");
assertEq(originARM.withdrawsClaimed(), DEFAULT_AMOUNT, "Claimed amount should be DEFAULT_AMOUNT");
assertEq(weth.balanceOf(alice), balanceBefore + DEFAULT_AMOUNT, "Alice should receive her WETH");
assertEq(originARM.claimable(), DEFAULT_AMOUNT + MIN_TOTAL_SUPPLY, "Claimable should be updated");
}
}
3 changes: 3 additions & 0 deletions test/unit/OriginARM/Deposit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ contract Unit_Concrete_OriginARM_Deposit_Test_ is Unit_Shared_Test {
// Expected values
uint256 expectedShares = originARM.convertToShares(DEFAULT_AMOUNT);

uint256 previewDeposit = originARM.previewDeposit(DEFAULT_AMOUNT);
assertEq(previewDeposit, expectedShares, "Preview deposit should match expected shares");

// Expected event
vm.expectEmit(address(originARM));
emit AbstractARM.Deposit(alice, DEFAULT_AMOUNT, expectedShares);
Expand Down
22 changes: 21 additions & 1 deletion test/unit/OriginARM/ManageMarket.sol
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ contract Unit_Concrete_OriginARM_ManageMarket_Test_ is Unit_Shared_Test {
assertEq(originARM.activeMarket(), address(market2));
}

function test_SetActiveMarket_WithPreviousMarket_NonEmpty()
function test_SetActiveMarket_WithPreviousMarket_NonEmpty_NoShares()
public
addMarket(address(market))
setActiveMarket(address(market))
Expand All @@ -213,6 +213,26 @@ contract Unit_Concrete_OriginARM_ManageMarket_Test_ is Unit_Shared_Test {
assertEq(originARM.activeMarket(), address(market2));
}

function test_SetActiveMarket_WithPreviousMarket_NonEmpty_WithShares()
public
deposit(alice, DEFAULT_AMOUNT)
setARMBuffer(0)
addMarket(address(market))
setActiveMarket(address(market))
addMarket(address(market2))
asGovernor
{
// Assertions before
assertEq(originARM.activeMarket(), address(market));

vm.expectEmit(address(originARM));
emit AbstractARM.ActiveMarketUpdated(address(market2));
originARM.setActiveMarket(address(market2));

// Assertions after
assertEq(originARM.activeMarket(), address(market2));
}

function test_SetActiveMarket_ToPreviousMarket()
public
addMarket(address(market))
Expand Down
2 changes: 2 additions & 0 deletions test/unit/OriginARM/RequestRedeem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ contract Unit_Concrete_OriginARM_RequestRedeem_Test_ is Unit_Shared_Test {
uint256 requestIndex = originARM.nextWithdrawalIndex();
uint128 queued = originARM.withdrawsQueued();
int128 lastAvailableAssets = originARM.lastAvailableAssets();
uint256 previewRedeem = originARM.previewRedeem(DEFAULT_AMOUNT);
assertEq(previewRedeem, expectedShares, "Preview redeem should match expected shares");

// Expected event
vm.expectEmit(address(originARM));
Expand Down
11 changes: 11 additions & 0 deletions test/unit/OriginARM/TotalAssets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,15 @@ contract Unit_Concrete_OriginARM_TotalAssets_Test_ is Unit_Shared_Test {
{
assertEq(originARM.totalAssets(), MIN_TOTAL_SUPPLY, "Wrong total assets");
}

function test_TotalAssets_When_AssetIsLessThanOutstandingWithdrawals()
public
deposit(alice, DEFAULT_AMOUNT)
requestRedeemAll(alice)
{
// Simulate a loss on the ARM
deal(address(weth), address(originARM), 0);

assertEq(originARM.totalAssets(), MIN_TOTAL_SUPPLY, "Wrong total assets");
}
}