Skip to content

Commit

Permalink
test: use "given" instead of "when" (#678)
Browse files Browse the repository at this point in the history
* test: use "given" instead of "when"

* test: correct "given" branches

---------

Co-authored-by: andreivladbrg <[email protected]>
  • Loading branch information
PaulRBerg and andreivladbrg authored Sep 4, 2023
1 parent d7ea52b commit 98d8fa0
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ contract StreamedAmountOf_LockupDynamic_Integration_Concrete_Test is
assertEq(actualStreamedAmount, expectedStreamedAmount, "streamedAmount");
}

modifier whenCurrentMilestoneNot1st() {
modifier givenCurrentMilestoneNot1st() {
_;
}

Expand All @@ -102,7 +102,7 @@ contract StreamedAmountOf_LockupDynamic_Integration_Concrete_Test is
givenStatusStreaming
whenStartTimeInThePast
givenMultipleSegments
whenCurrentMilestoneNot1st
givenCurrentMilestoneNot1st
{
// Simulate the passage of time. 750 seconds is ~10% of the way in the second segment.
vm.warp({ timestamp: defaults.START_TIME() + defaults.CLIFF_DURATION() + 750 seconds });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
streamedAmountOf.t.sol
└── given the stream's status is "STREAMING"
├── when the start time is in the future
├── given the start time is in the future
│ └── it should return zero
├── when the start time is in the present
├── given the start time is in the present
│ └── it should return zero
└── when the start time is in the past
└── given the start time is in the past
├── given there is one segment
│ └── it should return the correct streamed amount
└── given there are multiple segments
├── when the current milestone is the 1st in the array
├── given the current milestone is the 1st in the array
│ └── it should return the correct streamed amount
└── when the current milestone is not the 1st in the array
└── given the current milestone is not the 1st in the array
└── it should return the correct streamed amount
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract WithdrawableAmountOf_LockupDynamic_Integration_Concrete_Test is
assertEq(actualWithdrawableAmount, expectedWithdrawableAmount, "withdrawableAmount");
}

modifier whenStartTimeInThePast() {
modifier givenStartTimeInThePast() {
_;
}

Expand All @@ -39,7 +39,7 @@ contract WithdrawableAmountOf_LockupDynamic_Integration_Concrete_Test is
givenNotNull
givenStreamHasNotBeenCanceled
givenStatusStreaming
whenStartTimeInThePast
givenStartTimeInThePast
{
// Simulate the passage of time.
vm.warp({ timestamp: defaults.START_TIME() + defaults.CLIFF_DURATION() + 3750 seconds });
Expand All @@ -60,7 +60,7 @@ contract WithdrawableAmountOf_LockupDynamic_Integration_Concrete_Test is
givenNotNull
givenStreamHasNotBeenCanceled
givenStatusStreaming
whenStartTimeInThePast
givenStartTimeInThePast
whenWithWithdrawals
{
// Simulate the passage of time.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
withdrawableAmountOf.t.sol
└── given the stream's status is "STREAMING"
├── when the start time is in the present
├── given the start time is in the present
│ └── it should return zero
└── when the start time is in the past
└── given the start time is in the past
├── given there are no previous withdrawals
│ └── it should return the correct withdrawable amount
└── given there are previous withdrawals
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
streamedAmountOf.t.sol
└── given the stream's status is "STREAMING"
├── when the cliff time is in the past
├── given the cliff time is in the past
│ └── it should return zero
├── when the cliff time is in the present
├── given the cliff time is in the present
│ └── it should return the correct streamed amount
└── when the cliff time is not in the future
└── given the cliff time is not in the future
└── it should return the correct streamed amount
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract WithdrawableAmountOf_LockupLinear_Integration_Concrete_Test is
assertEq(actualWithdrawableAmount, expectedWithdrawableAmount, "withdrawableAmount");
}

modifier whenCliffTimeNotInTheFuture() {
modifier givenCliffTimeNotInTheFuture() {
vm.warp({ timestamp: defaults.WARP_26_PERCENT() });
_;
}
Expand All @@ -39,7 +39,7 @@ contract WithdrawableAmountOf_LockupLinear_Integration_Concrete_Test is
givenNotNull
givenStreamHasNotBeenCanceled
givenStatusStreaming
whenCliffTimeNotInTheFuture
givenCliffTimeNotInTheFuture
{
uint128 actualWithdrawableAmount = lockupLinear.withdrawableAmountOf(defaultStreamId);
uint128 expectedWithdrawableAmount = defaults.WITHDRAW_AMOUNT();
Expand All @@ -56,7 +56,7 @@ contract WithdrawableAmountOf_LockupLinear_Integration_Concrete_Test is
givenNotNull
givenStreamHasNotBeenCanceled
givenStatusStreaming
whenCliffTimeNotInTheFuture
givenCliffTimeNotInTheFuture
givenPreviousWithdrawals
{
uint128 actualWithdrawableAmount = lockupLinear.withdrawableAmountOf(defaultStreamId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
withdrawableAmountOf.t.sol
└── given the stream's status is "STREAMING"
├── when the cliff time is in the future
├── given the cliff time is in the future
│ └── it should return zero
└── when the cliff time is not in the future
└── given the cliff time is not in the future
├── given there are no previous withdrawals
│ └── it should return the correct withdrawable amount
└── given there are previous withdrawals
Expand Down
6 changes: 3 additions & 3 deletions test/integration/concrete/lockup/status-of/statusOf.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ abstract contract StatusOf_Integration_Concrete_Test is Integration_Test, Lockup
assertEq(actualStatus, expectedStatus);
}

modifier whenStartTimeNotInTheFuture() {
modifier givenStartTimeNotInTheFuture() {
_;
}

Expand All @@ -68,7 +68,7 @@ abstract contract StatusOf_Integration_Concrete_Test is Integration_Test, Lockup
givenNotNull
givenAssetsNotFullyWithdrawn
givenStreamNotCanceled
whenStartTimeNotInTheFuture
givenStartTimeNotInTheFuture
{
vm.warp({ timestamp: defaults.END_TIME() });
Lockup.Status actualStatus = lockup.statusOf(defaultStreamId);
Expand All @@ -85,7 +85,7 @@ abstract contract StatusOf_Integration_Concrete_Test is Integration_Test, Lockup
givenNotNull
givenAssetsNotFullyWithdrawn
givenStreamNotCanceled
whenStartTimeNotInTheFuture
givenStartTimeNotInTheFuture
givenRefundableAmountNotZero
{
vm.warp({ timestamp: defaults.START_TIME() + 1 seconds });
Expand Down
4 changes: 2 additions & 2 deletions test/integration/concrete/lockup/status-of/statusOf.tree
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ statusOf.t.sol
├── given the stream has been canceled
│ └── it should return CANCELED
└── given the stream has not been canceled
├── when the start time is in the future
├── given the start time is in the future
│ └── it should return PENDING
└── when the start time is not in the future
└── given the start time is not in the future
├── given the refundable amount is zero
│ └── it should return SETTLED
└── given the refundable amount is not zero
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ abstract contract WithdrawMax_Integration_Concrete_Test is Integration_Test, Wit
assertEq(actualNFTowner, expectedNFTOwner, "NFT owner");
}

function test_WithdrawMax() external whenEndTimeInTheFuture {
function test_WithdrawMax() external givenEndTimeInTheFuture {
// Simulate the passage of time.
vm.warp({ timestamp: defaults.WARP_26_PERCENT() });

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
withdrawMax.t.sol
├── when the end time is not in the future
├── given the end time is not in the future
│ ├── it should make the max withdrawal
│ ├── it should update the withdrawn amount
│ ├── it should mark the stream as depleted
│ ├── it should make the stream not cancelable
│ └── it should emit a {WithdrawFromLockupStream} event
└── when the end time is in the future
└── given the end time is in the future
├── it should make the max withdrawal
├── it should update the withdrawn amount
└── it should emit a {WithdrawFromLockupStream} event
14 changes: 7 additions & 7 deletions test/integration/concrete/lockup/withdraw/withdraw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ abstract contract Withdraw_Integration_Concrete_Test is Integration_Test, Withdr
assertEq(actualNFTowner, expectedNFTOwner, "NFT owner");
}

modifier whenEndTimeInTheFuture() {
modifier givenEndTimeInTheFuture() {
// Simulate the passage of time.
vm.warp({ timestamp: defaults.WARP_26_PERCENT() });
_;
Expand All @@ -241,7 +241,7 @@ abstract contract Withdraw_Integration_Concrete_Test is Integration_Test, Withdr
whenWithdrawAmountNotZero
whenNoOverdraw
whenCallerSender
whenEndTimeInTheFuture
givenEndTimeInTheFuture
givenRecipientContract
givenRecipientImplementsHook
whenRecipientDoesNotRevert
Expand Down Expand Up @@ -285,7 +285,7 @@ abstract contract Withdraw_Integration_Concrete_Test is Integration_Test, Withdr
whenWithdrawAmountNotZero
whenNoOverdraw
whenCallerSender
whenEndTimeInTheFuture
givenEndTimeInTheFuture
whenStreamHasNotBeenCanceled
{
// Set the withdraw amount to the streamed amount.
Expand Down Expand Up @@ -326,7 +326,7 @@ abstract contract Withdraw_Integration_Concrete_Test is Integration_Test, Withdr
whenWithdrawAmountNotZero
whenNoOverdraw
whenCallerSender
whenEndTimeInTheFuture
givenEndTimeInTheFuture
whenStreamHasNotBeenCanceled
givenRecipientContract
{
Expand Down Expand Up @@ -370,7 +370,7 @@ abstract contract Withdraw_Integration_Concrete_Test is Integration_Test, Withdr
whenWithdrawAmountNotZero
whenNoOverdraw
whenCallerSender
whenEndTimeInTheFuture
givenEndTimeInTheFuture
whenStreamHasNotBeenCanceled
givenRecipientContract
givenRecipientImplementsHook
Expand Down Expand Up @@ -415,7 +415,7 @@ abstract contract Withdraw_Integration_Concrete_Test is Integration_Test, Withdr
whenWithdrawAmountNotZero
whenNoOverdraw
whenCallerSender
whenEndTimeInTheFuture
givenEndTimeInTheFuture
whenStreamHasNotBeenCanceled
givenRecipientContract
givenRecipientImplementsHook
Expand Down Expand Up @@ -464,7 +464,7 @@ abstract contract Withdraw_Integration_Concrete_Test is Integration_Test, Withdr
whenWithdrawAmountNotZero
whenNoOverdraw
whenCallerSender
whenEndTimeInTheFuture
givenEndTimeInTheFuture
whenStreamHasNotBeenCanceled
givenRecipientContract
givenRecipientImplementsHook
Expand Down
4 changes: 2 additions & 2 deletions test/integration/concrete/lockup/withdraw/withdraw.tree
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ withdraw.t.sol
│ ├── it should make the withdrawal
│ └── it should update the withdrawn amount
└── when the caller is the sender
├── when the end time is not in the future
├── given the end time is not in the future
│ ├── it should make the withdrawal
│ ├── it should mark the stream as depleted
│ └── it should make the stream not cancelable
└── when the end time is in the future
└── given the end time is in the future
├── given the stream has been canceled
│ ├── it should make the withdrawal
│ ├── it should mark the stream as depleted
Expand Down
2 changes: 1 addition & 1 deletion test/integration/fuzz/lockup/withdrawMax.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ abstract contract WithdrawMax_Integration_Fuzz_Test is Integration_Test, Withdra
assertEq(actualNFTowner, expectedNFTOwner, "NFT owner");
}

function testFuzz_WithdrawMax(uint256 timeJump) external whenEndTimeInTheFuture {
function testFuzz_WithdrawMax(uint256 timeJump) external givenEndTimeInTheFuture {
timeJump = _bound(timeJump, defaults.CLIFF_DURATION(), defaults.TOTAL_DURATION() - 1 seconds);

// Simulate the passage of time.
Expand Down
2 changes: 1 addition & 1 deletion test/integration/shared/lockup/withdrawMax.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract contract WithdrawMax_Integration_Shared_Test is Lockup_Integration_Shar
changePrank({ msgSender: users.recipient });
}

modifier whenEndTimeInTheFuture() {
modifier givenEndTimeInTheFuture() {
_;
}
}

0 comments on commit 98d8fa0

Please sign in to comment.