Skip to content

Commit

Permalink
fix: tests (#23)
Browse files Browse the repository at this point in the history
* fix: tests

* test: function collisions

* fix: oracle test

* forge install: tokenized-strategy-periphery

b1ed340316b891488195c3704c253f20c4da1373

* fix: modules
  • Loading branch information
Schlagonia authored Nov 28, 2023
1 parent 87d51bd commit f500a11
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 12 deletions.
98 changes: 98 additions & 0 deletions src/test/FunctionSignature.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.18;

import "forge-std/console.sol";

Check warning on line 4 in src/test/FunctionSignature.t.sol

View workflow job for this annotation

GitHub Actions / solidity

global import of path forge-std/console.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)
import {Setup, ERC20, IStrategyInterface} from "./utils/Setup.sol";

Check warning on line 5 in src/test/FunctionSignature.t.sol

View workflow job for this annotation

GitHub Actions / solidity

imported name IStrategyInterface is not used

contract FunctionSignatureTest is Setup {
function setUp() public virtual override {
super.setUp();
}

// This test should not be overridden and checks that
// no function signature collisions occurred from the custom functions.
// Does not check functions that are strategy dependant and will be checked in other tests
function test_functionCollisions() public {

Check warning on line 15 in src/test/FunctionSignature.t.sol

View workflow job for this annotation

GitHub Actions / solidity

Function body contains 81 lines but allowed no more than 50 lines

Check warning on line 15 in src/test/FunctionSignature.t.sol

View workflow job for this annotation

GitHub Actions / solidity

Function name must be in mixedCase
uint256 wad = 1e18;
vm.expectRevert("initialized");
strategy.init(
address(asset),
"name",
management,
performanceFeeRecipient,
keeper
);

// Check view functions
assertEq(strategy.convertToAssets(wad), wad, "convert to assets");
assertEq(strategy.convertToShares(wad), wad, "convert to shares");
assertEq(strategy.previewDeposit(wad), wad, "preview deposit");
assertEq(strategy.previewMint(wad), wad, "preview mint");
assertEq(strategy.previewWithdraw(wad), wad, "preview withdraw");
assertEq(strategy.previewRedeem(wad), wad, "preview redeem");
assertEq(strategy.totalAssets(), 0, "total assets");
assertEq(strategy.totalSupply(), 0, "total supply");
assertEq(strategy.unlockedShares(), 0, "unlocked shares");
assertEq(strategy.asset(), address(asset), "asset");
assertEq(strategy.apiVersion(), "3.0.1", "api");
assertEq(strategy.totalIdle(), 0, "idle");
assertEq(strategy.totalDebt(), 0, "debt");
assertEq(strategy.MAX_FEE(), 5_000, "max fee");
assertEq(strategy.MIN_FEE(), 500, "min fee");
assertEq(strategy.fullProfitUnlockDate(), 0, "unlock date");
assertEq(strategy.profitUnlockingRate(), 0, "unlock rate");
assertGt(strategy.lastReport(), 0, "last report");
assertEq(strategy.pricePerShare(), 10 ** asset.decimals(), "pps");
assertTrue(!strategy.isShutdown());
assertEq(
strategy.symbol(),
string(abi.encodePacked("ys", asset.symbol())),
"symbol"
);
assertEq(strategy.decimals(), asset.decimals(), "decimals");

// Assure modifiers are working
vm.startPrank(user);
vm.expectRevert("!management");
strategy.setPendingManagement(user);
vm.expectRevert("!pending");
strategy.acceptManagement();
vm.expectRevert("!management");
strategy.setKeeper(user);
vm.expectRevert("!management");
strategy.setEmergencyAdmin(user);
vm.expectRevert("!management");
strategy.setPerformanceFee(uint16(2_000));
vm.expectRevert("!management");
strategy.setPerformanceFeeRecipient(user);
vm.expectRevert("!management");
strategy.setProfitMaxUnlockTime(1);
vm.stopPrank();

// Assure checks are being used
vm.startPrank(strategy.management());
vm.expectRevert("MIN FEE");
strategy.setPerformanceFee(uint16(0));
vm.expectRevert("Cannot be self");
strategy.setPerformanceFeeRecipient(address(strategy));
vm.expectRevert("too long");
strategy.setProfitMaxUnlockTime(type(uint256).max);
vm.stopPrank();

// Mint some shares to the user
airdrop(ERC20(address(strategy)), user, wad);
assertEq(strategy.balanceOf(address(user)), wad, "balance");
vm.prank(user);
strategy.transfer(keeper, wad);
assertEq(strategy.balanceOf(user), 0, "second balance");
assertEq(strategy.balanceOf(keeper), wad, "keeper balance");
assertEq(strategy.allowance(keeper, user), 0, "allowance");
vm.prank(keeper);
assertTrue(strategy.approve(user, wad), "approval");
assertEq(strategy.allowance(keeper, user), wad, "second allowance");
vm.prank(user);
assertTrue(strategy.transferFrom(keeper, user, wad), "transfer from");
assertEq(strategy.balanceOf(user), wad, "second balance");
assertEq(strategy.balanceOf(keeper), 0, "keeper balance");
}
}
6 changes: 3 additions & 3 deletions src/test/Operation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
pragma solidity ^0.8.18;

import "forge-std/console.sol";

Check warning on line 4 in src/test/Operation.t.sol

View workflow job for this annotation

GitHub Actions / solidity

global import of path forge-std/console.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)
import {Setup} from "./utils/Setup.sol";
import {Setup, ERC20, IStrategyInterface} from "./utils/Setup.sol";

contract OperationTest is Setup {
function setUp() public override {
function setUp() public virtual override {
super.setUp();
}

function testSetupStrategyOK() public {
function test_setupStrategyOK() public {
console.log("address of strategy", address(strategy));
assertTrue(address(0) != address(strategy));
assertEq(strategy.asset(), address(asset));
Expand Down
13 changes: 7 additions & 6 deletions src/test/Oracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,19 @@ contract OracleTest is Setup {
// The apr should go up if deposits go down
assertLt(currentApr, negativeDebtChangeApr, "negative change");
uint256 positiveDebtChangeApr = oracle.aprAfterDebtChange(_strategy, _delta);
uint256 positiveDebtChangeApr = oracle.aprAfterDebtChange(_strategy, int256(_delta));
assertGt(currentApr, positiveDebtChangeApr, "positive change");
*/

// TODO: Uncomment if there are setter functions to test.
/**
vm.expectRevert("Ownable: caller is not the owner");
oracle.setterFunction(setterVariable, sender=user);
oracle.setterFunction(setterVariable, sender=management);
vm.expectRevert("!governance");
vm.prank(user);
oracle.setterFunction(setterVariable);
vm.prank(management);
oracle.setterFunction(setterVariable);
assertEq(oracle.setterVariable(), setterVariable);
*/
Expand All @@ -52,7 +54,6 @@ contract OracleTest is Setup {

mintAndDepositIntoStrategy(strategy, user, _amount);

// TODO: adjust the number to base _percentChange off of.
uint256 _delta = (_amount * _percentChange) / MAX_BPS;

checkOracle(address(strategy), _delta);
Expand Down
4 changes: 2 additions & 2 deletions src/test/Shutdown.t.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pragma solidity ^0.8.18;

import "forge-std/console.sol";
import {Setup} from "./utils/Setup.sol";
import {Setup, ERC20, IStrategyInterface} from "./utils/Setup.sol";

contract ShutdownTest is Setup {
function setUp() public override {
function setUp() public virtual override {
super.setUp();
}

Expand Down

0 comments on commit f500a11

Please sign in to comment.