Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2232,11 +2232,7 @@ pub mod pallet {
netuid: NetUid,
enabled: bool,
) -> DispatchResult {
let maybe_owner = pallet_subtensor::Pallet::<T>::ensure_sn_owner_or_root_with_limits(
origin,
netuid,
&[Hyperparameter::SubnetEmissionEnabled.into()],
)?;
ensure_root(origin)?;
pallet_subtensor::Pallet::<T>::ensure_admin_window_open(netuid)?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MEDIUM] Add a regression test for the new root-only origin

This line is the entire behavior change, but the PR only cites a storage-level coinbase test that would still pass if this dispatch remained subnet-owner-or-root. Add an admin-utils dispatch test that sets SubnetOwner, verifies a signed subnet owner now receives DispatchError::BadOrigin and leaves SubnetEmissionEnabled unchanged, then verifies RuntimeOrigin::root() can still toggle the flag.

A focused test in pallets/admin-utils/src/tests/mod.rs should cover the changed authorization boundary directly.


ensure!(
Expand All @@ -2249,12 +2245,6 @@ pub mod pallet {
Self::deposit_event(Event::SubnetEmissionEnabledSet { netuid, enabled });
log::debug!("SubnetEmissionEnabledSet( netuid: {netuid:?}, enabled: {enabled:?} )");

pallet_subtensor::Pallet::<T>::record_owner_rl(
maybe_owner,
netuid,
&[Hyperparameter::SubnetEmissionEnabled.into()],
);

Ok(())
}
}
Expand Down
42 changes: 42 additions & 0 deletions pallets/admin-utils/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3104,3 +3104,45 @@ fn test_sudo_set_start_call_delay_permissions_and_zero_delay() {
);
});
}

#[test]
fn test_sudo_set_subnet_emission_enabled_root_only() {
new_test_ext().execute_with(|| {
let netuid = NetUid::from(1);
let sn_owner = U256::from(42);

add_network(netuid, 10);
SubnetOwner::<Test>::insert(netuid, sn_owner);

// Disable the admin freeze window so neither path is blocked by it.
SubtensorModule::set_admin_freeze_window(0);

let initial = pallet_subtensor::SubnetEmissionEnabled::<Test>::get(netuid);

// Signed subnet owner must be rejected with BadOrigin and storage unchanged.
assert_eq!(
AdminUtils::sudo_set_subnet_emission_enabled(
<<Test as Config>::RuntimeOrigin>::signed(sn_owner),
netuid,
!initial,
),
Err(DispatchError::BadOrigin)
);
assert_eq!(
pallet_subtensor::SubnetEmissionEnabled::<Test>::get(netuid),
initial,
"signed owner origin must not mutate SubnetEmissionEnabled"
);

// Root can still toggle the flag.
assert_ok!(AdminUtils::sudo_set_subnet_emission_enabled(
<<Test as Config>::RuntimeOrigin>::root(),
netuid,
!initial,
));
assert_eq!(
pallet_subtensor::SubnetEmissionEnabled::<Test>::get(netuid),
!initial
);
});
}
Loading