@@ -1815,7 +1815,7 @@ fn test_toggle_commit_reveal_weights_and_set_weights() {
1815
1815
1816
1816
#[ test]
1817
1817
fn test_tempo_change_during_commit_reveal_process ( ) {
1818
- new_test_ext ( 1 ) . execute_with ( || {
1818
+ new_test_ext ( 0 ) . execute_with ( || {
1819
1819
let netuid: u16 = 1 ;
1820
1820
let uids: Vec < u16 > = vec ! [ 0 , 1 ] ;
1821
1821
let weight_values: Vec < u16 > = vec ! [ 10 , 10 ] ;
@@ -1832,7 +1832,7 @@ fn test_tempo_change_during_commit_reveal_process() {
1832
1832
version_key,
1833
1833
) ) ;
1834
1834
1835
- System :: set_block_number ( 1 ) ;
1835
+ System :: set_block_number ( 0 ) ;
1836
1836
1837
1837
let tempo: u16 = 100 ;
1838
1838
add_network ( netuid, tempo, 0 ) ;
@@ -4059,3 +4059,72 @@ fn test_get_reveal_blocks() {
4059
4059
) ;
4060
4060
} )
4061
4061
}
4062
+
4063
+ #[ test]
4064
+ fn test_commit_weights_rate_limit ( ) {
4065
+ new_test_ext ( 1 ) . execute_with ( || {
4066
+ let netuid: u16 = 1 ;
4067
+ let uids: Vec < u16 > = vec ! [ 0 , 1 ] ;
4068
+ let weight_values: Vec < u16 > = vec ! [ 10 , 10 ] ;
4069
+ let salt: Vec < u16 > = vec ! [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ;
4070
+ let version_key: u64 = 0 ;
4071
+ let hotkey: U256 = U256 :: from ( 1 ) ;
4072
+
4073
+ let commit_hash: H256 = BlakeTwo256 :: hash_of ( & (
4074
+ hotkey,
4075
+ netuid,
4076
+ uids. clone ( ) ,
4077
+ weight_values. clone ( ) ,
4078
+ salt. clone ( ) ,
4079
+ version_key,
4080
+ ) ) ;
4081
+ System :: set_block_number ( 11 ) ;
4082
+
4083
+ let tempo: u16 = 5 ;
4084
+ add_network ( netuid, tempo, 0 ) ;
4085
+
4086
+ register_ok_neuron ( netuid, U256 :: from ( 3 ) , U256 :: from ( 4 ) , 300_000 ) ;
4087
+ register_ok_neuron ( netuid, U256 :: from ( 1 ) , U256 :: from ( 2 ) , 100_000 ) ;
4088
+ SubtensorModule :: set_weights_set_rate_limit ( netuid, 10 ) ; // Rate limit is 10 blocks
4089
+ SubtensorModule :: set_validator_permit_for_uid ( netuid, 0 , true ) ;
4090
+ SubtensorModule :: set_validator_permit_for_uid ( netuid, 1 , true ) ;
4091
+ SubtensorModule :: set_commit_reveal_weights_enabled ( netuid, true ) ;
4092
+
4093
+ let neuron_uid = SubtensorModule :: get_uid_for_net_and_hotkey ( netuid, & hotkey) . unwrap ( ) ;
4094
+ SubtensorModule :: set_last_update_for_uid ( netuid, neuron_uid, 0 ) ;
4095
+
4096
+ assert_ok ! ( SubtensorModule :: commit_weights(
4097
+ RuntimeOrigin :: signed( hotkey) ,
4098
+ netuid,
4099
+ commit_hash
4100
+ ) ) ;
4101
+
4102
+ let new_salt: Vec < u16 > = vec ! [ 9 ; 8 ] ;
4103
+ let new_commit_hash: H256 = BlakeTwo256 :: hash_of ( & (
4104
+ hotkey,
4105
+ netuid,
4106
+ uids. clone ( ) ,
4107
+ weight_values. clone ( ) ,
4108
+ new_salt. clone ( ) ,
4109
+ version_key,
4110
+ ) ) ;
4111
+ assert_err ! (
4112
+ SubtensorModule :: commit_weights( RuntimeOrigin :: signed( hotkey) , netuid, new_commit_hash) ,
4113
+ Error :: <Test >:: CommittingWeightsTooFast
4114
+ ) ;
4115
+
4116
+ step_block ( 5 ) ;
4117
+ assert_err ! (
4118
+ SubtensorModule :: commit_weights( RuntimeOrigin :: signed( hotkey) , netuid, new_commit_hash) ,
4119
+ Error :: <Test >:: CommittingWeightsTooFast
4120
+ ) ;
4121
+
4122
+ step_block ( 5 ) ; // Current block is now 21
4123
+
4124
+ assert_ok ! ( SubtensorModule :: commit_weights(
4125
+ RuntimeOrigin :: signed( hotkey) ,
4126
+ netuid,
4127
+ new_commit_hash
4128
+ ) ) ;
4129
+ } ) ;
4130
+ }
0 commit comments