Skip to content

Commit

Permalink
feat(nns): Enable new topics to be followed (#710)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
jasonz-dfinity authored Aug 1, 2024
1 parent d8a956a commit 51cbfe1
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 115 deletions.
10 changes: 0 additions & 10 deletions rs/nns/governance/src/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
105 changes: 0 additions & 105 deletions rs/nns/governance/src/governance/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 51cbfe1

Please sign in to comment.