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

Feat/record initial subnet tao in totalstake #1428

Merged
merged 10 commits into from
Mar 19, 2025
Prev Previous commit
Next Next commit
amend tests for stake trackers
  • Loading branch information
camfairchild committed Mar 18, 2025
commit 9004a013b622a54b132efb33058865e545324edb
33 changes: 31 additions & 2 deletions pallets/subtensor/src/tests/staking.rs
Original file line number Diff line number Diff line change
@@ -359,7 +359,6 @@ fn test_remove_stake_ok_no_emission() {
let coldkey_account_id = U256::from(4343);
let hotkey_account_id = U256::from(4968585);
let amount = DefaultMinStake::<Test>::get() * 10;
let fee = DefaultStakingFee::<Test>::get();
let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey);
register_ok_neuron(netuid, hotkey_account_id, coldkey_account_id, 192213123);

@@ -381,6 +380,16 @@ fn test_remove_stake_ok_no_emission() {
netuid,
amount,
);
assert_eq!(
SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id),
amount
);

// Add subnet TAO for the equivalent amount added at price
let amount_tao =
I96F32::saturating_from_num(amount) * SubtensorModule::get_alpha_price(netuid);
SubnetTAO::<Test>::mutate(netuid, |v| *v += amount_tao.saturating_to_num::<u64>());
TotalStake::<Test>::mutate(|v| *v += amount_tao.saturating_to_num::<u64>());

// Do the magic
assert_ok!(SubtensorModule::remove_stake(
@@ -390,6 +399,14 @@ fn test_remove_stake_ok_no_emission() {
amount
));

let fee = SubtensorModule::calculate_staking_fee(
Some((&hotkey_account_id, netuid)),
&coldkey_account_id,
None,
&coldkey_account_id,
I96F32::saturating_from_num(amount),
);

// we do not expect the exact amount due to slippage
assert!(SubtensorModule::get_coldkey_balance(&coldkey_account_id) > amount / 10 * 9 - fee);
assert_eq!(
@@ -525,7 +542,6 @@ fn test_remove_stake_total_balance_no_change() {
let hotkey_account_id = U256::from(571337);
let coldkey_account_id = U256::from(71337);
let amount = DefaultMinStake::<Test>::get() * 10;
let fee = DefaultStakingFee::<Test>::get();
let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey);
register_ok_neuron(netuid, hotkey_account_id, coldkey_account_id, 192213123);

@@ -550,6 +566,12 @@ fn test_remove_stake_total_balance_no_change() {
amount,
);

// Add subnet TAO for the equivalent amount added at price
let amount_tao =
I96F32::saturating_from_num(amount) * SubtensorModule::get_alpha_price(netuid);
SubnetTAO::<Test>::mutate(netuid, |v| *v += amount_tao.saturating_to_num::<u64>());
TotalStake::<Test>::mutate(|v| *v += amount_tao.saturating_to_num::<u64>());

// Do the magic
assert_ok!(SubtensorModule::remove_stake(
RuntimeOrigin::signed(coldkey_account_id),
@@ -558,6 +580,13 @@ fn test_remove_stake_total_balance_no_change() {
amount
));

let fee = SubtensorModule::calculate_staking_fee(
Some((&hotkey_account_id, netuid)),
&coldkey_account_id,
None,
&coldkey_account_id,
I96F32::saturating_from_num(amount),
);
assert_abs_diff_eq!(
SubtensorModule::get_coldkey_balance(&coldkey_account_id),
amount - fee,
Loading