@@ -441,6 +441,28 @@ contract BasedAppManagerTest is Test, OwnableUpgradeable {
441441 vm.stopPrank ();
442442 }
443443
444+ function testStrategyOptInToServiceWithMultipleTokens () public {
445+ testCreateStrategy ();
446+ testRegisterServiceWith2Tokens ();
447+ vm.startPrank (USER1);
448+ (address owner ,,,) = proxiedManager.strategies (1 );
449+ assertEq (owner, USER1, "Strategy owner " );
450+ address [] memory tokensInput = new address [](1 );
451+ tokensInput[0 ] = address (erc20mock);
452+ uint32 [] memory obligationPercentagesInput = new uint32 [](1 );
453+ obligationPercentagesInput[0 ] = 9000 ; // 90%
454+ proxiedManager.optInToService (1 , SERVICE1, tokensInput, obligationPercentagesInput);
455+ uint256 strategyId = proxiedManager.accountServiceStrategy (USER1, SERVICE1);
456+ assertEq (strategyId, 1 , "Strategy id " );
457+ uint256 obligationPercentage = proxiedManager.obligations (strategyId, SERVICE1, address (erc20mock));
458+ assertEq (obligationPercentage, 9000 , "Obligation percentage " );
459+ uint256 usedTokens = proxiedManager.usedTokens (strategyId, address (erc20mock));
460+ assertEq (usedTokens, 1 , "Used tokens " );
461+ uint32 numberOfObligations = proxiedManager.obligationsCounter (strategyId, SERVICE1);
462+ assertEq (numberOfObligations, 1 , "Number of obligations " );
463+ vm.stopPrank ();
464+ }
465+
444466 function testStrategyOptInToServiceWithETH () public {
445467 testCreateStrategy ();
446468 testRegisterServiceWithETH ();
@@ -463,6 +485,21 @@ contract BasedAppManagerTest is Test, OwnableUpgradeable {
463485 vm.stopPrank ();
464486 }
465487
488+ function testStrategyOptInWithNonOwner () public {
489+ testCreateStrategy ();
490+ testRegisterService ();
491+ vm.startPrank (ATTACKER);
492+ (address owner ,,,) = proxiedManager.strategies (1 );
493+ assertEq (owner, USER1, "Strategy owner " );
494+ address [] memory tokensInput = new address [](1 );
495+ tokensInput[0 ] = address (erc20mock);
496+ uint32 [] memory obligationPercentagesInput = new uint32 [](1 );
497+ obligationPercentagesInput[0 ] = 9000 ; // 90%
498+ vm.expectRevert ("Strategy: not the owner " );
499+ proxiedManager.optInToService (1 , SERVICE1, tokensInput, obligationPercentagesInput);
500+ vm.stopPrank ();
501+ }
502+
466503 function testStrategyOptInToServiceNonMatchingTokensAndObligations () public {
467504 testCreateStrategy ();
468505 testRegisterService ();
@@ -558,7 +595,7 @@ contract BasedAppManagerTest is Test, OwnableUpgradeable {
558595 vm.stopPrank ();
559596 }
560597
561- function testCreateObligationETHAndDepositETH () public {
598+ function testCreateStrategyETHAndDepositETH () public {
562599 testStrategyOptInToServiceWithETH ();
563600 vm.startPrank (USER1);
564601 uint256 strategyTokenBalance = proxiedManager.strategyTokenBalances (1 , USER1, address (erc20mock));
@@ -607,6 +644,17 @@ contract BasedAppManagerTest is Test, OwnableUpgradeable {
607644 vm.stopPrank ();
608645 }
609646
647+ function testCreateNewObligationSuccessful () public {
648+ testStrategyOptInToServiceWithMultipleTokens ();
649+ vm.startPrank (USER1);
650+ address [] memory tokens = proxiedManager.getServiceTokens (SERVICE1);
651+ assertEq (tokens[0 ], address (erc20mock), "Service token " );
652+ assertEq (tokens[1 ], address (erc20mock2), "Service token 2 " );
653+ assertEq (tokens.length , 2 , "Service token length " );
654+ proxiedManager.createObligation (STRATEGY1, SERVICE1, address (erc20mock2), 10_000 );
655+ vm.stopPrank ();
656+ }
657+
610658 function testFastWithdrawErc20FromStrategy () public {
611659 testStrategyOwnerDepositERC20WithNoObligation (200 );
612660 vm.startPrank (USER1);
@@ -721,7 +769,7 @@ contract BasedAppManagerTest is Test, OwnableUpgradeable {
721769 vm.stopPrank ();
722770 }
723771
724- function testUpdateStrategyObligationFinalize () public {
772+ function testUpdateStrategyObligationFinalizeOnInitialLimit () public {
725773 testStrategyOptInToService ();
726774 vm.startPrank (USER1);
727775 proxiedManager.proposeUpdateObligation (STRATEGY1, SERVICE1, address (erc20mock), 1000 );
@@ -741,7 +789,116 @@ contract BasedAppManagerTest is Test, OwnableUpgradeable {
741789 vm.stopPrank ();
742790 }
743791
792+ function testUpdateStrategyObligationFinalizeOnLatestLimit () public {
793+ testStrategyOptInToService ();
794+ vm.startPrank (USER1);
795+ proxiedManager.proposeUpdateObligation (STRATEGY1, SERVICE1, address (erc20mock), 1000 );
796+ (uint32 percentage , uint256 requestTime ) =
797+ proxiedManager.obligationRequests (STRATEGY1, SERVICE1, address (erc20mock));
798+ uint32 oldPercentage = proxiedManager.obligations (STRATEGY1, SERVICE1, address (erc20mock));
799+ assertEq (oldPercentage, 9000 , "Obligation percentage proposed " );
800+ assertEq (percentage, 1000 , "Obligation percentage proposed " );
801+ assertEq (requestTime, 1 , "Obligation update time " );
802+ vm.warp (block .timestamp + 7 days + 1 days);
803+ proxiedManager.finalizeUpdateObligation (STRATEGY1, SERVICE1, address (erc20mock));
804+ (percentage, requestTime) = proxiedManager.obligationRequests (STRATEGY1, SERVICE1, address (erc20mock));
805+ assertEq (percentage, 1000 , "Obligation percentage proposed " );
806+ assertEq (requestTime, 1 , "Obligation update time " );
807+ uint32 newPercentage = proxiedManager.obligations (STRATEGY1, SERVICE1, address (erc20mock));
808+ assertEq (newPercentage, 1000 , "Obligation new percentage " );
809+ vm.stopPrank ();
810+ }
811+
812+ function testUpdateStrategyObligationRemoval () public {
813+ testStrategyOptInToService ();
814+ vm.startPrank (USER1);
815+ proxiedManager.proposeUpdateObligation (STRATEGY1, SERVICE1, address (erc20mock), 0 );
816+ (uint32 percentage , uint256 requestTime ) =
817+ proxiedManager.obligationRequests (STRATEGY1, SERVICE1, address (erc20mock));
818+ uint32 oldPercentage = proxiedManager.obligations (STRATEGY1, SERVICE1, address (erc20mock));
819+ uint32 obligationCounter = proxiedManager.obligationsCounter (STRATEGY1, SERVICE1);
820+ assertEq (obligationCounter, 1 , "Obligation counter " );
821+ assertEq (oldPercentage, 9000 , "Obligation percentage proposed " );
822+ assertEq (percentage, 0 , "Obligation percentage proposed " );
823+ assertEq (requestTime, 1 , "Obligation update time " );
824+ vm.warp (block .timestamp + 7 days + 1 days);
825+ proxiedManager.finalizeUpdateObligation (STRATEGY1, SERVICE1, address (erc20mock));
826+ (percentage, requestTime) = proxiedManager.obligationRequests (STRATEGY1, SERVICE1, address (erc20mock));
827+ assertEq (percentage, 0 , "Obligation percentage proposed " );
828+ assertEq (requestTime, 1 , "Obligation update time " );
829+ uint32 newPercentage = proxiedManager.obligations (STRATEGY1, SERVICE1, address (erc20mock));
830+ assertEq (newPercentage, 0 , "Obligation new percentage " );
831+ uint32 newObligationCounter = proxiedManager.obligationsCounter (STRATEGY1, SERVICE1);
832+ assertEq (newObligationCounter, 0 , "Obligation counter " );
833+ vm.stopPrank ();
834+ }
835+
836+ function testUpdateStrategyObligationFinalizeTooLate () public {
837+ testStrategyOptInToService ();
838+ vm.startPrank (USER1);
839+ proxiedManager.proposeUpdateObligation (STRATEGY1, SERVICE1, address (erc20mock), 1000 );
840+ (uint32 percentage , uint256 requestTime ) =
841+ proxiedManager.obligationRequests (STRATEGY1, SERVICE1, address (erc20mock));
842+ uint32 oldPercentage = proxiedManager.obligations (STRATEGY1, SERVICE1, address (erc20mock));
843+ assertEq (oldPercentage, 9000 , "Obligation percentage proposed " );
844+ assertEq (percentage, 1000 , "Obligation percentage proposed " );
845+ assertEq (requestTime, 1 , "Obligation update time " );
846+ vm.warp (block .timestamp + 7 days + 1 days + 1 seconds);
847+ vm.expectRevert ("Update expired " );
848+ proxiedManager.finalizeUpdateObligation (STRATEGY1, SERVICE1, address (erc20mock));
849+ (percentage, requestTime) = proxiedManager.obligationRequests (STRATEGY1, SERVICE1, address (erc20mock));
850+ assertEq (percentage, 1000 , "Obligation percentage proposed " );
851+ assertEq (requestTime, 1 , "Obligation update time " );
852+ uint32 newPercentage = proxiedManager.obligations (STRATEGY1, SERVICE1, address (erc20mock));
853+ assertEq (newPercentage, 9000 , "Obligation new percentage is still the same " );
854+ vm.stopPrank ();
855+ }
856+
857+ function testUpdateStrategyObligationFinalizeTooEarly () public {
858+ testStrategyOptInToService ();
859+ vm.startPrank (USER1);
860+ proxiedManager.proposeUpdateObligation (STRATEGY1, SERVICE1, address (erc20mock), 1000 );
861+ (uint32 percentage , uint256 requestTime ) =
862+ proxiedManager.obligationRequests (STRATEGY1, SERVICE1, address (erc20mock));
863+ uint32 oldPercentage = proxiedManager.obligations (STRATEGY1, SERVICE1, address (erc20mock));
864+ assertEq (oldPercentage, 9000 , "Obligation percentage proposed " );
865+ assertEq (percentage, 1000 , "Obligation percentage proposed " );
866+ assertEq (requestTime, 1 , "Obligation update time " );
867+ vm.warp (block .timestamp + 7 days - 1 seconds);
868+ vm.expectRevert ("Timelock not elapsed " );
869+ proxiedManager.finalizeUpdateObligation (STRATEGY1, SERVICE1, address (erc20mock));
870+ (percentage, requestTime) = proxiedManager.obligationRequests (STRATEGY1, SERVICE1, address (erc20mock));
871+ assertEq (percentage, 1000 , "Obligation percentage proposed " );
872+ assertEq (requestTime, 1 , "Obligation update time " );
873+ uint32 newPercentage = proxiedManager.obligations (STRATEGY1, SERVICE1, address (erc20mock));
874+ assertEq (newPercentage, 9000 , "Obligation new percentage is still the same " );
875+ vm.stopPrank ();
876+ }
877+
878+ // function testFastRemovalObligation() public {
879+ // testStrategyOptInToService();
880+ // vm.startPrank(USER1);
881+ // proxiedManager.createObligation(STRATEGY1, SERVICE1, address(erc20mock2), 10000);
882+ // uint32 percentage = proxiedManager.obligations(STRATEGY1, SERVICE1, address(erc20mock2));
883+ // assertEq(percentage, 10000, "Obligation percentage");
884+ // uint32 numberOfObligations = proxiedManager.obligationsCounter(STRATEGY1, SERVICE1);
885+ // assertEq(numberOfObligations, 2, "Number of obligations");
886+ // proxiedManager.fastRemoveObligation(STRATEGY1, SERVICE1, address(erc20mock2));
887+ // percentage = proxiedManager.obligations(STRATEGY1, SERVICE1, address(erc20mock2));
888+ // assertEq(percentage, 0, "Obligation percentage");
889+ // numberOfObligations = proxiedManager.obligationsCounter(STRATEGY1, SERVICE1);
890+ // assertEq(numberOfObligations, 1, "Number of obligations");
891+ // vm.stopPrank();
892+ // }
893+
894+ // function testRevertFastRemovalObligationInvalid() public {
895+
896+ // }
897+
744898 // todo check update removal obligation
899+ // todo test empty updates, when no request was sent before, so just the finalize.
900+ // todo test double finalize
901+ // fastRemove obligation
745902
746903 // ********************
747904 // ** Section: bApps **
@@ -766,6 +923,28 @@ contract BasedAppManagerTest is Test, OwnableUpgradeable {
766923 vm.stopPrank ();
767924 }
768925
926+ function testRegisterServiceWith2Tokens () public {
927+ vm.startPrank (USER1);
928+ address [] memory tokensInput = new address [](2 );
929+ tokensInput[0 ] = address (erc20mock);
930+ tokensInput[1 ] = address (erc20mock2);
931+ uint32 sharedRiskLevelInput = 102 ;
932+ uint32 slashingCorrelationPenaltyInput = 100 ;
933+ proxiedManager.registerService (
934+ USER1, SERVICE1, tokensInput, sharedRiskLevelInput, slashingCorrelationPenaltyInput
935+ );
936+ (address owner , uint32 slashingCorrelationPenalty , uint32 sharedRiskLevel ) = proxiedManager.services (SERVICE1);
937+ assertEq (owner, USER1, "Service owner " );
938+ assertEq (sharedRiskLevelInput, sharedRiskLevel, "Service sharedRiskLevel " );
939+ assertEq (slashingCorrelationPenaltyInput, slashingCorrelationPenalty, "Service slashingCorrelationPenalty " );
940+ address [] memory tokens = proxiedManager.getServiceTokens (SERVICE1);
941+ assertEq (tokens[0 ], address (erc20mock), "Service token " );
942+ assertEq (tokensInput[0 ], address (erc20mock), "Service token " );
943+ assertEq (tokens[1 ], address (erc20mock2), "Service token 2 " );
944+ assertEq (tokensInput[1 ], address (erc20mock2), "Service token 2 " );
945+ vm.stopPrank ();
946+ }
947+
769948 function testRegisterServiceWithETH () public {
770949 vm.startPrank (USER1);
771950 address [] memory tokensInput = new address [](1 );
0 commit comments