Skip to content

Commit 22e2538

Browse files
committed
Test actual coldkey alphas in share pool migration
1 parent b54f38d commit 22e2538

File tree

1 file changed

+48
-9
lines changed

1 file changed

+48
-9
lines changed

pallets/subtensor/src/tests/migration.rs

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,15 +2980,20 @@ fn test_migrate_share_pool_high_precision() {
29802980
let netuid = NetUid::from(1u16);
29812981

29822982
let hotkey = U256::from(100u64);
2983-
let coldkey = U256::from(101u64);
2983+
let coldkey1 = U256::from(101u64);
2984+
let coldkey2 = U256::from(102u64);
29842985

2985-
// OK to mismatch
2986+
// OK to mismatch the sum of coldkey alphas and THS
29862987
let ths = U64F64::from_num(12345.678);
2987-
let alpha = U64F64::from_num(123.45);
2988+
let alpha1 = U64F64::from_num(0.00000001234);
2989+
let alpha2 = U64F64::from_num(432.123458765);
2990+
let total_alpha = 1_123_000_000_u64;
29882991

29892992
// Insert the enties into TotalHotkeyShares and Alpha maps
29902993
TotalHotkeyShares::<Test>::insert(hotkey, netuid, ths);
2991-
Alpha::<Test>::insert((hotkey, coldkey, netuid), alpha);
2994+
Alpha::<Test>::insert((hotkey, coldkey1, netuid), alpha1);
2995+
Alpha::<Test>::insert((hotkey, coldkey2, netuid), alpha2);
2996+
TotalHotkeyAlpha::<Test>::insert(hotkey, netuid, AlphaCurrency::from(total_alpha));
29922997

29932998
assert!(
29942999
!HasMigrationRun::<Test>::get(MIGRATION_NAME.as_bytes().to_vec()),
@@ -3006,9 +3011,13 @@ fn test_migrate_share_pool_high_precision() {
30063011
let migrated_ths: SafeFloat = (&migrated_ths_serializable).into();
30073012
let migrated_ths_f64: f64 = migrated_ths.into();
30083013

3009-
let migrated_alpha_serializable = AlphaV2::<Test>::get((hotkey, coldkey, netuid));
3010-
let migrated_alpha: SafeFloat = (&migrated_alpha_serializable).into();
3011-
let migrated_alpha_f64: f64 = migrated_alpha.into();
3014+
let migrated_alpha_serializable1 = AlphaV2::<Test>::get((hotkey, coldkey1, netuid));
3015+
let migrated_alpha1: SafeFloat = (&migrated_alpha_serializable1).into();
3016+
let migrated_alpha1_f64: f64 = migrated_alpha1.into();
3017+
3018+
let migrated_alpha_serializable2 = AlphaV2::<Test>::get((hotkey, coldkey2, netuid));
3019+
let migrated_alpha2: SafeFloat = (&migrated_alpha_serializable2).into();
3020+
let migrated_alpha2_f64: f64 = migrated_alpha2.into();
30123021

30133022
assert_abs_diff_eq!(
30143023
migrated_ths_f64,
@@ -3017,11 +3026,41 @@ fn test_migrate_share_pool_high_precision() {
30173026
);
30183027

30193028
assert_abs_diff_eq!(
3020-
migrated_alpha_f64,
3021-
alpha.to_num::<f64>(),
3029+
migrated_alpha1_f64,
3030+
alpha1.to_num::<f64>(),
3031+
epsilon = 0.000000001
3032+
);
3033+
3034+
assert_abs_diff_eq!(
3035+
migrated_alpha2_f64,
3036+
alpha2.to_num::<f64>(),
30223037
epsilon = 0.000000001
30233038
);
30243039

3040+
// Check that coldkey alpha makes sense after migration
3041+
let expected_coldkey_alpha1: u64 = (total_alpha as f64 * alpha1.to_num::<f64>() / ths.to_num::<f64>()) as u64;
3042+
let expected_coldkey_alpha2: u64 = (total_alpha as f64 * alpha2.to_num::<f64>() / ths.to_num::<f64>()) as u64;
3043+
let actual_coldkey_alpha1 = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
3044+
&hotkey,
3045+
&coldkey1,
3046+
netuid
3047+
);
3048+
let actual_coldkey_alpha2 = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
3049+
&hotkey,
3050+
&coldkey2,
3051+
netuid
3052+
);
3053+
3054+
assert_eq!(
3055+
expected_coldkey_alpha1,
3056+
u64::from(actual_coldkey_alpha1)
3057+
);
3058+
3059+
assert_eq!(
3060+
expected_coldkey_alpha2,
3061+
u64::from(actual_coldkey_alpha2)
3062+
);
3063+
30253064
assert!(
30263065
!weight.is_zero(),
30273066
"Migration weight should be non-zero."

0 commit comments

Comments
 (0)