Skip to content

Commit

Permalink
Extend test with old serialized updates
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tnull committed Jul 18, 2022
1 parent 9b523ad commit 331996b
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions lightning/src/routing/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2953,7 +2953,6 @@ mod tests {
let node_chanmgrs = ::ln::functional_test_utils::create_node_chanmgrs(2, &node_cfgs, &[None, None, None, None]);
let nodes = ::ln::functional_test_utils::create_network(2, &node_cfgs, &node_chanmgrs);

// First make sure we can encode/decode ChannelUpdateInfo.
let chan_update_info = ChannelUpdateInfo {
last_update: 23,
enabled: true,
Expand All @@ -2964,17 +2963,23 @@ mod tests {
last_update_message: None,
};

let mut buf: Vec<u8> = Vec::new();
assert!(chan_update_info.write(&mut buf).is_ok());
let mut encoded_chan_update_info: Vec<u8> = Vec::new();
assert!(chan_update_info.write(&mut encoded_chan_update_info).is_ok());

let read_chan_update_info_result: Option<ChannelUpdateInfo> = ::util::ser::MaybeReadable::read(&mut buf.as_slice()).unwrap();
if let Some(read_chan_update_info) = read_chan_update_info_result {
assert_eq!(chan_update_info, read_chan_update_info);
} else {
panic!();
}
// First make sure we can read ChannelUpdateInfos we just wrote
let read_chan_update_info: ChannelUpdateInfo = ::util::ser::Readable::read(&mut encoded_chan_update_info.as_slice()).unwrap();
assert_eq!(chan_update_info, read_chan_update_info);

// Check the serialization hasn't changed.
let old_chan_update_info_with_some: Vec<u8> = hex::decode("340004000000170201010402002a060800000000000004d2080909000000000000162e0a0d0c00040000000902040000000a0c0100").unwrap();
assert_eq!(encoded_chan_update_info, old_chan_update_info_with_some);

// Then check we can encode/decode ChannelInfo without ChannelUpdateInfo fields present.
// Check we fail if htlc_maximum_msat is not present.
let old_chan_update_info_with_none: Vec<u8> = hex::decode("2c0004000000170201010402002a060800000000000004d20801000a0d0c00040000000902040000000a0c0100").unwrap();
let read_chan_update_info_res: Result<ChannelUpdateInfo, ::ln::msgs::DecodeError> = ::util::ser::Readable::read(&mut old_chan_update_info_with_none.as_slice());
assert!(read_chan_update_info_res.is_err());

// Check we can encode/decode ChannelInfo without ChannelUpdateInfo fields present.
let chan_info_none_updates = ChannelInfo {
features: ChannelFeatures::known(),
node_one: NodeId::from_pubkey(&nodes[0].node.get_our_node_id()),
Expand All @@ -2986,10 +2991,10 @@ mod tests {
announcement_received_time: 87654,
};

let mut buf: Vec<u8> = Vec::new();
assert!(chan_info_none_updates.write(&mut buf).is_ok());
let mut encoded_chan_info: Vec<u8> = Vec::new();
assert!(chan_info_none_updates.write(&mut encoded_chan_info).is_ok());

let read_chan_info: ChannelInfo = ::util::ser::Readable::read(&mut buf.as_slice()).unwrap();
let read_chan_info: ChannelInfo = ::util::ser::Readable::read(&mut encoded_chan_info.as_slice()).unwrap();
assert_eq!(chan_info_none_updates, read_chan_info);

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

let mut buf: Vec<u8> = Vec::new();
assert!(chan_info_some_updates.write(&mut buf).is_ok());
let mut encoded_chan_info: Vec<u8> = Vec::new();
assert!(chan_info_some_updates.write(&mut encoded_chan_info).is_ok());

let read_chan_info: ChannelInfo = ::util::ser::Readable::read(&mut buf.as_slice()).unwrap();
let read_chan_info: ChannelInfo = ::util::ser::Readable::read(&mut encoded_chan_info.as_slice()).unwrap();
assert_eq!(chan_info_some_updates, read_chan_info);
}
}
Expand Down

0 comments on commit 331996b

Please sign in to comment.