Skip to content

Commit

Permalink
Merge pull request #26 from sablier-labs/build/bump-forge-std
Browse files Browse the repository at this point in the history
Bump forge-std and remove prb-test
  • Loading branch information
andreivladbrg authored Apr 4, 2024
2 parents 6fa28ca + f2c0bed commit 839203b
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 40 deletions.
Binary file modified bun.lockb
Binary file not shown.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
},
"dependencies": {
"@openzeppelin/contracts": "5.0.1",
"@prb/math": "4.0.2"
"@prb/math": "github:PaulRBerg/prb-math#a111d11"
},
"devDependencies": {
"@prb/test": "0.6.4",
"forge-std": "github:foundry-rs/forge-std#v1.5.6",
"forge-std": "github:foundry-rs/forge-std#v1.8.1",
"prettier": "3.0.0",
"solhint": "^4.0.0"
},
Expand Down
3 changes: 1 addition & 2 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@forge-std/=node_modules/forge-std/
@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/
@prb/math/=node_modules/@prb/math/
@prb/test/=node_modules/@prb/test/
@prb/math/=node_modules/@prb/math/
4 changes: 2 additions & 2 deletions test/Base.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.22;

import { StdCheats } from "@forge-std/src/StdCheats.sol";
import { Test } from "@forge-std/src/Test.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";

Expand All @@ -18,7 +18,7 @@ struct Users {
address recipient;
}

abstract contract Base_Test is Assertions, Events, Modifiers, StdCheats {
abstract contract Base_Test is Assertions, Events, Modifiers, Test {
using SafeCast for uint256;

/*//////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ contract adjustRatePerSecond_Integration_Test is Integration_Test {
whenratePerSecondNonZero
whenratePerSecondNotDifferent
{
vm.warp({ timestamp: WARP_ONE_MONTH });
vm.warp({ newTimestamp: WARP_ONE_MONTH });

uint128 actualratePerSecond = openEnded.getRatePerSecond(defaultStreamId);
uint128 expectedratePerSecond = RATE_PER_SECOND;
Expand Down Expand Up @@ -149,7 +149,7 @@ contract adjustRatePerSecond_Integration_Test is Integration_Test {

function test_adjustRatePerSecond(uint256 streamId, IERC20 asset) internal {
openEnded.deposit(streamId, DEPOSIT_AMOUNT);
vm.warp({ timestamp: WARP_ONE_MONTH });
vm.warp({ newTimestamp: WARP_ONE_MONTH });

uint128 actualratePerSecond = openEnded.getRatePerSecond(streamId);
uint128 expectedratePerSecond = RATE_PER_SECOND;
Expand Down
6 changes: 3 additions & 3 deletions test/integration/cancel/cancel.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ contract Cancel_Integration_Test is Integration_Test {
function setUp() public override {
Integration_Test.setUp();

vm.warp({ timestamp: WARP_ONE_MONTH });
vm.warp({ newTimestamp: WARP_ONE_MONTH });
}

function test_RevertWhen_DelegateCall() external {
Expand Down Expand Up @@ -89,10 +89,10 @@ contract Cancel_Integration_Test is Integration_Test {
whenNoOverrefund
{
// Set the timestamp to 1 month ago to create the stream with the same `lastTimeUpdate` as `defaultStreamId`.
vm.warp({ timestamp: WARP_ONE_MONTH - ONE_MONTH });
vm.warp({ newTimestamp: WARP_ONE_MONTH - ONE_MONTH });
uint256 streamId = createDefaultStreamWithAsset(IERC20(address(usdt)));
openEnded.deposit(streamId, DEPOSIT_AMOUNT);
vm.warp({ timestamp: WARP_ONE_MONTH });
vm.warp({ newTimestamp: WARP_ONE_MONTH });

test_Cancel(streamId, IERC20(address(usdt)));
}
Expand Down
6 changes: 3 additions & 3 deletions test/integration/refund-from-stream/refundFromStream.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract RefundFromStream_Integration_Test is Integration_Test {

defaultDeposit();

vm.warp({ timestamp: WARP_ONE_MONTH });
vm.warp({ newTimestamp: WARP_ONE_MONTH });
}

function test_RevertWhen_DelegateCall() external {
Expand Down Expand Up @@ -103,10 +103,10 @@ contract RefundFromStream_Integration_Test is Integration_Test {
whenNoOverrefund
{
// Set the timestamp to 1 month ago to create the stream with the same `lastTimeUpdate` as `defaultStreamId`.
vm.warp({ timestamp: WARP_ONE_MONTH - ONE_MONTH });
vm.warp({ newTimestamp: WARP_ONE_MONTH - ONE_MONTH });
uint256 streamId = createDefaultStreamWithAsset(IERC20(address(usdt)));
openEnded.deposit(streamId, DEPOSIT_AMOUNT);
vm.warp({ timestamp: WARP_ONE_MONTH });
vm.warp({ newTimestamp: WARP_ONE_MONTH });

test_RefundFromStream(streamId, IERC20(address(usdt)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract RefundableAmountOf_Integration_Test is Integration_Test {
openEnded.refundableAmountOf(defaultStreamId);
}

function test_RefundableAmountOf_BalanceZero() external givenNotNull givenNotCanceled {
function test_RefundableAmountOf_BalanceZero() external view givenNotNull givenNotCanceled {
uint128 refundableAmount = openEnded.refundableAmountOf(defaultStreamId);
assertEq(refundableAmount, 0, "refundable amount");
}
Expand All @@ -27,15 +27,15 @@ contract RefundableAmountOf_Integration_Test is Integration_Test {
uint128 depositAmount = 1e18;
openEnded.deposit(defaultStreamId, depositAmount);

vm.warp({ timestamp: WARP_ONE_MONTH });
vm.warp({ newTimestamp: WARP_ONE_MONTH });
uint128 refundableAmount = openEnded.refundableAmountOf(defaultStreamId);
assertEq(refundableAmount, 0, "refundable amount");
}

function test_RefundableAmountOf() external givenNotNull givenNotCanceled {
defaultDeposit();

vm.warp({ timestamp: WARP_ONE_MONTH });
vm.warp({ newTimestamp: WARP_ONE_MONTH });
uint128 refundableAmount = openEnded.refundableAmountOf(defaultStreamId);
assertEq(refundableAmount, ONE_MONTH_REFUNDABLE_AMOUNT, "refundable amount");
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/stream-debt/streamDebt.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract StreamDebt_Integration_Test is Integration_Test {
}

function test_StreamDebt() external givenNotNull givenNotCanceled {
vm.warp({ timestamp: WARP_ONE_MONTH });
vm.warp({ newTimestamp: WARP_ONE_MONTH });
uint128 streamDebt = openEnded.streamDebt(defaultStreamId);
assertEq(streamDebt, ONE_MONTH_STREAMED_AMOUNT, "stream debt");
}
Expand Down
4 changes: 2 additions & 2 deletions test/integration/streamed-amount-of/streamedAmountOf.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ contract StreamedAmountOf_Integration_Test is Integration_Test {
openEnded.streamedAmountOf(defaultStreamId);
}

function test_StreamedAmountOf_LastTimeUpdateInThePresent() external givenNotNull givenNotCanceled {
function test_StreamedAmountOf_LastTimeUpdateInThePresent() external view givenNotNull givenNotCanceled {
uint128 streamedAmount = openEnded.streamedAmountOf(defaultStreamId);
assertEq(streamedAmount, 0, "streamed amount");
}

function test_StreamedAmountOf() external givenNotNull givenNotCanceled {
vm.warp({ timestamp: WARP_ONE_MONTH });
vm.warp({ newTimestamp: WARP_ONE_MONTH });
uint128 streamedAmount = openEnded.streamedAmountOf(defaultStreamId);
assertEq(streamedAmount, ONE_MONTH_STREAMED_AMOUNT, "streamed amount");
}
Expand Down
6 changes: 3 additions & 3 deletions test/integration/withdraw/withdraw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract Withdraw_Integration_Test is Integration_Test {

defaultDeposit();

vm.warp({ timestamp: WARP_ONE_MONTH });
vm.warp({ newTimestamp: WARP_ONE_MONTH });
}

function test_RevertWhen_DelegateCall() external {
Expand Down Expand Up @@ -136,10 +136,10 @@ contract Withdraw_Integration_Test is Integration_Test {
whenTimeNotGreaterThanCurrentTime
{
// Set the timestamp to 1 month ago to create the stream with the same `lastTimeUpdate` as `defaultStreamId`.
vm.warp({ timestamp: WARP_ONE_MONTH - ONE_MONTH });
vm.warp({ newTimestamp: WARP_ONE_MONTH - ONE_MONTH });
uint256 streamId = createDefaultStreamWithAsset(IERC20(address(usdt)));
openEnded.deposit(streamId, DEPOSIT_AMOUNT);
vm.warp({ timestamp: WARP_ONE_MONTH });
vm.warp({ newTimestamp: WARP_ONE_MONTH });

test_Withdraw(streamId, IERC20(address(usdt)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ contract WithdrawableAmountOf_Integration_Test is Integration_Test {
uint128 depositAmount = 1e18;
openEnded.deposit(defaultStreamId, depositAmount);

vm.warp({ timestamp: WARP_ONE_MONTH });
vm.warp({ newTimestamp: WARP_ONE_MONTH });
uint128 withdrawableAmount = openEnded.withdrawableAmountOf(defaultStreamId);
assertEq(withdrawableAmount, depositAmount, "withdrawable amount");
}

function test_WithdrawableAmountOf() external givenNotNull givenNotCanceled {
defaultDeposit();

vm.warp({ timestamp: WARP_ONE_MONTH });
vm.warp({ newTimestamp: WARP_ONE_MONTH });
uint128 withdrawableAmount = openEnded.withdrawableAmountOf(defaultStreamId);
assertEq(withdrawableAmount, ONE_MONTH_STREAMED_AMOUNT, "withdrawable amount");
}
Expand Down
4 changes: 1 addition & 3 deletions test/invariant/Invariant.t.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.22 <0.9.0;

import { StdInvariant } from "@forge-std/src/StdInvariant.sol";

import { Base_Test } from "../Base.t.sol";
import { TimestampStore } from "./stores/TimestampStore.sol";

/// @notice Common logic needed by all invariant tests.
abstract contract Invariant_Test is Base_Test, StdInvariant {
abstract contract Invariant_Test is Base_Test {
/*//////////////////////////////////////////////////////////////////////////
TEST CONTRACTS
//////////////////////////////////////////////////////////////////////////*/
Expand Down
12 changes: 6 additions & 6 deletions test/invariant/OpenEnded.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ contract OpenEnded_Invariant_Test is Invariant_Test {
uint256 lastStreamId = openEndedStore.lastStreamId();
for (uint256 i = 0; i < lastStreamId; ++i) {
uint256 streamId = openEndedStore.streamIds(i);
assertGte(
assertGe(
uint40(block.timestamp),
openEnded.getLastTimeUpdate(streamId),
"Invariant violation: block timestamp < last time update"
Expand All @@ -81,7 +81,7 @@ contract OpenEnded_Invariant_Test is Invariant_Test {
streamBalancesSumNormalized += uint256(normalizeBalance(streamId));
}

assertGte(
assertGe(
contractBalance,
streamBalancesSumNormalized,
unicode"Invariant violation: contract balances < Σ stream balances normalized"
Expand All @@ -92,7 +92,7 @@ contract OpenEnded_Invariant_Test is Invariant_Test {
uint256 streamDepositedAmountsSum = openEndedStore.streamDepositedAmountsSum();
uint256 streamExtractedAmountsSum = openEndedStore.streamExtractedAmountsSum();

assertGte(
assertGe(
streamDepositedAmountsSum,
streamExtractedAmountsSum,
"Invariant violation: stream deposited amounts sum < stream extracted amounts sum"
Expand Down Expand Up @@ -126,7 +126,7 @@ contract OpenEnded_Invariant_Test is Invariant_Test {
for (uint256 i = 0; i < lastStreamId; ++i) {
uint256 streamId = openEndedStore.streamIds(i);
if (!openEnded.isCanceled(streamId)) {
assertGte(
assertGe(
openEnded.getBalance(streamId),
openEnded.withdrawableAmountOf(streamId),
"Invariant violation: stream balance < withdrawable amount"
Expand All @@ -140,7 +140,7 @@ contract OpenEnded_Invariant_Test is Invariant_Test {
for (uint256 i = 0; i < lastStreamId; ++i) {
uint256 streamId = openEndedStore.streamIds(i);
if (!openEnded.isCanceled(streamId)) {
assertGte(
assertGe(
openEnded.getBalance(streamId),
openEnded.refundableAmountOf(streamId),
"Invariant violation: stream balance < refundable amount"
Expand All @@ -154,7 +154,7 @@ contract OpenEnded_Invariant_Test is Invariant_Test {
for (uint256 i = 0; i < lastStreamId; ++i) {
uint256 streamId = openEndedStore.streamIds(i);
if (!openEnded.isCanceled(streamId)) {
assertGte(
assertGe(
openEnded.streamedAmountOf(streamId),
openEnded.withdrawableAmountOf(streamId),
"Invariant violation: streamed amount < withdrawable amount"
Expand Down
10 changes: 5 additions & 5 deletions test/utils/Assertions.sol
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.22;

import { PRBTest } from "@prb/test/src/PRBTest.sol";
import { StdAssertions } from "forge-std/src/StdAssertions.sol";

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { OpenEnded } from "src/types/DataTypes.sol";

abstract contract Assertions is PRBTest {
abstract contract Assertions is StdAssertions {
/*//////////////////////////////////////////////////////////////////////////
ASSERTIONS
//////////////////////////////////////////////////////////////////////////*/

/// @dev Compares two {IERC20} values.
function assertEq(IERC20 a, IERC20 b) internal {
function assertEq(IERC20 a, IERC20 b) internal pure {
assertEq(address(a), address(b));
}

/// @dev Compares two {IERC20} values.
function assertEq(IERC20 a, IERC20 b, string memory err) internal {
function assertEq(IERC20 a, IERC20 b, string memory err) internal pure {
assertEq(address(a), address(b), err);
}

/// @dev Compares two {OpenEnded.Stream} struct entities.
function assertEq(OpenEnded.Stream memory a, OpenEnded.Stream memory b) internal {
function assertEq(OpenEnded.Stream memory a, OpenEnded.Stream memory b) internal pure {
assertEq(a.ratePerSecond, b.ratePerSecond, "ratePerSecond");
assertEq(a.asset, b.asset, "asset");
assertEq(a.assetDecimals, b.assetDecimals, "assetDecimals");
Expand Down

0 comments on commit 839203b

Please sign in to comment.