Skip to content

Commit

Permalink
Added test for Vaults with 0 yield
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasia committed Jul 12, 2024
1 parent fd4804a commit ff11f76
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
18 changes: 16 additions & 2 deletions packages/contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ forge build
forge test
```

### Advanced Testing
## Advanced Testing

1. Code Coverage Summary
```bash
Expand All @@ -51,4 +51,18 @@ forge test
2. ```bash
forge coverage --report lcov
genhtml lcov.info -o out/coverage
```
```

## Reset Submodules

Update each submodules to latest commit recorded
```bash
# run from project root dir
git submodule update --init --recursive
```

Reset the checked out commit for each submodule
```bash
cd packages/contracts/lib/<SUBMODULE>
git reset --hard HEAD
```
23 changes: 21 additions & 2 deletions packages/contracts/test/src/CredbullFixedYieldVaultTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ contract CredbullFixedYieldVaultTest is Test {
assertEq(vault.expectedAssetsOnMaturity(), expectedAssetValue);
}

function test__FixedYieldVault__ExpectedAssetOnMaturityZeroFixedYield() public {
params.promisedYield = 0; // zero fixed yield

CredbullFixedYieldVault zeroFixedYieldVault = new CredbullFixedYieldVault(params);

uint256 depositAmount = 10 * precision;
deposit(zeroFixedYieldVault, alice, depositAmount, false);

uint256 expectedAssetValue = depositAmount;
assertEq(zeroFixedYieldVault.expectedAssetsOnMaturity(), expectedAssetValue);
}

function test__FixedYieldVault__RevertMaturityToggleIfNotAdmin() public {
vm.startPrank(params.roles.operator);
vm.expectRevert(
Expand Down Expand Up @@ -295,16 +307,23 @@ contract CredbullFixedYieldVaultTest is Test {
}

function deposit(address user, uint256 assets, bool warp) internal returns (uint256 shares) {
return deposit(vault, user, assets, warp);
}

function deposit(CredbullFixedYieldVault fixedYieldVault, address user, uint256 assets, bool warp)
internal
returns (uint256 shares)
{
// first, approve the deposit
vm.startPrank(user);
params.maturityVault.vault.asset.approve(address(vault), assets);
params.maturityVault.vault.asset.approve(address(fixedYieldVault), assets);

// wrap if set to true
if (warp) {
vm.warp(params.windowPlugin.depositWindow.opensAt);
}

shares = vault.deposit(assets, user);
shares = fixedYieldVault.deposit(assets, user);
vm.stopPrank();
}
}

0 comments on commit ff11f76

Please sign in to comment.