-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test: add getters tests * test: fix category in getters test suite --------- Co-authored-by: smol-ninja <[email protected]>
- Loading branch information
1 parent
9213c4e
commit 5b3e293
Showing
2 changed files
with
285 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,196 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.22; | ||
|
||
import { ud21x18 } from "@prb/math/src/UD21x18.sol"; | ||
|
||
import { Integration_Test, Flow } from "../../Integration.t.sol"; | ||
|
||
contract Getters_Integration_Concrete_Test is Integration_Test { | ||
/*////////////////////////////////////////////////////////////////////////// | ||
GET-BALANCE | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
function test_GetBalanceRevertGiven_Null() external { | ||
bytes memory callData = abi.encodeCall(flow.getBalance, nullStreamId); | ||
expectRevert_Null(callData); | ||
} | ||
|
||
function test_GetBalanceGivenZero() external view givenNotNull { | ||
assertEq(flow.getBalance(defaultStreamId), 0, "balance"); | ||
} | ||
|
||
function test_GetBalanceGivenNotZero() external givenNotNull { | ||
depositToDefaultStream(); | ||
assertEq(flow.getBalance(defaultStreamId), DEPOSIT_AMOUNT_6D, "balance"); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
GET-RATE-PER-SECOND | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
function test_GetRatePerSecondRevertGiven_Null() external { | ||
bytes memory callData = abi.encodeCall(flow.getRatePerSecond, nullStreamId); | ||
expectRevert_Null(callData); | ||
} | ||
|
||
function test_GetRatePerSecondGivenZero() external givenNotNull { | ||
flow.pause(defaultStreamId); | ||
assertEq(flow.getRatePerSecond(defaultStreamId), ud21x18(0), "rate per second"); | ||
} | ||
|
||
function test_GetRatePerSecondGivenNotZero() external view givenNotNull { | ||
assertEq(flow.getRatePerSecond(defaultStreamId), RATE_PER_SECOND, "rate per second"); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
GET-RECIPIENT | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
function test_GetRecipientRevertGiven_Null() external { | ||
bytes memory callData = abi.encodeCall(flow.getRecipient, nullStreamId); | ||
expectRevert_Null(callData); | ||
} | ||
|
||
function test_GetRecipientGivenNotNull() external view { | ||
assertEq(flow.getRecipient(defaultStreamId), users.recipient, "recipient"); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
GET-SENDER | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
function test_GetSenderRevertGiven_Null() external { | ||
bytes memory callData = abi.encodeCall(flow.getSender, nullStreamId); | ||
expectRevert_Null(callData); | ||
} | ||
|
||
function test_GetSenderGivenNotNull() external view { | ||
assertEq(flow.getSender(defaultStreamId), users.sender, "sender"); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
GET-SNAPSHOT-DEBT-SCALED | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
function test_GetSnapshotDebtScaledRevertGiven_Null() external { | ||
bytes memory callData = abi.encodeCall(flow.getSnapshotDebtScaled, nullStreamId); | ||
expectRevert_Null(callData); | ||
} | ||
|
||
function test_GetSnapshotDebtScaledGivenZero() external view givenNotNull { | ||
assertEq(flow.getSnapshotDebtScaled(defaultStreamId), 0, "snapshot debt scaled"); | ||
} | ||
|
||
function test_GetSnapshotDebtScaledGivenNotZero() external givenNotNull { | ||
vm.warp(WARP_ONE_MONTH); | ||
flow.adjustRatePerSecond(defaultStreamId, ud21x18(1)); | ||
assertEq(flow.getSnapshotDebtScaled(defaultStreamId), ONE_MONTH_DEBT_18D, "snapshot debt scaled"); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
GET-SNAPSHOT-TIME | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
function test_GetSnapshotTimeRevertGiven_Null() external { | ||
bytes memory callData = abi.encodeCall(flow.getSnapshotTime, nullStreamId); | ||
expectRevert_Null(callData); | ||
} | ||
|
||
function test_GetSnapshotTimeGivenNotNull() external view { | ||
assertEq(flow.getSnapshotTime(defaultStreamId), OCT_1_2024, "snapshot time"); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
GET-STREAM | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
function test_GetStreamRevertGiven_Null() external { | ||
bytes memory callData = abi.encodeCall(flow.getStream, nullStreamId); | ||
expectRevert_Null(callData); | ||
} | ||
|
||
function test_GetStreamGivenNotNull() external view { | ||
Flow.Stream memory stream = defaultStream(); | ||
stream.snapshotTime = OCT_1_2024; | ||
assertEq(abi.encode(flow.getStream(defaultStreamId)), abi.encode(stream), "stream"); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
GET-TOKEN-DECIMALS | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
function test_GetTokenDecimalsRevertGiven_Null() external { | ||
bytes memory callData = abi.encodeCall(flow.getTokenDecimals, nullStreamId); | ||
expectRevert_Null(callData); | ||
} | ||
|
||
function test_GetTokenDecimalsGivenNotNull() external view { | ||
assertEq(flow.getTokenDecimals(defaultStreamId), DECIMALS, "token decimals"); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
IS-PAUSED | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
function test_IsPausedRevertGiven_Null() external { | ||
bytes memory callData = abi.encodeCall(flow.isPaused, nullStreamId); | ||
expectRevert_Null(callData); | ||
} | ||
|
||
function test_IsPausedGivenTrue() external givenNotNull { | ||
flow.pause(defaultStreamId); | ||
assertTrue(flow.isPaused(defaultStreamId), "paused"); | ||
} | ||
|
||
function test_IsPausedGivenNotTrue() external view givenNotNull { | ||
assertFalse(flow.isPaused(defaultStreamId), "paused"); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
IS-STREAM | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
function test_IsStreamGivenNull() external view { | ||
assertFalse(flow.isStream(nullStreamId), "is stream"); | ||
} | ||
|
||
function test_IsStreamGivenNotNull() external view { | ||
assertTrue(flow.isStream(defaultStreamId), "is stream"); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
IS-TRANSFERABLE | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
function test_IsTransferableRevertGiven_Null() external { | ||
bytes memory callData = abi.encodeCall(flow.isTransferable, nullStreamId); | ||
expectRevert_Null(callData); | ||
} | ||
|
||
function test_IsTransferableGivenTrue() external view givenNotNull { | ||
assertTrue(flow.isTransferable(defaultStreamId), "transferable"); | ||
} | ||
|
||
function test_IsTransferableGivenFalse() external givenNotNull { | ||
uint256 streamId = flow.create(users.sender, users.recipient, RATE_PER_SECOND, usdc, false); | ||
assertFalse(flow.isTransferable(streamId), "transferable"); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
IS-VOIDED | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
function test_IsVoidedRevertGiven_Null() external { | ||
bytes memory callData = abi.encodeCall(flow.isVoided, nullStreamId); | ||
expectRevert_Null(callData); | ||
} | ||
|
||
function test_IsVoidedGivenTrue() external givenNotNull { | ||
flow.void(defaultStreamId); | ||
assertEq(flow.isVoided(defaultStreamId), true, "voided"); | ||
} | ||
|
||
function test_IsVoidedGivenFalse() external view givenNotNull { | ||
assertFalse(flow.isVoided(defaultStreamId), "voided"); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
Getters_Integration_Concrete_Test::getBalance | ||
βββ given null | ||
β βββ it should revert | ||
βββ given not null | ||
βββ given zero | ||
β βββ it should return zero value | ||
βββ given not zero | ||
βββ it should return non-zero value | ||
|
||
Getters_Integration_Concrete_Test::getRatePerSecond | ||
βββ given null | ||
β βββ it should revert | ||
βββ given not null | ||
βββ given zero | ||
β βββ it should return zero value | ||
βββ given not zero | ||
βββ it should return non-zero value | ||
|
||
Getters_Integration_Concrete_Test::getRecipient | ||
βββ given null | ||
β βββ it should revert | ||
βββ given not null | ||
βββ it should return the correct recipient | ||
|
||
Getters_Integration_Concrete_Test::getSender | ||
βββ given null | ||
β βββ it should revert | ||
βββ given not null | ||
βββ it should return the correct sender | ||
|
||
Getters_Integration_Concrete_Test::getSnapshotDebtScaled | ||
βββ given null | ||
β βββ it should revert | ||
βββ given not null | ||
βββ given zero | ||
β βββ it should return zero value | ||
βββ given not zero | ||
βββ it should return non-zero value | ||
|
||
Getters_Integration_Concrete_Test::getSnapshotTime | ||
βββ given null | ||
β βββ it should revert | ||
βββ given not null | ||
βββ it should return the correct snapshot time | ||
|
||
Getters_Integration_Concrete_Test::getStream | ||
βββ given null | ||
β βββ it should revert | ||
βββ given not null | ||
βββ it should return the stream | ||
|
||
Getters_Integration_Concrete_Test::getTokenDecimals | ||
βββ given null | ||
β βββ it should revert | ||
βββ given not null | ||
βββ it should return token decimals | ||
|
||
Getters_Integration_Concrete_Test::isPaused | ||
βββ given null | ||
β βββ it should revert | ||
βββ given not null | ||
βββ given true | ||
β βββ it should return true | ||
βββ given not true | ||
βββ it should return false | ||
|
||
Getters_Integration_Concrete_Test::isStream | ||
βββ given null | ||
β βββ it should return false | ||
βββ given not null | ||
βββ it should return true | ||
|
||
Getters_Integration_Concrete_Test::isTransferable | ||
βββ given null | ||
β βββ it should revert | ||
βββ given not null | ||
βββ given true | ||
β βββ it should return true | ||
βββ given false | ||
βββ it should return false | ||
|
||
Getters_Integration_Concrete_Test::isVoided | ||
βββ given null | ||
β βββ it should revert | ||
βββ given not null | ||
βββ given true | ||
β βββ it should return true | ||
βββ given false | ||
βββ it should return false |