-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: rename test to "withdraw no delay"
test: polish delay test
- Loading branch information
1 parent
c971673
commit ed9cae0
Showing
1 changed file
with
11 additions
and
12 deletions.
There are no files selected for viewing
23 changes: 11 additions & 12 deletions
23
...ple-withdrawals/multipleWithdrawals.t.sol → ...e/withdraw-no-delay/withdrawNoDelay.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,45 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.22; | ||
|
||
import { UD21x18 } from "@prb/math/src/UD21x18.sol"; | ||
import { ud21x18 } from "@prb/math/src/UD21x18.sol"; | ||
|
||
import { Integration_Test } from "../../Integration.t.sol"; | ||
|
||
contract MultipleWithdrawals_Integration_Concrete_Test is Integration_Test { | ||
contract WithdrawNoDelay_Integration_Concrete_Test is Integration_Test { | ||
function test_AmountWithdrawn_MultipleWithdrawals() external { | ||
uint128 scaleFactor = getScaledAmount(1, DECIMALS); | ||
|
||
// Choose an rps such that rps < scaleFactor. | ||
UD21x18 rps = UD21x18.wrap(0.000000011574e18); | ||
|
||
assertLt(rps.unwrap(), scaleFactor, "rps must be less than scaleFactor"); | ||
uint128 rps = 0.000000011574e18; | ||
assertLt(rps, scaleFactor, "rps must be less than scaleFactor"); | ||
|
||
// Create the stream. | ||
uint256 streamId = flow.createAndDeposit(users.sender, users.recipient, rps, usdc, TRANSFERABLE, 1000); | ||
uint256 streamId = flow.createAndDeposit(users.sender, users.recipient, ud21x18(rps), usdc, TRANSFERABLE, 1000); | ||
|
||
// Interval at which withdraw will be called. | ||
uint40 withdrawInterval = 3600; // ~ 1 hour | ||
|
||
// Number of times withdraw will be called. | ||
uint128 withdrawCount = 20; | ||
|
||
uint128 actualAmountWithdrawn; | ||
uint128 actualTotalAmountWithdrawn; | ||
|
||
// Call withdraw multiple times. | ||
for (uint256 i; i < withdrawCount; ++i) { | ||
// Warp to the withdrawInterval. | ||
vm.warp(uint40(block.timestamp) + withdrawInterval); | ||
vm.warp(getBlockTimestamp() + withdrawInterval); | ||
|
||
// Withdraw the maximum amount. | ||
uint128 withdrawnAmount = flow.withdrawMax(streamId, users.recipient); | ||
|
||
// Update the actual amount withdrawn to the recipient | ||
actualAmountWithdrawn += withdrawnAmount; | ||
// Update the total amount withdrawn to the recipient | ||
actualTotalAmountWithdrawn += withdrawnAmount; | ||
} | ||
|
||
// Expect this amount to be withdrawn if there were no precision loss. This is also the real streamed value. | ||
uint128 expectedAmountWithdrawn = getDescaledAmount(rps.unwrap() * withdrawInterval * withdrawCount, DECIMALS); | ||
uint128 expectedTotalAmountWithdrawn = getDescaledAmount(rps * withdrawInterval * withdrawCount, DECIMALS); | ||
|
||
// Assert that the actual amount withdrawn is equal to the expected amount. | ||
assertEq(expectedAmountWithdrawn, actualAmountWithdrawn, "Streaming loss"); | ||
assertEq(actualTotalAmountWithdrawn, expectedTotalAmountWithdrawn, "Streaming loss"); | ||
} | ||
} |