Cli: improve vote-account vote-authority display (#95)

* Simplify vote-authority display

* Add handling for new vote authority

* Add proper None handling, because unit test (shouldn't happen IRL, though)

* Unwrap->expect
This commit is contained in:
Tyera 2024-03-06 00:23:32 -07:00 committed by GHA: Update Upstream From Fork
parent f3c6c08752
commit e6a71366fa
1 changed files with 19 additions and 3 deletions

View File

@ -1648,7 +1648,23 @@ impl VerboseDisplay for CliAuthorizedVoters {}
impl fmt::Display for CliAuthorizedVoters {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self.authorized_voters)
if let Some((_epoch, current_authorized_voter)) = self.authorized_voters.first_key_value() {
write!(f, "{current_authorized_voter}")?;
} else {
write!(f, "None")?;
}
if self.authorized_voters.len() > 1 {
let (epoch, upcoming_authorized_voter) = self
.authorized_voters
.last_key_value()
.expect("CliAuthorizedVoters::authorized_voters.len() > 1");
writeln!(f)?;
write!(
f,
" New Vote Authority as of Epoch {epoch}: {upcoming_authorized_voter}"
)?;
}
Ok(())
}
}
@ -3379,12 +3395,12 @@ mod tests {
..CliVoteAccount::default()
};
let s = format!("{c}");
assert_eq!(s, "Account Balance: 0.00001 SOL\nValidator Identity: 11111111111111111111111111111111\nVote Authority: {}\nWithdraw Authority: \nCredits: 0\nCommission: 0%\nRoot Slot: ~\nRecent Timestamp: 1970-01-01T00:00:00Z from slot 0\nEpoch Rewards:\n Epoch Reward Slot Time Amount New Balance Percent Change APR Commission\n 1 100 1970-01-01 00:00:00 UTC ◎0.000000010 ◎0.000000100 11.000% 10.00% 1%\n 2 200 1970-01-12 13:46:40 UTC ◎0.000000012 ◎0.000000100 11.000% 13.00% 1%\n");
assert_eq!(s, "Account Balance: 0.00001 SOL\nValidator Identity: 11111111111111111111111111111111\nVote Authority: None\nWithdraw Authority: \nCredits: 0\nCommission: 0%\nRoot Slot: ~\nRecent Timestamp: 1970-01-01T00:00:00Z from slot 0\nEpoch Rewards:\n Epoch Reward Slot Time Amount New Balance Percent Change APR Commission\n 1 100 1970-01-01 00:00:00 UTC ◎0.000000010 ◎0.000000100 11.000% 10.00% 1%\n 2 200 1970-01-12 13:46:40 UTC ◎0.000000012 ◎0.000000100 11.000% 13.00% 1%\n");
println!("{s}");
c.use_csv = true;
let s = format!("{c}");
assert_eq!(s, "Account Balance: 0.00001 SOL\nValidator Identity: 11111111111111111111111111111111\nVote Authority: {}\nWithdraw Authority: \nCredits: 0\nCommission: 0%\nRoot Slot: ~\nRecent Timestamp: 1970-01-01T00:00:00Z from slot 0\nEpoch Rewards:\nEpoch,Reward Slot,Time,Amount,New Balance,Percent Change,APR,Commission\n1,100,1970-01-01 00:00:00 UTC,0.00000001,0.0000001,11%,10.00%,1%\n2,200,1970-01-12 13:46:40 UTC,0.000000012,0.0000001,11%,13.00%,1%\n");
assert_eq!(s, "Account Balance: 0.00001 SOL\nValidator Identity: 11111111111111111111111111111111\nVote Authority: None\nWithdraw Authority: \nCredits: 0\nCommission: 0%\nRoot Slot: ~\nRecent Timestamp: 1970-01-01T00:00:00Z from slot 0\nEpoch Rewards:\nEpoch,Reward Slot,Time,Amount,New Balance,Percent Change,APR,Commission\n1,100,1970-01-01 00:00:00 UTC,0.00000001,0.0000001,11%,10.00%,1%\n2,200,1970-01-12 13:46:40 UTC,0.000000012,0.0000001,11%,13.00%,1%\n");
println!("{s}");
}
}