Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnReedV committed Sep 12, 2024
1 parent 9f93e4c commit ecb7c4b
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions pallets/subtensor/tests/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2315,11 +2315,11 @@ fn test_migrate_remove_zero_stakes() {
let hotkey1 = U256::from(3);
let hotkey2 = U256::from(4);

Stake::<Test>::insert(&hotkey1, &coldkey1, 0);
Stake::<Test>::insert(&hotkey2, &coldkey2, 100);
Stake::<Test>::insert(hotkey1, coldkey1, 0);
Stake::<Test>::insert(hotkey2, coldkey2, 100);

assert_eq!(Stake::<Test>::get(&hotkey1, &coldkey1), 0);
assert_eq!(Stake::<Test>::get(&hotkey2, &coldkey2), 100);
assert_eq!(Stake::<Test>::get(hotkey1, coldkey1), 0);
assert_eq!(Stake::<Test>::get(hotkey2, coldkey2), 100);

assert!(!HasMigrationRun::<Test>::get(
b"remove_zero_stakes_v1".to_vec()
Expand All @@ -2334,11 +2334,11 @@ fn test_migrate_remove_zero_stakes() {
b"remove_zero_stakes_v1".to_vec()
));

assert_eq!(Stake::<Test>::get(&hotkey1, &coldkey1), 0); // Default is 0
assert!(!Stake::<Test>::contains_key(&hotkey1, &coldkey1));
assert_eq!(Stake::<Test>::get(hotkey1, coldkey1), 0); // Default is 0
assert!(!Stake::<Test>::contains_key(hotkey1, coldkey1));

assert_eq!(Stake::<Test>::get(&hotkey2, &coldkey2), 100);
assert!(Stake::<Test>::contains_key(&hotkey2, &coldkey2));
assert_eq!(Stake::<Test>::get(hotkey2, coldkey2), 100);
assert!(Stake::<Test>::contains_key(hotkey2, coldkey2));

assert!(
weight != Weight::zero(),
Expand All @@ -2353,16 +2353,16 @@ fn test_decrease_stake_non_zero_stake() {
let hotkey = U256::from(1);
let coldkey = U256::from(2);

TotalColdkeyStake::<Test>::insert(&coldkey, 200);
TotalHotkeyStake::<Test>::insert(&hotkey, 150);
Stake::<Test>::insert(&hotkey, &coldkey, 100);
TotalColdkeyStake::<Test>::insert(coldkey, 200);
TotalHotkeyStake::<Test>::insert(hotkey, 150);
Stake::<Test>::insert(hotkey, coldkey, 100);
TotalStake::<Test>::put(300);

SubtensorModule::decrease_stake_on_coldkey_hotkey_account(&coldkey, &hotkey, 50);

assert_eq!(TotalColdkeyStake::<Test>::get(&coldkey), 150);
assert_eq!(TotalHotkeyStake::<Test>::get(&hotkey), 100);
assert_eq!(Stake::<Test>::get(&hotkey, &coldkey), 50);
assert_eq!(TotalColdkeyStake::<Test>::get(coldkey), 150);
assert_eq!(TotalHotkeyStake::<Test>::get(hotkey), 100);
assert_eq!(Stake::<Test>::get(hotkey, coldkey), 50);
assert_eq!(TotalStake::<Test>::get(), 250);
});
}
Expand All @@ -2374,18 +2374,18 @@ fn test_decrease_stake_to_zero() {
let coldkey = U256::from(2);

// Insert initial stake
TotalColdkeyStake::<Test>::insert(&coldkey, 150);
TotalHotkeyStake::<Test>::insert(&hotkey, 100);
Stake::<Test>::insert(&hotkey, &coldkey, 50);
TotalColdkeyStake::<Test>::insert(coldkey, 150);
TotalHotkeyStake::<Test>::insert(hotkey, 100);
Stake::<Test>::insert(hotkey, coldkey, 50);
TotalStake::<Test>::put(250);

// Decrease stake to zero
SubtensorModule::decrease_stake_on_coldkey_hotkey_account(&coldkey, &hotkey, 50);

// Check that the stake is removed
assert_eq!(TotalColdkeyStake::<Test>::get(&coldkey), 100);
assert_eq!(TotalHotkeyStake::<Test>::get(&hotkey), 50);
assert!(!Stake::<Test>::contains_key(&hotkey, &coldkey));
assert_eq!(TotalColdkeyStake::<Test>::get(coldkey), 100);
assert_eq!(TotalHotkeyStake::<Test>::get(hotkey), 50);
assert!(!Stake::<Test>::contains_key(hotkey, coldkey));
assert_eq!(TotalStake::<Test>::get(), 200);
});
}
Expand All @@ -2397,18 +2397,18 @@ fn test_decrease_stake_more_than_available() {
let coldkey = U256::from(2);

// Insert initial stake
TotalColdkeyStake::<Test>::insert(&coldkey, 80);
TotalHotkeyStake::<Test>::insert(&hotkey, 70);
Stake::<Test>::insert(&hotkey, &coldkey, 60);
TotalColdkeyStake::<Test>::insert(coldkey, 80);
TotalHotkeyStake::<Test>::insert(hotkey, 70);
Stake::<Test>::insert(hotkey, coldkey, 60);
TotalStake::<Test>::put(150);

// Decrease by more than available stake
SubtensorModule::decrease_stake_on_coldkey_hotkey_account(&coldkey, &hotkey, 100);

// Check that the stake is zero and removed
assert_eq!(TotalColdkeyStake::<Test>::get(&coldkey), 0);
assert_eq!(TotalHotkeyStake::<Test>::get(&hotkey), 0);
assert!(!Stake::<Test>::contains_key(&hotkey, &coldkey));
assert_eq!(TotalColdkeyStake::<Test>::get(coldkey), 0);
assert_eq!(TotalHotkeyStake::<Test>::get(hotkey), 0);
assert!(!Stake::<Test>::contains_key(hotkey, coldkey));
assert_eq!(TotalStake::<Test>::get(), 50);
});
}
Expand All @@ -2420,18 +2420,18 @@ fn test_decrease_stake_no_existing_stake() {
let coldkey = U256::from(2);

// Insert zero stake for coldkey and hotkey
TotalColdkeyStake::<Test>::insert(&coldkey, 0);
TotalHotkeyStake::<Test>::insert(&hotkey, 0);
Stake::<Test>::remove(&hotkey, &coldkey);
TotalColdkeyStake::<Test>::insert(coldkey, 0);
TotalHotkeyStake::<Test>::insert(hotkey, 0);
Stake::<Test>::remove(hotkey, coldkey);
TotalStake::<Test>::put(0);

// Try to decrease stake when no stake exists
SubtensorModule::decrease_stake_on_coldkey_hotkey_account(&coldkey, &hotkey, 10);

// Assert no changes were made
assert_eq!(TotalColdkeyStake::<Test>::get(&coldkey), 0);
assert_eq!(TotalHotkeyStake::<Test>::get(&hotkey), 0);
assert!(!Stake::<Test>::contains_key(&hotkey, &coldkey));
assert_eq!(TotalColdkeyStake::<Test>::get(coldkey), 0);
assert_eq!(TotalHotkeyStake::<Test>::get(hotkey), 0);
assert!(!Stake::<Test>::contains_key(hotkey, coldkey));
assert_eq!(TotalStake::<Test>::get(), 0);
});
}

0 comments on commit ecb7c4b

Please sign in to comment.