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: refactor fork tests to use a shared contract #1179

Merged
merged 5 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"func-visibility": ["error", { "ignoreConstructors": true }],
"gas-custom-errors": "off",
"max-states-count": ["warn", 20],
"max-line-length": ["error", 124],
"max-line-length": ["error", 130],
"named-parameters-mapping": "warn",
"no-empty-blocks": "off",
"not-rely-on-time": "off",
Expand Down
20 changes: 10 additions & 10 deletions src/libraries/StreamingMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,16 @@ library StreamingMath {
return 0;
}

// If the end time is not in the future, return the deposited amount.
if (timestamps.end <= blockTimestamp) {
return depositedAmount;
}

// If the cliff time is in the future, return the start unlock amount.
if (cliffTime > blockTimestamp) {
return unlockAmounts.start;
}

// If the end time is not in the future, return the deposited amount.
if (timestamps.end <= blockTimestamp) {
return depositedAmount;
}

unchecked {
uint128 unlockAmountsSum = unlockAmounts.start + unlockAmounts.cliff;

Expand Down Expand Up @@ -231,16 +231,16 @@ library StreamingMath {
return 0;
}

// If the end time is not in the future, return the deposited amount.
if (timestamps.end <= blockTimestamp) {
return depositedAmount;
}

// If the first tranche's timestamp is in the future, return zero.
if (tranches[0].timestamp > blockTimestamp) {
return 0;
}

// If the end time is not in the future, return the deposited amount.
if (timestamps.end <= blockTimestamp) {
return depositedAmount;
}

// Sum the amounts in all tranches that have already been streamed.
// Using unchecked arithmetic is safe because the sum of the tranche amounts is equal to the total amount
// at this point.
Expand Down
14 changes: 10 additions & 4 deletions tests/fork/Fork.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import { Base_Test } from "./../Base.t.sol";

/// @notice Common logic needed by all fork tests.
/// @notice Base logic needed by the fork tests.
abstract contract Fork_Test is Base_Test {
/*//////////////////////////////////////////////////////////////////////////
STATE VARIABLES
//////////////////////////////////////////////////////////////////////////*/

IERC20 internal immutable FORK_TOKEN;
address internal forkTokenHolder;
uint256 internal initialHolderBalance;
uint128 internal initialHolderBalance;

/*//////////////////////////////////////////////////////////////////////////
CONSTRUCTOR
Expand Down Expand Up @@ -45,11 +45,14 @@ abstract contract Fork_Test is Base_Test {
// Label the addresses.
labelContracts();

// Deal token balance to the user.
initialHolderBalance = 1e7 * 10 ** IERC20Metadata(address(FORK_TOKEN)).decimals();
// Deal 1M tokens to the user.
initialHolderBalance = uint128(1e6 * (10 ** IERC20Metadata(address(FORK_TOKEN)).decimals()));
deal({ token: address(FORK_TOKEN), to: forkTokenHolder, give: initialHolderBalance });

resetPrank({ msgSender: forkTokenHolder });

// Approve {SablierLockup} to transfer the holder's tokens.
approveContract({ token_: address(FORK_TOKEN), from: forkTokenHolder, spender: address(lockup) });
}

/*//////////////////////////////////////////////////////////////////////////
Expand All @@ -69,6 +72,9 @@ abstract contract Fork_Test is Base_Test {
// Avoid users blacklisted by USDC or USDT.
assumeNoBlacklisted(address(FORK_TOKEN), sender);
assumeNoBlacklisted(address(FORK_TOKEN), recipient);

// Make the holder the caller.
resetPrank(forkTokenHolder);
}

/// @dev Labels the most relevant addresses.
Expand Down
Loading
Loading