From 51cbfe127abb4a03f931b02ed31f64e86d6998c6 Mon Sep 17 00:00:00 2001 From: jasonz-dfinity <133917836+jasonz-dfinity@users.noreply.github.com> Date: Thu, 1 Aug 2024 23:21:36 +0200 Subject: [PATCH] feat(nns): Enable new topics to be followed (#710) # Why New topics are created ([context](https://forum.dfinity.org/t/refine-nns-proposals-topics/32125)). They previously cannot be followed on as NNS Dapp cannot display the topics yet, but now NNS Dapp can. # What Remove the restriction on the mainnet for following to be set on the new topics. --- rs/nns/governance/src/governance.rs | 10 -- rs/nns/governance/src/governance/tests/mod.rs | 105 ------------------ 2 files changed, 115 deletions(-) diff --git a/rs/nns/governance/src/governance.rs b/rs/nns/governance/src/governance.rs index a2f493febc3..bde89b0541e 100644 --- a/rs/nns/governance/src/governance.rs +++ b/rs/nns/governance/src/governance.rs @@ -5833,16 +5833,6 @@ impl Governance { ) })?; - #[cfg(not(feature = "test"))] - if topic == Topic::ProtocolCanisterManagement - || topic == Topic::ServiceNervousSystemManagement - { - return Err(GovernanceError::new_with_message( - ErrorType::InvalidCommand, - format!("Cannot follow the {:?} topic yet", topic), - )); - } - self.with_neuron_mut(id, |neuron| { if follow_request.followees.is_empty() { neuron.followees.remove(&(topic as i32)) diff --git a/rs/nns/governance/src/governance/tests/mod.rs b/rs/nns/governance/src/governance/tests/mod.rs index 853f14b0554..45febf0da14 100644 --- a/rs/nns/governance/src/governance/tests/mod.rs +++ b/rs/nns/governance/src/governance/tests/mod.rs @@ -1540,111 +1540,6 @@ fn test_validate_execute_nns_function() { } } -// TODO(NNS1-3204): Remove this test when the new topics are enabled. -#[test] -fn test_follow_new_topics() { - // Step 1: set up a neuron with no followees. - let mut governance = Governance::new( - GovernanceProto { - economics: Some(NetworkEconomics::with_default_values()), - ..Default::default() - }, - Box::new(MockEnvironment::new(vec![], 100)), - Box::new(StubIcpLedger {}), - Box::new(StubCMC {}), - ); - let neuron_id = NeuronId { id: 1 }; - let controller = PrincipalId::new_user_test_id(1); - governance - .neuron_store - .add_neuron( - NeuronBuilder::new( - neuron_id, - Subaccount::try_from(vec![0u8; 32].as_slice()).unwrap(), - controller, - DissolveStateAndAge::NotDissolving { - dissolve_delay_seconds: 42, - aging_since_timestamp_seconds: 1, - }, - 123_456_789, - ) - .build(), - ) - .unwrap(); - - // Step 2: sanity check to make sure `follow()` works. - governance - .follow( - &neuron_id, - &controller, - &manage_neuron::Follow { - topic: Topic::Unspecified as i32, - followees: [NeuronId { id: 2 }].to_vec(), - }, - ) - .unwrap(); - - // Step 3: following a new topic works with feature = "test". - #[cfg(feature = "test")] - { - assert_eq!( - governance.follow( - &neuron_id, - &controller, - &manage_neuron::Follow { - topic: Topic::ProtocolCanisterManagement as i32, - followees: [NeuronId { id: 2 }].to_vec(), - }, - ), - Ok(()) - ); - assert_eq!( - governance.follow( - &neuron_id, - &controller, - &manage_neuron::Follow { - topic: Topic::ServiceNervousSystemManagement as i32, - followees: [NeuronId { id: 2 }].to_vec(), - }, - ), - Ok(()) - ); - } - - // Step 4: following a new topic fails without feature = "test". - #[cfg(not(feature = "test"))] - { - assert_eq!( - governance.follow( - &neuron_id, - &controller, - &manage_neuron::Follow { - topic: Topic::ProtocolCanisterManagement as i32, - followees: [NeuronId { id: 2 }].to_vec(), - }, - ), - Err(GovernanceError::new_with_message( - ErrorType::InvalidCommand, - "Cannot follow the ProtocolCanisterManagement topic yet".to_string() - )) - ); - assert_eq!( - governance.follow( - &neuron_id, - &controller, - &manage_neuron::Follow { - topic: Topic::ServiceNervousSystemManagement as i32, - followees: [NeuronId { id: 2 }].to_vec(), - }, - ), - Err(GovernanceError::new_with_message( - ErrorType::InvalidCommand, - "Cannot follow the ServiceNervousSystemManagement topic yet".to_string() - )) - ); - } -} - #[test] fn topic_min_max_test() { use strum::IntoEnumIterator;