Skip to content

Commit 45480ee

Browse files
committed
add tests for #1125
1 parent c46628d commit 45480ee

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pallets/subtensor/src/tests/swap_hotkey.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,12 +1257,16 @@ fn test_swap_parent_hotkey_childkey_maps() {
12571257
let parent_old = U256::from(1);
12581258
let coldkey = U256::from(2);
12591259
let child = U256::from(3);
1260+
let child_other = U256::from(4);
12601261
let parent_new = U256::from(4);
12611262
add_network(netuid, 1, 0);
12621263
SubtensorModule::create_account_if_non_existent(&coldkey, &parent_old);
12631264

12641265
// Set child and verify state maps
12651266
mock_set_children(&coldkey, &parent_old, netuid, &[(u64::MAX, child)]);
1267+
// Schedule some pending child keys.
1268+
mock_schedule_children(&coldkey, &parent_old, netuid, &[(u64::MAX, child_other)]);
1269+
12661270
assert_eq!(
12671271
ParentKeys::<Test>::get(child, netuid),
12681272
vec![(u64::MAX, parent_old)]
@@ -1271,6 +1275,8 @@ fn test_swap_parent_hotkey_childkey_maps() {
12711275
ChildKeys::<Test>::get(parent_old, netuid),
12721276
vec![(u64::MAX, child)]
12731277
);
1278+
let existing_pending_child_keys = PendingChildKeys::<Test>::get(netuid, parent_old);
1279+
assert_eq!(existing_pending_child_keys.0, vec![(u64::MAX, child_other)]);
12741280

12751281
// Swap
12761282
let mut weight = Weight::zero();
@@ -1290,6 +1296,10 @@ fn test_swap_parent_hotkey_childkey_maps() {
12901296
ChildKeys::<Test>::get(parent_new, netuid),
12911297
vec![(u64::MAX, child)]
12921298
);
1299+
assert_eq!(
1300+
PendingChildKeys::<Test>::get(netuid, parent_new),
1301+
existing_pending_child_keys // Entry under new hotkey.
1302+
);
12931303
})
12941304
}
12951305

@@ -1307,6 +1317,8 @@ fn test_swap_child_hotkey_childkey_maps() {
13071317

13081318
// Set child and verify state maps
13091319
mock_set_children(&coldkey, &parent, netuid, &[(u64::MAX, child_old)]);
1320+
// Schedule some pending child keys.
1321+
mock_schedule_children(&coldkey, &parent, netuid, &[(u64::MAX, child_old)]);
13101322

13111323
assert_eq!(
13121324
ParentKeys::<Test>::get(child_old, netuid),
@@ -1316,6 +1328,8 @@ fn test_swap_child_hotkey_childkey_maps() {
13161328
ChildKeys::<Test>::get(parent, netuid),
13171329
vec![(u64::MAX, child_old)]
13181330
);
1331+
let existing_pending_child_keys = PendingChildKeys::<Test>::get(netuid, parent);
1332+
assert_eq!(existing_pending_child_keys.0, vec![(u64::MAX, child_old)]);
13191333

13201334
// Swap
13211335
let mut weight = Weight::zero();
@@ -1335,5 +1349,9 @@ fn test_swap_child_hotkey_childkey_maps() {
13351349
ChildKeys::<Test>::get(parent, netuid),
13361350
vec![(u64::MAX, child_new)]
13371351
);
1352+
assert_eq!(
1353+
PendingChildKeys::<Test>::get(netuid, parent),
1354+
(vec![(u64::MAX, child_new)], existing_pending_child_keys.1) // Same cooldown block.
1355+
);
13381356
})
13391357
}

0 commit comments

Comments
 (0)