Skip to content

Commit

Permalink
Add rustfmt::skip as needed
Browse files Browse the repository at this point in the history
In preparation for enabling `rustfmt` crate wide add various skip
statements and do minor format fixes.

Note, for some reason adding `rustfmt::skip` to the
`sha256t_hash_newtype` causes build to fail due to ambiguous naming (we
have the exact same macro in `bitcoin_hashes`). The macros are identical
except for the `rust-bitcoin` version adds docs to the created structs.
Until that can be pushed upstream to `bitcoin_hashes` I've renamed the
macro to `_sha256t_hash_newtype` and added a comment.
  • Loading branch information
tcharding committed May 26, 2022
1 parent 324fa0f commit 01a1d1f
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 24 deletions.
5 changes: 3 additions & 2 deletions src/blockdata/script.rs
Expand Up @@ -1266,14 +1266,15 @@ mod test {
}

#[test]
#[rustfmt::skip]
fn scriptint_round_trip() {
assert_eq!(build_scriptint(-1), vec![0x81]);
assert_eq!(build_scriptint(255), vec![255, 0]);
assert_eq!(build_scriptint(256), vec![0, 1]);
assert_eq!(build_scriptint(257), vec![1, 1]);
assert_eq!(build_scriptint(511), vec![255, 1]);
for &i in [10, 100, 255, 256, 1000, 10000, 25000, 200000, 5000000, 1000000000,
(1 << 31) - 1, -((1 << 31) - 1)].iter() {
for &i in [10, 100, 255, 256, 1000, 10000, 25000, 200000, 5000000, 1000000000, (1 << 31) - 1, -((1 << 31) - 1)].iter()
{
assert_eq!(Ok(i), read_scriptint(&build_scriptint(i)));
assert_eq!(Ok(-i), read_scriptint(&build_scriptint(-i)));
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Expand Up @@ -112,6 +112,7 @@ pub mod network;
pub mod blockdata;
pub mod util;
pub mod consensus;
#[rustfmt::skip] // `hash_newtype` statements are easier to read on a single line.
pub mod hash_types;
pub mod policy;

Expand Down Expand Up @@ -173,6 +174,7 @@ mod io_extras {
}
}

#[rustfmt::skip] // One line use statements to reduce number of cfg statements required.
mod prelude {
#[cfg(all(not(feature = "std"), not(test)))]
pub use alloc::{string::{String, ToString}, vec::Vec, boxed::Box, borrow::{Cow, ToOwned}, slice, rc, sync};
Expand Down
16 changes: 9 additions & 7 deletions src/network/address.rs
Expand Up @@ -306,14 +306,16 @@ mod test {
use crate::consensus::encode::{deserialize, serialize};

#[test]
#[rustfmt::skip]
fn serialize_address_test() {
assert_eq!(serialize(&Address {
services: ServiceFlags::NETWORK,
address: [0, 0, 0, 0, 0, 0xffff, 0x0a00, 0x0001],
port: 8333
}),
vec![1u8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0xff, 0xff, 0x0a, 0, 0, 1, 0x20, 0x8d]);
assert_eq!(
serialize(&Address {
services: ServiceFlags::NETWORK,
address: [0, 0, 0, 0, 0, 0xffff, 0x0a00, 0x0001],
port: 8333
}),
vec![1u8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0xff, 0xff, 0x0a, 0, 0, 1, 0x20, 0x8d]);
}

#[test]
Expand Down
38 changes: 23 additions & 15 deletions src/network/message.rs
Expand Up @@ -511,45 +511,51 @@ mod test {
}

#[test]
#[rustfmt::skip]
fn serialize_verack_test() {
assert_eq!(serialize(&RawNetworkMessage { magic: 0xd9b4bef9, payload: NetworkMessage::Verack }),
vec![0xf9, 0xbe, 0xb4, 0xd9, 0x76, 0x65, 0x72, 0x61,
0x63, 0x6B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2]);
vec![0xf9, 0xbe, 0xb4, 0xd9, 0x76, 0x65, 0x72, 0x61,
0x63, 0x6B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2]);
}

#[test]
#[rustfmt::skip]
fn serialize_ping_test() {
assert_eq!(serialize(&RawNetworkMessage { magic: 0xd9b4bef9, payload: NetworkMessage::Ping(100) }),
vec![0xf9, 0xbe, 0xb4, 0xd9, 0x70, 0x69, 0x6e, 0x67,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x24, 0x67, 0xf1, 0x1d,
0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
vec![0xf9, 0xbe, 0xb4, 0xd9, 0x70, 0x69, 0x6e, 0x67,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x24, 0x67, 0xf1, 0x1d,
0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
}


#[test]
#[rustfmt::skip]
fn serialize_mempool_test() {
assert_eq!(serialize(&RawNetworkMessage { magic: 0xd9b4bef9, payload: NetworkMessage::MemPool }),
vec![0xf9, 0xbe, 0xb4, 0xd9, 0x6d, 0x65, 0x6d, 0x70,
0x6f, 0x6f, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2]);
vec![0xf9, 0xbe, 0xb4, 0xd9, 0x6d, 0x65, 0x6d, 0x70,
0x6f, 0x6f, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2]);
}

#[test]
#[rustfmt::skip]
fn serialize_getaddr_test() {
assert_eq!(serialize(&RawNetworkMessage { magic: 0xd9b4bef9, payload: NetworkMessage::GetAddr }),
vec![0xf9, 0xbe, 0xb4, 0xd9, 0x67, 0x65, 0x74, 0x61,
0x64, 0x64, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2]);
vec![0xf9, 0xbe, 0xb4, 0xd9, 0x67, 0x65, 0x74, 0x61,
0x64, 0x64, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2]);
}

#[test]
fn deserialize_getaddr_test() {
#[rustfmt::skip]
let msg = deserialize(
&[0xf9, 0xbe, 0xb4, 0xd9, 0x67, 0x65, 0x74, 0x61,
0x64, 0x64, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2]);
0x64, 0x64, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2]);

let preimage = RawNetworkMessage { magic: 0xd9b4bef9, payload: NetworkMessage::GetAddr };
assert!(msg.is_ok());
let msg : RawNetworkMessage = msg.unwrap();
Expand All @@ -559,6 +565,7 @@ mod test {

#[test]
fn deserialize_version_test() {
#[rustfmt::skip]
let msg = deserialize::<RawNetworkMessage>(
&[ 0xf9, 0xbe, 0xb4, 0xd9, 0x76, 0x65, 0x72, 0x73,
0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand Down Expand Up @@ -595,6 +602,7 @@ mod test {

#[test]
fn deserialize_partial_message_test() {
#[rustfmt::skip]
let data = [ 0xf9, 0xbe, 0xb4, 0xd9, 0x76, 0x65, 0x72, 0x73,
0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00,
0x66, 0x00, 0x00, 0x00, 0xbe, 0x61, 0xb8, 0x27,
Expand Down
5 changes: 5 additions & 0 deletions src/network/stream_reader.rs
Expand Up @@ -70,6 +70,7 @@ mod test {

// First, let's define some byte arrays for sample messages - dumps are taken from live
// Bitcoin Core node v0.17.1 with Wireshark
#[rustfmt::skip]
const MSG_VERSION: [u8; 126] = [
0xf9, 0xbe, 0xb4, 0xd9, 0x76, 0x65, 0x72, 0x73,
0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand All @@ -89,19 +90,22 @@ mod test {
0x2f, 0x93, 0x8c, 0x08, 0x00, 0x01
];

#[rustfmt::skip]
const MSG_VERACK: [u8; 24] = [
0xf9, 0xbe, 0xb4, 0xd9, 0x76, 0x65, 0x72, 0x61,
0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2
];

#[rustfmt::skip]
const MSG_PING: [u8; 32] = [
0xf9, 0xbe, 0xb4, 0xd9, 0x70, 0x69, 0x6e, 0x67,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x24, 0x67, 0xf1, 0x1d,
0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
];

#[rustfmt::skip]
const MSG_ALERT: [u8; 192] = [
0xf9, 0xbe, 0xb4, 0xd9, 0x61, 0x6c, 0x65, 0x72,
0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand Down Expand Up @@ -148,6 +152,7 @@ mod test {
fn check_alert_msg(msg: &RawNetworkMessage) {
assert_eq!(msg.magic, 0xd9b4bef9);
if let NetworkMessage::Alert(ref alert) = msg.payload {
#[rustfmt::skip]
assert_eq!(alert.clone(), [
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
Expand Down
1 change: 1 addition & 0 deletions src/util/base58.rs
Expand Up @@ -124,6 +124,7 @@ impl<T: Default + Copy> SmallVec<T> {

static BASE58_CHARS: &[u8] = b"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";

#[rustfmt::skip]
static BASE58_DIGITS: [Option<u8>; 128] = [
None, None, None, None, None, None, None, None, // 0-7
None, None, None, None, None, None, None, None, // 8-15
Expand Down
1 change: 1 addition & 0 deletions src/util/bip32.rs
Expand Up @@ -1120,6 +1120,7 @@ mod tests {
pub fn encode_fingerprint_chaincode() {
use serde_json;
let fp = Fingerprint::from(&[1u8,2,3,42][..]);
#[rustfmt::skip]
let cc = ChainCode::from(
&[1u8,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2][..]
);
Expand Down
2 changes: 2 additions & 0 deletions src/util/key.rs
Expand Up @@ -555,13 +555,15 @@ mod tests {
9b6347398505f5ec93826dc61c19f47c66c0283ee9be980e29ce325a0f4679ef\
87288ed73ce47fc4f5c79d19ebfa57da7cff3aff6e819e4ee971d86b5e61875d\
";
#[rustfmt::skip]
static PK_BYTES: [u8; 33] = [
0x03,
0x9b, 0x63, 0x47, 0x39, 0x85, 0x05, 0xf5, 0xec,
0x93, 0x82, 0x6d, 0xc6, 0x1c, 0x19, 0xf4, 0x7c,
0x66, 0xc0, 0x28, 0x3e, 0xe9, 0xbe, 0x98, 0x0e,
0x29, 0xce, 0x32, 0x5a, 0x0f, 0x46, 0x79, 0xef,
];
#[rustfmt::skip]
static PK_BYTES_U: [u8; 65] = [
0x04,
0x9b, 0x63, 0x47, 0x39, 0x85, 0x05, 0xf5, 0xec,
Expand Down

0 comments on commit 01a1d1f

Please sign in to comment.