Skip to content

Commit 9cfd18c

Browse files
committed
ln/refactor: move hex test helpers from blinded payments to test_utils
1 parent 2b92b08 commit 9cfd18c

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// You may not use this file except in accordance with one or both of these
1010
// licenses.
1111

12-
use bitcoin::hashes::hex::FromHex;
1312
use bitcoin::hex::DisplayHex;
1413
use bitcoin::secp256k1::{PublicKey, Scalar, Secp256k1, SecretKey, schnorr};
1514
use bitcoin::secp256k1::ecdh::SharedSecret;
@@ -37,7 +36,7 @@ use crate::routing::router::{BlindedTail, Path, Payee, PaymentParameters, RouteH
3736
use crate::sign::{NodeSigner, PeerStorageKey, ReceiveAuthKey, Recipient};
3837
use crate::util::config::UserConfig;
3938
use crate::util::ser::{WithoutLength, Writeable};
40-
use crate::util::test_utils;
39+
use crate::util::test_utils::{self, bytes_from_hex, secret_from_hex, pubkey_from_hex};
4140
use lightning_invoice::RawBolt11Invoice;
4241
use types::features::Features;
4342
use crate::blinded_path::BlindedHop;
@@ -1495,18 +1494,6 @@ fn blinded_payment_path_padding() {
14951494
claim_payment(&nodes[0], &[&nodes[1], &nodes[2], &nodes[3], &nodes[4]], payment_preimage);
14961495
}
14971496

1498-
fn secret_from_hex(hex: &str) -> SecretKey {
1499-
SecretKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()).unwrap()
1500-
}
1501-
1502-
fn bytes_from_hex(hex: &str) -> Vec<u8> {
1503-
<Vec<u8>>::from_hex(hex).unwrap()
1504-
}
1505-
1506-
fn pubkey_from_hex(hex: &str) -> PublicKey {
1507-
PublicKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()).unwrap()
1508-
}
1509-
15101497
fn update_add_msg(
15111498
amount_msat: u64, cltv_expiry: u32, blinding_point: Option<PublicKey>,
15121499
onion_routing_packet: msgs::OnionPacket

lightning/src/util/test_utils.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ use bitcoin::block::Block;
6767
use bitcoin::constants::genesis_block;
6868
use bitcoin::constants::ChainHash;
6969
use bitcoin::hash_types::{BlockHash, Txid};
70-
use bitcoin::hashes::Hash;
70+
use bitcoin::hashes::{hex::FromHex, Hash};
7171
use bitcoin::network::Network;
7272
use bitcoin::script::{Builder, Script, ScriptBuf};
7373
use bitcoin::sighash::{EcdsaSighashType, SighashCache};
@@ -107,6 +107,18 @@ pub fn privkey(byte: u8) -> SecretKey {
107107
SecretKey::from_slice(&[byte; 32]).unwrap()
108108
}
109109

110+
pub fn secret_from_hex(hex: &str) -> SecretKey {
111+
SecretKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()).unwrap()
112+
}
113+
114+
pub fn bytes_from_hex(hex: &str) -> Vec<u8> {
115+
<Vec<u8>>::from_hex(hex).unwrap()
116+
}
117+
118+
pub fn pubkey_from_hex(hex: &str) -> PublicKey {
119+
PublicKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()).unwrap()
120+
}
121+
110122
pub struct TestVecWriter(pub Vec<u8>);
111123
impl Writer for TestVecWriter {
112124
fn write_all(&mut self, buf: &[u8]) -> Result<(), io::Error> {

0 commit comments

Comments
 (0)