Skip to content

Commit

Permalink
test: function collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlagonia committed Nov 16, 2023
1 parent 1610751 commit 1fdbc6c
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 1 deletion.
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");
}
}
2 changes: 1 addition & 1 deletion src/test/Operation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract OperationTest is Setup {
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

0 comments on commit 1fdbc6c

Please sign in to comment.