Skip to content

Commit 475888f

Browse files
committed
remove test with LastAddStakeIncrease
1 parent f2b367c commit 475888f

File tree

1 file changed

+1
-161
lines changed

1 file changed

+1
-161
lines changed

pallets/subtensor/tests/coinbase.rs

+1-161
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::mock::*;
33
mod mock;
44
use frame_support::assert_ok;
55

6-
use pallet_subtensor::{LastAddStakeIncrease, TargetStakesPerInterval};
6+
use pallet_subtensor::TargetStakesPerInterval;
77
use sp_core::U256;
88
use substrate_fixed::types::I64F64;
99

@@ -415,166 +415,6 @@ fn test_coinbase_nominator_drainage_overflow() {
415415
});
416416
}
417417

418-
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --test coinbase test_coinbase_nominator_drainage_no_affected_by_last_add_stake -- --nocapture
419-
#[test]
420-
fn test_coinbase_nominator_drainage_no_affected_by_last_add_stake() {
421-
new_test_ext(1).execute_with(|| {
422-
// 1. Set up the network and accounts
423-
let netuid: u16 = 1;
424-
let hotkey = U256::from(0);
425-
let coldkey = U256::from(3);
426-
let nominator1 = U256::from(1);
427-
let nominator2 = U256::from(2);
428-
429-
log::debug!("Setting up network with netuid: {}", netuid);
430-
log::debug!("Hotkey: {:?}, Coldkey: {:?}", hotkey, coldkey);
431-
log::debug!("Nominators: {:?}, {:?}", nominator1, nominator2);
432-
433-
// 2. Create network and register neuron
434-
add_network(netuid, 1, 0);
435-
register_ok_neuron(netuid, hotkey, coldkey, 100000);
436-
SubtensorModule::create_account_if_non_existent(&coldkey, &hotkey);
437-
438-
log::debug!("Network created and neuron registered");
439-
440-
// 3. Set up balances and stakes
441-
SubtensorModule::add_balance_to_coldkey_account(&coldkey, 1000);
442-
SubtensorModule::add_balance_to_coldkey_account(&nominator1, 1500);
443-
SubtensorModule::add_balance_to_coldkey_account(&nominator2, 1500);
444-
445-
log::debug!("Balances added to accounts");
446-
447-
// 4. Make the hotkey a delegate
448-
let vali_take = (u16::MAX as u64 / 10);
449-
assert_ok!(SubtensorModule::do_become_delegate(
450-
RuntimeOrigin::signed(coldkey),
451-
hotkey,
452-
vali_take as u16
453-
));
454-
455-
log::debug!("Hotkey became a delegate with minimum take");
456-
457-
// Add stakes for nominators
458-
// Add the stake directly to their coldkey-hotkey account
459-
// This bypasses the accounting in stake delta
460-
SubtensorModule::increase_stake_on_coldkey_hotkey_account(&nominator1, &hotkey, 5e9 as u64);
461-
SubtensorModule::increase_stake_on_coldkey_hotkey_account(&nominator2, &hotkey, 5e9 as u64);
462-
let initial_stake = 5e9 as u64;
463-
464-
// Make add_stake call for nominator1
465-
// This should not affect the emission distribution
466-
467-
// Will be greater than the bock emission
468-
LastAddStakeIncrease::<Test>::insert(hotkey, nominator1, 100);
469-
470-
// Log the stakes for hotkey, nominator1, and nominator2
471-
log::debug!(
472-
"Initial stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}",
473-
SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey),
474-
SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey),
475-
SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey)
476-
);
477-
log::debug!("Stakes added for nominators");
478-
479-
// 5. Set emission and verify initial states
480-
let to_emit = 20_000e9 as u64;
481-
SubtensorModule::set_emission_values(&[netuid], vec![to_emit]).unwrap();
482-
assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), to_emit);
483-
assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0);
484-
assert_eq!(
485-
SubtensorModule::get_total_stake_for_hotkey(&hotkey),
486-
initial_stake * 2
487-
);
488-
assert_eq!(SubtensorModule::get_pending_emission(netuid), 0);
489-
490-
log::debug!("Emission set and initial states verified");
491-
492-
// 6. Set hotkey emission tempo
493-
SubtensorModule::set_hotkey_emission_tempo(1);
494-
log::debug!("Hotkey emission tempo set to 1");
495-
496-
// 7. Simulate blocks and check emissions
497-
next_block();
498-
assert_eq!(SubtensorModule::get_pending_emission(netuid), to_emit);
499-
log::debug!(
500-
"After first block, pending emission: {}",
501-
SubtensorModule::get_pending_emission(netuid)
502-
);
503-
504-
next_block();
505-
assert_eq!(SubtensorModule::get_pending_emission(netuid), 0);
506-
assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0);
507-
log::debug!("After second block, pending emission drained");
508-
509-
// 8. Check final stakes
510-
let hotkey_stake = SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey);
511-
let nominator1_stake =
512-
SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey);
513-
let nominator2_stake =
514-
SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey);
515-
516-
log::debug!(
517-
"Final stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}",
518-
hotkey_stake,
519-
nominator1_stake,
520-
nominator2_stake
521-
);
522-
523-
// 9. Verify distribution
524-
let total_emission = to_emit * 2; // to_emit per block for 2 blocks
525-
let hotkey_emission = (I64F64::from_num(total_emission) / I64F64::from_num(u16::MAX)
526-
* I64F64::from_num(vali_take))
527-
.to_num::<u64>();
528-
let remaining_emission = total_emission - hotkey_emission;
529-
let nominator_emission = remaining_emission / 2;
530-
531-
log::debug!(
532-
"Calculated emissions - Hotkey: {}, Each Nominator: {}",
533-
hotkey_emission,
534-
nominator_emission
535-
);
536-
537-
// Debug: Print the actual stakes
538-
log::debug!("Actual hotkey stake: {}", hotkey_stake);
539-
log::debug!("Actual nominator1 stake: {}", nominator1_stake);
540-
log::debug!("Actual nominator2 stake: {}", nominator2_stake);
541-
542-
// Debug: Check the total stake for the hotkey
543-
let total_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey);
544-
log::debug!("Total stake for hotkey: {}", total_stake);
545-
546-
// Assertions
547-
let expected_hotkey_stake = 4_000e9 as u64;
548-
let eps = 0.5e9 as u64;
549-
assert!(
550-
hotkey_stake >= expected_hotkey_stake - eps
551-
&& hotkey_stake <= expected_hotkey_stake + eps,
552-
"Hotkey stake mismatch - expected: {}, actual: {}",
553-
expected_hotkey_stake,
554-
hotkey_stake
555-
);
556-
assert_eq!(
557-
nominator1_stake,
558-
initial_stake + nominator_emission,
559-
"Nominator1 stake mismatch"
560-
);
561-
assert_eq!(
562-
nominator2_stake,
563-
initial_stake + nominator_emission,
564-
"Nominator2 stake mismatch"
565-
);
566-
567-
// 10. Check total stake
568-
assert_eq!(
569-
total_stake,
570-
initial_stake + initial_stake + total_emission,
571-
"Total stake mismatch"
572-
);
573-
574-
log::debug!("Test completed");
575-
});
576-
}
577-
578418
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --test coinbase test_coinbase_nominator_drainage_no_deltas -- --nocapture
579419
#[test]
580420
fn test_coinbase_nominator_drainage_no_deltas() {

0 commit comments

Comments
 (0)