Skip to content

Commit

Permalink
remove duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
sam0x17 committed Nov 13, 2024
1 parent 71e0e9c commit 850c8e7
Showing 1 changed file with 0 additions and 88 deletions.
88 changes: 0 additions & 88 deletions pallets/subtensor/tests/swap_hotkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1334,91 +1334,3 @@ fn test_swap_child_hotkey_childkey_maps() {
);
})
}

// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test swap_hotkey -- test_hotkey_swap_stake_delta --exact --nocapture
#[test]
fn test_hotkey_swap_stake_delta() {
new_test_ext(1).execute_with(|| {
let old_hotkey = U256::from(3);
let new_hotkey = U256::from(4);
let coldkey = U256::from(7);

let coldkeys = [U256::from(1), U256::from(2), U256::from(5)];

let mut weight = Weight::zero();

// Set up initial state
// Add stake delta for each coldkey and the old_hotkey
for &coldkey in coldkeys.iter() {
StakeDeltaSinceLastEmissionDrain::<Test>::insert(
old_hotkey,
coldkey,
(123 + coldkey.saturated_into::<i128>()),
);

StakingHotkeys::<Test>::insert(coldkey, vec![old_hotkey]);
}

// Add stake delta for one coldkey and the new_hotkey
StakeDeltaSinceLastEmissionDrain::<Test>::insert(new_hotkey, coldkeys[0], 456);
// Add corresponding StakingHotkeys
StakingHotkeys::<Test>::insert(coldkeys[0], vec![old_hotkey, new_hotkey]);

// Perform the swap
SubtensorModule::perform_hotkey_swap(&old_hotkey, &new_hotkey, &coldkey, &mut weight);

// Ensure the stake delta is correctly transferred for each coldkey
// -- coldkey[0] maintains its stake delta from the new_hotkey and the old_hotkey
assert_eq!(
StakeDeltaSinceLastEmissionDrain::<Test>::get(new_hotkey, coldkeys[0]),
123 + coldkeys[0].saturated_into::<i128>() + 456
);
// -- coldkey[1..] maintains its stake delta from the old_hotkey
for &coldkey in coldkeys[1..].iter() {
assert_eq!(
StakeDeltaSinceLastEmissionDrain::<Test>::get(new_hotkey, coldkey),
123 + coldkey.saturated_into::<i128>()
);
assert!(!StakeDeltaSinceLastEmissionDrain::<Test>::contains_key(
old_hotkey, coldkey
));
}
});
}

// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test swap_hotkey -- test_swap_hotkey_with_pending_emissions --exact --nocapture
#[test]
fn test_swap_hotkey_with_pending_emissions() {
new_test_ext(1).execute_with(|| {
let old_hotkey = U256::from(1);
let new_hotkey = U256::from(2);
let coldkey = U256::from(3);
let netuid = 0u16;
let mut weight = Weight::zero();

let pending_emission = 123_456_789u64;

// Set up initial state
add_network(netuid, 0, 1);

// Set up pending emissions
PendingdHotkeyEmission::<Test>::insert(old_hotkey, pending_emission);
// Verify the pending emissions are set
assert_eq!(
PendingdHotkeyEmission::<Test>::get(old_hotkey),
pending_emission
);
// Verify the new hotkey does not have any pending emissions
assert!(!PendingdHotkeyEmission::<Test>::contains_key(new_hotkey));

// Perform the swap
SubtensorModule::perform_hotkey_swap(&old_hotkey, &new_hotkey, &coldkey, &mut weight);

// Verify the pending emissions are transferred
assert_eq!(
PendingdHotkeyEmission::<Test>::get(new_hotkey),
pending_emission
);
assert!(!PendingdHotkeyEmission::<Test>::contains_key(old_hotkey));
});
}

0 comments on commit 850c8e7

Please sign in to comment.