Skip to content

Commit 3a46ad3

Browse files
committed
Change Display for ChannelId to avoid allocation, add unit test
1 parent ef25201 commit 3a46ad3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lightning/src/ln/channel.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ impl ToHex for ChannelId {
674674

675675
impl fmt::Display for ChannelId {
676676
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
677-
f.write_str(&self.to_hex())
677+
crate::util::logger::DebugBytes(&self.data).fmt(f)
678678
}
679679
}
680680

@@ -7601,6 +7601,12 @@ mod tests {
76017601
assert_eq!(channel_id_2.bytes(), &data);
76027602
}
76037603

7604+
#[test]
7605+
fn test_channel_id_display() {
7606+
let channel_id = ChannelId::from_bytes([42; 32]);
7607+
assert_eq!(format!("{}", &channel_id), "2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a");
7608+
}
7609+
76047610
#[test]
76057611
fn test_max_funding_satoshis_no_wumbo() {
76067612
assert_eq!(TOTAL_BITCOIN_SUPPLY_SATOSHIS, 21_000_000 * 100_000_000);

0 commit comments

Comments
 (0)