@@ -107,7 +107,7 @@ fn test_set_rootweights_validate() {
107107 assert_err ! (
108108 // Should get an invalid transaction error
109109 result_no_stake,
110- TransactionValidityError :: Invalid ( InvalidTransaction :: Call , )
110+ TransactionValidityError :: Invalid ( InvalidTransaction :: Custom ( 4 ) )
111111 ) ;
112112
113113 // Increase the stake to be equal to the minimum
@@ -207,7 +207,7 @@ fn test_commit_weights_validate() {
207207 assert_err ! (
208208 // Should get an invalid transaction error
209209 result_no_stake,
210- TransactionValidityError :: Invalid ( InvalidTransaction :: Call , )
210+ TransactionValidityError :: Invalid ( InvalidTransaction :: Custom ( 1 ) )
211211 ) ;
212212
213213 // Increase the stake to be equal to the minimum
@@ -259,6 +259,66 @@ fn test_reveal_weights_dispatch_info_ok() {
259259 } ) ;
260260}
261261
262+ #[ test]
263+ fn test_set_weights_validate ( ) {
264+ // Testing the signed extension validate function
265+ // correctly filters the `set_weights` transaction.
266+
267+ new_test_ext ( 0 ) . execute_with ( || {
268+ let netuid: u16 = 1 ;
269+ let coldkey = U256 :: from ( 0 ) ;
270+ let hotkey: U256 = U256 :: from ( 1 ) ;
271+ assert_ne ! ( hotkey, coldkey) ;
272+
273+ let who = hotkey; // The hotkey signs this transaction
274+
275+ let call = RuntimeCall :: SubtensorModule ( SubtensorCall :: set_weights {
276+ netuid,
277+ dests : vec ! [ 1 , 1 ] ,
278+ weights : vec ! [ 1 , 1 ] ,
279+ version_key : 0 ,
280+ } ) ;
281+
282+ // Create netuid
283+ add_network ( netuid, 0 , 0 ) ;
284+ // Register the hotkey
285+ SubtensorModule :: append_neuron ( netuid, & hotkey, 0 ) ;
286+ Owner :: < Test > :: insert ( hotkey, coldkey) ;
287+
288+ let min_stake = 500_000_000_000 ;
289+ // Set the minimum stake
290+ SubtensorModule :: set_weights_min_stake ( min_stake) ;
291+
292+ // Verify stake is less than minimum
293+ assert ! ( SubtensorModule :: get_total_stake_for_hotkey( & hotkey) < min_stake) ;
294+ let info: DispatchInfo =
295+ DispatchInfoOf :: < <Test as frame_system:: Config >:: RuntimeCall > :: default ( ) ;
296+
297+ let extension = pallet_subtensor:: SubtensorSignedExtension :: < Test > :: new ( ) ;
298+ // Submit to the signed extension validate function
299+ let result_no_stake = extension. validate ( & who, & call. clone ( ) , & info, 10 ) ;
300+ // Should fail due to insufficient stake
301+ assert_err ! (
302+ result_no_stake,
303+ TransactionValidityError :: Invalid ( InvalidTransaction :: Custom ( 3 ) )
304+ ) ;
305+
306+ // Increase the stake to be equal to the minimum
307+ SubtensorModule :: increase_stake_on_hotkey_account ( & hotkey, min_stake) ;
308+
309+ // Verify stake is equal to minimum
310+ assert_eq ! (
311+ SubtensorModule :: get_total_stake_for_hotkey( & hotkey) ,
312+ min_stake
313+ ) ;
314+
315+ // Submit to the signed extension validate function
316+ let result_min_stake = extension. validate ( & who, & call. clone ( ) , & info, 10 ) ;
317+ // Now the call should pass
318+ assert_ok ! ( result_min_stake) ;
319+ } ) ;
320+ }
321+
262322#[ test]
263323fn test_reveal_weights_validate ( ) {
264324 // Testing the signed extension validate function
@@ -306,7 +366,7 @@ fn test_reveal_weights_validate() {
306366 assert_err ! (
307367 // Should get an invalid transaction error
308368 result_no_stake,
309- TransactionValidityError :: Invalid ( InvalidTransaction :: Call , )
369+ TransactionValidityError :: Invalid ( InvalidTransaction :: Custom ( 2 ) )
310370 ) ;
311371
312372 // Increase the stake to be equal to the minimum
0 commit comments