diff --git a/tests/integration/fuzz/lockup-dynamic/createWithTimestampsLD.t.sol b/tests/integration/fuzz/lockup-dynamic/createWithTimestampsLD.t.sol index 28f5d07ab..9c7bbc2a0 100644 --- a/tests/integration/fuzz/lockup-dynamic/createWithTimestampsLD.t.sol +++ b/tests/integration/fuzz/lockup-dynamic/createWithTimestampsLD.t.sol @@ -132,7 +132,6 @@ contract CreateWithTimestampsLD_Integration_Fuzz_Test is Lockup_Dynamic_Integrat Lockup.Status expectedStatus; bool isCancelable; bool isSettled; - uint128 depositAmount; } /// @dev Given enough fuzz runs, all of the following scenarios will be fuzzed: @@ -181,9 +180,7 @@ contract CreateWithTimestampsLD_Integration_Fuzz_Test is Lockup_Dynamic_Integrat // Fuzz the segment amounts and calculate the deposit amount Vars memory vars; - vars.depositAmount = fuzzDynamicStreamAmounts({ upperBound: MAX_UINT128, segments: segments }); - - params.depositAmount = vars.depositAmount; + params.depositAmount = fuzzDynamicStreamAmounts({ upperBound: MAX_UINT128, segments: segments }); // Make the fuzzed funder the caller in the rest of this test. resetPrank(funder); @@ -191,13 +188,13 @@ contract CreateWithTimestampsLD_Integration_Fuzz_Test is Lockup_Dynamic_Integrat uint256 expectedStreamId = lockup.nextStreamId(); // Mint enough tokens to the fuzzed funder. - deal({ token: address(dai), to: funder, give: vars.depositAmount }); + deal({ token: address(dai), to: funder, give: params.depositAmount }); // Approve {SablierLockup} to transfer the tokens from the fuzzed funder. dai.approve({ spender: address(lockup), value: MAX_UINT256 }); // Expect the tokens to be transferred from the funder to {SablierLockup}. - expectCallToTransferFrom({ from: funder, to: address(lockup), value: vars.depositAmount }); + expectCallToTransferFrom({ from: funder, to: address(lockup), value: params.depositAmount }); // Expect the relevant event to be emitted. vm.expectEmit({ emitter: address(lockup) }); @@ -207,7 +204,7 @@ contract CreateWithTimestampsLD_Integration_Fuzz_Test is Lockup_Dynamic_Integrat funder: funder, sender: params.sender, recipient: params.recipient, - depositAmount: vars.depositAmount, + depositAmount: params.depositAmount, token: dai, cancelable: params.cancelable, transferable: params.transferable, @@ -226,7 +223,7 @@ contract CreateWithTimestampsLD_Integration_Fuzz_Test is Lockup_Dynamic_Integrat vars.isCancelable = vars.isSettled ? false : params.cancelable; // It should create the stream. - assertEq(lockup.getDepositedAmount(streamId), vars.depositAmount, "depositedAmount"); + assertEq(lockup.getDepositedAmount(streamId), params.depositAmount, "depositedAmount"); assertEq(lockup.getEndTime(streamId), params.timestamps.end, "endTime"); assertEq(lockup.isCancelable(streamId), vars.isCancelable, "isCancelable"); assertFalse(lockup.isDepleted(streamId), "isDepleted"); diff --git a/tests/integration/fuzz/lockup-tranched/createWithTimestampsLT.t.sol b/tests/integration/fuzz/lockup-tranched/createWithTimestampsLT.t.sol index cae2d83f3..02bd6a348 100644 --- a/tests/integration/fuzz/lockup-tranched/createWithTimestampsLT.t.sol +++ b/tests/integration/fuzz/lockup-tranched/createWithTimestampsLT.t.sol @@ -139,7 +139,6 @@ contract CreateWithTimestampsLT_Integration_Fuzz_Test is Lockup_Tranched_Integra Lockup.Status expectedStatus; bool isCancelable; bool isSettled; - uint128 depositAmount; } /// @dev Given enough fuzz runs, all of the following scenarios will be fuzzed: @@ -186,23 +185,19 @@ contract CreateWithTimestampsLT_Integration_Fuzz_Test is Lockup_Tranched_Integra fuzzTrancheTimestamps(tranches, params.timestamps.start); params.timestamps.end = tranches[tranches.length - 1].timestamp; - // Fuzz the tranche amounts and calculate the deposit amount. - Vars memory vars; - vars.depositAmount = fuzzTranchedStreamAmounts({ upperBound: MAX_UINT128, tranches: tranches }); - - params.depositAmount = vars.depositAmount; + params.depositAmount = fuzzTranchedStreamAmounts({ upperBound: MAX_UINT128, tranches: tranches }); // Make the fuzzed funder the caller in the rest of this test. resetPrank(funder); // Mint enough tokens to the fuzzed funder. - deal({ token: address(dai), to: funder, give: vars.depositAmount }); + deal({ token: address(dai), to: funder, give: params.depositAmount }); // Approve {SablierLockup} to transfer the tokens from the fuzzed funder. dai.approve({ spender: address(lockup), value: MAX_UINT256 }); // Expect the tokens to be transferred from the funder to {SablierLockup}. - expectCallToTransferFrom({ from: funder, to: address(lockup), value: vars.depositAmount }); + expectCallToTransferFrom({ from: funder, to: address(lockup), value: params.depositAmount }); uint256 expectedStreamId = lockup.nextStreamId(); @@ -214,7 +209,7 @@ contract CreateWithTimestampsLT_Integration_Fuzz_Test is Lockup_Tranched_Integra funder: funder, sender: params.sender, recipient: params.recipient, - depositAmount: vars.depositAmount, + depositAmount: params.depositAmount, token: dai, cancelable: params.cancelable, transferable: params.transferable, @@ -227,13 +222,16 @@ contract CreateWithTimestampsLT_Integration_Fuzz_Test is Lockup_Tranched_Integra // Create the stream. uint256 streamId = lockup.createWithTimestampsLT(params, tranches); + // Fuzz the tranche amounts and calculate the deposit amount. + Vars memory vars; + // Check if the stream is settled. It is possible for a Lockup Tranched stream to settle at the time of creation // because some tranche amounts can be zero. vars.isSettled = (lockup.getDepositedAmount(streamId) - lockup.streamedAmountOf(streamId)) == 0; vars.isCancelable = vars.isSettled ? false : params.cancelable; // It should create the stream. - assertEq(lockup.getDepositedAmount(streamId), vars.depositAmount, "depositedAmount"); + assertEq(lockup.getDepositedAmount(streamId), params.depositAmount, "depositedAmount"); assertEq(lockup.getEndTime(streamId), params.timestamps.end, "endTime"); assertEq(lockup.isCancelable(streamId), vars.isCancelable, "isCancelable"); assertFalse(lockup.isDepleted(streamId), "isDepleted"); diff --git a/tests/utils/Defaults.sol b/tests/utils/Defaults.sol index 3067f5ced..a642760c7 100644 --- a/tests/utils/Defaults.sol +++ b/tests/utils/Defaults.sol @@ -105,17 +105,6 @@ contract Defaults is Constants { return lockupCreateEvent(depositAmount, token, timestamps); } - function lockupCreateEvent( - IERC20 token_, - Lockup.Timestamps memory timestamps - ) - public - view - returns (Lockup.CreateEventCommon memory) - { - return lockupCreateEvent(DEPOSIT_AMOUNT, token_, timestamps); - } - function lockupCreateEvent( uint128 depositAmount, IERC20 token_, diff --git a/tests/utils/Fuzzers.sol b/tests/utils/Fuzzers.sol index 638ab2b01..f161b7581 100644 --- a/tests/utils/Fuzzers.sol +++ b/tests/utils/Fuzzers.sol @@ -63,20 +63,15 @@ abstract contract Fuzzers is Constants, Utils { // Precompute the first segment amount to prevent zero deposit amounts. segments[0].amount = boundUint128(segments[0].amount, 100, maxSegmentAmount); - uint128 estimatedDepositAmount = segments[0].amount; + depositAmount = segments[0].amount; // Fuzz the other segment amounts by bounding from 0. unchecked { for (uint256 i = 1; i < segmentCount; ++i) { segments[i].amount = boundUint128(segments[i].amount, 0, maxSegmentAmount); - estimatedDepositAmount += segments[i].amount; + depositAmount += segments[i].amount; } } - - depositAmount = estimatedDepositAmount; - - // Here, we account for rounding errors and adjust the estimated deposit amount and the segments. - segments[segments.length - 1].amount += (depositAmount - estimatedDepositAmount); } /// @dev Fuzzes the segment durations. @@ -219,19 +214,14 @@ abstract contract Fuzzers is Constants, Utils { // Precompute the first tranche amount to prevent zero deposit amounts. tranches[0].amount = boundUint128(tranches[0].amount, 100, maxTrancheAmount); - uint128 estimatedDepositAmount = tranches[0].amount; + depositAmount = tranches[0].amount; // Fuzz the other tranche amounts by bounding from 0. unchecked { for (uint256 i = 1; i < trancheCount; ++i) { tranches[i].amount = boundUint128(tranches[i].amount, 0, maxTrancheAmount); - estimatedDepositAmount += tranches[i].amount; + depositAmount += tranches[i].amount; } } - - depositAmount = estimatedDepositAmount; - - // Here, we account for rounding errors and adjust the estimated deposit amount and the tranches. - tranches[tranches.length - 1].amount += (depositAmount - estimatedDepositAmount); } }