Skip to content

Commit af8cd5e

Browse files
committed
Fix tests and transfer stake after merging devnet-ready
1 parent cce2ee0 commit af8cd5e

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

pallets/subtensor/src/staking/move_stake.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ impl<T: Config> Pallet<T> {
181181
);
182182

183183
// 6. Unstake from the origin coldkey; this returns an amount of TAO.
184-
let origin_tao = Self::unstake_from_subnet(&hotkey, &coldkey, origin_netuid, alpha_amount);
184+
let fee = DefaultMinStake::<T>::get().saturating_div(2);
185+
let origin_tao =
186+
Self::unstake_from_subnet(&hotkey, &coldkey, origin_netuid, alpha_amount, fee);
185187

186188
// 7. Ensure the returned TAO meets a minimum stake requirement (if required).
187189
ensure!(
@@ -196,6 +198,7 @@ impl<T: Config> Pallet<T> {
196198
&destination_coldkey,
197199
destination_netuid,
198200
origin_tao,
201+
fee,
199202
);
200203

201204
// 9. Emit an event for logging/monitoring.

pallets/subtensor/src/tests/move_stake.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,7 @@ fn test_do_transfer_success() {
813813
let subnet_owner_coldkey = U256::from(1001);
814814
let subnet_owner_hotkey = U256::from(1002);
815815
let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey);
816+
let fee = DefaultMinStake::<Test>::get();
816817

817818
// 2. Define the origin coldkey, destination coldkey, and hotkey to be used.
818819
let origin_coldkey = U256::from(1);
@@ -823,7 +824,7 @@ fn test_do_transfer_success() {
823824
// 3. Set up initial stake: (origin_coldkey, hotkey) on netuid.
824825
SubtensorModule::create_account_if_non_existent(&origin_coldkey, &hotkey);
825826
SubtensorModule::create_account_if_non_existent(&destination_coldkey, &hotkey);
826-
SubtensorModule::stake_into_subnet(&hotkey, &origin_coldkey, netuid, stake_amount);
827+
SubtensorModule::stake_into_subnet(&hotkey, &origin_coldkey, netuid, stake_amount, 0);
827828
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
828829
&hotkey,
829830
&origin_coldkey,
@@ -855,7 +856,7 @@ fn test_do_transfer_success() {
855856
&destination_coldkey,
856857
netuid
857858
),
858-
stake_amount,
859+
stake_amount - fee,
859860
epsilon = stake_amount / 1000
860861
);
861862
});
@@ -922,7 +923,7 @@ fn test_do_transfer_insufficient_stake() {
922923
let stake_amount = DefaultMinStake::<Test>::get() * 10;
923924

924925
SubtensorModule::create_account_if_non_existent(&origin_coldkey, &hotkey);
925-
SubtensorModule::stake_into_subnet(&hotkey, &origin_coldkey, netuid, stake_amount);
926+
SubtensorModule::stake_into_subnet(&hotkey, &origin_coldkey, netuid, stake_amount, 0);
926927

927928
let alpha = stake_amount * 2;
928929
assert_noop!(
@@ -950,11 +951,12 @@ fn test_do_transfer_wrong_origin() {
950951
let wrong_coldkey = U256::from(9999);
951952
let destination_coldkey = U256::from(2);
952953
let hotkey = U256::from(3);
953-
let stake_amount = 100_000;
954+
let stake_amount = DefaultMinStake::<Test>::get() * 10;
955+
let fee = DefaultMinStake::<Test>::get();
954956

955957
SubtensorModule::create_account_if_non_existent(&origin_coldkey, &hotkey);
956-
SubtensorModule::add_balance_to_coldkey_account(&origin_coldkey, 1_000_000_000);
957-
SubtensorModule::stake_into_subnet(&hotkey, &origin_coldkey, netuid, stake_amount);
958+
SubtensorModule::add_balance_to_coldkey_account(&origin_coldkey, stake_amount + fee);
959+
SubtensorModule::stake_into_subnet(&hotkey, &origin_coldkey, netuid, stake_amount, fee);
958960

959961
assert_noop!(
960962
SubtensorModule::do_transfer_stake(
@@ -983,7 +985,7 @@ fn test_do_transfer_minimum_stake_check() {
983985

984986
let stake_amount = DefaultMinStake::<Test>::get();
985987
SubtensorModule::create_account_if_non_existent(&origin_coldkey, &hotkey);
986-
SubtensorModule::stake_into_subnet(&hotkey, &origin_coldkey, netuid, stake_amount);
988+
SubtensorModule::stake_into_subnet(&hotkey, &origin_coldkey, netuid, stake_amount, 0);
987989

988990
assert_err!(
989991
SubtensorModule::do_transfer_stake(
@@ -1013,6 +1015,7 @@ fn test_do_transfer_different_subnets() {
10131015
let destination_coldkey = U256::from(2);
10141016
let hotkey = U256::from(3);
10151017
let stake_amount = DefaultMinStake::<Test>::get() * 10;
1018+
let fee = DefaultMinStake::<Test>::get();
10161019

10171020
// 3. Create accounts if needed.
10181021
SubtensorModule::create_account_if_non_existent(&origin_coldkey, &hotkey);
@@ -1022,7 +1025,13 @@ fn test_do_transfer_different_subnets() {
10221025
SubtensorModule::add_balance_to_coldkey_account(&origin_coldkey, 1_000_000_000);
10231026

10241027
// 5. Stake into the origin subnet.
1025-
SubtensorModule::stake_into_subnet(&hotkey, &origin_coldkey, origin_netuid, stake_amount);
1028+
SubtensorModule::stake_into_subnet(
1029+
&hotkey,
1030+
&origin_coldkey,
1031+
origin_netuid,
1032+
stake_amount,
1033+
0,
1034+
);
10261035

10271036
// 6. Transfer entire stake from origin_netuid -> destination_netuid.
10281037
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
@@ -1055,6 +1064,10 @@ fn test_do_transfer_different_subnets() {
10551064
&destination_coldkey,
10561065
destination_netuid,
10571066
);
1058-
assert_abs_diff_eq!(dest_stake, stake_amount, epsilon = stake_amount / 1000);
1067+
assert_abs_diff_eq!(
1068+
dest_stake,
1069+
stake_amount - fee,
1070+
epsilon = stake_amount / 1000
1071+
);
10591072
});
10601073
}

0 commit comments

Comments
 (0)