Skip to content

Commit 331996b

Browse files
committed
Extend test with old serialized updates
We now also check that the serialization format has not changed and suceed/fail to read the updates depending on whether `htlc_maximum_msat` is present.
1 parent 9b523ad commit 331996b

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

lightning/src/routing/gossip.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2953,7 +2953,6 @@ mod tests {
29532953
let node_chanmgrs = ::ln::functional_test_utils::create_node_chanmgrs(2, &node_cfgs, &[None, None, None, None]);
29542954
let nodes = ::ln::functional_test_utils::create_network(2, &node_cfgs, &node_chanmgrs);
29552955

2956-
// First make sure we can encode/decode ChannelUpdateInfo.
29572956
let chan_update_info = ChannelUpdateInfo {
29582957
last_update: 23,
29592958
enabled: true,
@@ -2964,17 +2963,23 @@ mod tests {
29642963
last_update_message: None,
29652964
};
29662965

2967-
let mut buf: Vec<u8> = Vec::new();
2968-
assert!(chan_update_info.write(&mut buf).is_ok());
2966+
let mut encoded_chan_update_info: Vec<u8> = Vec::new();
2967+
assert!(chan_update_info.write(&mut encoded_chan_update_info).is_ok());
29692968

2970-
let read_chan_update_info_result: Option<ChannelUpdateInfo> = ::util::ser::MaybeReadable::read(&mut buf.as_slice()).unwrap();
2971-
if let Some(read_chan_update_info) = read_chan_update_info_result {
2972-
assert_eq!(chan_update_info, read_chan_update_info);
2973-
} else {
2974-
panic!();
2975-
}
2969+
// First make sure we can read ChannelUpdateInfos we just wrote
2970+
let read_chan_update_info: ChannelUpdateInfo = ::util::ser::Readable::read(&mut encoded_chan_update_info.as_slice()).unwrap();
2971+
assert_eq!(chan_update_info, read_chan_update_info);
2972+
2973+
// Check the serialization hasn't changed.
2974+
let old_chan_update_info_with_some: Vec<u8> = hex::decode("340004000000170201010402002a060800000000000004d2080909000000000000162e0a0d0c00040000000902040000000a0c0100").unwrap();
2975+
assert_eq!(encoded_chan_update_info, old_chan_update_info_with_some);
29762976

2977-
// Then check we can encode/decode ChannelInfo without ChannelUpdateInfo fields present.
2977+
// Check we fail if htlc_maximum_msat is not present.
2978+
let old_chan_update_info_with_none: Vec<u8> = hex::decode("2c0004000000170201010402002a060800000000000004d20801000a0d0c00040000000902040000000a0c0100").unwrap();
2979+
let read_chan_update_info_res: Result<ChannelUpdateInfo, ::ln::msgs::DecodeError> = ::util::ser::Readable::read(&mut old_chan_update_info_with_none.as_slice());
2980+
assert!(read_chan_update_info_res.is_err());
2981+
2982+
// Check we can encode/decode ChannelInfo without ChannelUpdateInfo fields present.
29782983
let chan_info_none_updates = ChannelInfo {
29792984
features: ChannelFeatures::known(),
29802985
node_one: NodeId::from_pubkey(&nodes[0].node.get_our_node_id()),
@@ -2986,10 +2991,10 @@ mod tests {
29862991
announcement_received_time: 87654,
29872992
};
29882993

2989-
let mut buf: Vec<u8> = Vec::new();
2990-
assert!(chan_info_none_updates.write(&mut buf).is_ok());
2994+
let mut encoded_chan_info: Vec<u8> = Vec::new();
2995+
assert!(chan_info_none_updates.write(&mut encoded_chan_info).is_ok());
29912996

2992-
let read_chan_info: ChannelInfo = ::util::ser::Readable::read(&mut buf.as_slice()).unwrap();
2997+
let read_chan_info: ChannelInfo = ::util::ser::Readable::read(&mut encoded_chan_info.as_slice()).unwrap();
29932998
assert_eq!(chan_info_none_updates, read_chan_info);
29942999

29953000
// Finally check we can encode/decode ChannelInfo with ChannelUpdateInfo fields present.
@@ -3004,10 +3009,10 @@ mod tests {
30043009
announcement_received_time: 87654,
30053010
};
30063011

3007-
let mut buf: Vec<u8> = Vec::new();
3008-
assert!(chan_info_some_updates.write(&mut buf).is_ok());
3012+
let mut encoded_chan_info: Vec<u8> = Vec::new();
3013+
assert!(chan_info_some_updates.write(&mut encoded_chan_info).is_ok());
30093014

3010-
let read_chan_info: ChannelInfo = ::util::ser::Readable::read(&mut buf.as_slice()).unwrap();
3015+
let read_chan_info: ChannelInfo = ::util::ser::Readable::read(&mut encoded_chan_info.as_slice()).unwrap();
30113016
assert_eq!(chan_info_some_updates, read_chan_info);
30123017
}
30133018
}

0 commit comments

Comments
 (0)