Skip to content

Commit

Permalink
test(fork): rename ASSET to FORK_ASSET (#969)
Browse files Browse the repository at this point in the history
* [Implement] issues #900 - Rename ASSET to FORK_ASSET in Fork.t.sol

* [Fix] lint / forge-lint CLI  tests

* Update test/fork/Fork.t.sol

Co-authored-by: smol-ninja <[email protected]>

* Update test/fork/Fork.t.sol

Co-authored-by: smol-ninja <[email protected]>

* Update test/fork/Fork.t.sol

Co-authored-by: smol-ninja <[email protected]>

* Update test/fork/LockupDynamic.t.sol

Co-authored-by: smol-ninja <[email protected]>

* Update test/fork/LockupLinear.t.sol

Co-authored-by: smol-ninja <[email protected]>

* Update test/fork/LockupTranched.t.sol

Co-authored-by: smol-ninja <[email protected]>

---------

Co-authored-by: smol-ninja <[email protected]>
  • Loading branch information
EbiPenMan and smol-ninja authored Jul 19, 2024
1 parent 199b3f8 commit fe60d98
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 89 deletions.
32 changes: 16 additions & 16 deletions test/fork/Fork.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ abstract contract Fork_Test is Base_Test {
STATE VARIABLES
//////////////////////////////////////////////////////////////////////////*/

IERC20 internal immutable ASSET;
address internal immutable HOLDER;
IERC20 internal immutable FORK_ASSET;
address internal immutable FORK_ASSET_HOLDER;
uint256 internal initialHolderBalance;

/*//////////////////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////////////////*/

constructor(IERC20 asset, address holder) {
ASSET = asset;
HOLDER = holder;
constructor(IERC20 forkAsset, address forkAssetHolder) {
FORK_ASSET = forkAsset;
FORK_ASSET_HOLDER = forkAssetHolder;
}

/*//////////////////////////////////////////////////////////////////////////
Expand All @@ -39,11 +39,11 @@ abstract contract Fork_Test is Base_Test {
// Label the contracts.
labelContracts();

// Make the ASSET HOLDER the caller in this test suite.
resetPrank({ msgSender: HOLDER });
// Make the forked asset holder the caller in this test suite.
resetPrank({ msgSender: FORK_ASSET_HOLDER });

// Query the initial balance of the ASSET HOLDER.
initialHolderBalance = ASSET.balanceOf(HOLDER);
// Query the initial balance of the forked asset holder.
initialHolderBalance = FORK_ASSET.balanceOf(FORK_ASSET_HOLDER);
}

/*//////////////////////////////////////////////////////////////////////////
Expand All @@ -55,20 +55,20 @@ abstract contract Fork_Test is Base_Test {
// The protocol does not allow the zero address to interact with it.
vm.assume(sender != address(0) && recipient != address(0) && broker != address(0));

// The goal is to not have overlapping users because the ASSET balance tests would fail otherwise.
// The goal is to not have overlapping users because the forked asset balance tests would fail otherwise.
vm.assume(sender != recipient && sender != broker && recipient != broker);
vm.assume(sender != HOLDER && recipient != HOLDER && broker != HOLDER);
vm.assume(sender != FORK_ASSET_HOLDER && recipient != FORK_ASSET_HOLDER && broker != FORK_ASSET_HOLDER);
vm.assume(sender != sablierContract && recipient != sablierContract && broker != sablierContract);

// Avoid users blacklisted by USDC or USDT.
assumeNoBlacklisted(address(ASSET), sender);
assumeNoBlacklisted(address(ASSET), recipient);
assumeNoBlacklisted(address(ASSET), broker);
assumeNoBlacklisted(address(FORK_ASSET), sender);
assumeNoBlacklisted(address(FORK_ASSET), recipient);
assumeNoBlacklisted(address(FORK_ASSET), broker);
}

/// @dev Labels the most relevant contracts.
function labelContracts() internal {
vm.label({ account: address(ASSET), newLabel: IERC20Metadata(address(ASSET)).symbol() });
vm.label({ account: HOLDER, newLabel: "HOLDER" });
vm.label({ account: address(FORK_ASSET), newLabel: IERC20Metadata(address(FORK_ASSET)).symbol() });
vm.label({ account: FORK_ASSET_HOLDER, newLabel: "FORK_ASSET_HOLDER" });
}
}
34 changes: 18 additions & 16 deletions test/fork/LockupDynamic.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract contract LockupDynamic_Fork_Test is Fork_Test {
CONSTRUCTOR
//////////////////////////////////////////////////////////////////////////*/

constructor(IERC20 asset, address holder) Fork_Test(asset, holder) { }
constructor(IERC20 forkAsset, address forkAssetHolder) Fork_Test(forkAsset, forkAssetHolder) { }

/*//////////////////////////////////////////////////////////////////////////
SET-UP FUNCTION
Expand All @@ -24,7 +24,8 @@ abstract contract LockupDynamic_Fork_Test is Fork_Test {

// Approve {SablierV2LockupDynamic} to transfer the holder's assets.
// We use a low-level call to ignore reverts because the asset can have the missing return value bug.
(bool success,) = address(ASSET).call(abi.encodeCall(IERC20.approve, (address(lockupDynamic), MAX_UINT256)));
(bool success,) =
address(FORK_ASSET).call(abi.encodeCall(IERC20.approve, (address(lockupDynamic), MAX_UINT256)));
success;
}

Expand Down Expand Up @@ -124,15 +125,15 @@ abstract contract LockupDynamic_Fork_Test is Fork_Test {
});

// Make the holder the caller.
resetPrank(HOLDER);
resetPrank(FORK_ASSET_HOLDER);

/*//////////////////////////////////////////////////////////////////////////
CREATE
//////////////////////////////////////////////////////////////////////////*/

// Load the pre-create asset balances.
vars.balances =
getTokenBalances(address(ASSET), Solarray.addresses(address(lockupDynamic), params.broker.account));
getTokenBalances(address(FORK_ASSET), Solarray.addresses(address(lockupDynamic), params.broker.account));
vars.initialLockupDynamicBalance = vars.balances[0];
vars.initialBrokerBalance = vars.balances[1];

Expand All @@ -148,11 +149,11 @@ abstract contract LockupDynamic_Fork_Test is Fork_Test {
vm.expectEmit({ emitter: address(lockupDynamic) });
emit CreateLockupDynamicStream({
streamId: vars.streamId,
funder: HOLDER,
funder: FORK_ASSET_HOLDER,
sender: params.sender,
recipient: params.recipient,
amounts: vars.createAmounts,
asset: ASSET,
asset: FORK_ASSET,
cancelable: true,
transferable: true,
segments: params.segments,
Expand All @@ -166,7 +167,7 @@ abstract contract LockupDynamic_Fork_Test is Fork_Test {
sender: params.sender,
recipient: params.recipient,
totalAmount: vars.totalAmount,
asset: ASSET,
asset: FORK_ASSET,
cancelable: true,
transferable: true,
startTime: params.startTime,
Expand All @@ -183,7 +184,7 @@ abstract contract LockupDynamic_Fork_Test is Fork_Test {
// Assert that the stream has been created.
LockupDynamic.StreamLD memory actualStream = lockupDynamic.getStream(vars.streamId);
assertEq(actualStream.amounts, Lockup.Amounts(vars.createAmounts.deposit, 0, 0));
assertEq(actualStream.asset, ASSET, "asset");
assertEq(actualStream.asset, FORK_ASSET, "asset");
assertEq(actualStream.endTime, vars.timestamps.end, "endTime");
assertEq(actualStream.isCancelable, vars.isCancelable, "isCancelable");
assertEq(actualStream.isDepleted, false, "isDepleted");
Expand Down Expand Up @@ -217,8 +218,9 @@ abstract contract LockupDynamic_Fork_Test is Fork_Test {
assertEq(vars.actualNFTOwner, vars.expectedNFTOwner, "post-create NFT owner");

// Load the post-create asset balances.
vars.balances =
getTokenBalances(address(ASSET), Solarray.addresses(address(lockupDynamic), HOLDER, params.broker.account));
vars.balances = getTokenBalances(
address(FORK_ASSET), Solarray.addresses(address(lockupDynamic), FORK_ASSET_HOLDER, params.broker.account)
);
vars.actualLockupDynamicBalance = vars.balances[0];
vars.actualHolderBalance = vars.balances[1];
vars.actualBrokerBalance = vars.balances[2];
Expand Down Expand Up @@ -261,14 +263,14 @@ abstract contract LockupDynamic_Fork_Test is Fork_Test {
if (params.withdrawAmount > 0) {
// Load the pre-withdraw asset balances.
vars.initialLockupDynamicBalance = vars.actualLockupDynamicBalance;
vars.initialRecipientBalance = ASSET.balanceOf(params.recipient);
vars.initialRecipientBalance = FORK_ASSET.balanceOf(params.recipient);

// Expect the relevant events to be emitted.
vm.expectEmit({ emitter: address(lockupDynamic) });
emit WithdrawFromLockupStream({
streamId: vars.streamId,
to: params.recipient,
asset: ASSET,
asset: FORK_ASSET,
amount: params.withdrawAmount
});
vm.expectEmit({ emitter: address(lockupDynamic) });
Expand Down Expand Up @@ -296,7 +298,7 @@ abstract contract LockupDynamic_Fork_Test is Fork_Test {

// Load the post-withdraw asset balances.
vars.balances =
getTokenBalances(address(ASSET), Solarray.addresses(address(lockupDynamic), params.recipient));
getTokenBalances(address(FORK_ASSET), Solarray.addresses(address(lockupDynamic), params.recipient));
vars.actualLockupDynamicBalance = vars.balances[0];
vars.actualRecipientBalance = vars.balances[1];

Expand All @@ -321,7 +323,7 @@ abstract contract LockupDynamic_Fork_Test is Fork_Test {
if (!vars.isDepleted && !vars.isSettled) {
// Load the pre-cancel asset balances.
vars.balances = getTokenBalances(
address(ASSET), Solarray.addresses(address(lockupDynamic), params.sender, params.recipient)
address(FORK_ASSET), Solarray.addresses(address(lockupDynamic), params.sender, params.recipient)
);
vars.initialLockupDynamicBalance = vars.balances[0];
vars.initialSenderBalance = vars.balances[1];
Expand All @@ -332,7 +334,7 @@ abstract contract LockupDynamic_Fork_Test is Fork_Test {
vars.senderAmount = lockupDynamic.refundableAmountOf(vars.streamId);
vars.recipientAmount = lockupDynamic.withdrawableAmountOf(vars.streamId);
emit CancelLockupStream(
vars.streamId, params.sender, params.recipient, ASSET, vars.senderAmount, vars.recipientAmount
vars.streamId, params.sender, params.recipient, FORK_ASSET, vars.senderAmount, vars.recipientAmount
);
vm.expectEmit({ emitter: address(lockupDynamic) });
emit MetadataUpdate({ _tokenId: vars.streamId });
Expand All @@ -348,7 +350,7 @@ abstract contract LockupDynamic_Fork_Test is Fork_Test {

// Load the post-cancel asset balances.
vars.balances = getTokenBalances(
address(ASSET), Solarray.addresses(address(lockupDynamic), params.sender, params.recipient)
address(FORK_ASSET), Solarray.addresses(address(lockupDynamic), params.sender, params.recipient)
);
vars.actualLockupDynamicBalance = vars.balances[0];
vars.actualSenderBalance = vars.balances[1];
Expand Down
33 changes: 17 additions & 16 deletions test/fork/LockupLinear.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract contract LockupLinear_Fork_Test is Fork_Test {
CONSTRUCTOR
//////////////////////////////////////////////////////////////////////////*/

constructor(IERC20 asset, address holder) Fork_Test(asset, holder) { }
constructor(IERC20 forkAsset, address forkAssetHolder) Fork_Test(forkAsset, forkAssetHolder) { }

/*//////////////////////////////////////////////////////////////////////////
SET-UP FUNCTION
Expand All @@ -25,7 +25,7 @@ abstract contract LockupLinear_Fork_Test is Fork_Test {

// Approve {SablierV2LockupLinear} to transfer the asset holder's assets.
// We use a low-level call to ignore reverts because the asset can have the missing return value bug.
(bool success,) = address(ASSET).call(abi.encodeCall(IERC20.approve, (address(lockupLinear), MAX_UINT256)));
(bool success,) = address(FORK_ASSET).call(abi.encodeCall(IERC20.approve, (address(lockupLinear), MAX_UINT256)));
success;
}

Expand Down Expand Up @@ -134,15 +134,15 @@ abstract contract LockupLinear_Fork_Test is Fork_Test {
boundUint40(params.timestamps.end, vars.endTimeLowerBound + 1 seconds, MAX_UNIX_TIMESTAMP);

// Make the holder the caller.
resetPrank(HOLDER);
resetPrank(FORK_ASSET_HOLDER);

/*//////////////////////////////////////////////////////////////////////////
CREATE
//////////////////////////////////////////////////////////////////////////*/

// Load the pre-create asset balances.
vars.balances =
getTokenBalances(address(ASSET), Solarray.addresses(address(lockupLinear), params.broker.account));
getTokenBalances(address(FORK_ASSET), Solarray.addresses(address(lockupLinear), params.broker.account));
vars.initialLockupLinearBalance = vars.balances[0];
vars.initialBrokerBalance = vars.balances[1];

Expand All @@ -158,11 +158,11 @@ abstract contract LockupLinear_Fork_Test is Fork_Test {
vm.expectEmit({ emitter: address(lockupLinear) });
emit CreateLockupLinearStream({
streamId: vars.streamId,
funder: HOLDER,
funder: FORK_ASSET_HOLDER,
sender: params.sender,
recipient: params.recipient,
amounts: vars.createAmounts,
asset: ASSET,
asset: FORK_ASSET,
cancelable: true,
transferable: true,
timestamps: params.timestamps,
Expand All @@ -175,7 +175,7 @@ abstract contract LockupLinear_Fork_Test is Fork_Test {
sender: params.sender,
recipient: params.recipient,
totalAmount: params.totalAmount,
asset: ASSET,
asset: FORK_ASSET,
cancelable: true,
transferable: true,
timestamps: params.timestamps,
Expand All @@ -186,7 +186,7 @@ abstract contract LockupLinear_Fork_Test is Fork_Test {
// Assert that the stream has been created.
LockupLinear.StreamLL memory actualStream = lockupLinear.getStream(vars.streamId);
assertEq(actualStream.amounts, Lockup.Amounts(vars.createAmounts.deposit, 0, 0));
assertEq(actualStream.asset, ASSET, "asset");
assertEq(actualStream.asset, FORK_ASSET, "asset");
assertEq(actualStream.cliffTime, params.timestamps.cliff, "cliffTime");
assertEq(actualStream.endTime, params.timestamps.end, "endTime");
assertEq(actualStream.isCancelable, true, "isCancelable");
Expand Down Expand Up @@ -215,8 +215,9 @@ abstract contract LockupLinear_Fork_Test is Fork_Test {
assertEq(vars.actualNFTOwner, vars.expectedNFTOwner, "post-create NFT owner");

// Load the post-create asset balances.
vars.balances =
getTokenBalances(address(ASSET), Solarray.addresses(address(lockupLinear), HOLDER, params.broker.account));
vars.balances = getTokenBalances(
address(FORK_ASSET), Solarray.addresses(address(lockupLinear), FORK_ASSET_HOLDER, params.broker.account)
);
vars.actualLockupLinearBalance = vars.balances[0];
vars.actualHolderBalance = vars.balances[1];
vars.actualBrokerBalance = vars.balances[2];
Expand Down Expand Up @@ -258,14 +259,14 @@ abstract contract LockupLinear_Fork_Test is Fork_Test {
if (params.withdrawAmount > 0) {
// Load the pre-withdraw asset balances.
vars.initialLockupLinearBalance = vars.actualLockupLinearBalance;
vars.initialRecipientBalance = ASSET.balanceOf(params.recipient);
vars.initialRecipientBalance = FORK_ASSET.balanceOf(params.recipient);

// Expect the relevant events to be emitted.
vm.expectEmit({ emitter: address(lockupLinear) });
emit WithdrawFromLockupStream({
streamId: vars.streamId,
to: params.recipient,
asset: ASSET,
asset: FORK_ASSET,
amount: params.withdrawAmount
});
vm.expectEmit({ emitter: address(lockupLinear) });
Expand Down Expand Up @@ -293,7 +294,7 @@ abstract contract LockupLinear_Fork_Test is Fork_Test {

// Load the post-withdraw asset balances.
vars.balances =
getTokenBalances(address(ASSET), Solarray.addresses(address(lockupLinear), params.recipient));
getTokenBalances(address(FORK_ASSET), Solarray.addresses(address(lockupLinear), params.recipient));
vars.actualLockupLinearBalance = vars.balances[0];
vars.actualRecipientBalance = vars.balances[1];

Expand All @@ -316,7 +317,7 @@ abstract contract LockupLinear_Fork_Test is Fork_Test {
if (!vars.isDepleted && !vars.isSettled) {
// Load the pre-cancel asset balances.
vars.balances = getTokenBalances(
address(ASSET), Solarray.addresses(address(lockupLinear), params.sender, params.recipient)
address(FORK_ASSET), Solarray.addresses(address(lockupLinear), params.sender, params.recipient)
);
vars.initialLockupLinearBalance = vars.balances[0];
vars.initialSenderBalance = vars.balances[1];
Expand All @@ -327,7 +328,7 @@ abstract contract LockupLinear_Fork_Test is Fork_Test {
vars.senderAmount = lockupLinear.refundableAmountOf(vars.streamId);
vars.recipientAmount = lockupLinear.withdrawableAmountOf(vars.streamId);
emit CancelLockupStream(
vars.streamId, params.sender, params.recipient, ASSET, vars.senderAmount, vars.recipientAmount
vars.streamId, params.sender, params.recipient, FORK_ASSET, vars.senderAmount, vars.recipientAmount
);
vm.expectEmit({ emitter: address(lockupLinear) });
emit MetadataUpdate({ _tokenId: vars.streamId });
Expand All @@ -343,7 +344,7 @@ abstract contract LockupLinear_Fork_Test is Fork_Test {

// Load the post-cancel asset balances.
vars.balances = getTokenBalances(
address(ASSET), Solarray.addresses(address(lockupLinear), params.sender, params.recipient)
address(FORK_ASSET), Solarray.addresses(address(lockupLinear), params.sender, params.recipient)
);
vars.actualLockupLinearBalance = vars.balances[0];
vars.actualSenderBalance = vars.balances[1];
Expand Down
Loading

0 comments on commit fe60d98

Please sign in to comment.