|
1 | 1 | #![allow(clippy::expect_used)] |
2 | 2 |
|
3 | | -use crate::RootAlphaDividendsPerSubnet; |
4 | 3 | 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, |
6 | 6 | }; |
7 | 7 | use crate::{ |
8 | 8 | DefaultMinRootClaimAmount, Error, MAX_NUM_ROOT_CLAIMS, MAX_ROOT_CLAIM_THRESHOLD, NetworksAdded, |
9 | 9 | NumRootClaim, NumStakingColdkeys, PendingRootAlphaDivs, RootClaimable, RootClaimableThreshold, |
10 | 10 | StakingColdkeys, StakingColdkeysByIndex, SubnetAlphaIn, SubnetMechanism, SubnetMovingPrice, |
11 | 11 | SubnetTAO, SubnetTaoFlow, SubtokenEnabled, Tempo, pallet, |
12 | 12 | }; |
| 13 | +use crate::{Event, RootAlphaDividendsPerSubnet}; |
13 | 14 | use crate::{RootClaimType, RootClaimTypeEnum, RootClaimed, ValidatorClaimType}; |
14 | 15 | use approx::assert_abs_diff_eq; |
15 | 16 | use frame_support::dispatch::RawOrigin; |
@@ -1566,6 +1567,55 @@ fn test_claim_root_with_unrelated_subnets() { |
1566 | 1567 | }); |
1567 | 1568 | } |
1568 | 1569 |
|
| 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 | + |
1569 | 1619 | #[test] |
1570 | 1620 | fn test_claim_root_with_delegated_claim_type() { |
1571 | 1621 | new_test_ext(1).execute_with(|| { |
|
0 commit comments