Skip to content

Commit 2b8ed3a

Browse files
author
unconst
committed
new test root tao
1 parent 4f900ca commit 2b8ed3a

File tree

1 file changed

+76
-2
lines changed

1 file changed

+76
-2
lines changed

pallets/subtensor/src/tests/coinbase.rs

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,13 +704,87 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_am
704704
let root_after2 = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
705705
&hotkey2, &coldkey, root,
706706
);
707-
let expected_stake = I96F32::from_num(stake_before) + I96F32::from_num(pending_alpha) * I96F32::from_num(0.6);
707+
let expected_stake = I96F32::from_num(stake_before) + I96F32::from_num(pending_alpha) * I96F32::from_num(3/5);
708708
close(expected_stake.to_num::<u64>(), stake_after1, 10); // Registered gets 60% of emission
709-
let expected_stake2 = I96F32::from_num(stake_before) + I96F32::from_num(pending_alpha) * I96F32::from_num(0.4);
709+
let expected_stake2 = I96F32::from_num(stake_before) + I96F32::from_num(pending_alpha) * I96F32::from_num(2/5);
710710
close(expected_stake2.to_num::<u64>(), stake_after2, 10); // Registered gets 40% emission
711711
let expected_root1 = I96F32::from_num(2 * stake_before) + I96F32::from_num(pending_tao) * I96F32::from_num(2.0/3.0);
712712
close(expected_root1.to_num::<u64>(), root_after1, 10); // Registered gets 2/3 tao emission
713713
let expected_root2 = I96F32::from_num(stake_before) + I96F32::from_num(pending_tao) * I96F32::from_num(1.0/3.0);
714714
close(expected_root2.to_num::<u64>(), root_after2, 10); // Registered gets 1/3 tao emission
715715
});
716+
}
717+
718+
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_amounts_half_tao_weight --exact --show-output --nocapture
719+
#[test]
720+
fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_amounts_half_tao_weight() {
721+
new_test_ext(1).execute_with(|| {
722+
let root: u16 = 0;
723+
let netuid: u16 = 1;
724+
add_network(netuid, 1, 0);
725+
let hotkey1 = U256::from(1);
726+
let hotkey2 = U256::from(2);
727+
let coldkey = U256::from(3);
728+
let stake_before: u64 = 1_000_000_000;
729+
register_ok_neuron(netuid, hotkey1, coldkey, 0);
730+
register_ok_neuron(netuid, hotkey2, coldkey, 0);
731+
SubtensorModule::set_tao_weight( u64::MAX/2 ); // Set TAO weight to 0.5
732+
SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
733+
&hotkey1,
734+
&coldkey,
735+
netuid,
736+
stake_before,
737+
);
738+
SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
739+
&hotkey1,
740+
&coldkey,
741+
root,
742+
2 * stake_before, // Hotkey 1 has twice as much root weight.
743+
);
744+
SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
745+
&hotkey2,
746+
&coldkey,
747+
netuid,
748+
stake_before,
749+
);
750+
SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
751+
&hotkey2,
752+
&coldkey,
753+
root,
754+
stake_before,
755+
);
756+
let pending_tao: u64 = 1_000_000_000;
757+
let pending_alpha: u64 = 1_000_000_000;
758+
SubtensorModule::drain_pending_emission(
759+
netuid,
760+
pending_alpha,
761+
pending_tao,
762+
0,
763+
0,
764+
);
765+
let stake_after1 = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
766+
&hotkey1, &coldkey, netuid,
767+
);
768+
let root_after1 = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
769+
&hotkey1, &coldkey, root,
770+
);
771+
let stake_after2 = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
772+
&hotkey2, &coldkey, netuid,
773+
);
774+
let root_after2 = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
775+
&hotkey2, &coldkey, root,
776+
);
777+
// hotkey 1 has (1 + (2 * 0.5))/( 1 + 1*0.5 + 1 + (2 * 0.5)) = 0.5714285714 of the hotkey emission.
778+
let expected_stake = I96F32::from_num(stake_before) + I96F32::from_num(pending_alpha) * I96F32::from_num(0.5714285714);
779+
close(expected_stake.to_num::<u64>(), stake_after1, 10);
780+
// hotkey 2 has (1 + 1*0.5)/( 1 + 1*0.5 + 1 + (2 * 0.5)) = 0.4285714286 of the hotkey emission.
781+
let expected_stake2 = I96F32::from_num(stake_before) + I96F32::from_num(pending_alpha) * I96F32::from_num(0.4285714286);
782+
close(expected_stake2.to_num::<u64>(), stake_after2, 10);
783+
// hotkey 1 has 2 / 3 root tao
784+
let expected_root1 = I96F32::from_num(2 * stake_before) + I96F32::from_num(pending_tao) * I96F32::from_num(2.0/3.0);
785+
close(expected_root1.to_num::<u64>(), root_after1, 10);
786+
// hotkey 1 has 1 / 3 root tao
787+
let expected_root2 = I96F32::from_num(stake_before) + I96F32::from_num(pending_tao) * I96F32::from_num(1.0/3.0);
788+
close(expected_root2.to_num::<u64>(), root_after2, 10);
789+
});
716790
}

0 commit comments

Comments
 (0)