@@ -3,7 +3,7 @@ use crate::*;
3
3
use approx:: assert_abs_diff_eq;
4
4
use frame_support:: { assert_err, assert_noop, assert_ok} ;
5
5
use sp_core:: { Get , U256 } ;
6
- use substrate_fixed:: types:: I96F32 ;
6
+ use substrate_fixed:: types:: { I96F32 , U64F64 } ;
7
7
8
8
// 1. test_do_move_success
9
9
// Description: Test a successful move of stake between two hotkeys in the same subnet
@@ -1641,3 +1641,112 @@ fn test_stake_transfers_disabled_validate() {
1641
1641
assert_ok ! ( result3) ;
1642
1642
} ) ;
1643
1643
}
1644
+
1645
+ #[ test]
1646
+ // RUST_LOG=info cargo test --package pallet-subtensor --lib -- tests::staking::test_move_stake_specific_stake_into_subnet_fail --exact --show-output
1647
+ fn test_move_stake_specific_stake_into_subnet_fail ( ) {
1648
+ new_test_ext ( 1 ) . execute_with ( || {
1649
+ let sn_owner_coldkey = U256 :: from ( 55453 ) ;
1650
+
1651
+ let hotkey_account_id = U256 :: from ( 533453 ) ;
1652
+ let coldkey_account_id = U256 :: from ( 55454 ) ;
1653
+ let hotkey_owner_account_id = U256 :: from ( 533454 ) ;
1654
+
1655
+ let existing_shares: U64F64 =
1656
+ U64F64 :: from_num ( 161_986_254 ) . saturating_div ( U64F64 :: from_num ( u64:: MAX ) ) ;
1657
+ let existing_stake = 36_711_495_953 ;
1658
+
1659
+ let tao_in = 2_409_892_148_947 ;
1660
+ let alpha_in = 15_358_708_513_716 ;
1661
+
1662
+ let tao_staked = 200_000_000 ;
1663
+
1664
+ //add network
1665
+ let netuid: u16 = add_dynamic_network ( & sn_owner_coldkey, & sn_owner_coldkey) ;
1666
+
1667
+ let origin_netuid: u16 = add_dynamic_network ( & sn_owner_coldkey, & sn_owner_coldkey) ;
1668
+
1669
+ // Register hotkey on netuid
1670
+ register_ok_neuron ( netuid, hotkey_account_id, hotkey_owner_account_id, 0 ) ;
1671
+ // Register hotkey on origin netuid
1672
+ register_ok_neuron ( origin_netuid, hotkey_account_id, hotkey_owner_account_id, 0 ) ;
1673
+
1674
+ // Check we have zero staked
1675
+ assert_eq ! (
1676
+ SubtensorModule :: get_total_stake_for_hotkey( & hotkey_account_id) ,
1677
+ 0
1678
+ ) ;
1679
+
1680
+ // Set a hotkey pool for the hotkey on destination subnet
1681
+ let mut hotkey_pool = SubtensorModule :: get_alpha_share_pool ( hotkey_account_id, netuid) ;
1682
+ hotkey_pool. update_value_for_one ( & hotkey_owner_account_id, 1234 ) ; // Doesn't matter, will be overridden
1683
+
1684
+ // Adjust the total hotkey stake and shares to match the existing values
1685
+ TotalHotkeyShares :: < Test > :: insert ( hotkey_account_id, netuid, existing_shares) ;
1686
+ TotalHotkeyAlpha :: < Test > :: insert ( hotkey_account_id, netuid, existing_stake) ;
1687
+
1688
+ // Make the hotkey a delegate
1689
+ Delegates :: < Test > :: insert ( hotkey_account_id, 0 ) ;
1690
+
1691
+ // Setup Subnet pool
1692
+ SubnetAlphaIn :: < Test > :: insert ( netuid, alpha_in) ;
1693
+ SubnetTAO :: < Test > :: insert ( netuid, tao_in) ;
1694
+
1695
+ // Give TAO balance to coldkey
1696
+ SubtensorModule :: add_balance_to_coldkey_account (
1697
+ & coldkey_account_id,
1698
+ tao_staked + 1_000_000_000 ,
1699
+ ) ;
1700
+
1701
+ // Setup Subnet pool for origin netuid
1702
+ SubnetAlphaIn :: < Test > :: insert ( origin_netuid, alpha_in + 10_000_000 ) ;
1703
+ SubnetTAO :: < Test > :: insert ( origin_netuid, tao_in + 10_000_000 ) ;
1704
+
1705
+ // Add stake as new hotkey
1706
+ assert_ok ! ( SubtensorModule :: add_stake(
1707
+ RuntimeOrigin :: signed( coldkey_account_id) ,
1708
+ hotkey_account_id,
1709
+ origin_netuid,
1710
+ tao_staked,
1711
+ ) , ) ;
1712
+ let alpha_to_move = SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet (
1713
+ & hotkey_account_id,
1714
+ & coldkey_account_id,
1715
+ origin_netuid,
1716
+ ) ;
1717
+
1718
+ // Move stake to destination subnet
1719
+ assert_ok ! ( SubtensorModule :: move_stake(
1720
+ RuntimeOrigin :: signed( coldkey_account_id) ,
1721
+ hotkey_account_id,
1722
+ hotkey_account_id,
1723
+ origin_netuid,
1724
+ netuid,
1725
+ alpha_to_move,
1726
+ ) ) ;
1727
+
1728
+ // Check that the stake has been moved
1729
+ assert_eq ! (
1730
+ SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet(
1731
+ & hotkey_account_id,
1732
+ & coldkey_account_id,
1733
+ origin_netuid
1734
+ ) ,
1735
+ 0
1736
+ ) ;
1737
+ let fee = DefaultStakingFee :: < Test > :: get ( ) ;
1738
+ let alpha_fee: I96F32 = I96F32 :: from_num ( fee) / SubtensorModule :: get_alpha_price ( netuid) ;
1739
+ let expected_value = I96F32 :: from_num ( alpha_to_move)
1740
+ * SubtensorModule :: get_alpha_price ( origin_netuid)
1741
+ / SubtensorModule :: get_alpha_price ( netuid) ;
1742
+ assert_abs_diff_eq ! (
1743
+ SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet(
1744
+ & hotkey_account_id,
1745
+ & coldkey_account_id,
1746
+ netuid
1747
+ ) ,
1748
+ ( expected_value - alpha_fee) . to_num:: <u64 >( ) ,
1749
+ epsilon = ( expected_value / 1000 ) . to_num:: <u64 >( )
1750
+ ) ;
1751
+ } ) ;
1752
+ }
0 commit comments