@@ -2836,6 +2836,57 @@ fn test_unstake_low_liquidity_validate() {
28362836 } ) ;
28372837}
28382838
2839+ #[ test]
2840+ fn test_unstake_all_validate ( ) {
2841+ // Testing the signed extension validate function
2842+ // correctly filters the `unstake_all` transaction.
2843+
2844+ new_test_ext ( 0 ) . execute_with ( || {
2845+ let subnet_owner_coldkey = U256 :: from ( 1001 ) ;
2846+ let subnet_owner_hotkey = U256 :: from ( 1002 ) ;
2847+ let hotkey = U256 :: from ( 2 ) ;
2848+ let coldkey = U256 :: from ( 3 ) ;
2849+ let amount_staked = DefaultMinStake :: < Test > :: get ( ) * 10 + DefaultStakingFee :: < Test > :: get ( ) ;
2850+
2851+ let netuid = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
2852+ SubtensorModule :: create_account_if_non_existent ( & coldkey, & hotkey) ;
2853+ SubtensorModule :: add_balance_to_coldkey_account ( & coldkey, amount_staked) ;
2854+
2855+ // Simulate stake for hotkey
2856+ SubnetTAO :: < Test > :: insert ( netuid, u64:: MAX / 1000 ) ;
2857+ SubnetAlphaIn :: < Test > :: insert ( netuid, u64:: MAX / 1000 ) ;
2858+ SubtensorModule :: stake_into_subnet ( & hotkey, & coldkey, netuid, amount_staked, 0 ) ;
2859+
2860+ // Set the liquidity at lowest possible value so that all staking requests fail
2861+ SubnetTAO :: < Test > :: insert (
2862+ netuid,
2863+ DefaultMinimumPoolLiquidity :: < Test > :: get ( ) . to_num :: < u64 > ( ) ,
2864+ ) ;
2865+ SubnetAlphaIn :: < Test > :: insert (
2866+ netuid,
2867+ DefaultMinimumPoolLiquidity :: < Test > :: get ( ) . to_num :: < u64 > ( ) ,
2868+ ) ;
2869+
2870+ // unstake_all call
2871+ let call = RuntimeCall :: SubtensorModule ( SubtensorCall :: unstake_all { hotkey } ) ;
2872+
2873+ let info: DispatchInfo =
2874+ DispatchInfoOf :: < <Test as frame_system:: Config >:: RuntimeCall > :: default ( ) ;
2875+
2876+ let extension = SubtensorSignedExtension :: < Test > :: new ( ) ;
2877+ // Submit to the signed extension validate function
2878+ let result_no_stake = extension. validate ( & coldkey, & call. clone ( ) , & info, 10 ) ;
2879+
2880+ // Should fail due to insufficient stake
2881+ assert_err ! (
2882+ result_no_stake,
2883+ TransactionValidityError :: Invalid ( InvalidTransaction :: Custom (
2884+ CustomTransactionError :: StakeAmountTooLow . into( )
2885+ ) )
2886+ ) ;
2887+ } ) ;
2888+ }
2889+
28392890#[ test]
28402891fn test_max_amount_add_root ( ) {
28412892 new_test_ext ( 0 ) . execute_with ( || {
0 commit comments