Skip to content

Commit

Permalink
Fmt version 2
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Mar 26, 2021
1 parent 71f790d commit 1ddc3f3
Show file tree
Hide file tree
Showing 23 changed files with 273 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub(crate) async fn add_peer(
return Err(reject::custom(CustomRejection::BadRequest(
"Invalid peer descriptor. The multi address did not have a valid peer id as its last segment."
.to_string(),
)))
)));
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub(crate) async fn milestone_utxo_changes<B: StorageBackend>(
None => {
return Err(reject::custom(CustomRejection::NotFound(
"can not find UTXO changes for given milestone index".to_string(),
)))
)));
}
};
Ok(warp::reply::json(&SuccessBody::new(MilestoneUtxoChangesResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,7 @@ pub(crate) async fn submit_message<B: StorageBackend>(
"invalid nonce: expected an u64-string".to_string(),
))
})?;
if parsed == 0 {
None
} else {
Some(parsed)
}
if parsed == 0 { None } else { Some(parsed) }
};

let message = if let Some(nonce) = nonce {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub(crate) async fn transaction_included_message<B: StorageBackend>(
None => {
return Err(reject::custom(CustomRejection::NotFound(
"Can not find output".to_string(),
)))
)));
}
}
}
14 changes: 7 additions & 7 deletions bee-api/bee-rest-api/src/types/dtos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ impl TryFrom<&RegularEssence> for RegularEssenceDto {
payload: match value.payload() {
Some(Payload::Indexation(i)) => Some(PayloadDto::Indexation(Box::new(i.as_ref().into()))),
Some(_) => {
return Err("invalid transaction essence: expected an optional indexation-payload".to_string())
return Err("invalid transaction essence: expected an optional indexation-payload".to_string());
}
None => None,
},
Expand Down Expand Up @@ -667,13 +667,13 @@ impl TryFrom<&UnlockBlockDto> for UnlockBlock {
UnlockBlockDto::Signature(s) => match &s.signature {
SignatureDto::Ed25519(ed) => {
let mut public_key = [0u8; 32];
hex::decode_to_slice(&ed.public_key, &mut public_key).map_err(|_| {
"invalid public key in signature unlock block: expected a hex-string of length 64"
})?; // TODO access ED25519_PUBLIC_KEY_LENGTH when available
hex::decode_to_slice(&ed.public_key, &mut public_key).map_err(
|_| "invalid public key in signature unlock block: expected a hex-string of length 64",
)?; // TODO access ED25519_PUBLIC_KEY_LENGTH when available
let signature = hex::decode(&ed.signature)
.map_err(|_| {
"invalid signature in signature unlock block: expected a hex-string of length 128"
})? // TODO access ED25519_SIGNATURE_LENGTH when available
.map_err(
|_| "invalid signature in signature unlock block: expected a hex-string of length 128",
)? // TODO access ED25519_SIGNATURE_LENGTH when available
.into_boxed_slice();
Ok(UnlockBlock::Signature(SignatureUnlock::Ed25519(Ed25519Signature::new(
public_key, signature,
Expand Down
4 changes: 2 additions & 2 deletions bee-ledger/src/types/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Receipt {
None => {
return Err(Error::InvalidMigratedFundsAmount(
migrated_amount + funds.output().amount(),
))
));
}
}
}
Expand All @@ -62,7 +62,7 @@ impl Receipt {
None => {
return Err(Error::InvalidMigratedFundsAmount(
consumed_treasury_output.inner().amount() - migrated_amount,
))
));
}
};

Expand Down
20 changes: 11 additions & 9 deletions bee-message/tests/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,18 @@ fn invalid_length() {

#[test]
fn unpack_valid_no_remaining_bytes() {
assert!(Message::unpack(
&mut vec![
42, 0, 0, 0, 0, 0, 0, 0, 2, 140, 28, 186, 52, 147, 145, 96, 9, 105, 89, 78, 139, 3, 71, 249, 97, 149, 190,
63, 238, 168, 202, 82, 140, 227, 66, 173, 19, 110, 93, 117, 34, 225, 202, 251, 10, 156, 58, 144, 225, 54,
79, 62, 38, 20, 121, 95, 90, 112, 109, 6, 166, 126, 145, 13, 62, 52, 68, 248, 135, 223, 119, 137, 13, 0, 0,
0, 0, 21, 205, 91, 7, 0, 0, 0, 0,
]
.as_slice()
assert!(
Message::unpack(
&mut vec![
42, 0, 0, 0, 0, 0, 0, 0, 2, 140, 28, 186, 52, 147, 145, 96, 9, 105, 89, 78, 139, 3, 71, 249, 97, 149,
190, 63, 238, 168, 202, 82, 140, 227, 66, 173, 19, 110, 93, 117, 34, 225, 202, 251, 10, 156, 58, 144,
225, 54, 79, 62, 38, 20, 121, 95, 90, 112, 109, 6, 166, 126, 145, 13, 62, 52, 68, 248, 135, 223, 119,
137, 13, 0, 0, 0, 0, 21, 205, 91, 7, 0, 0, 0, 0,
]
.as_slice()
)
.is_ok()
)
.is_ok())
}

#[test]
Expand Down
30 changes: 19 additions & 11 deletions bee-message/tests/milestone_payload_essence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,19 @@ fn new_invalid_too_many_public_keys() {

#[test]
fn new_valid_sorted_unique_public_keys() {
assert!(MilestonePayloadEssence::new(
MilestoneIndex(0),
0,
rand_parents(),
[0; MILESTONE_MERKLE_PROOF_LENGTH],
vec![[0; 32], [1; 32], [2; 32], [3; 32], [4; 32], [5; 32], [6; 32], [7; 32], [8; 32], [9; 32]],
None,
)
.is_ok());
assert!(
MilestonePayloadEssence::new(
MilestoneIndex(0),
0,
rand_parents(),
[0; MILESTONE_MERKLE_PROOF_LENGTH],
vec![
[0; 32], [1; 32], [2; 32], [3; 32], [4; 32], [5; 32], [6; 32], [7; 32], [8; 32], [9; 32]
],
None,
)
.is_ok()
);
}

#[test]
Expand All @@ -55,7 +59,9 @@ fn new_invalid_sorted_not_unique_public_keys() {
0,
rand_parents(),
[0; MILESTONE_MERKLE_PROOF_LENGTH],
vec![[0; 32], [1; 32], [2; 32], [3; 32], [4; 32], [4; 32], [6; 32], [7; 32], [8; 32], [9; 32]],
vec![
[0; 32], [1; 32], [2; 32], [3; 32], [4; 32], [4; 32], [6; 32], [7; 32], [8; 32], [9; 32]
],
None,
),
Err(Error::MilestonePublicKeysNotUniqueSorted)
Expand All @@ -70,7 +76,9 @@ fn new_invalid_not_sorted_unique_public_keys() {
0,
rand_parents(),
[0; MILESTONE_MERKLE_PROOF_LENGTH],
vec![[0; 32], [1; 32], [3; 32], [2; 32], [4; 32], [5; 32], [6; 32], [7; 32], [8; 32], [9; 32]],
vec![
[0; 32], [1; 32], [3; 32], [2; 32], [4; 32], [5; 32], [6; 32], [7; 32], [8; 32], [9; 32]
],
None,
),
Err(Error::MilestonePublicKeysNotUniqueSorted)
Expand Down
36 changes: 19 additions & 17 deletions bee-message/tests/unlock_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,23 @@ fn new_invalid_duplicate_signature() {

#[test]
fn new_valid() {
assert!(UnlockBlocks::new(vec![
SignatureUnlock::from(Ed25519Signature::new([0; 32], Box::new([0; 64]))).into(),
ReferenceUnlock::new(0).unwrap().into(),
ReferenceUnlock::new(0).unwrap().into(),
SignatureUnlock::from(Ed25519Signature::new([1; 32], Box::new([1; 64]))).into(),
SignatureUnlock::from(Ed25519Signature::new([2; 32], Box::new([2; 64]))).into(),
SignatureUnlock::from(Ed25519Signature::new([3; 32], Box::new([3; 64]))).into(),
ReferenceUnlock::new(3).unwrap().into(),
ReferenceUnlock::new(4).unwrap().into(),
ReferenceUnlock::new(3).unwrap().into(),
ReferenceUnlock::new(4).unwrap().into(),
ReferenceUnlock::new(5).unwrap().into(),
SignatureUnlock::from(Ed25519Signature::new([4; 32], Box::new([4; 64]))).into(),
ReferenceUnlock::new(11).unwrap().into(),
SignatureUnlock::from(Ed25519Signature::new([5; 32], Box::new([5; 64]))).into(),
])
.is_ok());
assert!(
UnlockBlocks::new(vec![
SignatureUnlock::from(Ed25519Signature::new([0; 32], Box::new([0; 64]))).into(),
ReferenceUnlock::new(0).unwrap().into(),
ReferenceUnlock::new(0).unwrap().into(),
SignatureUnlock::from(Ed25519Signature::new([1; 32], Box::new([1; 64]))).into(),
SignatureUnlock::from(Ed25519Signature::new([2; 32], Box::new([2; 64]))).into(),
SignatureUnlock::from(Ed25519Signature::new([3; 32], Box::new([3; 64]))).into(),
ReferenceUnlock::new(3).unwrap().into(),
ReferenceUnlock::new(4).unwrap().into(),
ReferenceUnlock::new(3).unwrap().into(),
ReferenceUnlock::new(4).unwrap().into(),
ReferenceUnlock::new(5).unwrap().into(),
SignatureUnlock::from(Ed25519Signature::new([4; 32], Box::new([4; 64]))).into(),
ReferenceUnlock::new(11).unwrap().into(),
SignatureUnlock::from(Ed25519Signature::new([5; 32], Box::new([5; 64]))).into(),
])
.is_ok()
);
}
6 changes: 1 addition & 5 deletions bee-network/src/peer/peerlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,7 @@ impl PeerList {
self.0.read().await.iter().fold(
0,
|count, (_, (info, state))| {
if predicate(info, state) {
count + 1
} else {
count
}
if predicate(info, state) { count + 1 } else { count }
},
)
}
Expand Down
4 changes: 3 additions & 1 deletion bee-node/src/node/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use thiserror::Error;

#[derive(Error, Debug)]
pub enum Error {
#[error("Invalid or no identity private key provided. Add the newly generated {0} (or generate one with `bee p2p-identity`) to the configuration file and re-run the node.")]
#[error(
"Invalid or no identity private key provided. Add the newly generated {0} (or generate one with `bee p2p-identity`) to the configuration file and re-run the node."
)]
InvalidOrNoIdentityPrivateKey(String),
#[error("Storage backend operation failed: {0}.")]
StorageBackend(Box<dyn std::error::Error>),
Expand Down
7 changes: 3 additions & 4 deletions bee-snapshot/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,13 @@ async fn import_snapshot<B: StorageBackend>(
info!(
"Imported {} snapshot file from {} with sep index {}, ledger index {}, {} solid entry points{} and {} milestone diffs.",
kind_str,
Utc.timestamp(header.timestamp() as i64, 0)
.format("%d-%m-%Y %H:%M:%S"),
Utc.timestamp(header.timestamp() as i64, 0).format("%d-%m-%Y %H:%M:%S"),
*header.sep_index(),
*header.ledger_index(),
header.sep_count(),
match header.kind() {
Kind::Full=> format!(", {} outputs", header.output_count()),
Kind::Delta=> "".to_owned()
Kind::Full => format!(", {} outputs", header.output_count()),
Kind::Delta => "".to_owned(),
},
header.milestone_diff_count()
);
Expand Down
20 changes: 12 additions & 8 deletions bee-storage/bee-storage-rocksdb/tests/address_to_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ async fn access() {
let (address, balance) = (rand_address(), rand_balance());

assert!(!Exist::<Address, Balance>::exist(&storage, &address).await.unwrap());
assert!(Fetch::<Address, Balance>::fetch(&storage, &address)
.await
.unwrap()
.is_none());
assert!(
Fetch::<Address, Balance>::fetch(&storage, &address)
.await
.unwrap()
.is_none()
);

Insert::<Address, Balance>::insert(&storage, &address, &balance)
.await
Expand All @@ -49,10 +51,12 @@ async fn access() {
Delete::<Address, Balance>::delete(&storage, &address).await.unwrap();

assert!(!Exist::<Address, Balance>::exist(&storage, &address).await.unwrap());
assert!(Fetch::<Address, Balance>::fetch(&storage, &address)
.await
.unwrap()
.is_none());
assert!(
Fetch::<Address, Balance>::fetch(&storage, &address)
.await
.unwrap()
.is_none()
);

let mut batch = Storage::batch_begin();

Expand Down
24 changes: 14 additions & 10 deletions bee-storage/bee-storage-rocksdb/tests/index_to_message_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ async fn access() {
.await
.unwrap()
);
assert!(Fetch::<HashedIndex, Vec<MessageId>>::fetch(&storage, &index)
.await
.unwrap()
.unwrap()
.is_empty());
assert!(
Fetch::<HashedIndex, Vec<MessageId>>::fetch(&storage, &index)
.await
.unwrap()
.unwrap()
.is_empty()
);

Insert::<(HashedIndex, MessageId), ()>::insert(&storage, &(index, message_id), &())
.await
Expand Down Expand Up @@ -61,11 +63,13 @@ async fn access() {
.await
.unwrap()
);
assert!(Fetch::<HashedIndex, Vec<MessageId>>::fetch(&storage, &index)
.await
.unwrap()
.unwrap()
.is_empty());
assert!(
Fetch::<HashedIndex, Vec<MessageId>>::fetch(&storage, &index)
.await
.unwrap()
.unwrap()
.is_empty()
);

let mut batch = Storage::batch_begin();

Expand Down
20 changes: 12 additions & 8 deletions bee-storage/bee-storage-rocksdb/tests/message_id_to_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ async fn access() {
let (message_id, message) = (rand_message_id(), rand_message());

assert!(!Exist::<MessageId, Message>::exist(&storage, &message_id).await.unwrap());
assert!(Fetch::<MessageId, Message>::fetch(&storage, &message_id)
.await
.unwrap()
.is_none());
assert!(
Fetch::<MessageId, Message>::fetch(&storage, &message_id)
.await
.unwrap()
.is_none()
);

Insert::<MessageId, Message>::insert(&storage, &message_id, &message)
.await
Expand All @@ -50,10 +52,12 @@ async fn access() {
.unwrap();

assert!(!Exist::<MessageId, Message>::exist(&storage, &message_id).await.unwrap());
assert!(Fetch::<MessageId, Message>::fetch(&storage, &message_id)
.await
.unwrap()
.is_none());
assert!(
Fetch::<MessageId, Message>::fetch(&storage, &message_id)
.await
.unwrap()
.is_none()
);

let mut batch = Storage::batch_begin();

Expand Down
Loading

0 comments on commit 1ddc3f3

Please sign in to comment.