ln/refactor: move hex test helpers from blinded payments to test_utils
What changed, and why it matters
This commit is a simple code cleanup: it moves three small helper functions used only in tests from one test file into a shared test utility file. There is no change to production code, no security fix, and no behavior change.
No action needed; this is a non-functional test refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors three hex-parsing helper functions (secret_from_hex, bytes_from_hex, pubkey_from_hex) out of lightning/src/ln/blinded_payment_tests.rs and into lightning/src/util/test_utils.rs as pub helpers. It updates the import in the original file and adds the required FromHex import in test_utils.rs. The functions are identical and remain test-only code.
Changed components
lightning/src/ln/blinded_payment_tests.rslightning/src/util/test_utils.rsInspect captured patch +14 / −15
diff --git a/lightning/src/ln/blinded_payment_tests.rs b/lightning/src/ln/blinded_payment_tests.rs
index cfb2878..dd04799 100644
--- a/lightning/src/ln/blinded_payment_tests.rs
+++ b/lightning/src/ln/blinded_payment_tests.rs
@@ -9,7 +9,6 @@
// You may not use this file except in accordance with one or both of these
// licenses.
-use bitcoin::hashes::hex::FromHex;
use bitcoin::hex::DisplayHex;
use bitcoin::secp256k1::{PublicKey, Scalar, Secp256k1, SecretKey, schnorr};
use bitcoin::secp256k1::ecdh::SharedSecret;
@@ -37,7 +36,7 @@ use crate::routing::router::{BlindedTail, Path, Payee, PaymentParameters, RouteH
use crate::sign::{NodeSigner, PeerStorageKey, ReceiveAuthKey, Recipient};
use crate::util::config::UserConfig;
use crate::util::ser::{WithoutLength, Writeable};
-use crate::util::test_utils;
+use crate::util::test_utils::{self, bytes_from_hex, secret_from_hex, pubkey_from_hex};
use lightning_invoice::RawBolt11Invoice;
use types::features::Features;
use crate::blinded_path::BlindedHop;
@@ -1495,18 +1494,6 @@ fn blinded_payment_path_padding() {
claim_payment(&nodes[0], &[&nodes[1], &nodes[2], &nodes[3], &nodes[4]], payment_preimage);
}
-fn secret_from_hex(hex: &str) -> SecretKey {
- SecretKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()).unwrap()
-}
-
-fn bytes_from_hex(hex: &str) -> Vec<u8> {
- <Vec<u8>>::from_hex(hex).unwrap()
-}
-
-fn pubkey_from_hex(hex: &str) -> PublicKey {
- PublicKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()).unwrap()
-}
-
fn update_add_msg(
amount_msat: u64, cltv_expiry: u32, blinding_point: Option<PublicKey>,
onion_routing_packet: msgs::OnionPacket
diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs
index e195b48..8e89078 100644
--- a/lightning/src/util/test_utils.rs
+++ b/lightning/src/util/test_utils.rs
@@ -67,7 +67,7 @@ use bitcoin::block::Block;
use bitcoin::constants::genesis_block;
use bitcoin::constants::ChainHash;
use bitcoin::hash_types::{BlockHash, Txid};
-use bitcoin::hashes::Hash;
+use bitcoin::hashes::{hex::FromHex, Hash};
use bitcoin::network::Network;
use bitcoin::script::{Builder, Script, ScriptBuf};
use bitcoin::sighash::{EcdsaSighashType, SighashCache};
@@ -107,6 +107,18 @@ pub fn privkey(byte: u8) -> SecretKey {
SecretKey::from_slice(&[byte; 32]).unwrap()
}
+pub fn secret_from_hex(hex: &str) -> SecretKey {
+ SecretKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()).unwrap()
+}
+
+pub fn bytes_from_hex(hex: &str) -> Vec<u8> {
+ <Vec<u8>>::from_hex(hex).unwrap()
+}
+
+pub fn pubkey_from_hex(hex: &str) -> PublicKey {
+ PublicKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()).unwrap()
+}
+
pub struct TestVecWriter(pub Vec<u8>);
impl Writer for TestVecWriter {
fn write_all(&mut self, buf: &[u8]) -> Result<(), io::Error> {
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.