-
Notifications
You must be signed in to change notification settings - Fork 48
/
Dynamic.t.sol
142 lines (120 loc) · 6.56 KB
/
Dynamic.t.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.19 <0.9.0;
import { IERC20 } from "@openzeppelin/token/ERC20/IERC20.sol";
import { Broker, LockupDynamic } from "../../../src/types/DataTypes.sol";
import { Lockup_Shared_Test } from "../lockup/Lockup.t.sol";
/// @title Dynamic_Shared_Test
/// @notice Common testing logic needed across {SablierV2LockupDynamic} unit and fuzz tests.
abstract contract Dynamic_Shared_Test is Lockup_Shared_Test {
struct CreateParams {
LockupDynamic.CreateWithDeltas createWithDeltas;
LockupDynamic.CreateWithMilestones createWithMilestones;
}
/// @dev These have to be pre-declared so that `vm.expectRevert` does not expect a revert in `defaults`.
/// See https://github.com/foundry-rs/foundry/issues/4762.
CreateParams private _params;
function setUp() public virtual override {
Lockup_Shared_Test.setUp();
_params.createWithDeltas.sender = users.sender;
_params.createWithDeltas.recipient = users.recipient;
_params.createWithDeltas.totalAmount = defaults.TOTAL_AMOUNT();
_params.createWithDeltas.asset = dai;
_params.createWithDeltas.cancelable = true;
_params.createWithDeltas.broker = defaults.broker();
_params.createWithMilestones.sender = users.sender;
_params.createWithMilestones.recipient = users.recipient;
_params.createWithMilestones.totalAmount = defaults.TOTAL_AMOUNT();
_params.createWithMilestones.asset = dai;
_params.createWithMilestones.cancelable = true;
_params.createWithMilestones.startTime = defaults.START_TIME();
_params.createWithMilestones.broker = defaults.broker();
// See https://github.com/ethereum/solidity/issues/12783
LockupDynamic.SegmentWithDelta[] memory segmentsWithDeltas = defaults.segmentsWithDeltas();
LockupDynamic.Segment[] memory segments = defaults.segments();
for (uint256 i = 0; i < defaults.SEGMENT_COUNT(); ++i) {
_params.createWithDeltas.segments.push(segmentsWithDeltas[i]);
_params.createWithMilestones.segments.push(segments[i]);
}
}
/// @dev Creates the default stream.
function createDefaultStream() internal override returns (uint256 streamId) {
streamId = dynamic.createWithMilestones(_params.createWithMilestones);
}
/// @dev Creates the default stream with the provided asset.
function createDefaultStreamWithAsset(IERC20 asset) internal override returns (uint256 streamId) {
LockupDynamic.CreateWithMilestones memory params = _params.createWithMilestones;
params.asset = asset;
streamId = dynamic.createWithMilestones(params);
}
/// @dev Creates the default stream with the provided broker.
function createDefaultStreamWithBroker(Broker memory broker) internal override returns (uint256 streamId) {
LockupDynamic.CreateWithMilestones memory params = _params.createWithMilestones;
params.broker = broker;
streamId = dynamic.createWithMilestones(params);
}
/// @dev Creates the default stream with deltas.
function createDefaultStreamWithDeltas() internal returns (uint256 streamId) {
streamId = dynamic.createWithDeltas(_params.createWithDeltas);
}
/// @dev Creates the default stream with the provided deltas.
function createDefaultStreamWithDeltas(LockupDynamic.SegmentWithDelta[] memory segments)
internal
returns (uint256 streamId)
{
LockupDynamic.CreateWithDeltas memory params = _params.createWithDeltas;
params.segments = segments;
streamId = dynamic.createWithDeltas(params);
}
/// @dev Creates the default stream with the provided end time.
function createDefaultStreamWithEndTime(uint40 endTime) internal override returns (uint256 streamId) {
LockupDynamic.CreateWithMilestones memory params = _params.createWithMilestones;
params.segments[1].milestone = endTime;
streamId = dynamic.createWithMilestones(params);
}
/// @dev Creates a stream that will not be cancelable.
function createDefaultStreamNotCancelable() internal override returns (uint256 streamId) {
LockupDynamic.CreateWithMilestones memory params = _params.createWithMilestones;
params.cancelable = false;
streamId = dynamic.createWithMilestones(params);
}
/// @dev Creates the default stream with the provided range.
function createDefaultStreamWithRange(LockupDynamic.Range memory range) internal returns (uint256 streamId) {
LockupDynamic.CreateWithMilestones memory params = _params.createWithMilestones;
params.startTime = range.start;
params.segments[1].milestone = range.end;
streamId = dynamic.createWithMilestones(params);
}
/// @dev Creates the default stream with the provided recipient.
function createDefaultStreamWithRecipient(address recipient) internal override returns (uint256 streamId) {
LockupDynamic.CreateWithMilestones memory params = _params.createWithMilestones;
params.recipient = recipient;
streamId = dynamic.createWithMilestones(params);
}
/// @dev Creates the default stream with the provided segments.
function createDefaultStreamWithSegments(LockupDynamic.Segment[] memory segments)
internal
returns (uint256 streamId)
{
LockupDynamic.CreateWithMilestones memory params = _params.createWithMilestones;
params.segments = segments;
streamId = dynamic.createWithMilestones(params);
}
/// @dev Creates the default stream with the provided sender.
function createDefaultStreamWithSender(address sender) internal override returns (uint256 streamId) {
LockupDynamic.CreateWithMilestones memory params = _params.createWithMilestones;
params.sender = sender;
streamId = dynamic.createWithMilestones(params);
}
/// @dev Creates the default stream with the provided start time..
function createDefaultStreamWithStartTime(uint40 startTime) internal override returns (uint256 streamId) {
LockupDynamic.CreateWithMilestones memory params = _params.createWithMilestones;
params.startTime = startTime;
streamId = dynamic.createWithMilestones(params);
}
/// @dev Creates the default stream with the provided total amount.
function createDefaultStreamWithTotalAmount(uint128 totalAmount) internal override returns (uint256 streamId) {
LockupDynamic.CreateWithMilestones memory params = _params.createWithMilestones;
params.totalAmount = totalAmount;
streamId = dynamic.createWithMilestones(params);
}
}