Skip to content

Commit e55109d

Browse files
Modify ValidatorClaimTypeSet event
1 parent c7c6747 commit e55109d

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

pallets/subtensor/src/macros/dispatches.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,6 +2461,7 @@ mod dispatches {
24612461
Self::deposit_event(Event::ValidatorClaimTypeSet {
24622462
hotkey: hotkey.clone(),
24632463
root_claim_type: new_claim_type,
2464+
netuid,
24642465
});
24652466
Ok(())
24662467
}

pallets/subtensor/src/macros/events.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,8 @@ mod events {
476476
hotkey: T::AccountId,
477477
/// root claim type enum
478478
root_claim_type: RootClaimTypeEnum,
479+
/// subnet UID
480+
netuid: NetUid,
479481
},
480482

481483
/// Subnet lease dividends have been distributed.

pallets/subtensor/src/tests/claim_root.rs

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
#![allow(clippy::expect_used)]
22

3-
use crate::RootAlphaDividendsPerSubnet;
43
use crate::tests::mock::{
5-
RuntimeOrigin, SubtensorModule, Test, add_dynamic_network, new_test_ext, run_to_block,
4+
RuntimeEvent, RuntimeOrigin, SubtensorModule, System, Test, add_dynamic_network, new_test_ext,
5+
run_to_block,
66
};
77
use crate::{
88
DefaultMinRootClaimAmount, Error, MAX_NUM_ROOT_CLAIMS, MAX_ROOT_CLAIM_THRESHOLD, NetworksAdded,
99
NumRootClaim, NumStakingColdkeys, PendingRootAlphaDivs, RootClaimable, RootClaimableThreshold,
1010
StakingColdkeys, StakingColdkeysByIndex, SubnetAlphaIn, SubnetMechanism, SubnetMovingPrice,
1111
SubnetTAO, SubnetTaoFlow, SubtokenEnabled, Tempo, pallet,
1212
};
13+
use crate::{Event, RootAlphaDividendsPerSubnet};
1314
use crate::{RootClaimType, RootClaimTypeEnum, RootClaimed, ValidatorClaimType};
1415
use approx::assert_abs_diff_eq;
1516
use frame_support::dispatch::RawOrigin;
@@ -1566,6 +1567,55 @@ fn test_claim_root_with_unrelated_subnets() {
15661567
});
15671568
}
15681569

1570+
#[test]
1571+
fn test_claim_root_with_set_validator_claim_type() {
1572+
new_test_ext(1).execute_with(|| {
1573+
let coldkey = U256::from(1001);
1574+
let hotkey = U256::from(1002);
1575+
let netuid = add_dynamic_network(&hotkey, &coldkey);
1576+
let new_claim_type = RootClaimTypeEnum::Swap;
1577+
1578+
// Default check
1579+
assert_eq!(
1580+
ValidatorClaimType::<Test>::get(hotkey, netuid),
1581+
RootClaimTypeEnum::Keep
1582+
);
1583+
1584+
// Set new type
1585+
assert_ok!(SubtensorModule::set_validator_claim_type(
1586+
RuntimeOrigin::signed(coldkey),
1587+
hotkey,
1588+
netuid,
1589+
new_claim_type.clone()
1590+
),);
1591+
1592+
// Result check
1593+
assert_eq!(
1594+
ValidatorClaimType::<Test>::get(hotkey, netuid),
1595+
new_claim_type
1596+
);
1597+
1598+
let event = System::events().into_iter().find(|e| {
1599+
matches!(
1600+
&e.event,
1601+
RuntimeEvent::SubtensorModule(Event::ValidatorClaimTypeSet { .. })
1602+
)
1603+
});
1604+
assert!(event.is_some());
1605+
1606+
if let Some(RuntimeEvent::SubtensorModule(Event::ValidatorClaimTypeSet {
1607+
hotkey: ev_hotkey,
1608+
root_claim_type: ev_claim_type,
1609+
netuid: ev_netuid,
1610+
})) = event.map(|e| e.event.clone())
1611+
{
1612+
assert_eq!(ev_hotkey, hotkey);
1613+
assert_eq!(ev_claim_type, new_claim_type);
1614+
assert_eq!(ev_netuid, netuid);
1615+
}
1616+
});
1617+
}
1618+
15691619
#[test]
15701620
fn test_claim_root_with_delegated_claim_type() {
15711621
new_test_ext(1).execute_with(|| {

0 commit comments

Comments
 (0)