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:
parent
1110fc93d7
commit
3cf48347a9
|
@ -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}");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue