@@ -6,13 +6,13 @@ import "../lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
6
6
import "forge-std/Test.sol " ;
7
7
import "forge-std/Vm.sol " ;
8
8
import "forge-std/console.sol " ;
9
- import "../src/Spleth .sol " ;
9
+ import "../src/WeSplit .sol " ;
10
10
import "../src/Arith.sol " ;
11
11
12
12
contract TestSpleth is Test {
13
13
using Arith for uint256 ;
14
14
15
- Spleth public spleth ;
15
+ WeSplit public weSplit ;
16
16
address user1 = address (123 );
17
17
address user2 = address (978 );
18
18
address DAI = address (0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063 );
@@ -21,7 +21,7 @@ contract TestSpleth is Test {
21
21
address [] users = new address [](2 );
22
22
23
23
function setUp () public {
24
- spleth = new Spleth ();
24
+ weSplit = new WeSplit ();
25
25
users[0 ] = user1;
26
26
users[1 ] = user2;
27
27
for (uint256 i; i < users.length ; i++ ) setUpUser (users[i]);
@@ -32,71 +32,71 @@ contract TestSpleth is Test {
32
32
deal (DAI, user, 1000 ether);
33
33
deal (USDC, user, 1000 * 1e6 );
34
34
vm.startPrank (user);
35
- IERC20 (DAI).approve (address (spleth ), type (uint256 ).max);
36
- IERC20 (USDC).approve (address (spleth ), type (uint256 ).max);
35
+ IERC20 (DAI).approve (address (weSplit ), type (uint256 ).max);
36
+ IERC20 (USDC).approve (address (weSplit ), type (uint256 ).max);
37
37
vm.stopPrank ();
38
38
}
39
39
40
40
function testCreate () public {
41
41
vm.prank (user1);
42
- uint256 splitId = spleth .create (users);
43
- assertEq (spleth .participantsLength (splitId), 2 );
44
- assertEq (spleth .participant (splitId, 0 ), user1);
45
- assertEq (spleth .participant (splitId, 1 ), user2);
42
+ uint256 splitId = weSplit .create (users);
43
+ assertEq (weSplit .participantsLength (splitId), 2 );
44
+ assertEq (weSplit .participant (splitId, 0 ), user1);
45
+ assertEq (weSplit .participant (splitId, 1 ), user2);
46
46
}
47
47
48
48
function testInitialize () public {
49
49
uint256 amount = 14 ether ;
50
50
vm.startPrank (user1);
51
- uint256 splitId = spleth .create (users);
52
- spleth .initialize (splitId, DAI, amount, receiver);
51
+ uint256 splitId = weSplit .create (users);
52
+ weSplit .initialize (splitId, DAI, amount, receiver);
53
53
vm.stopPrank ();
54
54
55
- assertEq (spleth .token (splitId), DAI, "running token " );
56
- assertEq (spleth .amount (splitId), uint256 (amount), "running amount " );
57
- assertEq (spleth .receiver (splitId), receiver, "running receiver " );
55
+ assertEq (weSplit .token (splitId), DAI, "running token " );
56
+ assertEq (weSplit .amount (splitId), uint256 (amount), "running amount " );
57
+ assertEq (weSplit .receiver (splitId), receiver, "running receiver " );
58
58
}
59
59
60
60
function testPartialApproval () public {
61
61
uint256 amount = 1 ether ;
62
62
vm.prank (user1);
63
- uint256 splitId = spleth .createInitializeApprove (users, DAI, amount, receiver);
63
+ uint256 splitId = weSplit .createInitializeApprove (users, DAI, amount, receiver);
64
64
65
- assertTrue (spleth .approval (splitId, user1), "has approve " );
66
- assertEq (IERC20 (DAI).balanceOf (address (spleth )), amount / 2 , "balance spleth " );
65
+ assertTrue (weSplit .approval (splitId, user1), "has approve " );
66
+ assertEq (IERC20 (DAI).balanceOf (address (weSplit )), amount / 2 , "balance weSplit " );
67
67
}
68
68
69
69
function testSend () public {
70
70
uint256 amount = 3 ether + 1 ;
71
71
vm.startPrank (user1);
72
- uint256 splitId = spleth .create (users);
73
- assertEq (spleth .token (splitId), address (0 ));
74
- spleth .initializeApprove (splitId, DAI, amount, receiver);
72
+ uint256 splitId = weSplit .create (users);
73
+ assertEq (weSplit .token (splitId), address (0 ));
74
+ weSplit .initializeApprove (splitId, DAI, amount, receiver);
75
75
vm.stopPrank ();
76
76
77
77
vm.prank (user2);
78
- spleth .approve (splitId);
78
+ weSplit .approve (splitId);
79
79
80
80
uint256 balanceReceiver = IERC20 (DAI).balanceOf (receiver);
81
- uint256 balanceSpleth = IERC20 (DAI).balanceOf (address (spleth ));
81
+ uint256 balanceSpleth = IERC20 (DAI).balanceOf (address (weSplit ));
82
82
83
83
assertEq (balanceReceiver, amount, "transferred amount " );
84
84
assertEq (balanceSpleth, 2 * amount.divUp (2 ) - amount, "dust amount " );
85
85
// split amount is reset at the end of the function:
86
- assertEq (spleth .amount (splitId), 0 );
86
+ assertEq (weSplit .amount (splitId), 0 );
87
87
88
88
// split properties will be overwritten/reset at the start of a new tx:
89
- assertEq (spleth .approvalCount (splitId), 2 );
90
- assertEq (spleth .token (splitId), DAI);
91
- assertEq (spleth .receiver (splitId), receiver);
89
+ assertEq (weSplit .approvalCount (splitId), 2 );
90
+ assertEq (weSplit .token (splitId), DAI);
91
+ assertEq (weSplit .receiver (splitId), receiver);
92
92
//
93
93
vm.prank (user1);
94
- spleth .initialize (splitId, USDC, amount / 4 , address (1000 ));
94
+ weSplit .initialize (splitId, USDC, amount / 4 , address (1000 ));
95
95
//
96
- assertEq (spleth .approvalCount (splitId), 0 );
97
- assertEq (spleth .token (splitId), USDC);
98
- assertEq (spleth .receiver (splitId), address (1000 ));
99
- assertEq (spleth .amount (splitId), amount / 4 );
96
+ assertEq (weSplit .approvalCount (splitId), 0 );
97
+ assertEq (weSplit .token (splitId), USDC);
98
+ assertEq (weSplit .receiver (splitId), address (1000 ));
99
+ assertEq (weSplit .amount (splitId), amount / 4 );
100
100
}
101
101
102
102
function testTwoGroups () public {
@@ -105,18 +105,18 @@ contract TestSpleth is Test {
105
105
uint256 balanceReceiverBefore = IERC20 (DAI).balanceOf (receiver);
106
106
107
107
vm.prank (user1);
108
- uint256 firstSplitId = spleth .createInitializeApprove (users, DAI, amount, receiver);
108
+ uint256 firstSplitId = weSplit .createInitializeApprove (users, DAI, amount, receiver);
109
109
110
110
vm.prank (user2);
111
- uint256 secondSplitId = spleth .createInitializeApprove (users, DAI, amount, receiver);
111
+ uint256 secondSplitId = weSplit .createInitializeApprove (users, DAI, amount, receiver);
112
112
113
113
assertFalse (firstSplitId == secondSplitId, "split ids should be different " );
114
114
115
115
vm.prank (user1);
116
- spleth .approve (secondSplitId);
116
+ weSplit .approve (secondSplitId);
117
117
118
118
vm.prank (user2);
119
- spleth .approve (firstSplitId);
119
+ weSplit .approve (firstSplitId);
120
120
121
121
uint256 balanceReceiverAfter = IERC20 (DAI).balanceOf (receiver);
122
122
0 commit comments