Update `test_peer_storage` style to match newer tests
What changed, and why it matters
This commit is a minor cleanup of a single test file. It introduces local variables for node IDs and reuses an Init message object to make the test code shorter and more readable. There is no change to production code or to the test's actual behavior.
No security action needed; this is a non-functional test refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies only lightning/src/ln/reload_tests.rs, specifically the test_peer_storage unit test. It replaces repeated calls to nodes[i].node.get_our_node_id() with pre-bound node_a_id/node_b_id variables, factors out a duplicated msgs::Init construction, and adjusts rustfmt formatting. No functional logic, assertions, or panic expectations were changed.
Changed components
lightning/src/ln/reload_tests.rsInspect captured patch +19 / −35
diff --git a/lightning/src/ln/reload_tests.rs b/lightning/src/ln/reload_tests.rs
index 66e7ec6..bc2cbc6 100644
--- a/lightning/src/ln/reload_tests.rs
+++ b/lightning/src/ln/reload_tests.rs
@@ -1318,6 +1318,9 @@ fn test_peer_storage() {
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
+ let node_a_id = nodes[0].node.get_our_node_id();
+ let node_b_id = nodes[1].node.get_our_node_id();
+
let (_, _, cid, _) = create_announced_chan_between_nodes(&nodes, 0, 1);
send_payment(&nodes[0], &[&nodes[1]], 1000);
let nodes_0_serialized = nodes[0].node.encode();
@@ -1339,8 +1342,8 @@ fn test_peer_storage() {
for ps_msg in peer_storage_msg_events_node0 {
match ps_msg {
MessageSendEvent::SendPeerStorage { ref node_id, ref msg } => {
- assert_eq!(*node_id, nodes[1].node.get_our_node_id());
- nodes[1].node.handle_peer_storage(nodes[0].node.get_our_node_id(), msg.clone());
+ assert_eq!(*node_id, node_b_id);
+ nodes[1].node.handle_peer_storage(node_a_id, msg.clone());
},
_ => panic!("Unexpected event"),
}
@@ -1349,15 +1352,15 @@ fn test_peer_storage() {
for ps_msg in peer_storage_msg_events_node1 {
match ps_msg {
MessageSendEvent::SendPeerStorage { ref node_id, ref msg } => {
- assert_eq!(*node_id, nodes[0].node.get_our_node_id());
- nodes[0].node.handle_peer_storage(nodes[1].node.get_our_node_id(), msg.clone());
+ assert_eq!(*node_id, node_a_id);
+ nodes[0].node.handle_peer_storage(node_b_id, msg.clone());
},
_ => panic!("Unexpected event"),
}
}
- nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id());
- nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id());
+ nodes[0].node.peer_disconnected(node_b_id);
+ nodes[1].node.peer_disconnected(node_a_id);
// Reload Node!
// TODO: Handle the case where we've completely forgotten about an active channel.
@@ -1371,31 +1374,14 @@ fn test_peer_storage() {
nodes_0_deserialized
);
- nodes[0]
- .node
- .peer_connected(
- nodes[1].node.get_our_node_id(),
- &msgs::Init {
- features: nodes[1].node.init_features(),
- networks: None,
- remote_network_address: None,
- },
- true,
- )
- .unwrap();
+ let init_msg = msgs::Init {
+ features: nodes[1].node.init_features(),
+ networks: None,
+ remote_network_address: None,
+ };
- nodes[1]
- .node
- .peer_connected(
- nodes[0].node.get_our_node_id(),
- &msgs::Init {
- features: nodes[0].node.init_features(),
- networks: None,
- remote_network_address: None,
- },
- false,
- )
- .unwrap();
+ nodes[0].node.peer_connected(node_b_id, &init_msg, true).unwrap();
+ nodes[1].node.peer_connected(node_a_id, &init_msg, true).unwrap();
let node_1_events = nodes[1].node.get_and_clear_pending_msg_events();
assert_eq!(node_1_events.len(), 2);
@@ -1405,19 +1391,17 @@ fn test_peer_storage() {
match node_0_events[0] {
MessageSendEvent::SendChannelReestablish { ref node_id, .. } => {
- assert_eq!(*node_id, nodes[1].node.get_our_node_id());
+ assert_eq!(*node_id, node_b_id);
// nodes[0] would send a stale channel reestablish, so there's no need to handle this.
},
_ => panic!("Unexpected event"),
}
if let MessageSendEvent::SendPeerStorageRetrieval { node_id, msg } = &node_1_events[0] {
- assert_eq!(*node_id, nodes[0].node.get_our_node_id());
+ assert_eq!(*node_id, node_a_id);
// Should Panic here!
let res = std::panic::catch_unwind(|| {
- nodes[0]
- .node
- .handle_peer_storage_retrieval(nodes[1].node.get_our_node_id(), msg.clone())
+ nodes[0].node.handle_peer_storage_retrieval(node_b_id, msg.clone());
});
assert!(res.is_err());
} else {
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.