Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
j-berman committed Jan 8, 2024
1 parent d5ac9f2 commit 9a0dffb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions coins/monero/src/tests/extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ fn pub_key() -> EdwardsPoint {
.unwrap()
}

fn test_write_buf(extra: Extra, buf: Vec<u8>) {
fn test_write_buf(extra: &Extra, buf: &[u8]) {
let mut w: Vec<u8> = vec![];
Extra::write(&extra, &mut w).unwrap();
Extra::write(extra, &mut w).unwrap();
assert_eq!(buf, w);
}

Expand All @@ -31,31 +31,31 @@ fn empty_extra() {
let buf: Vec<u8> = vec![];
let extra = Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap();
assert!(extra.0.is_empty());
test_write_buf(extra, buf);
test_write_buf(&extra, &buf);
}

#[test]
fn padding_only_size_1() {
let buf: Vec<u8> = vec![0];
let extra = Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap();
assert_eq!(extra.0, vec![ExtraField::Padding(1)]);
test_write_buf(extra, buf);
test_write_buf(&extra, &buf);
}

#[test]
fn padding_only_size_2() {
let buf: Vec<u8> = vec![0, 0];
let extra = Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap();
assert_eq!(extra.0, vec![ExtraField::Padding(2)]);
test_write_buf(extra, buf);
test_write_buf(&extra, &buf);
}

#[test]
fn padding_only_max_size() {
let buf: Vec<u8> = vec![0; MAX_TX_EXTRA_PADDING_COUNT];
let extra = Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap();
assert_eq!(extra.0, vec![ExtraField::Padding(MAX_TX_EXTRA_PADDING_COUNT)]);
test_write_buf(extra, buf);
test_write_buf(&extra, &buf);
}

#[test]
Expand All @@ -77,15 +77,15 @@ fn pub_key_only() {
let buf: Vec<u8> = PUB_KEY_BYTES.to_vec();
let extra = Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap();
assert_eq!(extra.0, vec![ExtraField::PublicKey(pub_key())]);
test_write_buf(extra, buf);
test_write_buf(&extra, &buf);
}

#[test]
fn extra_nonce_only() {
let buf: Vec<u8> = vec![2, 1, 42];
let extra = Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap();
assert_eq!(extra.0, vec![ExtraField::Nonce(vec![42])]);
test_write_buf(extra, buf);
test_write_buf(&extra, &buf);
}

#[test]
Expand All @@ -107,7 +107,7 @@ fn pub_key_and_padding() {
]);
let extra = Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap();
assert_eq!(extra.0, vec![ExtraField::PublicKey(pub_key()), ExtraField::Padding(76)]);
test_write_buf(extra, buf);
test_write_buf(&extra, &buf);
}

#[test]
Expand All @@ -123,7 +123,7 @@ fn extra_mysterious_minergate_only() {
let buf: Vec<u8> = vec![222, 1, 42];
let extra = Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap();
assert_eq!(extra.0, vec![ExtraField::MysteriousMinergate(vec![42])]);
test_write_buf(extra, buf);
test_write_buf(&extra, &buf);
}

#[test]
Expand All @@ -133,7 +133,7 @@ fn extra_mysterious_minergate_only_large() {
buf.extend_from_slice(&vec![0; 512]);
let extra = Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap();
assert_eq!(extra.0, vec![ExtraField::MysteriousMinergate(vec![0; 512])]);
test_write_buf(extra, buf);
test_write_buf(&extra, &buf);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion coins/monero/src/wallet/extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl ExtraField {
loop {
let buf = r.fill_buf()?;
let mut n_consume = 0;
for v in buf.as_ref() {
for v in buf {
if *v != 0u8 {
Err(io::Error::other("non-zero value after padding"))?
}
Expand Down

0 comments on commit 9a0dffb

Please sign in to comment.