Skip to content

Commit 7175c63

Browse files
committed
Remove toggle_user_liquidity tests
1 parent 6a1a36d commit 7175c63

File tree

3 files changed

+182
-179
lines changed

3 files changed

+182
-179
lines changed

pallets/swap/src/pallet/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,9 @@ mod pallet {
617617
netuid,
618618
enable: false,
619619
});
620+
621+
// Remove provided liquidity
622+
// Self::do_dissolve_all_liquidity_providers(netuid)?;
620623
}
621624
}
622625

pallets/swap/src/pallet/tests.rs

Lines changed: 178 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -114,42 +114,42 @@ mod dispatchables {
114114
});
115115
}
116116

117-
#[test]
118-
fn test_toggle_user_liquidity() {
119-
new_test_ext().execute_with(|| {
120-
let netuid = NetUid::from(101);
121-
122-
assert!(!EnabledUserLiquidity::<Test>::get(netuid));
123-
124-
assert_ok!(Swap::toggle_user_liquidity(
125-
RuntimeOrigin::root(),
126-
netuid.into(),
127-
true
128-
));
129-
130-
assert!(EnabledUserLiquidity::<Test>::get(netuid));
131-
132-
assert_noop!(
133-
Swap::toggle_user_liquidity(RuntimeOrigin::signed(666), netuid.into(), true),
134-
DispatchError::BadOrigin
135-
);
136-
137-
assert_ok!(Swap::toggle_user_liquidity(
138-
RuntimeOrigin::signed(1),
139-
netuid.into(),
140-
true
141-
));
142-
143-
assert_noop!(
144-
Swap::toggle_user_liquidity(
145-
RuntimeOrigin::root(),
146-
NON_EXISTENT_NETUID.into(),
147-
true
148-
),
149-
Error::<Test>::MechanismDoesNotExist
150-
);
151-
});
152-
}
117+
// #[test]
118+
// fn test_toggle_user_liquidity() {
119+
// new_test_ext().execute_with(|| {
120+
// let netuid = NetUid::from(101);
121+
122+
// assert!(!EnabledUserLiquidity::<Test>::get(netuid));
123+
124+
// assert_ok!(Swap::toggle_user_liquidity(
125+
// RuntimeOrigin::root(),
126+
// netuid.into(),
127+
// true
128+
// ));
129+
130+
// assert!(EnabledUserLiquidity::<Test>::get(netuid));
131+
132+
// assert_noop!(
133+
// Swap::toggle_user_liquidity(RuntimeOrigin::signed(666), netuid.into(), true),
134+
// DispatchError::BadOrigin
135+
// );
136+
137+
// assert_ok!(Swap::toggle_user_liquidity(
138+
// RuntimeOrigin::signed(1),
139+
// netuid.into(),
140+
// true
141+
// ));
142+
143+
// assert_noop!(
144+
// Swap::toggle_user_liquidity(
145+
// RuntimeOrigin::root(),
146+
// NON_EXISTENT_NETUID.into(),
147+
// true
148+
// ),
149+
// Error::<Test>::MechanismDoesNotExist
150+
// );
151+
// });
152+
// }
153153
}
154154

155155
#[test]
@@ -1398,79 +1398,79 @@ fn test_convert_deltas() {
13981398
});
13991399
}
14001400

1401-
#[test]
1402-
fn test_user_liquidity_disabled() {
1403-
new_test_ext().execute_with(|| {
1404-
// Use a netuid above 100 since our mock enables liquidity for 0-100
1405-
let netuid = NetUid::from(101);
1406-
let tick_low = TickIndex::new_unchecked(-1000);
1407-
let tick_high = TickIndex::new_unchecked(1000);
1408-
let position_id = PositionId::from(1);
1409-
let liquidity = 1_000_000_000;
1410-
let liquidity_delta = 500_000_000;
1411-
1412-
assert!(!EnabledUserLiquidity::<Test>::get(netuid));
1413-
1414-
assert_noop!(
1415-
Swap::do_add_liquidity(
1416-
netuid,
1417-
&OK_COLDKEY_ACCOUNT_ID,
1418-
&OK_HOTKEY_ACCOUNT_ID,
1419-
tick_low,
1420-
tick_high,
1421-
liquidity
1422-
),
1423-
Error::<Test>::UserLiquidityDisabled
1424-
);
1425-
1426-
assert_noop!(
1427-
Swap::do_remove_liquidity(netuid, &OK_COLDKEY_ACCOUNT_ID, position_id),
1428-
Error::<Test>::LiquidityNotFound
1429-
);
1430-
1431-
assert_noop!(
1432-
Swap::modify_position(
1433-
RuntimeOrigin::signed(OK_COLDKEY_ACCOUNT_ID),
1434-
OK_HOTKEY_ACCOUNT_ID,
1435-
netuid,
1436-
position_id,
1437-
liquidity_delta
1438-
),
1439-
Error::<Test>::UserLiquidityDisabled
1440-
);
1441-
1442-
assert_ok!(Swap::toggle_user_liquidity(
1443-
RuntimeOrigin::root(),
1444-
netuid,
1445-
true
1446-
));
1447-
1448-
let position_id = Swap::do_add_liquidity(
1449-
netuid,
1450-
&OK_COLDKEY_ACCOUNT_ID,
1451-
&OK_HOTKEY_ACCOUNT_ID,
1452-
tick_low,
1453-
tick_high,
1454-
liquidity,
1455-
)
1456-
.unwrap()
1457-
.0;
1458-
1459-
assert_ok!(Swap::do_modify_position(
1460-
netuid.into(),
1461-
&OK_COLDKEY_ACCOUNT_ID,
1462-
&OK_HOTKEY_ACCOUNT_ID,
1463-
position_id,
1464-
liquidity_delta,
1465-
));
1466-
1467-
assert_ok!(Swap::do_remove_liquidity(
1468-
netuid,
1469-
&OK_COLDKEY_ACCOUNT_ID,
1470-
position_id,
1471-
));
1472-
});
1473-
}
1401+
// #[test]
1402+
// fn test_user_liquidity_disabled() {
1403+
// new_test_ext().execute_with(|| {
1404+
// // Use a netuid above 100 since our mock enables liquidity for 0-100
1405+
// let netuid = NetUid::from(101);
1406+
// let tick_low = TickIndex::new_unchecked(-1000);
1407+
// let tick_high = TickIndex::new_unchecked(1000);
1408+
// let position_id = PositionId::from(1);
1409+
// let liquidity = 1_000_000_000;
1410+
// let liquidity_delta = 500_000_000;
1411+
1412+
// assert!(!EnabledUserLiquidity::<Test>::get(netuid));
1413+
1414+
// assert_noop!(
1415+
// Swap::do_add_liquidity(
1416+
// netuid,
1417+
// &OK_COLDKEY_ACCOUNT_ID,
1418+
// &OK_HOTKEY_ACCOUNT_ID,
1419+
// tick_low,
1420+
// tick_high,
1421+
// liquidity
1422+
// ),
1423+
// Error::<Test>::UserLiquidityDisabled
1424+
// );
1425+
1426+
// assert_noop!(
1427+
// Swap::do_remove_liquidity(netuid, &OK_COLDKEY_ACCOUNT_ID, position_id),
1428+
// Error::<Test>::LiquidityNotFound
1429+
// );
1430+
1431+
// assert_noop!(
1432+
// Swap::modify_position(
1433+
// RuntimeOrigin::signed(OK_COLDKEY_ACCOUNT_ID),
1434+
// OK_HOTKEY_ACCOUNT_ID,
1435+
// netuid,
1436+
// position_id,
1437+
// liquidity_delta
1438+
// ),
1439+
// Error::<Test>::UserLiquidityDisabled
1440+
// );
1441+
1442+
// assert_ok!(Swap::toggle_user_liquidity(
1443+
// RuntimeOrigin::root(),
1444+
// netuid,
1445+
// true
1446+
// ));
1447+
1448+
// let position_id = Swap::do_add_liquidity(
1449+
// netuid,
1450+
// &OK_COLDKEY_ACCOUNT_ID,
1451+
// &OK_HOTKEY_ACCOUNT_ID,
1452+
// tick_low,
1453+
// tick_high,
1454+
// liquidity,
1455+
// )
1456+
// .unwrap()
1457+
// .0;
1458+
1459+
// assert_ok!(Swap::do_modify_position(
1460+
// netuid.into(),
1461+
// &OK_COLDKEY_ACCOUNT_ID,
1462+
// &OK_HOTKEY_ACCOUNT_ID,
1463+
// position_id,
1464+
// liquidity_delta,
1465+
// ));
1466+
1467+
// assert_ok!(Swap::do_remove_liquidity(
1468+
// netuid,
1469+
// &OK_COLDKEY_ACCOUNT_ID,
1470+
// position_id,
1471+
// ));
1472+
// });
1473+
// }
14741474

14751475
/// Test correctness of swap fees:
14761476
/// - Fees are distribued to (concentrated) liquidity providers
@@ -2047,75 +2047,75 @@ fn test_liquidate_v3_removes_positions_ticks_and_state() {
20472047

20482048
/// V3 path with user liquidity disabled at teardown:
20492049
/// must still remove positions and clear state (after protocol clear).
2050-
#[test]
2051-
fn test_liquidate_v3_with_user_liquidity_disabled() {
2052-
new_test_ext().execute_with(|| {
2053-
let netuid = NetUid::from(101);
2054-
2055-
assert_ok!(Pallet::<Test>::maybe_initialize_v3(netuid));
2056-
assert!(SwapV3Initialized::<Test>::get(netuid));
2057-
2058-
// Enable temporarily to add a user position
2059-
assert_ok!(Swap::toggle_user_liquidity(
2060-
RuntimeOrigin::root(),
2061-
netuid.into(),
2062-
true
2063-
));
2064-
2065-
let min_price = tick_to_price(TickIndex::MIN);
2066-
let max_price = tick_to_price(TickIndex::MAX);
2067-
let tick_low = price_to_tick(min_price);
2068-
let tick_high = price_to_tick(max_price);
2069-
let liquidity = 1_000_000_000_u64;
2070-
2071-
let (_pos_id, _tao, _alpha) = Pallet::<Test>::do_add_liquidity(
2072-
netuid,
2073-
&OK_COLDKEY_ACCOUNT_ID,
2074-
&OK_HOTKEY_ACCOUNT_ID,
2075-
tick_low,
2076-
tick_high,
2077-
liquidity,
2078-
)
2079-
.expect("add liquidity");
2080-
2081-
// Disable user LP *before* liquidation; removal must ignore this flag.
2082-
assert_ok!(Swap::toggle_user_liquidity(
2083-
RuntimeOrigin::root(),
2084-
netuid.into(),
2085-
false
2086-
));
2087-
2088-
// Users-only dissolve, then clear protocol liquidity/state.
2089-
assert_ok!(Pallet::<Test>::do_dissolve_all_liquidity_providers(netuid));
2090-
assert_ok!(Pallet::<Test>::do_clear_protocol_liquidity(netuid));
2091-
2092-
// ASSERT: positions & ticks gone, state reset
2093-
assert_eq!(
2094-
Pallet::<Test>::count_positions(netuid, &OK_COLDKEY_ACCOUNT_ID),
2095-
0
2096-
);
2097-
assert!(
2098-
Positions::<Test>::iter_prefix_values((netuid, OK_COLDKEY_ACCOUNT_ID))
2099-
.next()
2100-
.is_none()
2101-
);
2102-
assert!(Ticks::<Test>::iter_prefix(netuid).next().is_none());
2103-
assert!(
2104-
TickIndexBitmapWords::<Test>::iter_prefix((netuid,))
2105-
.next()
2106-
.is_none()
2107-
);
2108-
assert!(!SwapV3Initialized::<Test>::contains_key(netuid));
2109-
assert!(!AlphaSqrtPrice::<Test>::contains_key(netuid));
2110-
assert!(!CurrentTick::<Test>::contains_key(netuid));
2111-
assert!(!CurrentLiquidity::<Test>::contains_key(netuid));
2112-
assert!(!FeeGlobalTao::<Test>::contains_key(netuid));
2113-
assert!(!FeeGlobalAlpha::<Test>::contains_key(netuid));
2114-
2115-
// `EnabledUserLiquidity` is removed by protocol clear stage.
2116-
assert!(!EnabledUserLiquidity::<Test>::contains_key(netuid));
2117-
});
2118-
}
2050+
// #[test]
2051+
// fn test_liquidate_v3_with_user_liquidity_disabled() {
2052+
// new_test_ext().execute_with(|| {
2053+
// let netuid = NetUid::from(101);
2054+
2055+
// assert_ok!(Pallet::<Test>::maybe_initialize_v3(netuid));
2056+
// assert!(SwapV3Initialized::<Test>::get(netuid));
2057+
2058+
// // Enable temporarily to add a user position
2059+
// assert_ok!(Swap::toggle_user_liquidity(
2060+
// RuntimeOrigin::root(),
2061+
// netuid.into(),
2062+
// true
2063+
// ));
2064+
2065+
// let min_price = tick_to_price(TickIndex::MIN);
2066+
// let max_price = tick_to_price(TickIndex::MAX);
2067+
// let tick_low = price_to_tick(min_price);
2068+
// let tick_high = price_to_tick(max_price);
2069+
// let liquidity = 1_000_000_000_u64;
2070+
2071+
// let (_pos_id, _tao, _alpha) = Pallet::<Test>::do_add_liquidity(
2072+
// netuid,
2073+
// &OK_COLDKEY_ACCOUNT_ID,
2074+
// &OK_HOTKEY_ACCOUNT_ID,
2075+
// tick_low,
2076+
// tick_high,
2077+
// liquidity,
2078+
// )
2079+
// .expect("add liquidity");
2080+
2081+
// // Disable user LP *before* liquidation; removal must ignore this flag.
2082+
// assert_ok!(Swap::toggle_user_liquidity(
2083+
// RuntimeOrigin::root(),
2084+
// netuid.into(),
2085+
// false
2086+
// ));
2087+
2088+
// // Users-only dissolve, then clear protocol liquidity/state.
2089+
// assert_ok!(Pallet::<Test>::do_dissolve_all_liquidity_providers(netuid));
2090+
// assert_ok!(Pallet::<Test>::do_clear_protocol_liquidity(netuid));
2091+
2092+
// // ASSERT: positions & ticks gone, state reset
2093+
// assert_eq!(
2094+
// Pallet::<Test>::count_positions(netuid, &OK_COLDKEY_ACCOUNT_ID),
2095+
// 0
2096+
// );
2097+
// assert!(
2098+
// Positions::<Test>::iter_prefix_values((netuid, OK_COLDKEY_ACCOUNT_ID))
2099+
// .next()
2100+
// .is_none()
2101+
// );
2102+
// assert!(Ticks::<Test>::iter_prefix(netuid).next().is_none());
2103+
// assert!(
2104+
// TickIndexBitmapWords::<Test>::iter_prefix((netuid,))
2105+
// .next()
2106+
// .is_none()
2107+
// );
2108+
// assert!(!SwapV3Initialized::<Test>::contains_key(netuid));
2109+
// assert!(!AlphaSqrtPrice::<Test>::contains_key(netuid));
2110+
// assert!(!CurrentTick::<Test>::contains_key(netuid));
2111+
// assert!(!CurrentLiquidity::<Test>::contains_key(netuid));
2112+
// assert!(!FeeGlobalTao::<Test>::contains_key(netuid));
2113+
// assert!(!FeeGlobalAlpha::<Test>::contains_key(netuid));
2114+
2115+
// // `EnabledUserLiquidity` is removed by protocol clear stage.
2116+
// assert!(!EnabledUserLiquidity::<Test>::contains_key(netuid));
2117+
// });
2118+
// }
21192119

21202120
/// Non‑V3 path: V3 not initialized (no positions); function must still clear any residual storages and succeed.
21212121
#[test]

runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
237237
// `spec_version`, and `authoring_version` are the same between Wasm and native.
238238
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
239239
// the compatible custom types.
240-
spec_version: 356,
240+
spec_version: 357,
241241
impl_version: 1,
242242
apis: RUNTIME_API_VERSIONS,
243243
transaction_version: 1,

0 commit comments

Comments
 (0)