From bbc694511ab1e0292b4d82a3d81c3668f3b60774 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 8 Jan 2025 22:16:33 +0100 Subject: [PATCH] Fix set_alpha_disabled test --- pallets/subtensor/src/tests/epoch.rs | 60 ++++++++++++++-------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 7ab728c11..b12b2fd07 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -7,7 +7,7 @@ use super::mock::*; use crate::epoch::math::safe_exp; use crate::*; -use frame_support::assert_ok; +use frame_support::{assert_ok, assert_err}; // use frame_system::Config; use rand::{distributions::Uniform, rngs::StdRng, seq::SliceRandom, thread_rng, Rng, SeedableRng}; use sp_core::U256; @@ -1486,40 +1486,38 @@ fn test_bonds_with_liquid_alpha() { }); } -// +// #[test] fn test_set_alpha_disabled() { new_test_ext(1).execute_with(|| { - assert!(false); - - // let netuid: u16 = 1; - // let hotkey: U256 = U256::from(1); - // let coldkey: U256 = U256::from(1 + 456); - // let signer = <::RuntimeOrigin>::signed(coldkey); - - // // Enable Liquid Alpha and setup - // SubtensorModule::set_liquid_alpha_enabled(netuid, true); - // migrations::migrate_create_root_network::migrate_create_root_network::(); - // SubtensorModule::add_balance_to_coldkey_account(&coldkey, 1_000_000_000_000_000); - // assert_ok!(SubtensorModule::root_register(signer.clone(), hotkey,)); - // assert_ok!(SubtensorModule::add_stake(signer.clone(), hotkey, 1000)); - // // Only owner can set alpha values - // assert_ok!(SubtensorModule::register_network(signer.clone())); - - // // Explicitly set to false - // SubtensorModule::set_liquid_alpha_enabled(netuid, false); - // assert_err!( - // SubtensorModule::do_set_alpha_values(signer.clone(), netuid, 12_u16, u16::MAX), - // Error::::LiquidAlphaDisabled - // ); + let hotkey = U256::from(1); + let coldkey = U256::from(1 + 456); + let netuid = add_dynamic_network(&hotkey, &coldkey); + let signer = RuntimeOrigin::signed(coldkey); + + // Enable Liquid Alpha and setup + SubtensorModule::set_liquid_alpha_enabled(netuid, true); + migrations::migrate_create_root_network::migrate_create_root_network::(); + SubtensorModule::add_balance_to_coldkey_account(&coldkey, 1_000_000_000_000_000); + assert_ok!(SubtensorModule::root_register(signer.clone(), hotkey,)); + assert_ok!(SubtensorModule::add_stake(signer.clone(), hotkey, netuid, 1000)); + // Only owner can set alpha values + assert_ok!(SubtensorModule::register_network(signer.clone(), hotkey)); + + // Explicitly set to false + SubtensorModule::set_liquid_alpha_enabled(netuid, false); + assert_err!( + SubtensorModule::do_set_alpha_values(signer.clone(), netuid, 12_u16, u16::MAX), + Error::::LiquidAlphaDisabled + ); - // SubtensorModule::set_liquid_alpha_enabled(netuid, true); - // assert_ok!(SubtensorModule::do_set_alpha_values( - // signer.clone(), - // netuid, - // 12_u16, - // u16::MAX - // )); + SubtensorModule::set_liquid_alpha_enabled(netuid, true); + assert_ok!(SubtensorModule::do_set_alpha_values( + signer.clone(), + netuid, + 12_u16, + u16::MAX + )); }); }