Skip to content

Commit 323cbaf

Browse files
Fix liquidity limit.
1 parent 81ac427 commit 323cbaf

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

pallets/swap/src/pallet/impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

pallets/swap/src/pallet/tests.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff 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]
346380
fn test_add_liquidity_out_of_bounds() {
347381
new_test_ext().execute_with(|| {

0 commit comments

Comments
 (0)