Skip to content

Commit 1e40637

Browse files
committed
add test for other netuid not touched
1 parent 2b7067a commit 1e40637

File tree

1 file changed

+147
-0
lines changed

1 file changed

+147
-0
lines changed

pallets/subtensor/src/tests/migration.rs

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,3 +679,150 @@ fn test_migrate_dissolve_sn73_pays_out_subnet_tao() {
679679
}
680680
});
681681
}
682+
683+
#[test]
684+
fn test_migrate_dissolve_sn73_doesnt_affect_other_subnets() {
685+
new_test_ext(1).execute_with(|| {
686+
let this_netuid: u16 = 73;
687+
let other_netuid: u16 = 72; // Also created
688+
let sn_owner_hk: U256 = U256::from(1);
689+
let sn_owner_ck: U256 = U256::from(2);
690+
691+
let subnet_tao: u64 = 678_900_000_000;
692+
693+
let staker_0_hk: U256 = U256::from(3);
694+
let staker_0_ck: U256 = U256::from(4);
695+
696+
let staker_1_hk: U256 = U256::from(5);
697+
let staker_1_ck: U256 = U256::from(6);
698+
699+
let staker_2_hk: U256 = U256::from(7);
700+
let staker_2_ck: U256 = U256::from(8);
701+
702+
let delegate_0_ck: U256 = U256::from(9);
703+
let delegate_1_ck: U256 = U256::from(10);
704+
705+
let stakes = vec![
706+
(staker_0_hk, staker_0_ck, 100_000_000_000),
707+
(staker_1_hk, staker_1_ck, 200_000_000_000),
708+
(staker_2_hk, staker_2_ck, 123_456_789_000),
709+
(staker_2_hk, delegate_0_ck, 400_000_000_000), // delegates to hk 2
710+
(staker_2_hk, delegate_1_ck, 500_000_000_000), // delegates to hk 2
711+
(staker_1_hk, delegate_0_ck, 456_789_000_000), // delegate 0 also stakes to hk 1
712+
];
713+
let total_alpha = stakes.iter().map(|(_, _, stake)| stake).sum::<u64>();
714+
715+
let mut created_netuid = 0;
716+
while created_netuid < this_netuid {
717+
created_netuid = add_dynamic_network(&sn_owner_hk, &sn_owner_ck);
718+
}
719+
assert_eq!(created_netuid, this_netuid);
720+
721+
for netuid in [this_netuid, other_netuid] {
722+
// Stake to both subnets same amounts
723+
for (hk, ck, stake) in stakes.iter() {
724+
SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
725+
hk, ck, netuid, *stake,
726+
);
727+
}
728+
}
729+
730+
// Set subnetTAO
731+
SubnetTAO::<Test>::insert(this_netuid, subnet_tao);
732+
733+
// ===== Set some storage maps ====
734+
735+
// Set some child keys
736+
ParentKeys::<Test>::insert(U256::from(1), other_netuid, vec![(1, U256::from(2))]);
737+
ChildKeys::<Test>::insert(U256::from(2), other_netuid, vec![(1, U256::from(1))]);
738+
PendingChildKeys::<Test>::insert(
739+
other_netuid,
740+
U256::from(1),
741+
(vec![(1, U256::from(2))], 123),
742+
);
743+
744+
// Set some alpha dividends
745+
AlphaDividendsPerSubnet::<Test>::insert(other_netuid, U256::from(1), 100_000_000_000);
746+
TaoDividendsPerSubnet::<Test>::insert(other_netuid, U256::from(2), 200_000_000_000);
747+
748+
// Set pending emissions
749+
PendingEmission::<Test>::insert(other_netuid, 123);
750+
PendingAlphaSwapped::<Test>::insert(other_netuid, 456);
751+
PendingOwnerCut::<Test>::insert(other_netuid, 789);
752+
SubnetAlphaInEmission::<Test>::insert(other_netuid, 789);
753+
SubnetTaoInEmission::<Test>::insert(other_netuid, 101);
754+
SubnetAlphaOutEmission::<Test>::insert(other_netuid, 102);
755+
756+
// Set sn volume
757+
SubnetVolume::<Test>::insert(other_netuid, 123);
758+
759+
// Set alpha out
760+
SubnetAlphaOut::<Test>::insert(other_netuid, 100_000_000_000);
761+
// Set alpha in
762+
SubnetAlphaIn::<Test>::insert(other_netuid, 100_000_000_000);
763+
764+
// Set reg allowed maps
765+
NetworkRegistrationAllowed::<Test>::insert(other_netuid, true);
766+
NetworkPowRegistrationAllowed::<Test>::insert(other_netuid, true);
767+
768+
// ===== End of setting storage maps ====
769+
770+
// Run existing remove network dissolve
771+
SubtensorModule::remove_network(this_netuid);
772+
773+
// Run new dissolve migration code
774+
crate::migrations::migrate_dissolve_sn73::migrate_dissolve_sn73::<Test>();
775+
776+
// Verify that the other netuid is unaffected
777+
for (hk, ck, stake) in stakes.iter() {
778+
let stake_on_subnet =
779+
SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(hk, ck, other_netuid);
780+
781+
assert_eq!(stake_on_subnet, *stake);
782+
}
783+
784+
// Check other storages
785+
assert!(SubnetOwner::<Test>::try_get(other_netuid).is_ok());
786+
assert!(SubnetOwnerHotkey::<Test>::try_get(other_netuid).is_ok());
787+
788+
// Verify all the maps are not touched
789+
assert!(SubnetTAO::<Test>::try_get(other_netuid).is_ok());
790+
assert!(SubnetVolume::<Test>::try_get(other_netuid).is_ok());
791+
792+
assert!(ParentKeys::<Test>::try_get(U256::from(1), other_netuid).is_ok());
793+
assert!(ChildKeys::<Test>::try_get(U256::from(2), other_netuid).is_ok());
794+
assert!(PendingChildKeys::<Test>::try_get(other_netuid, U256::from(1)).is_ok());
795+
796+
// Verify div maps
797+
assert!(
798+
!AlphaDividendsPerSubnet::<Test>::iter_prefix(other_netuid)
799+
.collect::<Vec<_>>()
800+
.is_empty()
801+
);
802+
assert!(
803+
!TaoDividendsPerSubnet::<Test>::iter_prefix(other_netuid)
804+
.collect::<Vec<_>>()
805+
.is_empty()
806+
);
807+
808+
// Verify all the pending maps are not touched
809+
assert!(PendingEmission::<Test>::try_get(other_netuid).is_ok());
810+
assert!(PendingAlphaSwapped::<Test>::try_get(other_netuid).is_ok());
811+
assert!(PendingOwnerCut::<Test>::try_get(other_netuid).is_ok());
812+
assert!(SubnetAlphaInEmission::<Test>::try_get(other_netuid).is_ok());
813+
assert!(SubnetTaoInEmission::<Test>::try_get(other_netuid).is_ok());
814+
assert!(SubnetAlphaOutEmission::<Test>::try_get(other_netuid).is_ok());
815+
816+
// verify pool is present
817+
assert!(SubnetAlphaIn::<Test>::try_get(other_netuid).is_ok());
818+
assert!(SubnetAlphaOut::<Test>::try_get(other_netuid).is_ok());
819+
assert!(SubnetTAO::<Test>::try_get(other_netuid).is_ok());
820+
821+
// Verify sn volume is present
822+
assert!(SubnetVolume::<Test>::try_get(other_netuid).is_ok());
823+
824+
// verify reg allowed maps are present
825+
assert!(NetworkRegistrationAllowed::<Test>::try_get(other_netuid).is_ok());
826+
assert!(NetworkPowRegistrationAllowed::<Test>::try_get(other_netuid).is_ok());
827+
});
828+
}

0 commit comments

Comments
 (0)