Skip to content

Commit 2ffcdf9

Browse files
committed
Clean up types.rs hex deser to use more intermediate variables
...preventing rustfmt from making a mockery of our code.
1 parent a979d08 commit 2ffcdf9

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

lightning/src/ln/types.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ mod tests {
133133
use bitcoin::hashes::{
134134
Hash as _,
135135
HashEngine as _,
136-
hex::FromHex as _,
137136
sha256::Hash as Sha256,
138137
};
139138
use bitcoin::secp256k1::PublicKey;
@@ -146,10 +145,13 @@ mod tests {
146145
use crate::prelude::*;
147146
use crate::io;
148147

148+
use core::str::FromStr;
149+
149150
#[test]
150151
fn test_channel_id_v1_from_funding_txid() {
151152
let channel_id = ChannelId::v1_from_funding_txid(&[2; 32], 1);
152-
assert_eq!(channel_id.0.as_hex().to_string(), "0202020202020202020202020202020202020202020202020202020202020203");
153+
let expected = "0202020202020202020202020202020202020202020202020202020202020203";
154+
assert_eq!(channel_id.0.as_hex().to_string(), expected);
153155
}
154156

155157
#[test]
@@ -184,14 +186,17 @@ mod tests {
184186
#[test]
185187
fn test_channel_id_display() {
186188
let channel_id = ChannelId::v1_from_funding_txid(&[2; 32], 1);
187-
assert_eq!(format!("{}", &channel_id), "0202020202020202020202020202020202020202020202020202020202020203");
189+
let expected = "0202020202020202020202020202020202020202020202020202020202020203";
190+
assert_eq!(format!("{}", &channel_id), expected);
188191
}
189192

190193
#[test]
191194
fn test_channel_id_v2_from_basepoints() {
192195
// Ours greater than theirs
193-
let ours = RevocationBasepoint(PublicKey::from_slice(&<Vec<u8>>::from_hex("0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c").unwrap()[..]).unwrap());
194-
let theirs = RevocationBasepoint(PublicKey::from_slice(&<Vec<u8>>::from_hex("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").unwrap()[..]).unwrap());
196+
let our_pk = "0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c";
197+
let ours = RevocationBasepoint(PublicKey::from_str(&our_pk).unwrap());
198+
let their_pk = "02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619";
199+
let theirs = RevocationBasepoint(PublicKey::from_str(&their_pk).unwrap());
195200

196201
let mut engine = Sha256::engine();
197202
engine.input(&theirs.0.serialize());
@@ -201,8 +206,10 @@ mod tests {
201206
assert_eq!(ChannelId::v2_from_revocation_basepoints(&ours, &theirs), expected_id);
202207

203208
// Theirs greater than ours
204-
let ours = RevocationBasepoint(PublicKey::from_slice(&<Vec<u8>>::from_hex("027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007").unwrap()[..]).unwrap());
205-
let theirs = RevocationBasepoint(PublicKey::from_slice(&<Vec<u8>>::from_hex("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").unwrap()[..]).unwrap());
209+
let our_pk = "027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007";
210+
let ours = RevocationBasepoint(PublicKey::from_str(&our_pk).unwrap());
211+
let their_pk = "02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619";
212+
let theirs = RevocationBasepoint(PublicKey::from_str(&their_pk).unwrap());
206213

207214
let mut engine = Sha256::engine();
208215
engine.input(&ours.0.serialize());

0 commit comments

Comments
 (0)