File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -885,7 +885,7 @@ impl<T: Config> Pallet<T> {
885885 liquidity : u64 ,
886886 ) -> Result < ( Position < T > , u64 , u64 ) , Error < T > > {
887887 ensure ! (
888- Self :: count_positions( netuid, coldkey_account_id) <= T :: MaxPositions :: get( ) as usize ,
888+ Self :: count_positions( netuid, coldkey_account_id) < T :: MaxPositions :: get( ) as usize ,
889889 Error :: <T >:: MaxPositionsExceeded
890890 ) ;
891891
Original file line number Diff line number Diff line change @@ -342,6 +342,40 @@ fn test_add_liquidity_basic() {
342342 } ) ;
343343}
344344
345+ #[ test]
346+ fn test_add_liquidity_max_limit_enforced ( ) {
347+ new_test_ext ( ) . execute_with ( || {
348+ let netuid = NetUid :: from ( 1 ) ;
349+ let liquidity = 2_000_000_000_u64 ;
350+ assert_ok ! ( Pallet :: <Test >:: maybe_initialize_v3( netuid) ) ;
351+
352+ let limit = MaxPositions :: get ( ) as usize ;
353+
354+ for _ in 0 ..limit {
355+ Pallet :: < Test > :: do_add_liquidity (
356+ netuid,
357+ & OK_COLDKEY_ACCOUNT_ID ,
358+ & OK_HOTKEY_ACCOUNT_ID ,
359+ TickIndex :: MIN ,
360+ TickIndex :: MAX ,
361+ liquidity,
362+ )
363+ . unwrap ( ) ;
364+ }
365+
366+ let test_result = Pallet :: < Test > :: do_add_liquidity (
367+ netuid,
368+ & OK_COLDKEY_ACCOUNT_ID ,
369+ & OK_HOTKEY_ACCOUNT_ID ,
370+ TickIndex :: MIN ,
371+ TickIndex :: MAX ,
372+ liquidity,
373+ ) ;
374+
375+ assert_err ! ( test_result, Error :: <Test >:: MaxPositionsExceeded ) ;
376+ } ) ;
377+ }
378+
345379#[ test]
346380fn test_add_liquidity_out_of_bounds ( ) {
347381 new_test_ext ( ) . execute_with ( || {
You can’t perform that action at this time.
0 commit comments