Skip to content

Commit b5537e8

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 b5537e8

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lightning/src/ln/types.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ mod tests {
149149
#[test]
150150
fn test_channel_id_v1_from_funding_txid() {
151151
let channel_id = ChannelId::v1_from_funding_txid(&[2; 32], 1);
152-
assert_eq!(channel_id.0.as_hex().to_string(), "0202020202020202020202020202020202020202020202020202020202020203");
152+
let expected = "0202020202020202020202020202020202020202020202020202020202020203";
153+
assert_eq!(channel_id.0.as_hex().to_string(), expected);
153154
}
154155

155156
#[test]
@@ -184,14 +185,17 @@ mod tests {
184185
#[test]
185186
fn test_channel_id_display() {
186187
let channel_id = ChannelId::v1_from_funding_txid(&[2; 32], 1);
187-
assert_eq!(format!("{}", &channel_id), "0202020202020202020202020202020202020202020202020202020202020203");
188+
let expected = "0202020202020202020202020202020202020202020202020202020202020203";
189+
assert_eq!(format!("{}", &channel_id), expected);
188190
}
189191

190192
#[test]
191193
fn test_channel_id_v2_from_basepoints() {
192194
// 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());
195+
let our_pk = "0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c";
196+
let ours = RevocationBasepoint(PublicKey::from_str(&our_pk).unwrap());
197+
let their_pk = "02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619";
198+
let theirs = RevocationBasepoint(PublicKey::from_str(&their_pk).unwrap());
195199

196200
let mut engine = Sha256::engine();
197201
engine.input(&theirs.0.serialize());
@@ -201,8 +205,10 @@ mod tests {
201205
assert_eq!(ChannelId::v2_from_revocation_basepoints(&ours, &theirs), expected_id);
202206

203207
// 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());
208+
let our_pk = "027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007";
209+
let ours = RevocationBasepoint(PublicKey::from_str(&our_pk).unwrap());
210+
let their_pk = "02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619";
211+
let theirs = RevocationBasepoint(PublicKey::from_str(&their_pk).unwrap());
206212

207213
let mut engine = Sha256::engine();
208214
engine.input(&ours.0.serialize());

0 commit comments

Comments
 (0)