Skip to content

Commit 4e3b566

Browse files
committed
feat: we split ?
1 parent 3b40bc3 commit 4e3b566

File tree

4 files changed

+38
-40
lines changed

4 files changed

+38
-40
lines changed

script/DeploySpleth.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
pragma solidity ^0.8.13;
33

44
import "forge-std/Script.sol";
5-
import "../src/Spleth.sol";
5+
import "../src/WeSplit.sol";
66

77
contract DeploySpleth is Script {
88
function run() public {
99
vm.broadcast();
10-
new Spleth();
10+
new WeSplit();
1111
}
1212
}

src/Spleth.sol renamed to src/WeSplit.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pragma solidity ^0.8.13;
44
import "openzeppelin-contracts/token/ERC20/utils/SafeERC20.sol";
55
import "./Arith.sol";
66

7-
contract Spleth {
7+
contract WeSplit {
88
using Arith for uint256;
99

1010
uint256 public nextId;

test/TestArith.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import "forge-std/Vm.sol";
55
import "forge-std/console.sol";
66
import "forge-std/Test.sol";
77

8-
import "../src/Spleth.sol";
98
import "../src/Arith.sol";
109

1110
contract TestArith is Test {
@@ -21,5 +20,4 @@ contract TestArith is Test {
2120
assertEq(x.divUp(2), 7);
2221
assertEq(x.divUp(3), 5);
2322
}
24-
2523
}

test/TestSpleth.sol

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import "../lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
66
import "forge-std/Test.sol";
77
import "forge-std/Vm.sol";
88
import "forge-std/console.sol";
9-
import "../src/Spleth.sol";
9+
import "../src/WeSplit.sol";
1010
import "../src/Arith.sol";
1111

1212
contract TestSpleth is Test {
1313
using Arith for uint256;
1414

15-
Spleth public spleth;
15+
WeSplit public weSplit;
1616
address user1 = address(123);
1717
address user2 = address(978);
1818
address DAI = address(0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063);
@@ -21,7 +21,7 @@ contract TestSpleth is Test {
2121
address[] users = new address[](2);
2222

2323
function setUp() public {
24-
spleth = new Spleth();
24+
weSplit = new WeSplit();
2525
users[0] = user1;
2626
users[1] = user2;
2727
for (uint256 i; i < users.length; i++) setUpUser(users[i]);
@@ -32,71 +32,71 @@ contract TestSpleth is Test {
3232
deal(DAI, user, 1000 ether);
3333
deal(USDC, user, 1000 * 1e6);
3434
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);
3737
vm.stopPrank();
3838
}
3939

4040
function testCreate() public {
4141
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);
4646
}
4747

4848
function testInitialize() public {
4949
uint256 amount = 14 ether;
5050
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);
5353
vm.stopPrank();
5454

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");
5858
}
5959

6060
function testPartialApproval() public {
6161
uint256 amount = 1 ether;
6262
vm.prank(user1);
63-
uint256 splitId = spleth.createInitializeApprove(users, DAI, amount, receiver);
63+
uint256 splitId = weSplit.createInitializeApprove(users, DAI, amount, receiver);
6464

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");
6767
}
6868

6969
function testSend() public {
7070
uint256 amount = 3 ether + 1;
7171
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);
7575
vm.stopPrank();
7676

7777
vm.prank(user2);
78-
spleth.approve(splitId);
78+
weSplit.approve(splitId);
7979

8080
uint256 balanceReceiver = IERC20(DAI).balanceOf(receiver);
81-
uint256 balanceSpleth = IERC20(DAI).balanceOf(address(spleth));
81+
uint256 balanceSpleth = IERC20(DAI).balanceOf(address(weSplit));
8282

8383
assertEq(balanceReceiver, amount, "transferred amount");
8484
assertEq(balanceSpleth, 2 * amount.divUp(2) - amount, "dust amount");
8585
// split amount is reset at the end of the function:
86-
assertEq(spleth.amount(splitId), 0);
86+
assertEq(weSplit.amount(splitId), 0);
8787

8888
// 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);
9292
//
9393
vm.prank(user1);
94-
spleth.initialize(splitId, USDC, amount / 4, address(1000));
94+
weSplit.initialize(splitId, USDC, amount / 4, address(1000));
9595
//
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);
100100
}
101101

102102
function testTwoGroups() public {
@@ -105,18 +105,18 @@ contract TestSpleth is Test {
105105
uint256 balanceReceiverBefore = IERC20(DAI).balanceOf(receiver);
106106

107107
vm.prank(user1);
108-
uint256 firstSplitId = spleth.createInitializeApprove(users, DAI, amount, receiver);
108+
uint256 firstSplitId = weSplit.createInitializeApprove(users, DAI, amount, receiver);
109109

110110
vm.prank(user2);
111-
uint256 secondSplitId = spleth.createInitializeApprove(users, DAI, amount, receiver);
111+
uint256 secondSplitId = weSplit.createInitializeApprove(users, DAI, amount, receiver);
112112

113113
assertFalse(firstSplitId == secondSplitId, "split ids should be different");
114114

115115
vm.prank(user1);
116-
spleth.approve(secondSplitId);
116+
weSplit.approve(secondSplitId);
117117

118118
vm.prank(user2);
119-
spleth.approve(firstSplitId);
119+
weSplit.approve(firstSplitId);
120120

121121
uint256 balanceReceiverAfter = IERC20(DAI).balanceOf(receiver);
122122

0 commit comments

Comments
 (0)