@@ -1993,6 +1993,58 @@ contract AllocationManagerUnitTests_ModifyAllocations is AllocationManagerUnitTe
19931993 allocationManager.modifyAllocations (defaultOperator, allocateParams);
19941994 }
19951995
1996+ function test_revert_safeCastOverflow () public {
1997+ // setup additional operatorSets for tests
1998+ OperatorSet memory opSet1 = OperatorSet (defaultAVS, 1 );
1999+ _createOperatorSet (opSet1, defaultStrategies);
2000+ _registerOperator (defaultOperator);
2001+ _setAllocationDelay (defaultOperator, DEFAULT_OPERATOR_ALLOCATION_DELAY);
2002+ _registerForOperatorSet (defaultOperator, opSet1);
2003+
2004+ OperatorSet memory opSet2 = OperatorSet (defaultAVS, 2 );
2005+ _createOperatorSet (opSet2, defaultStrategies);
2006+ _registerOperator (defaultOperator);
2007+ _setAllocationDelay (defaultOperator, DEFAULT_OPERATOR_ALLOCATION_DELAY);
2008+ _registerForOperatorSet (defaultOperator, opSet2);
2009+
2010+ // 1. Allocate all available magnitude for the strategy (WAD)
2011+ AllocateParams[] memory allocateParams = _randAllocateParams_DefaultOpSet ();
2012+ allocateParams[0 ].newMagnitudes[0 ] = WAD;
2013+ cheats.prank (defaultOperator);
2014+ allocationManager.modifyAllocations (defaultOperator, allocateParams);
2015+ assertEq (
2016+ allocationManager.getAllocatableMagnitude (defaultOperator, strategyMock),
2017+ 0 ,
2018+ "Allocatable magnitude should be 0 "
2019+ );
2020+ assertEq (
2021+ allocationManager.getEncumberedMagnitude (defaultOperator, strategyMock),
2022+ WAD,
2023+ "Encumbered magnitude should be WAD "
2024+ );
2025+
2026+ // 2. allocate to another operatorSet for the same strategy to reset encumberedMagnitude back to 0
2027+ allocateParams[0 ].operatorSet = opSet1;
2028+ allocateParams[0 ].newMagnitudes[0 ] = type (uint64 ).max - WAD + 1 ;
2029+ cheats.prank (defaultOperator);
2030+ cheats.expectRevert ("SafeCast: value doesn't fit in 64 bits " );
2031+ allocationManager.modifyAllocations (defaultOperator, allocateParams);
2032+
2033+ // 3. after resetting encumberedMagnitude, attempt to allocate to opSet2 with WAD
2034+ allocateParams[0 ].operatorSet = opSet2;
2035+ allocateParams[0 ].newMagnitudes[0 ] = WAD;
2036+ cheats.prank (defaultOperator);
2037+ cheats.expectRevert (InsufficientMagnitude.selector );
2038+ allocationManager.modifyAllocations (defaultOperator, allocateParams);
2039+
2040+ // 4. after resetting encumberedMagnitude, attempt to allocate to opSet2 with 1
2041+ allocateParams[0 ].operatorSet = opSet2;
2042+ allocateParams[0 ].newMagnitudes[0 ] = 1 ;
2043+ cheats.prank (defaultOperator);
2044+ cheats.expectRevert (InsufficientMagnitude.selector );
2045+ allocationManager.modifyAllocations (defaultOperator, allocateParams);
2046+ }
2047+
19962048 /**
19972049 * @notice Tests edge cases around allocation delay:
19982050 * 1. Set allocation delay to a value greater than ALLOCATION_CONFIGURATION_DELAY
0 commit comments