Skip to content

Commit

Permalink
test: update periphery tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smol-ninja committed Nov 5, 2024
1 parent 070214a commit 3e371f1
Show file tree
Hide file tree
Showing 30 changed files with 454 additions and 609 deletions.
38 changes: 11 additions & 27 deletions test/Base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ pragma solidity >=0.8.22 <0.9.0;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import { ILockupNFTDescriptor } from "src/core/interfaces/ILockupNFTDescriptor.sol";
import { ISablierLockupDynamic } from "src/core/interfaces/ISablierLockupDynamic.sol";
import { ISablierLockupLinear } from "src/core/interfaces/ISablierLockupLinear.sol";
import { ISablierLockupTranched } from "src/core/interfaces/ISablierLockupTranched.sol";
import { ISablierLockup } from "src/core/interfaces/ISablierLockup.sol";
import { LockupNFTDescriptor } from "src/core/LockupNFTDescriptor.sol";
import { SablierLockupDynamic } from "src/core/SablierLockupDynamic.sol";
import { SablierLockupLinear } from "src/core/SablierLockupLinear.sol";
import { SablierLockupTranched } from "src/core/SablierLockupTranched.sol";
import { SablierLockup } from "src/core/SablierLockup.sol";
import { ISablierBatchLockup } from "src/periphery/interfaces/ISablierBatchLockup.sol";
import { ISablierMerkleFactory } from "src/periphery/interfaces/ISablierMerkleFactory.sol";
import { ISablierMerkleInstant } from "src/periphery/interfaces/ISablierMerkleInstant.sol";
Expand Down Expand Up @@ -45,9 +41,7 @@ abstract contract Base_Test is Assertions, Calculations, DeployOptimized, Modifi
ISablierBatchLockup internal batchLockup;
ERC20Mock internal dai;
Defaults internal defaults;
ISablierLockupDynamic internal lockupDynamic;
ISablierLockupLinear internal lockupLinear;
ISablierLockupTranched internal lockupTranched;
ISablierLockup internal lockup;
ISablierMerkleFactory internal merkleFactory;
ISablierMerkleInstant internal merkleInstant;
ISablierMerkleLL internal merkleLL;
Expand Down Expand Up @@ -107,11 +101,9 @@ abstract contract Base_Test is Assertions, Calculations, DeployOptimized, Modifi
// Set the variables in Modifiers contract.
setVariables(defaults, users);

// Approve `users.operator` to operate over lockups on behalf of the `users.recipient`.
// Approve `users.operator` to operate over lockup on behalf of the `users.recipient`.
resetPrank({ msgSender: users.recipient });
lockupDynamic.setApprovalForAll(users.operator, true);
lockupLinear.setApprovalForAll(users.operator, true);
lockupTranched.setApprovalForAll(users.operator, true);
lockup.setApprovalForAll(users.operator, true);

// Set sender as the default caller for the tests.
resetPrank({ msgSender: users.sender });
Expand All @@ -135,14 +127,10 @@ abstract contract Base_Test is Assertions, Calculations, DeployOptimized, Modifi
function approveProtocol(address from) internal {
resetPrank({ msgSender: from });
dai.approve({ spender: address(batchLockup), value: MAX_UINT256 });
dai.approve({ spender: address(lockupLinear), value: MAX_UINT256 });
dai.approve({ spender: address(lockupDynamic), value: MAX_UINT256 });
dai.approve({ spender: address(lockupTranched), value: MAX_UINT256 });
dai.approve({ spender: address(lockup), value: MAX_UINT256 });
dai.approve({ spender: address(merkleFactory), value: MAX_UINT256 });
usdt.approve({ spender: address(batchLockup), value: MAX_UINT256 });
usdt.approve({ spender: address(lockupLinear), value: MAX_UINT256 });
usdt.approve({ spender: address(lockupDynamic), value: MAX_UINT256 });
usdt.approve({ spender: address(lockupTranched), value: MAX_UINT256 });
usdt.approve({ spender: address(lockup), value: MAX_UINT256 });
usdt.approve({ spender: address(merkleFactory), value: MAX_UINT256 });
}

Expand All @@ -165,19 +153,15 @@ abstract contract Base_Test is Assertions, Calculations, DeployOptimized, Modifi
if (!isBenchmarkProfile() && !isTestOptimizedProfile()) {
batchLockup = new SablierBatchLockup();
nftDescriptor = new LockupNFTDescriptor();
lockupDynamic = new SablierLockupDynamic(users.admin, nftDescriptor, defaults.MAX_SEGMENT_COUNT());
lockupLinear = new SablierLockupLinear(users.admin, nftDescriptor);
lockupTranched = new SablierLockupTranched(users.admin, nftDescriptor, defaults.MAX_TRANCHE_COUNT());
lockup = new SablierLockup(users.admin, nftDescriptor, defaults.MAX_COUNT());
merkleFactory = new SablierMerkleFactory(users.admin);
} else {
(nftDescriptor, lockupDynamic, lockupLinear, lockupTranched, batchLockup, merkleFactory) =
deployOptimizedProtocol(users.admin, defaults.MAX_SEGMENT_COUNT(), defaults.MAX_TRANCHE_COUNT());
(nftDescriptor, lockup, batchLockup, merkleFactory) =
deployOptimizedProtocol(users.admin, defaults.MAX_COUNT());
}

vm.label({ account: address(batchLockup), newLabel: "BatchLockup" });
vm.label({ account: address(lockupDynamic), newLabel: "LockupDynamic" });
vm.label({ account: address(lockupLinear), newLabel: "LockupLinear" });
vm.label({ account: address(lockupTranched), newLabel: "LockupTranched" });
vm.label({ account: address(lockup), newLabel: "Lockup" });
vm.label({ account: address(merkleFactory), newLabel: "MerkleFactory" });
vm.label({ account: address(nftDescriptor), newLabel: "NFTDescriptor" });
}
Expand Down
6 changes: 3 additions & 3 deletions test/mocks/Hooks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity >=0.8.22;

import { IERC165, ERC165 } from "@openzeppelin/contracts/utils/introspection/ERC165.sol";

import { ISablierLockup } from "src/core/interfaces/ISablierLockup.sol";
import { ISablierLockupBase } from "src/core/interfaces/ISablierLockupBase.sol";
import { ISablierLockupRecipient } from "src/core/interfaces/ISablierLockupRecipient.sol";

contract RecipientGood is ISablierLockupRecipient, ERC165 {
Expand Down Expand Up @@ -138,7 +138,7 @@ contract RecipientReentrant is ISablierLockupRecipient, ERC165 {
senderAmount;
recipientAmount;

ISablierLockup(msg.sender).withdraw(streamId, address(this), recipientAmount);
ISablierLockupBase(msg.sender).withdraw(streamId, address(this), recipientAmount);

return ISablierLockupRecipient.onSablierLockupCancel.selector;
}
Expand All @@ -158,7 +158,7 @@ contract RecipientReentrant is ISablierLockupRecipient, ERC165 {
to;
amount;

ISablierLockup(msg.sender).withdraw(streamId, address(this), amount);
ISablierLockupBase(msg.sender).withdraw(streamId, address(this), amount);

return ISablierLockupRecipient.onSablierLockupWithdraw.selector;
}
Expand Down
72 changes: 36 additions & 36 deletions test/periphery/Periphery.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ pragma solidity >=0.8.22 <0.9.0;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import { ISablierLockupDynamic } from "src/core/interfaces/ISablierLockupDynamic.sol";
import { ISablierLockupLinear } from "src/core/interfaces/ISablierLockupLinear.sol";
import { ISablierLockupTranched } from "src/core/interfaces/ISablierLockupTranched.sol";
import { LockupDynamic, LockupLinear, LockupTranched } from "src/core/types/DataTypes.sol";
import { ISablierLockup } from "src/core/interfaces/ISablierLockup.sol";
import { Lockup, LockupDynamic, LockupLinear, LockupTranched } from "src/core/types/DataTypes.sol";

import { ISablierMerkleBase } from "src/periphery/interfaces/ISablierMerkleBase.sol";
import { SablierMerkleInstant } from "src/periphery/SablierMerkleInstant.sol";
Expand Down Expand Up @@ -41,93 +39,95 @@ contract Periphery_Test is Base_Test {
CALL EXPECTS - LOCKUP
//////////////////////////////////////////////////////////////////////////*/

/// @dev Expects multiple calls to {ISablierLockupDynamic.createWithDurations}, each with the specified
/// `params`.
/// @dev Expects multiple calls to {ISablierLockup.createWithDurationsLD}, each with the specified `params`.
function expectMultipleCallsToCreateWithDurationsLD(
uint64 count,
LockupDynamic.CreateWithDurations memory params
Lockup.CreateWithDurations memory params,
LockupDynamic.SegmentWithDuration[] memory segments
)
internal
{
vm.expectCall({
callee: address(lockupDynamic),
callee: address(lockup),
count: count,
data: abi.encodeCall(ISablierLockupDynamic.createWithDurations, (params))
data: abi.encodeCall(ISablierLockup.createWithDurationsLD, (params, segments))
});
}

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

/// @dev Expects multiple calls to {ISablierLockupTranched.createWithDurations}, each with the specified
/// `params`.
/// @dev Expects multiple calls to {ISablierLockup.createWithDurationsLT}, each with the specified `params`.
function expectMultipleCallsToCreateWithDurationsLT(
uint64 count,
LockupTranched.CreateWithDurations memory params
Lockup.CreateWithDurations memory params,
LockupTranched.TrancheWithDuration[] memory tranches
)
internal
{
vm.expectCall({
callee: address(lockupTranched),
callee: address(lockup),
count: count,
data: abi.encodeCall(ISablierLockupTranched.createWithDurations, (params))
data: abi.encodeCall(ISablierLockup.createWithDurationsLT, (params, tranches))
});
}

/// @dev Expects multiple calls to {ISablierLockupDynamic.createWithTimestamps}, each with the specified
/// `params`.
/// @dev Expects multiple calls to {ISablierLockup.createWithTimestampsLD}, each with the specified `params`.
function expectMultipleCallsToCreateWithTimestampsLD(
uint64 count,
LockupDynamic.CreateWithTimestamps memory params
Lockup.CreateWithTimestamps memory params,
LockupDynamic.Segment[] memory segments
)
internal
{
vm.expectCall({
callee: address(lockupDynamic),
callee: address(lockup),
count: count,
data: abi.encodeCall(ISablierLockupDynamic.createWithTimestamps, (params))
data: abi.encodeCall(ISablierLockup.createWithTimestampsLD, (params, segments))
});
}

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

/// @dev Expects multiple calls to {ISablierLockupTranched.createWithTimestamps}, each with the specified
/// @dev Expects multiple calls to {ISablierLockup.createWithTimestampsLT}, each with the specified
/// `params`.
function expectMultipleCallsToCreateWithTimestampsLT(
uint64 count,
LockupTranched.CreateWithTimestamps memory params
Lockup.CreateWithTimestamps memory params,
LockupTranched.Tranche[] memory tranches
)
internal
{
vm.expectCall({
callee: address(lockupTranched),
callee: address(lockup),
count: count,
data: abi.encodeCall(ISablierLockupTranched.createWithTimestamps, (params))
data: abi.encodeCall(ISablierLockup.createWithTimestampsLT, (params, tranches))
});
}

Expand Down Expand Up @@ -220,7 +220,7 @@ contract Periphery_Test is Base_Test {
abi.encode(defaults.IPFS_CID()),
merkleRoot,
defaults.NAME_BYTES32(),
lockupLinear,
lockup,
defaults.CANCELABLE(),
defaults.TRANSFERABLE(),
abi.encode(defaults.schedule())
Expand Down Expand Up @@ -256,7 +256,7 @@ contract Periphery_Test is Base_Test {
abi.encode(defaults.IPFS_CID()),
merkleRoot,
defaults.NAME_BYTES32(),
lockupTranched,
lockup,
defaults.CANCELABLE(),
defaults.TRANSFERABLE(),
defaults.STREAM_START_TIME_ZERO(),
Expand Down Expand Up @@ -307,7 +307,7 @@ contract Periphery_Test is Base_Test {
{
bytes memory constructorArgs = abi.encode(
defaults.baseParams(campaignOwner, asset_, expiration, merkleRoot),
lockupLinear,
lockup,
defaults.CANCELABLE(),
defaults.TRANSFERABLE(),
defaults.schedule(),
Expand All @@ -333,7 +333,7 @@ contract Periphery_Test is Base_Test {
{
bytes memory constructorArgs = abi.encode(
defaults.baseParams(campaignOwner, asset_, expiration, merkleRoot),
lockupTranched,
lockup,
defaults.CANCELABLE(),
defaults.TRANSFERABLE(),
defaults.STREAM_START_TIME_ZERO(),
Expand Down
24 changes: 7 additions & 17 deletions test/periphery/fork/Fork.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
pragma solidity >=0.8.22 <0.9.0;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { ISablierLockupDynamic } from "src/core/interfaces/ISablierLockupDynamic.sol";
import { ISablierLockupLinear } from "src/core/interfaces/ISablierLockupLinear.sol";
import { ISablierLockupTranched } from "src/core/interfaces/ISablierLockupTranched.sol";
import { ISablierLockup } from "src/core/interfaces/ISablierLockup.sol";
import { Merkle } from "./../../utils/Murky.sol";
import { Periphery_Test } from "./../Periphery.t.sol";

Expand All @@ -30,13 +28,15 @@ abstract contract Fork_Test is Periphery_Test, Merkle {

function setUp() public virtual override {
// Fork Ethereum Mainnet at a specific block number.
vm.createSelectFork({ blockNumber: 20_339_512, urlOrAlias: "mainnet" });
// TODO: Update to mainnet fork once deployed.
vm.createSelectFork({ blockNumber: 7_016_360, urlOrAlias: "sepolia" });

// Set up the parent test contract.
Periphery_Test.setUp();

// Load the external dependencies.
loadDependencies();
// Load the pre-deployed external dependencies.
// TODO: Update addresses once deployed.
lockup = ISablierLockup(0x6Fe81F4Bf1aF1b829f0E701647808f3Aa4b0BdE7);
}

/*//////////////////////////////////////////////////////////////////////////
Expand All @@ -50,20 +50,10 @@ abstract contract Fork_Test is Periphery_Test, Merkle {

// The goal is to not have overlapping users because the asset balance tests would fail otherwise.
vm.assume(user != recipient);
vm.assume(user != address(lockupDynamic) && recipient != address(lockupDynamic));
vm.assume(user != address(lockupLinear) && recipient != address(lockupLinear));
vm.assume(user != address(lockupTranched) && recipient != address(lockupTranched));
vm.assume(user != address(lockup) && recipient != address(lockup));

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

/// @dev Loads all dependencies pre-deployed on Mainnet.
// TODO: Update addresses once deployed.
function loadDependencies() private {
lockupDynamic = ISablierLockupDynamic(0x9DeaBf7815b42Bf4E9a03EEc35a486fF74ee7459);
lockupLinear = ISablierLockupLinear(0x3962f6585946823440d274aD7C719B02b49DE51E);
lockupTranched = ISablierLockupTranched(0xf86B359035208e4529686A1825F2D5BeE38c28A8);
}
}
3 changes: 2 additions & 1 deletion test/periphery/fork/assets/USDC.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { MerkleLL_Fork_Test } from "../merkle-campaign/MerkleLL.t.sol";
import { MerkleLT_Fork_Test } from "../merkle-campaign/MerkleLT.t.sol";

/// @dev An ERC-20 asset with 6 decimals.
IERC20 constant usdc = IERC20(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48);
// TODO: Update addresses to mainnet once deployed.
IERC20 constant usdc = IERC20(0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238);

contract USDC_CreateWithTimestamps_LockupDynamic_BatchLockup_Fork_Test is
CreateWithTimestamps_LockupDynamic_BatchLockup_Fork_Test(usdc)
Expand Down
3 changes: 2 additions & 1 deletion test/periphery/fork/assets/USDT.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { MerkleLL_Fork_Test } from "../merkle-campaign/MerkleLL.t.sol";
import { MerkleLT_Fork_Test } from "../merkle-campaign/MerkleLT.t.sol";

/// @dev An ERC-20 asset that suffers from the missing return value bug.
IERC20 constant usdt = IERC20(0xdAC17F958D2ee523a2206206994597C13D831ec7);
// TODO: Update addresses to mainnet once deployed.
IERC20 constant usdt = IERC20(0x7169D38820dfd117C3FA1f22a697dBA58d90BA06);

contract USDT_CreateWithTimestamps_LockupDynamic_BatchLockup_Fork_Test is
CreateWithTimestamps_LockupDynamic_BatchLockup_Fork_Test(usdt)
Expand Down
Loading

0 comments on commit 3e371f1

Please sign in to comment.