Skip to content
This repository was archived by the owner on Apr 3, 2026. It is now read-only.

Commit df782d7

Browse files
test: use forceApprove in fork tests (#476)
Co-authored-by: Andrei Vlad Birgaoanu <99738872+andreivladbrg@users.noreply.github.com>
1 parent 5809647 commit df782d7

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

flow/tests/fork/Flow.t.sol

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pragma solidity >=0.8.22;
33

44
import { IERC4906 } from "@openzeppelin/contracts/interfaces/IERC4906.sol";
55
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
6+
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
67
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
78
import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
89
import { ud21x18, UD21x18 } from "@prb/math/src/UD21x18.sol";
@@ -13,6 +14,8 @@ import { Flow } from "src/types/DataTypes.sol";
1314
import { Fork_Test } from "./Fork.t.sol";
1415

1516
abstract contract Flow_Fork_Test is Fork_Test {
17+
using SafeERC20 for IERC20;
18+
1619
/// @dev Total number of streams to create for each token.
1720
uint256 internal constant TOTAL_STREAMS = 20;
1821

@@ -356,7 +359,9 @@ abstract contract Flow_Fork_Test is Fork_Test {
356359
address sender = flow.getSender(streamId);
357360
setMsgSender(sender);
358361
deal({ token: address(FORK_TOKEN), to: sender, give: depositAmount });
359-
safeApprove(depositAmount);
362+
363+
// Use `forceApprove` for USDT compatibility.
364+
FORK_TOKEN.forceApprove(address(flow), depositAmount);
360365

361366
// Expect the relevant events to be emitted.
362367
vm.expectEmit({ emitter: address(FORK_TOKEN) });

flow/tests/fork/Fork.t.sol

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
pragma solidity >=0.8.22;
33

44
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
5+
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
56
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
67
import { ISablierFlow } from "src/interfaces/ISablierFlow.sol";
78

89
import { Base_Test } from "../Base.t.sol";
910

1011
/// @notice Common logic needed by all fork tests.
1112
abstract contract Fork_Test is Base_Test {
13+
using SafeERC20 for IERC20;
14+
1215
/*//////////////////////////////////////////////////////////////////////////
1316
STATE VARIABLES
1417
//////////////////////////////////////////////////////////////////////////*/
@@ -65,18 +68,13 @@ abstract contract Fork_Test is Base_Test {
6568
address sender = flow.getSender(streamId);
6669
setMsgSender(sender);
6770
deal({ token: address(FORK_TOKEN), to: sender, give: depositAmount });
68-
safeApprove(depositAmount);
71+
// Use `forceApprove` for USDT compatibility.
72+
FORK_TOKEN.forceApprove(address(flow), depositAmount);
6973
flow.deposit({
7074
streamId: streamId,
7175
amount: depositAmount,
7276
sender: sender,
7377
recipient: flow.getRecipient(streamId)
7478
});
7579
}
76-
77-
/// @dev Use a low-level call to ignore reverts in case of USDT.
78-
function safeApprove(uint256 amount) internal {
79-
(bool success,) = address(FORK_TOKEN).call(abi.encodeCall(IERC20.approve, (address(flow), amount)));
80-
success;
81-
}
8280
}

0 commit comments

Comments
 (0)