Skip to content

Commit af8ff1b

Browse files
Aditya Sharmaadi2011
Aditya Sharma
authored andcommitted
Add test for peer storage handling
This test ensures that PeerStorage & PeerStorageRetrieval handling behaves as expected. It simulates receiving a dummy peer storage message, disconnecting and reconnecting peers, and validates that the correct messages are exchanged during reestablishment. - Added a test case `test_peer_storage` to verify the handling of `PeerStorageMessage` and the validation of warning messages in the event of invalid peer storage retrieval. - Simulated peer storage retrieval upon reconnection between nodes. - Validated that a warning message is generated when `PeerStorageRetrievalMessage` is received. - Ensured the warning message contains the expected error description.
1 parent 948a2ad commit af8ff1b

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

lightning/src/ln/channelmanager.rs

+64
Original file line numberDiff line numberDiff line change
@@ -14808,6 +14808,70 @@ mod tests {
1480814808
}
1480914809
}
1481014810

14811+
#[test]
14812+
fn test_peer_storage() {
14813+
let chanmon_cfgs = create_chanmon_cfgs(2);
14814+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
14815+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
14816+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
14817+
14818+
create_announced_chan_between_nodes(&nodes, 0, 1);
14819+
14820+
// Since we do not send peer storage, we manually simulate receiving a dummy
14821+
// `PeerStorage` from the channel partner.
14822+
nodes[0].node.handle_peer_storage(nodes[1].node.get_our_node_id(), msgs::PeerStorage{data: vec![0; 100]});
14823+
14824+
nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id());
14825+
nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id());
14826+
14827+
nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init {
14828+
features: nodes[1].node.init_features(), networks: None, remote_network_address: None
14829+
}, true).unwrap();
14830+
nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init {
14831+
features: nodes[0].node.init_features(), networks: None, remote_network_address: None
14832+
}, false).unwrap();
14833+
14834+
let node_0_events = nodes[0].node.get_and_clear_pending_msg_events();
14835+
assert_eq!(node_0_events.len(), 2);
14836+
14837+
for msg in node_0_events{
14838+
if let MessageSendEvent::SendChannelReestablish { ref node_id, ref msg } = msg {
14839+
nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), msg);
14840+
assert_eq!(*node_id, nodes[1].node.get_our_node_id());
14841+
} else if let MessageSendEvent::SendPeerStorageRetrieval { ref node_id, ref msg } = msg {
14842+
nodes[1].node.handle_peer_storage_retrieval(nodes[0].node.get_our_node_id(), msg.clone());
14843+
assert_eq!(*node_id, nodes[1].node.get_our_node_id());
14844+
} else {
14845+
panic!("Unexpected event")
14846+
}
14847+
}
14848+
14849+
let msg_events_after_peer_storage_retrieval = nodes[1].node.get_and_clear_pending_msg_events();
14850+
14851+
// Check if we receive a warning message.
14852+
let peer_storage_warning: Vec<&MessageSendEvent> = msg_events_after_peer_storage_retrieval
14853+
.iter()
14854+
.filter(|event| match event {
14855+
MessageSendEvent::HandleError { .. } => true,
14856+
_ => false,
14857+
})
14858+
.collect();
14859+
14860+
assert_eq!(peer_storage_warning.len(), 1);
14861+
14862+
match peer_storage_warning[0] {
14863+
MessageSendEvent::HandleError { node_id, action } => {
14864+
assert_eq!(*node_id, nodes[0].node.get_our_node_id());
14865+
match action {
14866+
ErrorAction::SendWarningMessage { msg, .. } =>
14867+
assert_eq!(msg.data, "Invalid peer_storage_retrieval message received.".to_owned()),
14868+
_ => panic!("Unexpected error action"),
14869+
}
14870+
}
14871+
_ => panic!("Unexpected event"),
14872+
}
14873+
}
14874+
1481114875
#[test]
1481214876
fn test_keysend_dup_payment_hash() {
1481314877
// (1): Test that a keysend payment with a duplicate payment hash to an existing pending

0 commit comments

Comments
 (0)