Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
chore: tidy up w/ some use::anyhow
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuef committed Dec 28, 2020
1 parent a1392db commit 44fdf8b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
11 changes: 6 additions & 5 deletions src/messaging/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ impl Account {
mod tests {
use super::{Account, MAX_LOGIN_PACKET_BYTES};
use crate::{Error, Keypair};
use anyhow::{anyhow, Result};

#[test]
fn exceed_size_limit() -> anyhow::Result<()> {
fn exceed_size_limit() -> Result<()> {
let our_id = Keypair::new_ed25519(&mut rand::thread_rng());

let acc_data = vec![0; MAX_LOGIN_PACKET_BYTES + 1];
Expand All @@ -196,13 +197,13 @@ mod tests {

match res {
Err(Error::ExceededSize) => Ok(()),
Ok(_) => Err(anyhow::anyhow!("Unexpected success".to_string())),
Err(e) => Err(anyhow::anyhow!("Unexpected error: {:?}", e)),
Ok(_) => Err(anyhow!("Unexpected success".to_string())),
Err(e) => Err(anyhow!("Unexpected error: {:?}", e)),
}
}

#[test]
fn valid() -> anyhow::Result<()> {
fn valid() -> Result<()> {
let our_id = Keypair::new_ed25519(&mut rand::thread_rng());

let acc_data = vec![1; 16];
Expand All @@ -220,7 +221,7 @@ mod tests {
assert_eq!(ad.data(), acc_data.as_slice());
Ok(())
}
Err(e) => Err(anyhow::anyhow!("Unexpected error: {:?}", e)),
Err(e) => Err(anyhow!("Unexpected error: {:?}", e)),
}
}
}
6 changes: 3 additions & 3 deletions src/messaging/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ mod tests {
.contains("QueryResponse::GetSequence(AccessDenied(PublicKey::"));
Ok(())
} else {
Err(anyhow::anyhow!("Could not generate public key"))
Err(anyhow!("Could not generate public key"))
}
}

Expand All @@ -658,7 +658,7 @@ mod tests {
i_data,
GetBlob(Ok(i_data.clone()))
.try_into()
.map_err(|_| anyhow::anyhow!("Mismatched types".to_string()))?
.map_err(|_| anyhow!("Mismatched types".to_string()))?
);
assert_eq!(
Err(TryFromError::Response(e.clone())),
Expand All @@ -679,7 +679,7 @@ mod tests {
m_data,
GetMap(Ok(m_data.clone()))
.try_into()
.map_err(|_| anyhow::anyhow!("Mismatched types".to_string()))?
.map_err(|_| anyhow!("Mismatched types".to_string()))?
);
assert_eq!(
Err(TryFromError::Response(e.clone())),
Expand Down
12 changes: 5 additions & 7 deletions src/sequence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ mod tests {
SequencePublicPolicy, SequenceUser,
};

use anyhow::anyhow;
use proptest::prelude::*;
use rand::rngs::OsRng;
use rand::seq::SliceRandom;
Expand Down Expand Up @@ -1789,23 +1790,20 @@ mod tests {
fn check_not_causally_ready_failure(result: Result<()>) -> anyhow::Result<()> {
match result {
Err(Error::OpNotCausallyReady) => Ok(()),
Err(err) => Err(anyhow::anyhow!(
"Error returned was the unexpected one: {}",
err
)),
Ok(()) => Err(anyhow::anyhow!("Data op applied unexpectedly".to_string(),)),
Err(err) => Err(anyhow!("Error returned was the unexpected one: {}", err)),
Ok(()) => Err(anyhow!("Data op applied unexpectedly".to_string(),)),
}
}

// check it fails due to not having permissions
fn check_op_not_allowed_failure<T>(result: Result<T>) -> anyhow::Result<()> {
match result {
Err(Error::AccessDenied(_)) => Ok(()),
Err(err) => Err(anyhow::anyhow!(
Err(err) => Err(anyhow!(
"Error returned was the unexpected one for a non-allowed op: {}",
err
)),
Ok(_) => Err(anyhow::anyhow!(
Ok(_) => Err(anyhow!(
"Data operation succeded unexpectedly, an AccessDenied error was expected"
.to_string(),
)),
Expand Down

0 comments on commit 44fdf8b

Please sign in to comment.