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