Skip to content

Commit 01cabbd

Browse files
author
Samuel Dare
committed
chore: multiple network child key takes
1 parent c1dbc59 commit 01cabbd

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

pallets/subtensor/tests/children.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,58 @@ fn test_childkey_take_rate_limiting() {
969969
});
970970
}
971971

972+
// SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test children -- test_multiple_networks_childkey_take --exact --nocapture
973+
#[test]
974+
fn test_multiple_networks_childkey_take() {
975+
new_test_ext(1).execute_with(|| {
976+
const NUM_NETWORKS: u16 = 10;
977+
let coldkey = U256::from(1);
978+
let hotkey = U256::from(2);
979+
980+
// Create 10 networks and set up neurons (skip network 0)
981+
for netuid in 1..NUM_NETWORKS {
982+
// Add network
983+
add_network(netuid, 13, 0);
984+
985+
// Register neuron
986+
register_ok_neuron(netuid, hotkey, coldkey, 0);
987+
988+
// Set a unique childkey take value for each network
989+
let take_value = (netuid as u16 + 1) * 1000; // Values will be 1000, 2000, ..., 10000
990+
assert_ok!(SubtensorModule::set_childkey_take(
991+
RuntimeOrigin::signed(coldkey),
992+
hotkey,
993+
netuid,
994+
take_value
995+
));
996+
997+
// Verify the childkey take was set correctly
998+
let stored_take = SubtensorModule::get_childkey_take(&hotkey, netuid);
999+
assert_eq!(
1000+
stored_take, take_value,
1001+
"Childkey take not set correctly for network {}",
1002+
netuid
1003+
);
1004+
1005+
// Log the set value
1006+
log::info!("Network {}: Childkey take set to {}", netuid, take_value);
1007+
}
1008+
1009+
// Verify all networks have different childkey take values
1010+
for i in 1..NUM_NETWORKS {
1011+
for j in (i + 1)..NUM_NETWORKS {
1012+
let take_i = SubtensorModule::get_childkey_take(&hotkey, i);
1013+
let take_j = SubtensorModule::get_childkey_take(&hotkey, j);
1014+
assert_ne!(
1015+
take_i, take_j,
1016+
"Childkey take values should be different for networks {} and {}",
1017+
i, j
1018+
);
1019+
}
1020+
}
1021+
});
1022+
}
1023+
9721024
#[test]
9731025
fn test_do_set_children_multiple_empty_list() {
9741026
new_test_ext(1).execute_with(|| {

0 commit comments

Comments
 (0)