@@ -29,7 +29,7 @@ use crate::*;
2929use crate :: { Call , ColdkeySwapScheduleDuration , Error } ;
3030
3131#[ test]
32- fn test_announce_coldkey_swap_with_no_announcement_works ( ) {
32+ fn test_announce_coldkey_swap_works ( ) {
3333 new_test_ext ( 1 ) . execute_with ( || {
3434 let who = U256 :: from ( 1 ) ;
3535 let new_coldkey = U256 :: from ( 2 ) ;
@@ -121,7 +121,7 @@ fn test_announce_coldkey_swap_with_existing_announcement_not_past_delay_fails()
121121 RuntimeOrigin :: signed( who. clone( ) ) ,
122122 new_coldkey_2,
123123 ) ,
124- Error :: <Test >:: ColdkeySwapReannouncedTooEarly
124+ Error :: <Test >:: ColdKeySwapReannouncedTooEarly
125125 ) ;
126126 } ) ;
127127}
@@ -143,6 +143,103 @@ fn test_announce_coldkey_swap_with_bad_origin_fails() {
143143 } ) ;
144144}
145145
146+ #[ test]
147+ fn test_swap_coldkey_announced_too_early_fails ( ) {
148+ new_test_ext ( 1 ) . execute_with ( || {
149+ let who = U256 :: from ( 1 ) ;
150+ let new_coldkey = U256 :: from ( 2 ) ;
151+
152+ assert_ok ! ( SubtensorModule :: announce_coldkey_swap(
153+ RuntimeOrigin :: signed( who. clone( ) ) ,
154+ new_coldkey,
155+ ) ) ;
156+
157+ assert_noop ! (
158+ SubtensorModule :: swap_coldkey_announced(
159+ <Test as frame_system:: Config >:: RuntimeOrigin :: signed( who)
160+ ) ,
161+ Error :: <Test >:: ColdKeySwapTooEarly
162+ ) ;
163+ } )
164+ }
165+
166+ #[ test]
167+ fn test_swap_coldkey_announced_with_already_associated_coldkey_fails ( ) {
168+ new_test_ext ( 1 ) . execute_with ( || {
169+ let who = U256 :: from ( 1 ) ;
170+ let new_coldkey = U256 :: from ( 2 ) ;
171+ let hotkey = U256 :: from ( 3 ) ;
172+
173+ assert_ok ! ( SubtensorModule :: announce_coldkey_swap(
174+ RuntimeOrigin :: signed( who. clone( ) ) ,
175+ new_coldkey,
176+ ) ) ;
177+
178+ let now = System :: block_number ( ) ;
179+ let delay = ColdkeySwapScheduleDuration :: < Test > :: get ( ) + 1 ;
180+ System :: run_to_block :: < AllPalletsWithSystem > ( now + delay) ;
181+
182+ let swap_cost = SubtensorModule :: get_key_swap_cost ( ) ;
183+ SubtensorModule :: add_balance_to_coldkey_account ( & who, swap_cost. to_u64 ( ) ) ;
184+
185+ SubtensorModule :: create_account_if_non_existent ( & new_coldkey, & hotkey) ;
186+
187+ assert_noop ! (
188+ SubtensorModule :: swap_coldkey_announced(
189+ <Test as frame_system:: Config >:: RuntimeOrigin :: signed( who)
190+ ) ,
191+ Error :: <Test >:: ColdKeyAlreadyAssociated
192+ ) ;
193+ } )
194+ }
195+
196+ #[ test]
197+ fn test_swap_coldkey_announced_using_registered_hotkey_fails ( ) {
198+ new_test_ext ( 1 ) . execute_with ( || {
199+ let who = U256 :: from ( 1 ) ;
200+ let new_coldkey = U256 :: from ( 2 ) ;
201+ let hotkey = U256 :: from ( 3 ) ;
202+
203+ assert_ok ! ( SubtensorModule :: announce_coldkey_swap(
204+ RuntimeOrigin :: signed( who. clone( ) ) ,
205+ hotkey. clone( ) ,
206+ ) ) ;
207+
208+ let now = System :: block_number ( ) ;
209+ let delay = ColdkeySwapScheduleDuration :: < Test > :: get ( ) + 1 ;
210+ System :: run_to_block :: < AllPalletsWithSystem > ( now + delay) ;
211+
212+ let swap_cost = SubtensorModule :: get_key_swap_cost ( ) ;
213+ SubtensorModule :: add_balance_to_coldkey_account ( & who, swap_cost. to_u64 ( ) ) ;
214+
215+ SubtensorModule :: create_account_if_non_existent ( & new_coldkey, & hotkey) ;
216+
217+ assert_noop ! (
218+ SubtensorModule :: swap_coldkey_announced(
219+ <Test as frame_system:: Config >:: RuntimeOrigin :: signed( who)
220+ ) ,
221+ Error :: <Test >:: NewColdKeyIsHotkey
222+ ) ;
223+ } )
224+ }
225+
226+ #[ test]
227+ fn test_swap_coldkey_with_not_enough_balance_to_pay_swap_cost_fails ( ) {
228+ new_test_ext ( 1 ) . execute_with ( || {
229+ let who = U256 :: from ( 1 ) ;
230+ let new_coldkey = U256 :: from ( 2 ) ;
231+
232+ let now = System :: block_number ( ) ;
233+ let delay = ColdkeySwapScheduleDuration :: < Test > :: get ( ) + 1 ;
234+ System :: run_to_block :: < AllPalletsWithSystem > ( now + delay) ;
235+
236+ assert_noop ! (
237+ SubtensorModule :: do_swap_coldkey( & who, & new_coldkey) ,
238+ Error :: <Test >:: NotEnoughBalanceToPaySwapColdKey
239+ ) ;
240+ } ) ;
241+ }
242+
146243#[ test]
147244fn test_swap_subnet_owner ( ) {
148245 new_test_ext ( 1 ) . execute_with ( || {
@@ -662,28 +759,6 @@ fn test_swap_concurrent_modifications() {
662759 } ) ;
663760}
664761
665- #[ test]
666- fn test_swap_with_invalid_subnet_ownership ( ) {
667- new_test_ext ( 1 ) . execute_with ( || {
668- let old_coldkey = U256 :: from ( 1 ) ;
669- let new_coldkey = U256 :: from ( 2 ) ;
670- let netuid = NetUid :: from ( 1u16 ) ;
671-
672- SubnetOwner :: < Test > :: insert ( netuid, old_coldkey) ;
673-
674- // Simulate an invalid state where the subnet owner doesn't match the old_coldkey
675- SubnetOwner :: < Test > :: insert ( netuid, U256 :: from ( 3 ) ) ;
676-
677- let swap_cost = SubtensorModule :: get_key_swap_cost ( ) ;
678- SubtensorModule :: add_balance_to_coldkey_account ( & old_coldkey, swap_cost. to_u64 ( ) ) ;
679-
680- assert_ok ! ( SubtensorModule :: do_swap_coldkey( & old_coldkey, & new_coldkey, ) ) ;
681-
682- // The swap should not affect the mismatched subnet ownership
683- assert_eq ! ( SubnetOwner :: <Test >:: get( netuid) , U256 :: from( 3 ) ) ;
684- } ) ;
685- }
686-
687762#[ test]
688763fn test_do_swap_coldkey_success ( ) {
689764 new_test_ext ( 1 ) . execute_with ( || {
@@ -1917,20 +1992,6 @@ fn test_coldkey_swap_no_identity_no_changes_newcoldkey_exists() {
19171992 } ) ;
19181993}
19191994
1920- #[ test]
1921- fn test_cant_schedule_swap_without_enough_to_burn ( ) {
1922- new_test_ext ( 1 ) . execute_with ( || {
1923- let old_coldkey = U256 :: from ( 3 ) ;
1924- let new_coldkey = U256 :: from ( 4 ) ;
1925- let hotkey = U256 :: from ( 5 ) ;
1926-
1927- assert_noop ! (
1928- SubtensorModule :: do_swap_coldkey( & old_coldkey, & new_coldkey) ,
1929- Error :: <Test >:: NotEnoughBalanceToPaySwapColdKey
1930- ) ;
1931- } ) ;
1932- }
1933-
19341995#[ test]
19351996fn test_coldkey_in_swap_schedule_prevents_funds_usage ( ) {
19361997 // Testing the signed extension validate function
0 commit comments