@@ -1497,7 +1497,13 @@ fn test_get_parents_chain() {
14971497 let num_keys: usize = 5 ;
14981498 let proportion = u64:: MAX / 2 ; // 50% stake allocation
14991499
1500- log:: info!( "Test setup: netuid={}, coldkey={}, num_keys={}, proportion={}" , netuid, coldkey, num_keys, proportion) ;
1500+ log:: info!(
1501+ "Test setup: netuid={}, coldkey={}, num_keys={}, proportion={}" ,
1502+ netuid,
1503+ coldkey,
1504+ num_keys,
1505+ proportion
1506+ ) ;
15011507
15021508 // Create a vector of hotkeys
15031509 let hotkeys: Vec < U256 > = ( 0 ..num_keys) . map ( |i| U256 :: from ( i as u64 + 2 ) ) . collect ( ) ;
@@ -1512,7 +1518,12 @@ fn test_get_parents_chain() {
15121518 // Register all neurons
15131519 for hotkey in & hotkeys {
15141520 register_ok_neuron ( netuid, * hotkey, coldkey, 0 ) ;
1515- log:: info!( "Registered neuron: hotkey={}, coldkey={}, netuid={}" , hotkey, coldkey, netuid) ;
1521+ log:: info!(
1522+ "Registered neuron: hotkey={}, coldkey={}, netuid={}" ,
1523+ hotkey,
1524+ coldkey,
1525+ netuid
1526+ ) ;
15161527 }
15171528
15181529 // Set up parent-child relationships
@@ -1523,13 +1534,22 @@ fn test_get_parents_chain() {
15231534 netuid,
15241535 vec![ ( proportion, hotkeys[ i + 1 ] ) ]
15251536 ) ) ;
1526- log:: info!( "Set parent-child relationship: parent={}, child={}, proportion={}" , hotkeys[ i] , hotkeys[ i + 1 ] , proportion) ;
1537+ log:: info!(
1538+ "Set parent-child relationship: parent={}, child={}, proportion={}" ,
1539+ hotkeys[ i] ,
1540+ hotkeys[ i + 1 ] ,
1541+ proportion
1542+ ) ;
15271543 }
15281544
15291545 // Test get_parents for each hotkey
15301546 for i in 1 ..num_keys {
15311547 let parents = SubtensorModule :: get_parents ( & hotkeys[ i] , netuid) ;
1532- log:: info!( "Testing get_parents for hotkey {}: {:?}" , hotkeys[ i] , parents) ;
1548+ log:: info!(
1549+ "Testing get_parents for hotkey {}: {:?}" ,
1550+ hotkeys[ i] ,
1551+ parents
1552+ ) ;
15331553 assert_eq ! (
15341554 parents. len( ) ,
15351555 1 ,
@@ -1546,7 +1566,11 @@ fn test_get_parents_chain() {
15461566
15471567 // Test get_parents for the root (should be empty)
15481568 let root_parents = SubtensorModule :: get_parents ( & hotkeys[ 0 ] , netuid) ;
1549- log:: info!( "Testing get_parents for root hotkey {}: {:?}" , hotkeys[ 0 ] , root_parents) ;
1569+ log:: info!(
1570+ "Testing get_parents for root hotkey {}: {:?}" ,
1571+ hotkeys[ 0 ] ,
1572+ root_parents
1573+ ) ;
15501574 assert ! (
15511575 root_parents. is_empty( ) ,
15521576 "Root hotkey should have no parents"
@@ -1556,18 +1580,32 @@ fn test_get_parents_chain() {
15561580 let last_hotkey = hotkeys[ num_keys - 1 ] ;
15571581 let new_parent = U256 :: from ( num_keys as u64 + 2 ) ;
15581582 register_ok_neuron ( netuid, new_parent, coldkey, 0 ) ;
1559- log:: info!( "Registered new parent neuron: new_parent={}, coldkey={}, netuid={}" , new_parent, coldkey, netuid) ;
1583+ log:: info!(
1584+ "Registered new parent neuron: new_parent={}, coldkey={}, netuid={}" ,
1585+ new_parent,
1586+ coldkey,
1587+ netuid
1588+ ) ;
15601589
15611590 assert_ok ! ( SubtensorModule :: do_set_children(
15621591 RuntimeOrigin :: signed( coldkey) ,
15631592 new_parent,
15641593 netuid,
15651594 vec![ ( proportion / 2 , last_hotkey) ]
15661595 ) ) ;
1567- log:: info!( "Set additional parent-child relationship: parent={}, child={}, proportion={}" , new_parent, last_hotkey, proportion / 2 ) ;
1596+ log:: info!(
1597+ "Set additional parent-child relationship: parent={}, child={}, proportion={}" ,
1598+ new_parent,
1599+ last_hotkey,
1600+ proportion / 2
1601+ ) ;
15681602
15691603 let last_hotkey_parents = SubtensorModule :: get_parents ( & last_hotkey, netuid) ;
1570- log:: info!( "Testing get_parents for last hotkey {} with multiple parents: {:?}" , last_hotkey, last_hotkey_parents) ;
1604+ log:: info!(
1605+ "Testing get_parents for last hotkey {} with multiple parents: {:?}" ,
1606+ last_hotkey,
1607+ last_hotkey_parents
1608+ ) ;
15711609 assert_eq ! (
15721610 last_hotkey_parents. len( ) ,
15731611 2 ,
@@ -1583,3 +1621,55 @@ fn test_get_parents_chain() {
15831621 ) ;
15841622 } ) ;
15851623}
1624+
1625+ // SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test children -- test_childkey_take_removal_on_empty_children --exact --nocapture
1626+ #[ test]
1627+ fn test_childkey_take_removal_on_empty_children ( ) {
1628+ new_test_ext ( 1 ) . execute_with ( || {
1629+ let coldkey = U256 :: from ( 1 ) ;
1630+ let hotkey = U256 :: from ( 2 ) ;
1631+ let child = U256 :: from ( 3 ) ;
1632+ let netuid: u16 = 1 ;
1633+ let proportion: u64 = 1000 ;
1634+
1635+ // Add network and register hotkey
1636+ add_network ( netuid, 13 , 0 ) ;
1637+ register_ok_neuron ( netuid, hotkey, coldkey, 0 ) ;
1638+
1639+ // Set a child and childkey take
1640+ assert_ok ! ( SubtensorModule :: do_set_children(
1641+ RuntimeOrigin :: signed( coldkey) ,
1642+ hotkey,
1643+ netuid,
1644+ vec![ ( proportion, child) ]
1645+ ) ) ;
1646+
1647+ let take: u16 = u16:: MAX / 10 ; // 10% take
1648+ assert_ok ! ( SubtensorModule :: set_childkey_take(
1649+ RuntimeOrigin :: signed( coldkey) ,
1650+ hotkey,
1651+ netuid,
1652+ take
1653+ ) ) ;
1654+
1655+ // Verify childkey take is set
1656+ assert_eq ! ( SubtensorModule :: get_childkey_take( & hotkey, netuid) , take) ;
1657+
1658+ // Remove all children
1659+ assert_ok ! ( SubtensorModule :: do_set_children(
1660+ RuntimeOrigin :: signed( coldkey) ,
1661+ hotkey,
1662+ netuid,
1663+ vec![ ]
1664+ ) ) ;
1665+
1666+ // Verify children are removed
1667+ let children = SubtensorModule :: get_children ( & hotkey, netuid) ;
1668+ assert ! ( children. is_empty( ) ) ;
1669+
1670+ // Verify childkey take is removed
1671+ assert_eq ! ( SubtensorModule :: get_childkey_take( & hotkey, netuid) , 0 ) ;
1672+ // Verify childkey take storage is empty
1673+ assert_eq ! ( ChildkeyTake :: <Test >:: get( hotkey, netuid) , 0 ) ;
1674+ } ) ;
1675+ }
0 commit comments