|
1 | 1 | #![allow(unused, clippy::indexing_slicing, clippy::panic, clippy::unwrap_used)]
|
2 | 2 | use crate::mock::*;
|
3 | 3 | mod mock;
|
4 |
| -use frame_support::assert_ok; |
| 4 | +use frame_support::{assert_err, assert_ok}; |
5 | 5 | use sp_core::U256;
|
6 | 6 | use substrate_fixed::types::I64F64;
|
7 | 7 |
|
@@ -1448,3 +1448,58 @@ fn test_coinbase_nominator_drainage_with_net_negative_delta() {
|
1448 | 1448 | log::debug!("Test completed");
|
1449 | 1449 | });
|
1450 | 1450 | }
|
| 1451 | + |
| 1452 | +/// Tests that emission rewards are not distributed when subnet registration is disabled |
| 1453 | +/// This test verifies that: |
| 1454 | +/// 1. A subnet with registration disabled does not distribute emissions |
| 1455 | +/// 2. Pending emissions remain at 0 even after multiple blocks |
| 1456 | +/// 3. Total stake remains unchanged when registration is disabled |
| 1457 | +// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --test coinbase test_emission_with_registration_disabled_subnet -- --nocapture |
| 1458 | + |
| 1459 | +#[test] |
| 1460 | +fn test_emission_with_registration_disabled_subnet() { |
| 1461 | + new_test_ext(1).execute_with(|| { |
| 1462 | + // Initialize test network and accounts |
| 1463 | + let netuid: u16 = 1; |
| 1464 | + let hotkey = U256::from(0); // Validator hotkey |
| 1465 | + let coldkey = U256::from(1); // Validator coldkey |
| 1466 | + |
| 1467 | + // Create network and disable registration |
| 1468 | + add_network(netuid, 1, 0); // Creates subnet with netuid=1, tempo=1, modality=0 |
| 1469 | + SubtensorModule::set_network_registration_allowed(netuid, false); // Disable registration |
| 1470 | + |
| 1471 | + // Set up validator accounts and stake |
| 1472 | + // This simulates an existing validator before registration was disabled |
| 1473 | + SubtensorModule::create_account_if_non_existent(&coldkey, &hotkey); |
| 1474 | + SubtensorModule::increase_stake_on_coldkey_hotkey_account(&coldkey, &hotkey, 1000); |
| 1475 | + |
| 1476 | + // Configure emission rate for the subnet |
| 1477 | + SubtensorModule::set_emission_values(&[netuid], vec![10]).unwrap(); |
| 1478 | + assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), 10); |
| 1479 | + |
| 1480 | + // Verify initial emission state is zero |
| 1481 | + assert_eq!(SubtensorModule::get_pending_emission(netuid), 0); |
| 1482 | + assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); |
| 1483 | + |
| 1484 | + // Advance chain by 100 blocks |
| 1485 | + step_block(100); |
| 1486 | + |
| 1487 | + // Verify no emissions were distributed after 100 blocks |
| 1488 | + assert_eq!( |
| 1489 | + SubtensorModule::get_pending_hotkey_emission(&hotkey), |
| 1490 | + 0, |
| 1491 | + "Hotkey pending emission should remain zero" |
| 1492 | + ); |
| 1493 | + |
| 1494 | + // Advance chain by 1000 more blocks |
| 1495 | + step_block(1000); |
| 1496 | + |
| 1497 | + // Verify total stake remains unchanged after many blocks |
| 1498 | + // This confirms no emissions were added to stake |
| 1499 | + let total_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); |
| 1500 | + assert_eq!( |
| 1501 | + total_stake, 1000, |
| 1502 | + "Total stake should not increase when registration is disabled" |
| 1503 | + ); |
| 1504 | + }); |
| 1505 | +} |
0 commit comments