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

Test case optimization #41

Merged
merged 34 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9f6167f
test case optimization
TechnoGeek01 Feb 5, 2024
5d7fb59
Merge remote-tracking branch 'origin/dev' into test/optimization
TechnoGeek01 Feb 5, 2024
4095c72
test case optimization
TechnoGeek01 Feb 5, 2024
43bbd6e
test case optimization
TechnoGeek01 Feb 5, 2024
1d582b9
fix
TechnoGeek01 Feb 6, 2024
dfb123c
naming convention fix
TechnoGeek01 Feb 6, 2024
61b7d59
removed unnecessary fuzz in negative test cases
TechnoGeek01 Feb 6, 2024
3e014d6
rename and restructure of test cases
TechnoGeek01 Feb 6, 2024
ace463d
removed asserts and emit tests from deposit helper function and wrote…
TechnoGeek01 Feb 6, 2024
fc2a650
helper function optimization
TechnoGeek01 Feb 6, 2024
168e790
added camelot deposit test
TechnoGeek01 Feb 6, 2024
c068a42
cleanup
TechnoGeek01 Feb 6, 2024
134a4b2
added missing test contract inheritance
TechnoGeek01 Feb 6, 2024
91d60b5
rename
TechnoGeek01 Feb 6, 2024
6290c6f
remove unnecessary fuzz for negative cases
TechnoGeek01 Feb 6, 2024
5bcf284
fuzz functions rename
TechnoGeek01 Feb 6, 2024
1bee72d
update
TechnoGeek01 Feb 8, 2024
a092647
test optimization
TechnoGeek01 Feb 8, 2024
9412e17
Merge branch 'test/optimization' of https://github.com/Sperax/Demeter…
TechnoGeek01 Feb 8, 2024
78af9a9
optimization
TechnoGeek01 Feb 8, 2024
d904d7b
optimization
TechnoGeek01 Feb 9, 2024
21097ea
cleanup
TechnoGeek01 Feb 9, 2024
cfb78c7
optimization
TechnoGeek01 Feb 12, 2024
0a4fd8c
Merge remote-tracking branch 'origin/dev' into test/optimization
TechnoGeek01 Feb 12, 2024
2d21b12
rename
TechnoGeek01 Feb 12, 2024
4c09d51
Merge remote-tracking branch 'origin/dev' into test/optimization
parv3213 Feb 12, 2024
c404391
optimization
TechnoGeek01 Feb 12, 2024
8acdc50
rename
TechnoGeek01 Feb 12, 2024
236df94
cleanup
TechnoGeek01 Feb 12, 2024
6c701f7
update
TechnoGeek01 Feb 13, 2024
1d68764
rename revert tests for consistency
TechnoGeek01 Feb 13, 2024
51434d9
refactor(test): Remove redundant code from uniV3 test files
YashP16 Feb 14, 2024
41c14e8
refactor(contracts/BaseE20Farm): Remove redundancy in `recoverERC20` …
YashP16 Feb 14, 2024
8dbc579
refactor(test): Simplify test hierarchy
YashP16 Feb 14, 2024
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
26 changes: 15 additions & 11 deletions contracts/BaseFarm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,7 @@ abstract contract BaseFarm is BaseFarmStorage, Ownable, ReentrancyGuard, Initial
/// @notice Recover erc20 tokens other than the reward Tokens.
/// @param _token Address of token to be recovered.
function recoverERC20(address _token) external virtual onlyOwner nonReentrant {
if (rewardData[_token].tknManager != address(0)) {
revert CannotWithdrawRewardToken();
}

uint256 balance = IERC20(_token).balanceOf(address(this));
if (balance == 0) {
revert CannotWithdrawZeroAmount();
}

IERC20(_token).safeTransfer(msg.sender, balance);
emit RecoveredERC20(_token, balance);
_recoverE20(_token);
}

// --------------------- Token Manager Functions ---------------------
Expand Down Expand Up @@ -381,6 +371,20 @@ abstract contract BaseFarm is BaseFarmStorage, Ownable, ReentrancyGuard, Initial
return (supply - rewardsAcc);
}

function _recoverE20(address _token) internal {
if (rewardData[_token].tknManager != address(0)) {
revert CannotWithdrawRewardToken();
}

uint256 balance = IERC20(_token).balanceOf(address(this));
if (balance == 0) {
revert CannotWithdrawZeroAmount();
}

IERC20(_token).safeTransfer(msg.sender, balance);
emit RecoveredERC20(_token, balance);
YashP16 marked this conversation as resolved.
Show resolved Hide resolved
}

/// @notice Common logic for deposit in the demeter farm.
/// @param _account Address of the depositor.
/// @param _lockup Lockup option for the deposit.
Expand Down
15 changes: 3 additions & 12 deletions contracts/e20-farms/BaseE20Farm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract BaseE20Farm is BaseFarmWithExpiry, OperableDeposit {

// Custom Errors
error InvalidAmount();
error CannotWithdrawRewardTokenOrFarmToken();
error CannotWithdrawFarmToken();

/// @notice constructor
/// @param _farmStartTime - time of farm start
Expand Down Expand Up @@ -141,16 +141,7 @@ contract BaseE20Farm is BaseFarmWithExpiry, OperableDeposit {
/// @notice Recover erc20 tokens other than the reward Tokens and farm token.
/// @param _token Address of token to be recovered
function recoverERC20(address _token) external override onlyOwner nonReentrant {
if (rewardData[_token].tknManager != address(0) || _token == farmToken) {
revert CannotWithdrawRewardTokenOrFarmToken();
}

uint256 balance = IERC20(_token).balanceOf(address(this));
if (balance == 0) {
revert CannotWithdrawZeroAmount();
}

IERC20(_token).safeTransfer(owner(), balance);
emit RecoveredERC20(_token, balance);
if (_token == farmToken) revert CannotWithdrawFarmToken();
_recoverE20(_token);
}
}
Loading
Loading