From 0f61b4a41b0643f9a448c392a70ec26746685c7e Mon Sep 17 00:00:00 2001 From: Matt Morehouse Date: Thu, 1 Oct 2026 10:45:24 -0500 Subject: [PATCH] Stop using assert!() with is_empty() The latest clippy now flags this pattern since when the assert fails we don't get to see the actual contents. It's better to use assert_eq!() instead. --- smite-ir/src/mutators/operation_param.rs | 4 +-- smite-ir/src/tests.rs | 4 +-- smite-scenarios/src/executor/tests.rs | 18 ++++++------- smite/src/bolt/attribution_data.rs | 2 +- smite/src/bolt/init.rs | 8 +++--- smite/src/bolt/ping.rs | 4 +-- smite/src/bolt/pong.rs | 2 +- smite/src/bolt/shutdown.rs | 2 +- smite/src/bolt/wire.rs | 34 ++++++++++++------------ smitebot/src/commands/start.rs | 2 +- smitebot/src/config.rs | 2 +- 11 files changed, 41 insertions(+), 41 deletions(-) diff --git a/smite-ir/src/mutators/operation_param.rs b/smite-ir/src/mutators/operation_param.rs index 745aa415..b5152f6c 100644 --- a/smite-ir/src/mutators/operation_param.rs +++ b/smite-ir/src/mutators/operation_param.rs @@ -599,7 +599,7 @@ mod tests { let mut empty: Vec = vec![]; shuffle_subrange(&mut empty, &mut rng); - assert!(empty.is_empty()); + assert_eq!(empty, b""); let mut single = vec![0xFF]; shuffle_subrange(&mut single, &mut rng); @@ -664,7 +664,7 @@ mod tests { let mut rng = SmallRng::seed_from_u64(0); let mut empty: Vec = vec![]; fill_repeated(&mut empty, &mut rng); - assert!(empty.is_empty()); + assert_eq!(empty, b""); } #[test] diff --git a/smite-ir/src/tests.rs b/smite-ir/src/tests.rs index 2cb77285..53fdd3cf 100644 --- a/smite-ir/src/tests.rs +++ b/smite-ir/src/tests.rs @@ -2791,7 +2791,7 @@ fn dead_code_returns_false_on_empty_program() { instructions: vec![], }; assert!(!DeadCodeEliminator.minimize(&mut program)); - assert!(program.instructions.is_empty()); + assert_eq!(program.instructions, []); } /// Build a program with a dead load appended after the generated program. @@ -3020,7 +3020,7 @@ fn cse_returns_false_on_empty_program() { instructions: vec![], }; assert!(!CommonSubexpressionEliminator.minimize(&mut program)); - assert!(program.instructions.is_empty()); + assert_eq!(program.instructions, []); } #[test] diff --git a/smite-scenarios/src/executor/tests.rs b/smite-scenarios/src/executor/tests.rs index ed2f6362..3f030aa4 100644 --- a/smite-scenarios/src/executor/tests.rs +++ b/smite-scenarios/src/executor/tests.rs @@ -73,7 +73,7 @@ fn execute_build_channel_announcement() { assert_eq!(ca.node_id_2, pk(&node_sk_2_bytes)); assert_eq!(ca.bitcoin_key_1, pk(&bitcoin_sk_1_bytes)); assert_eq!(ca.bitcoin_key_2, pk(&bitcoin_sk_2_bytes)); - assert!(ca.extra.is_empty()); + assert_eq!(ca.extra, b""); assert!(ca.verify()); } @@ -112,7 +112,7 @@ fn execute_build_node_announcement() { assert_eq!(na.rgb_color, rgb_color); assert_eq!(na.alias, alias); assert_eq!(na.addresses, addresses_bytes); - assert!(na.extra.is_empty()); + assert_eq!(na.extra, b""); assert!(na.verify()); } @@ -168,7 +168,7 @@ fn execute_build_channel_update() { assert_eq!(cu.fee_base_msat, 1_000); assert_eq!(cu.fee_proportional_millionths, 100); assert_eq!(cu.htlc_maximum_msat, 99_000_000); - assert!(cu.extra.is_empty()); + assert_eq!(cu.extra, b""); let secp = Secp256k1::new(); let expected_node_id = @@ -638,7 +638,7 @@ fn execute_mine_blocks_invokes_cli() { // Verify that mine_blocks was called with the correct number assert_eq!(fx.bitcoin().mine_blocks_calls, vec![6]); - assert!(fx.bitcoin().mined_private_mempool.is_empty()); + assert_eq!(fx.bitcoin().mined_private_mempool, Vec::::new()); assert_eq!(fx.rpc().chain_syncs, 1); } @@ -713,7 +713,7 @@ fn execute_lookup_short_channel_id_unconfirmed_returns_sentinel() { // The mock was queried but returned None (zero confirmations), so the // executor took the sentinel path without panicking. - assert!(fx.bitcoin().mine_blocks_calls.is_empty()); + assert_eq!(fx.bitcoin().mine_blocks_calls, Vec::::new()); assert_eq!(fx.bitcoin().block_position_lookups.len(), 1); let ca: ChannelAnnouncement = fx.sent(0); @@ -740,7 +740,7 @@ fn execute_broadcast_dedupes_rejected_tx_in_private_mempool() { ); let rejected_hex = bitcoin::consensus::encode::serialize_hex(&fx.bitcoin().broadcast_calls[0]); - assert!(fx.private_mempool().is_empty()); + assert_eq!(fx.private_mempool(), []); assert_eq!(fx.bitcoin().mined_private_mempool, vec![rejected_hex]); } @@ -1116,7 +1116,7 @@ fn execute_send_shutdown_empty_scriptpubkey() { assert_eq!(fx.sent_len(), 1); let sd: Shutdown = fx.sent(0); assert_eq!(sd.channel_id, channel_id); - assert!(sd.scriptpubkey.is_empty()); + assert_eq!(sd.scriptpubkey, b""); } #[test] @@ -1172,7 +1172,7 @@ fn execute_recv_channel_ready_below_minimum_depth_is_noop() { // does not yet owe us a `channel_ready`, so `RecvChannelReady` must be a // no-op. fx.run(&recv_channel_ready_program(5)); - assert!(fx.bitcoin().mined_private_mempool.is_empty()); + assert_eq!(fx.bitcoin().mined_private_mempool, Vec::::new()); // The target's next per-commitment point is still unknown and the queued // `channel_ready` remains untouched. @@ -1193,7 +1193,7 @@ fn execute_recv_channel_ready_at_minimum_depth_records_point() { // At the negotiated `minimum_depth` confirmations the target owes us a // `channel_ready`, which `RecvChannelReady` receives and records. fx.run(&recv_channel_ready_program(6)); - assert!(fx.bitcoin().mined_private_mempool.is_empty()); + assert_eq!(fx.bitcoin().mined_private_mempool, Vec::::new()); // The `channel_ready` was consumed and the target's next per-commitment // point is now recorded. diff --git a/smite/src/bolt/attribution_data.rs b/smite/src/bolt/attribution_data.rs index 505c932d..f768f40d 100644 --- a/smite/src/bolt/attribution_data.rs +++ b/smite/src/bolt/attribution_data.rs @@ -223,6 +223,6 @@ mod tests { let mut cursor: &[u8] = &buf; let decoded = AttributionData::read(&mut cursor).unwrap(); assert_eq!(decoded, original); - assert!(cursor.is_empty()); + assert_eq!(cursor, b""); } } diff --git a/smite/src/bolt/init.rs b/smite/src/bolt/init.rs index 63a13bd5..c1ce119a 100644 --- a/smite/src/bolt/init.rs +++ b/smite/src/bolt/init.rs @@ -152,8 +152,8 @@ mod tests { #[test] fn empty_init() { let init = Init::empty(); - assert!(init.globalfeatures.is_empty()); - assert!(init.features.is_empty()); + assert_eq!(init.globalfeatures, b""); + assert_eq!(init.features, b""); assert!(init.tlvs.networks.is_none()); assert!(init.tlvs.remote_addr.is_none()); } @@ -247,8 +247,8 @@ mod tests { fn decode_empty() { let data = [0x00, 0x00, 0x00, 0x00]; let init = Init::decode(&data).unwrap(); - assert!(init.globalfeatures.is_empty()); - assert!(init.features.is_empty()); + assert_eq!(init.globalfeatures, b""); + assert_eq!(init.features, b""); assert!(init.tlvs.networks.is_none()); assert!(init.tlvs.remote_addr.is_none()); } diff --git a/smite/src/bolt/ping.rs b/smite/src/bolt/ping.rs index 0beaca1e..b4fa005b 100644 --- a/smite/src/bolt/ping.rs +++ b/smite/src/bolt/ping.rs @@ -67,7 +67,7 @@ mod tests { fn new_creates_empty_padding() { let ping = Ping::new(4); assert_eq!(ping.num_pong_bytes, 4); - assert!(ping.ignored.is_empty()); + assert_eq!(ping.ignored, b""); } #[test] @@ -99,7 +99,7 @@ mod tests { let data = [0x00, 0x04, 0x00, 0x00]; let ping = Ping::decode(&data).unwrap(); assert_eq!(ping.num_pong_bytes, 4); - assert!(ping.ignored.is_empty()); + assert_eq!(ping.ignored, b""); } #[test] diff --git a/smite/src/bolt/pong.rs b/smite/src/bolt/pong.rs index 4f58f395..7b344045 100644 --- a/smite/src/bolt/pong.rs +++ b/smite/src/bolt/pong.rs @@ -86,7 +86,7 @@ mod tests { fn decode_empty() { let data = [0x00, 0x00]; let pong = Pong::decode(&data).unwrap(); - assert!(pong.ignored.is_empty()); + assert_eq!(pong.ignored, b""); } #[test] diff --git a/smite/src/bolt/shutdown.rs b/smite/src/bolt/shutdown.rs index ce90a62d..c91a6af9 100644 --- a/smite/src/bolt/shutdown.rs +++ b/smite/src/bolt/shutdown.rs @@ -259,7 +259,7 @@ mod tests { let encoded = original.encode(); let decoded = Shutdown::decode(&encoded).unwrap(); assert_eq!(original, decoded); - assert!(decoded.scriptpubkey.is_empty()); + assert_eq!(decoded.scriptpubkey, b""); } #[test] diff --git a/smite/src/bolt/wire.rs b/smite/src/bolt/wire.rs index 4181e9d0..7142a6f9 100644 --- a/smite/src/bolt/wire.rs +++ b/smite/src/bolt/wire.rs @@ -304,7 +304,7 @@ mod tests { assert_eq!(u8::read(&mut data).unwrap(), 0); assert_eq!(data, &[0xff]); assert_eq!(u8::read(&mut data).unwrap(), 255); - assert!(data.is_empty()); + assert_eq!(data, b""); } #[test] @@ -336,7 +336,7 @@ mod tests { assert_eq!(u16::read(&mut data).unwrap(), 0); assert_eq!(data, &[0x00, 0x01]); assert_eq!(u16::read(&mut data).unwrap(), 1); - assert!(data.is_empty()); + assert_eq!(data, b""); } #[test] @@ -377,7 +377,7 @@ mod tests { assert_eq!(u32::read(&mut data).unwrap(), 0); assert_eq!(data, &[0x00, 0x00, 0x00, 0x01]); assert_eq!(u32::read(&mut data).unwrap(), 1); - assert!(data.is_empty()); + assert_eq!(data, b""); } #[test] @@ -421,7 +421,7 @@ mod tests { assert_eq!(u64::read(&mut data).unwrap(), 0); assert_eq!(data.len(), 8); assert_eq!(u64::read(&mut data).unwrap(), 1); - assert!(data.is_empty()); + assert_eq!(data, b""); } #[test] @@ -466,7 +466,7 @@ mod tests { assert_eq!(i64::read(&mut data).unwrap(), 0); assert_eq!(data.len(), 8); assert_eq!(i64::read(&mut data).unwrap(), 1); - assert!(data.is_empty()); + assert_eq!(data, b""); // Negative (-1 = 0xffffffffffffffff in two's complement) let mut data: &[u8] = &[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]; @@ -574,7 +574,7 @@ mod tests { let mut cursor: &[u8] = &buf; let decoded = <[u8; 5]>::read(&mut cursor).unwrap(); assert_eq!(decoded, original); - assert!(cursor.is_empty()); + assert_eq!(cursor, b""); } #[test] @@ -620,7 +620,7 @@ mod tests { let mut cursor: &[u8] = &buf; let decoded = PublicKey::read(&mut cursor).unwrap(); assert_eq!(decoded, pk); - assert!(cursor.is_empty()); + assert_eq!(cursor, b""); } #[test] @@ -633,7 +633,7 @@ mod tests { let mut cursor: &[u8] = &buf; let decoded = ChannelId::read(&mut cursor).unwrap(); assert_eq!(decoded, original); - assert!(cursor.is_empty()); + assert_eq!(cursor, b""); } #[test] @@ -666,7 +666,7 @@ mod tests { let mut cursor: &[u8] = &buf; let decoded = ShortChannelId::read(&mut cursor).unwrap(); assert_eq!(decoded, scid); - assert!(cursor.is_empty()); + assert_eq!(cursor, b""); } #[test] @@ -694,7 +694,7 @@ mod tests { let mut data: &[u8] = &[0x00, 0x00]; let result = Vec::::read(&mut data).unwrap(); assert_eq!(result, Vec::::new()); - assert!(data.is_empty()); + assert_eq!(data, b""); } #[test] @@ -702,7 +702,7 @@ mod tests { let mut data: &[u8] = &[0x00, 0x03, 0xaa, 0xbb, 0xcc]; let result = Vec::::read(&mut data).unwrap(); assert_eq!(result, vec![0xaa, 0xbb, 0xcc]); - assert!(data.is_empty()); + assert_eq!(data, b""); } #[test] @@ -746,7 +746,7 @@ mod tests { let mut cursor: &[u8] = &buf; let decoded = Vec::::read(&mut cursor).unwrap(); assert_eq!(decoded, original); - assert!(cursor.is_empty()); + assert_eq!(cursor, b""); } #[test] @@ -784,7 +784,7 @@ mod tests { let bs = BigSize::read(&mut cursor).expect("valid bigsize"); assert_eq!(bs.value(), *expected, "decoding {bytes:02x?}"); assert_eq!(bs.len(), bytes.len()); - assert!(cursor.is_empty()); + assert_eq!(cursor, b""); } } @@ -837,7 +837,7 @@ mod tests { let decoded = BigSize::read(&mut cursor).expect("valid bigsize"); assert_eq!(value, decoded.value()); assert_eq!(bs.len(), encoded.len()); - assert!(cursor.is_empty()); + assert_eq!(cursor, b""); } } @@ -958,7 +958,7 @@ mod tests { let mut cursor: &[u8] = &buf; let decoded = Txid::read(&mut cursor).unwrap(); assert_eq!(decoded, txid); - assert!(cursor.is_empty()); + assert_eq!(cursor, b""); } #[test] @@ -1007,7 +1007,7 @@ mod tests { let mut cursor: &[u8] = &buf; let decoded = Signature::read(&mut cursor).unwrap(); assert_eq!(decoded, sig); - assert!(cursor.is_empty()); + assert_eq!(cursor, b""); } #[test] @@ -1042,7 +1042,7 @@ mod tests { let mut cursor: &[u8] = &buf; let decoded = sha256::Hash::read(&mut cursor).unwrap(); assert_eq!(decoded, hash); - assert!(cursor.is_empty()); + assert_eq!(cursor, b""); } #[test] diff --git a/smitebot/src/commands/start.rs b/smitebot/src/commands/start.rs index d6e21731..b3aa2fea 100644 --- a/smitebot/src/commands/start.rs +++ b/smitebot/src/commands/start.rs @@ -1038,7 +1038,7 @@ sharedir = "{}" fn ir_mutator_envs_empty_for_non_ir_scenario() { let dir = tempfile::tempdir().unwrap(); let config = sample_config(dir.path()); - assert!(ir_mutator_envs(&config).is_empty()); + assert_eq!(ir_mutator_envs(&config), []); } fn sample_config(dir: &Path) -> CampaignConfig { diff --git a/smitebot/src/config.rs b/smitebot/src/config.rs index a5c4ebf6..bce8e551 100644 --- a/smitebot/src/config.rs +++ b/smitebot/src/config.rs @@ -457,7 +457,7 @@ sharedir = "/tmp/smite-nyx" let config = CampaignConfig::load(&path).unwrap(); assert!(config.afl_env.is_empty()); - assert!(config.afl_flags.is_empty()); + assert_eq!(config.afl_flags, Vec::::new()); } #[test]