Skip to content

Commit 28b2f6f

Browse files
committed
add more tests
1 parent ddf1770 commit 28b2f6f

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

pallets/subtensor/src/staking/add_stake.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ impl<T: Config> Pallet<T> {
137137
"do_add_stake( origin:{coldkey:?} hotkey:{hotkey:?}, netuid:{netuid:?}, stake_to_be_added:{stake_to_be_added:?} )"
138138
);
139139

140-
Self::ensure_subtoken_enabled(netuid)?;
141-
142140
// 2. Calculate the maximum amount that can be executed with price limit
143141
let max_amount: TaoCurrency = Self::get_max_amount_add(netuid, limit_price)?.into();
144142
let mut possible_stake = stake_to_be_added;

pallets/subtensor/src/staking/remove_stake.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,6 @@ impl<T: Config> Pallet<T> {
343343
"do_remove_stake( origin:{coldkey:?} hotkey:{hotkey:?}, netuid: {netuid:?}, alpha_unstaked:{alpha_unstaked:?} )"
344344
);
345345

346-
Self::ensure_subtoken_enabled(netuid)?;
347-
348346
// 2. Calculate the maximum amount that can be executed with price limit
349347
let max_amount = Self::get_max_amount_remove(netuid, limit_price)?;
350348
let mut possible_alpha = alpha_unstaked;
@@ -432,8 +430,6 @@ impl<T: Config> Pallet<T> {
432430
) -> DispatchResult {
433431
let coldkey = ensure_signed(origin.clone())?;
434432

435-
Self::ensure_subtoken_enabled(netuid)?;
436-
437433
let alpha_unstaked =
438434
Self::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey, &coldkey, netuid);
439435

pallets/swap/src/mock.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub const OK_HOTKEY_ACCOUNT_ID_RICH: AccountId = 1005;
3636
pub const NOT_SUBNET_OWNER: AccountId = 666;
3737
pub const NON_EXISTENT_NETUID: u16 = 999;
3838
pub const WRAPPING_FEES_NETUID: u16 = 124;
39-
39+
pub const SUBTOKEN_DISABLED_NETUID: u16 = 13579;
4040
parameter_types! {
4141
pub const BlockHashCount: u64 = 250;
4242
pub const SS58Prefix: u8 = 42;
@@ -116,8 +116,9 @@ impl SubnetInfo<AccountId> for MockLiquidityProvider {
116116
*account_id != NOT_SUBNET_OWNER
117117
}
118118

119-
fn is_subtoken_enabled(_netuid: NetUid) -> bool {
120-
true
119+
// Only disable one subnet for testing
120+
fn is_subtoken_enabled(netuid: NetUid) -> bool {
121+
netuid.inner() != SUBTOKEN_DISABLED_NETUID
121122
}
122123
}
123124

pallets/swap/src/pallet/tests.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,3 +1944,50 @@ fn test_less_price_movement() {
19441944
});
19451945
});
19461946
}
1947+
1948+
#[test]
1949+
fn test_swap_subtoken_disabled() {
1950+
new_test_ext().execute_with(|| {
1951+
let netuid = NetUid::from(SUBTOKEN_DISABLED_NETUID); // Use a netuid not used elsewhere
1952+
let price_low = 0.1;
1953+
let price_high = 0.2;
1954+
let tick_low = price_to_tick(price_low);
1955+
let tick_high = price_to_tick(price_high);
1956+
let liquidity = 1_000_000_u64;
1957+
1958+
assert_ok!(Pallet::<Test>::maybe_initialize_v3(netuid));
1959+
1960+
assert_noop!(
1961+
Pallet::<Test>::add_liquidity(
1962+
RuntimeOrigin::signed(OK_COLDKEY_ACCOUNT_ID),
1963+
OK_HOTKEY_ACCOUNT_ID,
1964+
netuid,
1965+
tick_low,
1966+
tick_high,
1967+
liquidity,
1968+
),
1969+
Error::<Test>::SubtokenDisabled
1970+
);
1971+
1972+
assert_noop!(
1973+
Pallet::<Test>::remove_liquidity(
1974+
RuntimeOrigin::signed(OK_COLDKEY_ACCOUNT_ID),
1975+
OK_HOTKEY_ACCOUNT_ID,
1976+
netuid,
1977+
PositionId::from(0),
1978+
),
1979+
Error::<Test>::SubtokenDisabled
1980+
);
1981+
1982+
assert_noop!(
1983+
Pallet::<Test>::modify_position(
1984+
RuntimeOrigin::signed(OK_COLDKEY_ACCOUNT_ID),
1985+
OK_HOTKEY_ACCOUNT_ID,
1986+
netuid,
1987+
PositionId::from(0),
1988+
liquidity as i64,
1989+
),
1990+
Error::<Test>::SubtokenDisabled
1991+
);
1992+
});
1993+
}

0 commit comments

Comments
 (0)