Skip to content

Commit

Permalink
test: statusOf function
Browse files Browse the repository at this point in the history
test: say "given" instead of "when"
  • Loading branch information
andreivladbrg committed Jun 15, 2024
1 parent 141ad3e commit 3e3ce32
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/SablierFlow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ contract SablierFlow is
bool hasDebt = _streamDebtOf(streamId) > 0;

if (_streams[streamId].isPaused) {
// If the stream is inactive and has debt, return PAUSED_SOLVENT.
// If the stream is inactive and has debt, return PAUSED_INSOLVENT.
if (hasDebt) {
return Flow.Status.PAUSED_INSOLVENT;
}

// If the stream is inactive and has no debt, return PAUSED_INSOLVENT.
// If the stream is inactive and has no debt, return PAUSED_SOLVENT.
return Flow.Status.PAUSED_SOLVENT;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ contract DepletionTimeOf_Integration_Concrete_Test is Integration_Test {
_;
}

function test_WhenStreamHasDebt() external givenNotNull givenNotPaused givenBalanceNotZero {
function test_GivenStreamHasDebt() external givenNotNull givenNotPaused givenBalanceNotZero {
vm.warp({ newTimestamp: WARP_SOLVENCY_PERIOD });
// It should return 0
uint40 depletionTime = flow.depletionTimeOf(defaultStreamId);
assertEq(depletionTime, 0, "depletion time");
}

function test_WhenStreamHasNoDebt() external givenNotNull givenNotPaused givenBalanceNotZero {
function test_GivenStreamHasNoDebt() external givenNotNull givenNotPaused givenBalanceNotZero {
// It should return the time at which the stream depletes its balance
uint40 depletionTime = flow.depletionTimeOf(defaultStreamId);
assertEq(depletionTime, WARP_SOLVENCY_PERIOD, "depletion time");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ DepletionTimeOf_Integration_Concrete_Test
β”œβ”€β”€ given balance zero
β”‚ └── it should return 0
└── given balance not zero
β”œβ”€β”€ when stream has debt
β”œβ”€β”€ given stream has debt
β”‚ └── it should return 0
└── when stream has no debt
└── given stream has no debt
└── it should return the time at which the stream depletes its balance
62 changes: 62 additions & 0 deletions test/integration/concrete/status-of/statusOf.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.22;

import { Flow } from "src/types/DataTypes.sol";

import { Integration_Test } from "../../Integration.t.sol";

contract StatusOf_Integration_Concrete_Test is Integration_Test {
function setUp() public override {
Integration_Test.setUp();

depositDefaultAmountToDefaultStream();
}

function test_RevertGiven_Null() external {
bytes memory callData = abi.encodeCall(flow.statusOf, nullStreamId);
expectRevert_Null(callData);
}

modifier givenInactive() {
_;
}

function test_GivenStreamDoesHaveDebt() external givenNotNull givenInactive {
vm.warp({ newTimestamp: WARP_SOLVENCY_PERIOD + 1 });
flow.pause(defaultStreamId);

// it should return PAUSED_INSOLVENT
uint8 actualStatus = uint8(flow.statusOf(defaultStreamId));
uint8 expectedStatus = uint8(Flow.Status.PAUSED_INSOLVENT);
assertEq(actualStatus, expectedStatus);
}

function test_GivenStreamDoesNotHaveDebt() external givenNotNull givenInactive {
flow.pause(defaultStreamId);

// it should return PAUSED_SOLVENT
uint8 actualStatus = uint8(flow.statusOf(defaultStreamId));
uint8 expectedStatus = uint8(Flow.Status.PAUSED_SOLVENT);
assertEq(actualStatus, expectedStatus);
}

modifier givenActive() {
_;
}

function test_GivenStreamHasDebt() external givenNotNull givenActive {
vm.warp({ newTimestamp: WARP_SOLVENCY_PERIOD + 1 });

// it should return STREAMING_INSOLVENT
uint8 actualStatus = uint8(flow.statusOf(defaultStreamId));
uint8 expectedStatus = uint8(Flow.Status.STREAMING_INSOLVENT);
assertEq(actualStatus, expectedStatus);
}

function test_GivenStreamHasNoDebt() external view givenNotNull givenActive {
// it should return STREAMING_SOLVENT
uint8 actualStatus = uint8(flow.statusOf(defaultStreamId));
uint8 expectedStatus = uint8(Flow.Status.STREAMING_SOLVENT);
assertEq(actualStatus, expectedStatus);
}
}
14 changes: 14 additions & 0 deletions test/integration/concrete/status-of/statusOf.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
StatusOf_Integration_Concrete_Test
β”œβ”€β”€ given null
β”‚ └── it should revert
└── given not null
β”œβ”€β”€ given inactive
β”‚ β”œβ”€β”€ given stream does have debt
β”‚ β”‚ └── it should return PAUSED_INSOLVENT
β”‚ └── given stream does not have debt
β”‚ └── it should return PAUSED_SOLVENT
└── given active
β”œβ”€β”€ given stream has debt
β”‚ └── it should return STREAMING_INSOLVENT
└── given stream has no debt
└── it should return STREAMING_SOLVENT

0 comments on commit 3e3ce32

Please sign in to comment.