Skip to content

Commit

Permalink
Clippy fixes (#1532)
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez authored Oct 5, 2022
1 parent 9beb24b commit e88bd4d
Show file tree
Hide file tree
Showing 41 changed files with 63 additions and 68 deletions.
2 changes: 1 addition & 1 deletion bee-api/bee-rest-api/src/routes/api/core/v2/white_flag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub(crate) async fn white_flag<B: StorageBackend>(
request_block(
&*args.tangle,
&args.block_requester,
&*args.requested_blocks,
&args.requested_blocks,
*parent,
index,
)
Expand Down
2 changes: 1 addition & 1 deletion bee-block/fuzz/fuzz_targets/fuzz_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ use libfuzzer_sys::fuzz_target;
use packable::PackableExt;

fuzz_target!(|data: &[u8]| {
let _ = Address::unpack_verified(&mut data.to_vec().as_slice());
let _ = Address::unpack_verified(data.to_vec().as_slice());
});
2 changes: 1 addition & 1 deletion bee-block/fuzz/fuzz_targets/fuzz_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ use libfuzzer_sys::fuzz_target;
use packable::PackableExt;

fuzz_target!(|data: &[u8]| {
let _ = Block::unpack_strict(&mut data.to_vec().as_slice(), &());
let _ = Block::unpack_strict(data.to_vec().as_slice(), &());
});
2 changes: 1 addition & 1 deletion bee-block/fuzz/fuzz_targets/fuzz_feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ use libfuzzer_sys::fuzz_target;
use packable::PackableExt;

fuzz_target!(|data: &[u8]| {
let _ = Feature::unpack_verified(&mut data.to_vec().as_slice());
let _ = Feature::unpack_verified(data.to_vec().as_slice());
});
2 changes: 1 addition & 1 deletion bee-block/fuzz/fuzz_targets/fuzz_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ use libfuzzer_sys::fuzz_target;
use packable::PackableExt;

fuzz_target!(|data: &[u8]| {
let _ = Input::unpack_verified(&mut data.to_vec().as_slice());
let _ = Input::unpack_verified(data.to_vec().as_slice());
});
2 changes: 1 addition & 1 deletion bee-block/fuzz/fuzz_targets/fuzz_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ use libfuzzer_sys::fuzz_target;
use packable::PackableExt;

fuzz_target!(|data: &[u8]| {
let _ = Output::unpack_verified(&mut data.to_vec().as_slice());
let _ = Output::unpack_verified(data.to_vec().as_slice());
});
2 changes: 1 addition & 1 deletion bee-block/fuzz/fuzz_targets/fuzz_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ use libfuzzer_sys::fuzz_target;
use packable::PackableExt;

fuzz_target!(|data: &[u8]| {
let _ = Payload::unpack_verified(&mut data.to_vec().as_slice());
let _ = Payload::unpack_verified(data.to_vec().as_slice());
});
2 changes: 1 addition & 1 deletion bee-block/fuzz/fuzz_targets/fuzz_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ use libfuzzer_sys::fuzz_target;
use packable::PackableExt;

fuzz_target!(|data: &[u8]| {
let _ = Signature::unpack_verified(&mut data.to_vec().as_slice());
let _ = Signature::unpack_verified(data.to_vec().as_slice());
});
2 changes: 1 addition & 1 deletion bee-block/fuzz/fuzz_targets/fuzz_unlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ use libfuzzer_sys::fuzz_target;
use packable::PackableExt;

fuzz_target!(|data: &[u8]| {
let _ = Unlock::unpack_verified(&mut data.to_vec().as_slice());
let _ = Unlock::unpack_verified(data.to_vec().as_slice());
});
2 changes: 1 addition & 1 deletion bee-block/fuzz/fuzz_targets/fuzz_unlock_condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ use libfuzzer_sys::fuzz_target;
use packable::PackableExt;

fuzz_target!(|data: &[u8]| {
let _ = UnlockCondition::unpack_verified(&mut data.to_vec().as_slice());
let _ = UnlockCondition::unpack_verified(data.to_vec().as_slice());
});
2 changes: 1 addition & 1 deletion bee-block/fuzz/src/fuzz_sorter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn main() -> io::Result<()> {

file.read_to_end(&mut buffer)?;

if let Err(err) = Block::unpack_strict(&mut buffer.as_slice(), &()) {
if let Err(err) = Block::unpack_strict(buffer.as_slice(), &()) {
if !matches!(err, UnpackError::Unpacker(..)) {
let mut file = OpenOptions::new()
.write(true)
Expand Down
2 changes: 1 addition & 1 deletion bee-block/tests/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ fn pack_unpack_valid_ed25519() {
assert_eq!(address_packed.len(), address.packed_len());
assert_eq!(
address,
PackableExt::unpack_verified(&mut address_packed.as_slice(), &()).unwrap()
PackableExt::unpack_verified(address_packed.as_slice(), &()).unwrap()
);
}
6 changes: 3 additions & 3 deletions bee-block/tests/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn invalid_payload_kind() {
fn unpack_valid_no_remaining_bytes() {
assert!(
Block::unpack_strict(
&mut vec![
vec![
2, 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,
Expand All @@ -94,7 +94,7 @@ fn unpack_valid_no_remaining_bytes() {
fn unpack_invalid_remaining_bytes() {
assert!(matches!(
Block::unpack_strict(
&mut vec![
vec![
2, 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,
Expand All @@ -119,7 +119,7 @@ fn pack_unpack_valid() {
assert_eq!(packed_block.len(), block.packed_len());
assert_eq!(
block,
PackableExt::unpack_verified(&mut packed_block.as_slice(), &protocol_parameters).unwrap()
PackableExt::unpack_verified(packed_block.as_slice(), &protocol_parameters).unwrap()
);
}

Expand Down
2 changes: 1 addition & 1 deletion bee-block/tests/block_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ fn pack_unpack_valid() {
assert_eq!(packed_block_id.len(), block_id.packed_len());
assert_eq!(
block_id,
PackableExt::unpack_verified(&mut packed_block_id.as_slice(), &()).unwrap()
PackableExt::unpack_verified(packed_block_id.as_slice(), &()).unwrap()
);
}
2 changes: 1 addition & 1 deletion bee-block/tests/ed25519_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ fn pack_unpack_valid() {

assert_eq!(
address,
PackableExt::unpack_verified(&mut packed_address.as_slice(), &()).unwrap()
PackableExt::unpack_verified(packed_address.as_slice(), &()).unwrap()
);
}
5 changes: 1 addition & 4 deletions bee-block/tests/ed25519_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,5 @@ fn pack_unpack_valid() {
let sig = Ed25519Signature::new(pub_key_bytes, sig_bytes);
let sig_packed = sig.pack_to_vec();

assert_eq!(
sig,
PackableExt::unpack_verified(&mut sig_packed.as_slice(), &()).unwrap()
);
assert_eq!(sig, PackableExt::unpack_verified(sig_packed.as_slice(), &()).unwrap());
}
4 changes: 2 additions & 2 deletions bee-block/tests/migrated_funds_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn pack_unpack_valid() {
protocol_parameters.token_supply(),
)
.unwrap();
let mfe_2 = MigratedFundsEntry::unpack_verified(&mut mfe_1.pack_to_vec().as_slice(), &protocol_parameters).unwrap();
let mfe_2 = MigratedFundsEntry::unpack_verified(mfe_1.pack_to_vec().as_slice(), &protocol_parameters).unwrap();

assert_eq!(mfe_1.tail_transaction_hash(), mfe_2.tail_transaction_hash());
assert_eq!(*mfe_1.address(), *mfe_2.address());
Expand All @@ -85,7 +85,7 @@ fn pack_unpack_invalid_amount() {
];

assert!(matches!(
MigratedFundsEntry::unpack_verified(&mut bytes.as_slice(), &protocol_parameters),
MigratedFundsEntry::unpack_verified(bytes.as_slice(), &protocol_parameters),
Err(UnpackError::Packable(Error::InvalidMigratedFundsEntryAmount(
3_038_287_259_199_220_266
)))
Expand Down
2 changes: 1 addition & 1 deletion bee-block/tests/milestone_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ fn pack_unpack_valid() {
assert_eq!(packed_milestone_id.len(), milestone_id.packed_len());
assert_eq!(
milestone_id,
PackableExt::unpack_verified(&mut packed_milestone_id.as_slice(), &()).unwrap()
PackableExt::unpack_verified(packed_milestone_id.as_slice(), &()).unwrap()
);
}
2 changes: 1 addition & 1 deletion bee-block/tests/milestone_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn display_impl() {
fn unpack() {
let packed = 0u32.pack_to_vec();
assert_eq!(
MilestoneIndex::unpack_verified(&mut packed.as_slice(), &()).unwrap(),
MilestoneIndex::unpack_verified(packed.as_slice(), &()).unwrap(),
MilestoneIndex(0)
);
}
Expand Down
2 changes: 1 addition & 1 deletion bee-block/tests/milestone_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ fn pack_unpack_valid() {
assert_eq!(payload.packed_len(), packed.len());
assert_eq!(
payload,
PackableExt::unpack_verified(&mut packed.as_slice(), &protocol_parameters).unwrap()
PackableExt::unpack_verified(packed.as_slice(), &protocol_parameters).unwrap()
)
}

Expand Down
2 changes: 1 addition & 1 deletion bee-block/tests/milestone_payload_essence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn pack_unpack_valid() {
let packed = milestone_payload.pack_to_vec();

assert_eq!(
MilestoneEssence::unpack_verified(&mut packed.as_slice(), &protocol_parameters).unwrap(),
MilestoneEssence::unpack_verified(packed.as_slice(), &protocol_parameters).unwrap(),
milestone_payload,
);
}
4 changes: 2 additions & 2 deletions bee-block/tests/output_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn packed_len() {
#[test]
fn pack_unpack_valid() {
let output_id_1 = OutputId::from_str(OUTPUT_ID).unwrap();
let output_id_2 = OutputId::unpack_verified(&mut output_id_1.pack_to_vec().as_slice(), &()).unwrap();
let output_id_2 = OutputId::unpack_verified(output_id_1.pack_to_vec().as_slice(), &()).unwrap();

assert_eq!(output_id_1, output_id_2);
}
Expand All @@ -115,7 +115,7 @@ fn pack_unpack_invalid() {
];

assert!(matches!(
OutputId::unpack_verified(&mut bytes.as_slice(), &()),
OutputId::unpack_verified(bytes.as_slice(), &()),
Err(UnpackError::Packable(Error::InvalidInputOutputIndex(
InvalidBoundedU16(128)
)))
Expand Down
10 changes: 5 additions & 5 deletions bee-block/tests/parents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn packed_len() {
#[test]
fn pack_unpack_valid() {
let parents_1 = Parents::new(rand_block_ids(8)).unwrap();
let parents_2 = Parents::unpack_verified(&mut parents_1.pack_to_vec().as_slice(), &()).unwrap();
let parents_2 = Parents::unpack_verified(parents_1.pack_to_vec().as_slice(), &()).unwrap();

assert_eq!(parents_1, parents_2);
}
Expand All @@ -91,7 +91,7 @@ fn pack_unpack_invalid_less_than_min() {
];

assert!(matches!(
Parents::unpack_verified(&mut bytes.as_slice(), &()),
Parents::unpack_verified(bytes.as_slice(), &()),
Err(UnpackError::Packable(Error::InvalidParentCount(
TryIntoBoundedU8Error::Invalid(0)
)))
Expand All @@ -107,7 +107,7 @@ fn pack_unpack_invalid_more_than_max() {
];

assert!(matches!(
Parents::unpack_verified(&mut bytes.as_slice(), &()),
Parents::unpack_verified(bytes.as_slice(), &()),
Err(UnpackError::Packable(Error::InvalidParentCount(
TryIntoBoundedU8Error::Invalid(9)
)))
Expand All @@ -121,7 +121,7 @@ fn unpack_invalid_not_sorted() {
let inner = VecPrefix::<_, u8>::try_from(inner).unwrap();

let packed = inner.pack_to_vec();
let parents = Parents::unpack_verified(&mut packed.as_slice(), &());
let parents = Parents::unpack_verified(packed.as_slice(), &());

assert!(matches!(
parents,
Expand All @@ -136,7 +136,7 @@ fn unpack_invalid_not_unique() {
let inner = VecPrefix::<_, u8>::try_from(inner).unwrap();

let packed = inner.pack_to_vec();
let parents = Parents::unpack_verified(&mut packed.as_slice(), &());
let parents = Parents::unpack_verified(packed.as_slice(), &());

assert!(matches!(
parents,
Expand Down
6 changes: 3 additions & 3 deletions bee-block/tests/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn transaction() {
assert!(matches!(payload, Payload::Transaction(_)));
assert_eq!(
payload,
PackableExt::unpack_verified(&mut packed.as_slice(), &protocol_parameters).unwrap()
PackableExt::unpack_verified(packed.as_slice(), &protocol_parameters).unwrap()
);
}

Expand Down Expand Up @@ -103,7 +103,7 @@ fn milestone() {
assert!(matches!(payload, Payload::Milestone(_)));
assert_eq!(
payload,
PackableExt::unpack_verified(&mut packed.as_slice(), &protocol_parameters).unwrap()
PackableExt::unpack_verified(packed.as_slice(), &protocol_parameters).unwrap()
);
}

Expand Down Expand Up @@ -135,6 +135,6 @@ fn treasury_transaction() {
assert!(matches!(payload, Payload::TreasuryTransaction(_)));
assert_eq!(
payload,
PackableExt::unpack_verified(&mut packed.as_slice(), &protocol_parameters).unwrap()
PackableExt::unpack_verified(packed.as_slice(), &protocol_parameters).unwrap()
);
}
2 changes: 1 addition & 1 deletion bee-block/tests/receipt_milestone_option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ fn pack_unpack_valid() {
assert_eq!(packed_receipt.len(), receipt.packed_len());
assert_eq!(
receipt,
PackableExt::unpack_verified(&mut packed_receipt.as_slice(), &protocol_parameters).unwrap()
PackableExt::unpack_verified(packed_receipt.as_slice(), &protocol_parameters).unwrap()
);
}

Expand Down
4 changes: 2 additions & 2 deletions bee-block/tests/reference_unlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ fn packed_len() {
#[test]
fn pack_unpack_valid() {
let reference_1 = ReferenceUnlock::try_from(42).unwrap();
let reference_2 = ReferenceUnlock::unpack_verified(&mut reference_1.pack_to_vec().as_slice(), &()).unwrap();
let reference_2 = ReferenceUnlock::unpack_verified(reference_1.pack_to_vec().as_slice(), &()).unwrap();

assert_eq!(reference_1, reference_2);
}

#[test]
fn pack_unpack_invalid_index() {
assert!(matches!(
ReferenceUnlock::unpack_verified(&mut vec![0x2a, 0x2a].as_slice(), &()),
ReferenceUnlock::unpack_verified(vec![0x2a, 0x2a].as_slice(), &()),
Err(UnpackError::Packable(Error::InvalidReferenceIndex(InvalidBoundedU16(
10794
))))
Expand Down
4 changes: 2 additions & 2 deletions bee-block/tests/signature_unlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn pack_unpack_valid_ed25519() {
rand_bytes(64).try_into().unwrap(),
)));
let signature_bytes = signature_1.pack_to_vec();
let signature_2 = SignatureUnlock::unpack_verified(&mut signature_bytes.as_slice(), &()).unwrap();
let signature_2 = SignatureUnlock::unpack_verified(signature_bytes.as_slice(), &()).unwrap();

assert_eq!(signature_bytes[0], 0);
assert_eq!(signature_1, signature_2);
Expand All @@ -69,7 +69,7 @@ fn pack_unpack_valid_ed25519() {
fn pack_unpack_invalid_kind() {
assert!(matches!(
SignatureUnlock::unpack_verified(
&mut vec![
vec![
1, 111, 225, 221, 28, 247, 253, 234, 110, 187, 52, 129, 153, 130, 84, 26, 7, 226, 27, 212, 145, 96,
151, 196, 124, 135, 176, 31, 48, 0, 213, 200, 82, 227, 169, 21, 179, 253, 115, 184, 209, 107, 138, 0,
62, 252, 20, 255, 24, 193, 203, 255, 137, 142, 158, 25, 171, 86, 195, 20, 70, 56, 136, 204, 2, 219,
Expand Down
9 changes: 4 additions & 5 deletions bee-block/tests/tagged_data_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,15 @@ fn packed_len() {
fn pack_unpack_valid() {
let tagged_data_1 =
TaggedDataPayload::new(rand_bytes(32), vec![0x42, 0xff, 0x84, 0xa2, 0x42, 0xff, 0x84, 0xa2]).unwrap();
let tagged_data_2 = TaggedDataPayload::unpack_verified(&mut tagged_data_1.pack_to_vec().as_slice(), &()).unwrap();
let tagged_data_2 = TaggedDataPayload::unpack_verified(tagged_data_1.pack_to_vec().as_slice(), &()).unwrap();

assert_eq!(tagged_data_1.tag(), tagged_data_2.tag());
assert_eq!(tagged_data_1.data(), tagged_data_2.data());
}

#[test]
fn unpack_valid_tag_length_min() {
let payload =
TaggedDataPayload::unpack_verified(&mut vec![0x00, 0x00, 0x00, 0x00, 0x00, 0x00].as_slice(), &()).unwrap();
let payload = TaggedDataPayload::unpack_verified(vec![0x00, 0x00, 0x00, 0x00, 0x00, 0x00].as_slice(), &()).unwrap();

assert!(payload.tag().is_empty());
}
Expand All @@ -97,7 +96,7 @@ fn unpack_valid_tag_length_min() {
fn unpack_invalid_tag_length_more_than_max() {
assert!(matches!(
TaggedDataPayload::unpack_verified(
&mut vec![
vec![
0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand All @@ -116,7 +115,7 @@ fn unpack_invalid_tag_length_more_than_max() {
#[test]
fn unpack_invalid_data_length_more_than_max() {
assert!(matches!(
TaggedDataPayload::unpack_verified(&mut vec![0x02, 0x00, 0x00, 0x35, 0x82, 0x00, 0x00].as_slice(), &()),
TaggedDataPayload::unpack_verified(vec![0x02, 0x00, 0x00, 0x35, 0x82, 0x00, 0x00].as_slice(), &()),
Err(UnpackError::Packable(Error::InvalidTaggedDataLength(
TryIntoBoundedU32Error::Invalid(33333)
)))
Expand Down
4 changes: 2 additions & 2 deletions bee-block/tests/tail_transaction_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn packed_len() {
fn pack_unpack_valid() {
let tth_1 = TailTransactionHash::try_from(HASH_BYTES).unwrap();
let tth_1_bytes = tth_1.pack_to_vec();
let tth_2 = TailTransactionHash::unpack_verified(&mut tth_1_bytes.as_slice(), &()).unwrap();
let tth_2 = TailTransactionHash::unpack_verified(tth_1_bytes.as_slice(), &()).unwrap();

assert_eq!(tth_1, tth_2);
}
Expand All @@ -75,7 +75,7 @@ fn pack_unpack_invalid() {
];

assert!(matches!(
TailTransactionHash::unpack_verified(&mut bytes.as_slice(), &()),
TailTransactionHash::unpack_verified(bytes.as_slice(), &()),
Err(UnpackError::Packable(Error::InvalidTailTransactionHash))
));
}
2 changes: 1 addition & 1 deletion bee-block/tests/transaction_essence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn essence_kind() {
#[test]
fn essence_unpack_invalid_kind() {
assert!(matches!(
TransactionEssence::unpack_verified(&mut vec![2u8; 32].as_slice(), &protocol_parameters()),
TransactionEssence::unpack_verified(vec![2u8; 32].as_slice(), &protocol_parameters()),
Err(UnpackError::Packable(Error::InvalidEssenceKind(2)))
));
}
Loading

0 comments on commit e88bd4d

Please sign in to comment.