Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new test for self-weight #1384

Merged
merged 1 commit into from
Mar 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions pallets/subtensor/src/tests/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2773,6 +2773,61 @@ fn test_blocks_since_last_step() {
});
}

#[test]
fn test_can_set_self_weight_as_subnet_owner() {
new_test_ext(1).execute_with(|| {
let subnet_owner_coldkey: U256 = U256::from(1);
let subnet_owner_hotkey: U256 = U256::from(1 + 456);

let other_hotkey: U256 = U256::from(2);

let stake = 5_000_000_000_000; // 5k TAO
let to_emit: u64 = 1_000_000_000; // 1 TAO

// Create subnet
let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey);

// Register the other hotkey
register_ok_neuron(netuid, other_hotkey, subnet_owner_coldkey, 0);

// Add stake to owner hotkey.
SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
&subnet_owner_hotkey,
&subnet_owner_coldkey,
netuid,
stake,
);

// Give vpermits to owner hotkey ONLY
ValidatorPermit::<Test>::insert(netuid, vec![true, false]);

// Set weight of 50% to each hotkey.
// This includes a self-weight
let fifty_percent: u16 = u16::MAX / 2;
Weights::<Test>::insert(netuid, 0, vec![(0, fifty_percent), (1, fifty_percent)]);

step_block(1);
// Set updated so weights are valid
LastUpdate::<Test>::insert(netuid, vec![2, 0]);

// Run epoch
let hotkey_emission: Vec<(U256, u64, u64)> = SubtensorModule::epoch(netuid, to_emit);

// hotkey_emission is [(hotkey, incentive, dividend)]
assert_eq!(hotkey_emission.len(), 2);
assert_eq!(hotkey_emission[0].0, subnet_owner_hotkey);
assert_eq!(hotkey_emission[1].0, other_hotkey);

log::debug!("hotkey_emission: {:?}", hotkey_emission);
// Both should have received incentive emission
assert!(hotkey_emission[0].1 > 0);
assert!(hotkey_emission[1].1 > 0);

// Their incentive should be equal
assert_eq!(hotkey_emission[0].1, hotkey_emission[1].1);
});
}

// Map the retention graph for consensus guarantees with an single epoch on a graph with 512 nodes,
// of which the first 64 are validators, the graph is split into a major and minor set, each setting
// specific weight on itself and the complement on the other.
Expand Down
Loading