Skip to content

Commit

Permalink
test: move generic functions to Base test contract
Browse files Browse the repository at this point in the history
test: rename recipient0 to recipient

test: refactor variables in Defaults

test(fork): allow leadData to have length 1
  • Loading branch information
smol-ninja authored and andreivladbrg committed Jul 30, 2024
1 parent efd65b1 commit 96e3209
Show file tree
Hide file tree
Showing 62 changed files with 314 additions and 322 deletions.
17 changes: 9 additions & 8 deletions benchmark/Benchmark.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ abstract contract Benchmark_Test is Base_Test {

uint128 internal immutable AMOUNT_PER_SEGMENT = 100e18;
uint128 internal immutable AMOUNT_PER_TRANCHE = 100e18;
uint256[7] internal streamIds = [50, 51, 52, 53, 54, 55, 56];

/// @dev The directory where the benchmark files are stored.
string internal benchmarkResults = "benchmark/results/";
Expand All @@ -27,6 +26,8 @@ abstract contract Benchmark_Test is Base_Test {

ISablierV2Lockup internal lockup;

uint256[7] internal streamIds = [50, 51, 52, 53, 54, 55, 56];

/*//////////////////////////////////////////////////////////////////////////
SET-UP FUNCTION
//////////////////////////////////////////////////////////////////////////*/
Expand All @@ -47,11 +48,11 @@ abstract contract Benchmark_Test is Base_Test {

function gasBurn() internal {
// Set the caller to the Recipient for `burn` and change timestamp to the end time.
resetPrank({ msgSender: users.recipient0 });
resetPrank({ msgSender: users.recipient });

vm.warp({ newTimestamp: defaults.END_TIME() });

lockup.withdrawMax(streamIds[0], users.recipient0);
lockup.withdrawMax(streamIds[0], users.recipient);

uint256 initialGas = gasleft();
lockup.burn(streamIds[0]);
Expand Down Expand Up @@ -101,7 +102,7 @@ abstract contract Benchmark_Test is Base_Test {
string memory gasUsed = vm.toString(initialGas - gasleft());

// Check if caller is recipient or not.
bool isCallerRecipient = caller == users.recipient0;
bool isCallerRecipient = caller == users.recipient;

string memory s = isCallerRecipient
? string.concat("| `withdraw` ", extraInfo, " (by Recipient) | ")
Expand Down Expand Up @@ -138,13 +139,13 @@ abstract contract Benchmark_Test is Base_Test {
}

function gasWithdraw_ByAnyone(uint256 streamId1, uint256 streamId2, string memory extraInfo) internal {
gasWithdraw_AfterEndTime(streamId1, users.sender, users.recipient0, extraInfo);
gasWithdraw_BeforeEndTime(streamId2, users.sender, users.recipient0, extraInfo);
gasWithdraw_AfterEndTime(streamId1, users.sender, users.recipient, extraInfo);
gasWithdraw_BeforeEndTime(streamId2, users.sender, users.recipient, extraInfo);
}

function gasWithdraw_ByRecipient(uint256 streamId1, uint256 streamId2, string memory extraInfo) internal {
gasWithdraw_AfterEndTime(streamId1, users.recipient0, users.alice, extraInfo);
gasWithdraw_BeforeEndTime(streamId2, users.recipient0, users.alice, extraInfo);
gasWithdraw_AfterEndTime(streamId1, users.recipient, users.alice, extraInfo);
gasWithdraw_BeforeEndTime(streamId2, users.recipient, users.alice, extraInfo);
}

/*//////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ coverage:
ignore:
- "precompiles"
- "script"
- "src/libraries/NFTSVG.sol"
- "src/libraries/SVGElements.sol"
- "src/core/libraries/NFTSVG.sol"
- "src/core/libraries/SVGElements.sol"
- "test"
4 changes: 4 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
]
gas_limit = 9223372036854775807
gas_reports = [
"SablierV2BatchLockup",
"SablierV2LockupDynamic",
"SablierV2LockupLinear",
"SablierV2LockupTranched",
"SablierV2MerkleLL",
"SablierV2MerkleLockupFactory",
"SablierV2MerkleLT",
"SablierV2NFTDescriptor",
]
optimizer = true
Expand Down
1 change: 0 additions & 1 deletion precompiles/Precompiles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ISablierV2LockupLinear } from "../src/core/interfaces/ISablierV2LockupL
import { ISablierV2LockupTranched } from "../src/core/interfaces/ISablierV2LockupTranched.sol";
import { ISablierV2NFTDescriptor } from "../src/core/interfaces/ISablierV2NFTDescriptor.sol";
import { SablierV2NFTDescriptor } from "../src/core/SablierV2NFTDescriptor.sol";

import { ISablierV2BatchLockup } from "../src/periphery/interfaces/ISablierV2BatchLockup.sol";
import { ISablierV2MerkleLockupFactory } from "../src/periphery/interfaces/ISablierV2MerkleLockupFactory.sol";

Expand Down
4 changes: 2 additions & 2 deletions shell/deploy-multi-chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ else
echo -e "${WC}Missing '.env.deployment'. Provide details below: ${NC}\n"

# initialize chains
initialize_interactive
initialize_interactive
fi

# Check for arguments passed to the script
Expand Down Expand Up @@ -201,7 +201,7 @@ for ((i=1; i<=$#; i++)); do

# Check if '--script' flag is provided in the arguments
if [[ ${arg} == "--script" || ${arg} == "-s" ]]; then
files=(script/*.s.sol)
files=(script/**/*.s.sol)

# Present the list of available scripts
echo "Please select a script:"
Expand Down
137 changes: 135 additions & 2 deletions test/Base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import { SablierV2LockupDynamic } from "src/core/SablierV2LockupDynamic.sol";
import { SablierV2LockupLinear } from "src/core/SablierV2LockupLinear.sol";
import { SablierV2LockupTranched } from "src/core/SablierV2LockupTranched.sol";
import { SablierV2NFTDescriptor } from "src/core/SablierV2NFTDescriptor.sol";
import { LockupDynamic, LockupLinear, LockupTranched } from "src/core/types/DataTypes.sol";
import { ISablierV2MerkleLockupFactory } from "src/periphery/interfaces/ISablierV2MerkleLockupFactory.sol";
import { ISablierV2BatchLockup } from "src/periphery/interfaces/ISablierV2BatchLockup.sol";
import { ISablierV2MerkleLL } from "src/periphery/interfaces/ISablierV2MerkleLL.sol";
import { ISablierV2MerkleLT } from "src/periphery/interfaces/ISablierV2MerkleLT.sol";
import { SablierV2BatchLockup } from "src/periphery/SablierV2BatchLockup.sol";
import { SablierV2MerkleLockupFactory } from "src/periphery/SablierV2MerkleLockupFactory.sol";

Expand Down Expand Up @@ -48,6 +51,8 @@ abstract contract Base_Test is Assertions, Calculations, Constants, DeployOptimi
ISablierV2LockupLinear internal lockupLinear;
ISablierV2LockupTranched internal lockupTranched;
ISablierV2MerkleLockupFactory internal merkleLockupFactory;
ISablierV2MerkleLL internal merkleLL;
ISablierV2MerkleLT internal merkleLT;
ISablierV2NFTDescriptor internal nftDescriptor;
Noop internal noop;
RecipientGood internal recipientGood;
Expand Down Expand Up @@ -86,7 +91,7 @@ abstract contract Base_Test is Assertions, Calculations, Constants, DeployOptimi
users.broker = createUser("Broker");
users.eve = createUser("Eve");
users.operator = createUser("Operator");
users.recipient0 = createUser("Recipient0");
users.recipient = createUser("Recipient");
users.recipient1 = createUser("Recipient1");
users.recipient2 = createUser("Recipient2");
users.recipient3 = createUser("Recipient3");
Expand All @@ -104,6 +109,13 @@ abstract contract Base_Test is Assertions, Calculations, Constants, DeployOptimi
HELPERS
//////////////////////////////////////////////////////////////////////////*/

/// @dev Approve `spender` to spend assets from `from`.
function approveContract(IERC20 asset_, address from, address spender) internal {
resetPrank({ msgSender: from });
(bool success,) = address(asset_).call(abi.encodeCall(IERC20.approve, (spender, MAX_UINT256)));
success;
}

/// @dev Approves all contracts to spend assets from the address passed.
function approveProtocol(address from) internal {
resetPrank({ msgSender: from });
Expand Down Expand Up @@ -156,7 +168,7 @@ abstract contract Base_Test is Assertions, Calculations, Constants, DeployOptimi
}

/*//////////////////////////////////////////////////////////////////////////
CALL EXPECTS
CALL EXPECTS - IERC20
//////////////////////////////////////////////////////////////////////////*/

/// @dev Expects a call to {IERC20.transfer}.
Expand All @@ -178,4 +190,125 @@ abstract contract Base_Test is Assertions, Calculations, Constants, DeployOptimi
function expectCallToTransferFrom(IERC20 asset, address from, address to, uint256 value) internal {
vm.expectCall({ callee: address(asset), data: abi.encodeCall(IERC20.transferFrom, (from, to, value)) });
}

/// @dev Expects multiple calls to {IERC20.transfer}.
function expectMultipleCallsToTransfer(uint64 count, address to, uint256 value) internal {
vm.expectCall({ callee: address(dai), count: count, data: abi.encodeCall(IERC20.transfer, (to, value)) });
}

/// @dev Expects multiple calls to {IERC20.transferFrom}.
function expectMultipleCallsToTransferFrom(uint64 count, address from, address to, uint256 value) internal {
expectMultipleCallsToTransferFrom(dai, count, from, to, value);
}

/// @dev Expects multiple calls to {IERC20.transferFrom}.
function expectMultipleCallsToTransferFrom(
IERC20 asset,
uint64 count,
address from,
address to,
uint256 value
)
internal
{
vm.expectCall({
callee: address(asset),
count: count,
data: abi.encodeCall(IERC20.transferFrom, (from, to, value))
});
}

/*//////////////////////////////////////////////////////////////////////////
CALL EXPECTS - LOCKUP
//////////////////////////////////////////////////////////////////////////*/

/// @dev Expects multiple calls to {ISablierV2LockupDynamic.createWithDurations}, each with the specified
/// `params`.
function expectMultipleCallsToCreateWithDurationsLD(
uint64 count,
LockupDynamic.CreateWithDurations memory params
)
internal
{
vm.expectCall({
callee: address(lockupDynamic),
count: count,
data: abi.encodeCall(ISablierV2LockupDynamic.createWithDurations, (params))
});
}

/// @dev Expects multiple calls to {ISablierV2LockupLinear.createWithDurations}, each with the specified
/// `params`.
function expectMultipleCallsToCreateWithDurationsLL(
uint64 count,
LockupLinear.CreateWithDurations memory params
)
internal
{
vm.expectCall({
callee: address(lockupLinear),
count: count,
data: abi.encodeCall(ISablierV2LockupLinear.createWithDurations, (params))
});
}

/// @dev Expects multiple calls to {ISablierV2LockupTranched.createWithDurations}, each with the specified
/// `params`.
function expectMultipleCallsToCreateWithDurationsLT(
uint64 count,
LockupTranched.CreateWithDurations memory params
)
internal
{
vm.expectCall({
callee: address(lockupTranched),
count: count,
data: abi.encodeCall(ISablierV2LockupTranched.createWithDurations, (params))
});
}

/// @dev Expects multiple calls to {ISablierV2LockupDynamic.createWithTimestamps}, each with the specified
/// `params`.
function expectMultipleCallsToCreateWithTimestampsLD(
uint64 count,
LockupDynamic.CreateWithTimestamps memory params
)
internal
{
vm.expectCall({
callee: address(lockupDynamic),
count: count,
data: abi.encodeCall(ISablierV2LockupDynamic.createWithTimestamps, (params))
});
}

/// @dev Expects multiple calls to {ISablierV2LockupLinear.createWithTimestamps}, each with the specified
/// `params`.
function expectMultipleCallsToCreateWithTimestampsLL(
uint64 count,
LockupLinear.CreateWithTimestamps memory params
)
internal
{
vm.expectCall({
callee: address(lockupLinear),
count: count,
data: abi.encodeCall(ISablierV2LockupLinear.createWithTimestamps, (params))
});
}

/// @dev Expects multiple calls to {ISablierV2LockupTranched.createWithTimestamps}, each with the specified
/// `params`.
function expectMultipleCallsToCreateWithTimestampsLT(
uint64 count,
LockupTranched.CreateWithTimestamps memory params
)
internal
{
vm.expectCall({
callee: address(lockupTranched),
count: count,
data: abi.encodeCall(ISablierV2LockupTranched.createWithTimestamps, (params))
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ contract CreateWithDurations_LockupDynamic_Integration_Concrete_Test is
streamId: streamId,
funder: funder,
sender: users.sender,
recipient: users.recipient0,
recipient: users.recipient,
amounts: defaults.lockupCreateAmounts(),
asset: dai,
cancelable: true,
Expand Down Expand Up @@ -179,7 +179,7 @@ contract CreateWithDurations_LockupDynamic_Integration_Concrete_Test is

// Assert that the NFT has been minted.
address actualNFTOwner = lockupDynamic.ownerOf({ tokenId: streamId });
address expectedNFTOwner = users.recipient0;
address expectedNFTOwner = users.recipient;
assertEq(actualNFTOwner, expectedNFTOwner, "NFT owner");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Concrete_Test is
streamId: streamId,
funder: funder,
sender: users.sender,
recipient: users.recipient0,
recipient: users.recipient,
amounts: defaults.lockupCreateAmounts(),
segments: defaults.segments(),
asset: IERC20(asset),
Expand Down Expand Up @@ -384,7 +384,7 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Concrete_Test is

// Assert that the NFT has been minted.
address actualNFTOwner = lockupDynamic.ownerOf({ tokenId: streamId });
address expectedNFTOwner = users.recipient0;
address expectedNFTOwner = users.recipient;
assertEq(actualNFTOwner, expectedNFTOwner, "NFT owner");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ contract WithdrawableAmountOf_LockupDynamic_Integration_Concrete_Test is
vm.warp({ newTimestamp: defaults.START_TIME() + defaults.CLIFF_DURATION() + 3750 seconds });

// Make the withdrawal.
lockupDynamic.withdraw({ streamId: defaultStreamId, to: users.recipient0, amount: defaults.WITHDRAW_AMOUNT() });
lockupDynamic.withdraw({ streamId: defaultStreamId, to: users.recipient, amount: defaults.WITHDRAW_AMOUNT() });

// Run the test.
uint128 actualWithdrawableAmount = lockupDynamic.withdrawableAmountOf(defaultStreamId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ contract CreateWithDurations_LockupLinear_Integration_Concrete_Test is
streamId: streamId,
funder: funder,
sender: users.sender,
recipient: users.recipient0,
recipient: users.recipient,
amounts: defaults.lockupCreateAmounts(),
asset: dai,
cancelable: true,
Expand Down Expand Up @@ -141,7 +141,7 @@ contract CreateWithDurations_LockupLinear_Integration_Concrete_Test is

// Assert that the NFT has been minted.
address actualNFTOwner = lockupLinear.ownerOf({ tokenId: streamId });
address expectedNFTOwner = users.recipient0;
address expectedNFTOwner = users.recipient;
assertEq(actualNFTOwner, expectedNFTOwner, "NFT owner");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ contract CreateWithTimestamps_LockupLinear_Integration_Concrete_Test is

// Assert that the NFT has been minted.
address actualNFTOwner = lockupLinear.ownerOf({ tokenId: streamId });
address expectedNFTOwner = users.recipient0;
address expectedNFTOwner = users.recipient;
assertEq(actualNFTOwner, expectedNFTOwner, "NFT owner");
}

Expand Down Expand Up @@ -260,7 +260,7 @@ contract CreateWithTimestamps_LockupLinear_Integration_Concrete_Test is
streamId: streamId,
funder: funder,
sender: users.sender,
recipient: users.recipient0,
recipient: users.recipient,
amounts: defaults.lockupCreateAmounts(),
asset: IERC20(asset),
cancelable: true,
Expand Down Expand Up @@ -290,7 +290,7 @@ contract CreateWithTimestamps_LockupLinear_Integration_Concrete_Test is

// Assert that the NFT has been minted.
address actualNFTOwner = lockupLinear.ownerOf({ tokenId: streamId });
address expectedNFTOwner = users.recipient0;
address expectedNFTOwner = users.recipient;
assertEq(actualNFTOwner, expectedNFTOwner, "NFT owner");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ contract WithdrawableAmountOf_LockupLinear_Integration_Concrete_Test is
}

modifier givenPreviousWithdrawals() {
lockupLinear.withdraw({ streamId: defaultStreamId, to: users.recipient0, amount: defaults.WITHDRAW_AMOUNT() });
lockupLinear.withdraw({ streamId: defaultStreamId, to: users.recipient, amount: defaults.WITHDRAW_AMOUNT() });
_;
}

Expand Down
Loading

0 comments on commit 96e3209

Please sign in to comment.