@@ -6,7 +6,7 @@ import "forge-std/console.sol";
66
77import {BasedAppManager} from "../src/BasedAppManager.sol " ;
88import {ICore} from "../src/interfaces/ICore.sol " ;
9- import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol " ; // For deploying the UUPS proxy
9+ import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol " ;
1010import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol " ;
1111import "./mocks/MockERC20.sol " ;
1212
@@ -52,6 +52,10 @@ contract BasedAppManagerTest is Test, OwnableUpgradeable {
5252 vm.stopPrank ();
5353 }
5454
55+ // *****************************************
56+ // ** Section: Ownership **
57+ // *****************************************
58+
5559 // Check the owner of the BasedAppManager
5660 function testOwner () public view {
5761 assertEq (proxiedManager.owner (), OWNER, "Owner should be the deployer " );
@@ -88,6 +92,10 @@ contract BasedAppManagerTest is Test, OwnableUpgradeable {
8892 assertEq (currentImplementation, address (newImplementation), "Implementation should be upgraded " );
8993 }
9094
95+ // *****************************************
96+ // ** Section: Delegate Validator Balance **
97+ // *****************************************
98+
9199 function testDelegateMinimumBalance () public {
92100 vm.startPrank (USER1);
93101 proxiedManager.delegateBalance (RECEIVER, 1 );
@@ -177,6 +185,29 @@ contract BasedAppManagerTest is Test, OwnableUpgradeable {
177185 vm.stopPrank ();
178186 }
179187
188+ function testRevertDoubleDelegateSameReceiver () public {
189+ vm.startPrank (USER1);
190+ proxiedManager.delegateBalance (RECEIVER, 1 );
191+ vm.expectRevert ("Delegation already exists " );
192+ proxiedManager.delegateBalance (RECEIVER, 2 );
193+ uint256 delegatedAmount = proxiedManager.delegations (USER1, RECEIVER);
194+ uint256 totalDelegatedPercentage = proxiedManager.totalDelegatedPercentage (USER1);
195+ assertEq (delegatedAmount, 1 , "Delegated amount should be 0.01% " );
196+ assertEq (totalDelegatedPercentage, 1 , "Total delegated percentage should be 0.01% " );
197+ vm.stopPrank ();
198+ }
199+
200+ function testRevertInvalidPercentageDelegateBalance () public {
201+ vm.startPrank (USER1);
202+ vm.expectRevert ("Invalid percentage " );
203+ proxiedManager.delegateBalance (RECEIVER, 1e4 + 1 );
204+ uint256 delegatedAmount = proxiedManager.delegations (USER1, RECEIVER);
205+ uint256 totalDelegatedPercentage = proxiedManager.totalDelegatedPercentage (USER1);
206+ assertEq (delegatedAmount, 0 , "Delegated amount should be 0.01% " );
207+ assertEq (totalDelegatedPercentage, 0 , "Total delegated percentage should be 0.01% " );
208+ vm.stopPrank ();
209+ }
210+
180211 function testUpdateTotalDelegatePercentageByTheSameUser () public {
181212 vm.startPrank (USER1);
182213 proxiedManager.delegateBalance (RECEIVER, 1 );
@@ -190,6 +221,78 @@ contract BasedAppManagerTest is Test, OwnableUpgradeable {
190221 vm.stopPrank ();
191222 }
192223
224+ function testRevertUpdateBalanceNotExisting () public {
225+ vm.startPrank (USER1);
226+ vm.expectRevert ("Delegation does not exist " );
227+ proxiedManager.updateDelegatedBalance (RECEIVER, 1e4 );
228+ uint256 delegatedAmount = proxiedManager.delegations (USER1, RECEIVER);
229+ uint256 totalDelegatedPercentage = proxiedManager.totalDelegatedPercentage (USER1);
230+ assertEq (delegatedAmount, 0 , "Delegated amount should be 100% " );
231+ assertEq (totalDelegatedPercentage, 0 , "Total delegated percentage should be 100% " );
232+ vm.stopPrank ();
233+ }
234+
235+ function testRevertUpdateBalanceTooHigh () public {
236+ vm.startPrank (USER1);
237+ proxiedManager.delegateBalance (RECEIVER, 1 );
238+ proxiedManager.delegateBalance (RECEIVER2, 1 );
239+ vm.expectRevert ("Percentage exceeds 100% " );
240+ proxiedManager.updateDelegatedBalance (RECEIVER, 1e4 );
241+ uint256 delegatedAmount = proxiedManager.delegations (USER1, RECEIVER);
242+ uint256 delegatedAmount2 = proxiedManager.delegations (USER1, RECEIVER2);
243+ uint256 totalDelegatedPercentage = proxiedManager.totalDelegatedPercentage (USER1);
244+ assertEq (delegatedAmount, 1 , "Delegated amount should be 100% " );
245+ assertEq (delegatedAmount2, 1 , "Delegated amount should be 100% " );
246+ assertEq (totalDelegatedPercentage, 2 , "Total delegated percentage should be 100% " );
247+ vm.stopPrank ();
248+ }
249+
250+ function testRemoveDelegateBalance () public {
251+ testDelegateFullBalance ();
252+ vm.startPrank (USER1);
253+ proxiedManager.removeDelegatedBalance (RECEIVER);
254+ uint256 delegatedAmount = proxiedManager.delegations (USER1, RECEIVER);
255+ uint256 totalDelegatedPercentage = proxiedManager.totalDelegatedPercentage (USER1);
256+ assertEq (delegatedAmount, 0 , "Delegated amount should be 0% " );
257+ assertEq (totalDelegatedPercentage, 0 , "Total delegated percentage should be 0% " );
258+ vm.stopPrank ();
259+ }
260+
261+ function testRemoveDelgateBalanceAndComputeTotal () public {
262+ testUpdateTotalDelegatedPercentage (100 , 200 );
263+ vm.startPrank (USER1);
264+ proxiedManager.removeDelegatedBalance (RECEIVER);
265+ uint256 delegatedAmount = proxiedManager.delegations (USER1, RECEIVER);
266+ uint256 delegatedAmount2 = proxiedManager.delegations (USER1, RECEIVER2);
267+ uint256 totalDelegatedPercentage = proxiedManager.totalDelegatedPercentage (USER1);
268+ assertEq (delegatedAmount, 0 , "Delegated amount should be 0% " );
269+ assertEq (delegatedAmount2, 200 , "Delegated amount should be 0.01% " );
270+ assertEq (totalDelegatedPercentage, 200 , "Total delegated percentage should be 0.01% " );
271+ proxiedManager.delegateBalance (RECEIVER, 1 );
272+ delegatedAmount = proxiedManager.delegations (USER1, RECEIVER);
273+ delegatedAmount2 = proxiedManager.delegations (USER1, RECEIVER2);
274+ totalDelegatedPercentage = proxiedManager.totalDelegatedPercentage (USER1);
275+ assertEq (delegatedAmount, 1 , "Delegated amount should be 0% " );
276+ assertEq (delegatedAmount2, 200 , "Delegated amount should be 0.01% " );
277+ assertEq (totalDelegatedPercentage, 201 , "Total delegated percentage should be 0.01% " );
278+ vm.stopPrank ();
279+ }
280+
281+ function testRevertRemoveNonExistingBalance () public {
282+ vm.startPrank (USER1);
283+ vm.expectRevert ("No delegation exists " );
284+ proxiedManager.removeDelegatedBalance (RECEIVER);
285+ uint256 delegatedAmount = proxiedManager.delegations (USER1, RECEIVER);
286+ uint256 totalDelegatedPercentage = proxiedManager.totalDelegatedPercentage (USER1);
287+ assertEq (delegatedAmount, 0 , "Delegated amount should be 0% " );
288+ assertEq (totalDelegatedPercentage, 0 , "Total delegated percentage should be 0% " );
289+ vm.stopPrank ();
290+ }
291+
292+ // ***********************
293+ // ** Section: Strategy **
294+ // ***********************
295+
193296 function testCreateStrategy () public {
194297 vm.startPrank (USER1);
195298 uint256 strategyId1 = proxiedManager.createStrategy (5 );
@@ -301,6 +404,10 @@ contract BasedAppManagerTest is Test, OwnableUpgradeable {
301404 vm.stopPrank ();
302405 }
303406
407+ // ********************
408+ // ** Section: bApps **
409+ // ********************
410+
304411 function testRegisterService () public {
305412 vm.startPrank (USER1);
306413 address [] memory tokensInput = new address [](1 );
0 commit comments