Skip to content

Commit

Permalink
refactor(tests): separate tests by functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
0xChin committed Dec 4, 2024
1 parent 8223dad commit 127134c
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 349 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"test:arbitrum-sepolia": "TESTING=true FORKED_NETWORK=arbitrum-sepolia FORK_BLOCK=98684306 forge test -vvv ",
"test:base": "TESTING=true FORKED_NETWORK=base FORK_BLOCK=20648648 forge test -vvv ",
"test:bnb": "TESTING=true FORKED_NETWORK=bnb FORK_BLOCK=44138162 forge test -vvv ",
"test:fuzz": "echidna test/invariants/fuzz/Greeter.t.sol --contract InvariantGreeter --corpus-dir test/invariants/fuzz/echidna_coverage/ --test-mode assertion",
"test:optimism": "TESTING=true FORKED_NETWORK=optimism FORK_BLOCK=121238511 forge test -vvv ",
"test:optimism-sepolia": "TESTING=true FORKED_NETWORK=optimism-sepolia FORK_BLOCK=20113040 forge test -vvv ",
"test:polygon": "TESTING=true FORKED_NETWORK=polygon FORK_BLOCK=62103393 forge test -vvv ",
Expand Down
5 changes: 1 addition & 4 deletions src/contracts/Grateful.sol
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,7 @@ contract Grateful is IGrateful, Ownable2Step, ReentrancyGuard {
/// @inheritdoc IGrateful
function removeToken(
address _token
) external onlyOwner {
if (!tokensWhitelisted[_token]) {
revert Grateful_TokenOrVaultNotFound();
}
) external onlyOwner onlyWhenTokenWhitelisted(_token) {
delete tokensWhitelisted[_token];
IERC20 token = IERC20(_token);
token.forceApprove(address(aavePool), 0);
Expand Down
50 changes: 50 additions & 0 deletions test/unit/Deploy.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

// Grateful contract and related interfaces
import {Grateful, IGrateful} from "contracts/Grateful.sol";

// Aave V3 interfaces
import {IPool} from "yield-daddy/aave-v3/AaveV3ERC4626.sol";

// Base test contract
import {UnitBase} from "./helpers/Base.t.sol";

contract UnitDeploy is UnitBase {
// Test the constructor with valid arguments
function test_ConstructorWhenPassingValidArgs() public {
// Deploy the Grateful contract
grateful = new Grateful(tokens, IPool(address(aavePool)), initialFee, initialPerformanceFee, owner);

// Check that the Grateful contract is deployed correctly
assertEq(grateful.owner(), owner);
assertEq(address(grateful.aavePool()), address(aavePool));
assertEq(grateful.fee(), initialFee);
assertEq(grateful.performanceFee(), initialPerformanceFee);
assertEq(grateful.tokensWhitelisted(address(token)), true);
}

// Test the constructor with an invalid pool address
function test_ConstructorWhenPassingInvalidPoolAddress() public {
vm.expectRevert(abi.encodeWithSelector(IGrateful.Grateful_InvalidAddress.selector));
grateful = new Grateful(tokens, IPool(address(0)), initialFee, initialPerformanceFee, owner);
}

// Test the constructor with an invalid max fee
function test_ConstructorWhenPassingInvalidMaxFee(
uint256 invalidFee
) public {
vm.assume(invalidFee > grateful.MAX_FEE());
vm.expectRevert(abi.encodeWithSelector(IGrateful.Grateful_FeeRateTooHigh.selector));
grateful = new Grateful(tokens, IPool(address(aavePool)), invalidFee, initialPerformanceFee, owner);
}

// Test the constructor with an invalid max performance fee
function test_ConstructorWhenPassingInvalidMaxPerformanceFee(
uint256 invalidPerformanceFee
) public {
vm.assume(invalidPerformanceFee > grateful.MAX_PERFORMANCE_FEE());
vm.expectRevert(abi.encodeWithSelector(IGrateful.Grateful_FeeRateTooHigh.selector));
grateful = new Grateful(tokens, IPool(address(aavePool)), initialFee, invalidPerformanceFee, owner);
}
}
Loading

0 comments on commit 127134c

Please sign in to comment.