Skip to content

Commit

Permalink
test(nns): Add recent_ballots_next_entry_index to NeuronBuilder and l…
Browse files Browse the repository at this point in the history
…et it be So… (#3073)

Going forward, `recent_ballots_next_entry_index` should always be
`Some(..)` except for neurons not migrated yet. Therefore tests, except
for those specifically designed for testing the migration, should use
`Some(..)`.
  • Loading branch information
jasonz-dfinity authored Dec 9, 2024
1 parent c7ce230 commit 00eb69d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion rs/nns/governance/src/neuron/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,8 @@ pub struct NeuronBuilder {
#[cfg(test)]
recent_ballots: Vec<BallotInfo>,
#[cfg(test)]
recent_ballots_next_entry_index: Option<usize>,
#[cfg(test)]
transfer: Option<NeuronStakeTransfer>,
#[cfg(test)]
staked_maturity_e8s_equivalent: Option<u64>,
Expand Down Expand Up @@ -1640,6 +1642,8 @@ impl NeuronBuilder {
#[cfg(test)]
recent_ballots: Vec::new(),
#[cfg(test)]
recent_ballots_next_entry_index: Some(0),
#[cfg(test)]
transfer: None,
#[cfg(test)]
staked_maturity_e8s_equivalent: None,
Expand Down Expand Up @@ -1730,7 +1734,10 @@ impl NeuronBuilder {

#[cfg(test)]
pub fn with_recent_ballots(mut self, recent_ballots: Vec<BallotInfo>) -> Self {
let recent_ballots_next_entry_index =
Some(recent_ballots.len() % MAX_NEURON_RECENT_BALLOTS);
self.recent_ballots = recent_ballots;
self.recent_ballots_next_entry_index = recent_ballots_next_entry_index;
self
}

Expand Down Expand Up @@ -1783,6 +1790,8 @@ impl NeuronBuilder {
#[cfg(test)]
recent_ballots,
#[cfg(test)]
recent_ballots_next_entry_index,
#[cfg(test)]
transfer,
#[cfg(test)]
staked_maturity_e8s_equivalent,
Expand All @@ -1804,6 +1813,8 @@ impl NeuronBuilder {
#[cfg(not(test))]
let recent_ballots = Vec::new();
#[cfg(not(test))]
let recent_ballots_next_entry_index = Some(0);
#[cfg(not(test))]
let transfer = None;
#[cfg(not(test))]
let staked_maturity_e8s_equivalent = None;
Expand All @@ -1822,6 +1833,7 @@ impl NeuronBuilder {
spawn_at_timestamp_seconds,
followees,
recent_ballots,
recent_ballots_next_entry_index,
kyc_verified,
transfer,
maturity_e8s_equivalent,
Expand All @@ -1833,7 +1845,6 @@ impl NeuronBuilder {
neuron_type,
visibility,
voting_power_refreshed_timestamp_seconds,
recent_ballots_next_entry_index: None,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions rs/nns/governance/tests/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4546,6 +4546,7 @@ fn create_mature_neuron(dissolved: bool) -> (fake::FakeDriver, Governance, Neuro
voting_power_refreshed_timestamp_seconds: Some(START_TIMESTAMP_SECONDS),
deciding_voting_power: Some(expected_voting_power),
potential_voting_power: Some(expected_voting_power),
recent_ballots_next_entry_index: Some(0),
..Default::default()
}
);
Expand Down

0 comments on commit 00eb69d

Please sign in to comment.