From 490db5dfe084a898ac04de6d8bdfb900d0494f1c Mon Sep 17 00:00:00 2001 From: Roland Sherwin Date: Mon, 12 Feb 2024 16:40:38 +0530 Subject: [PATCH] feat(test): assert PeerIds are not the same after restart --- sn_node/tests/common/mod.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sn_node/tests/common/mod.rs b/sn_node/tests/common/mod.rs index 4270a49750..7a34b18cbe 100644 --- a/sn_node/tests/common/mod.rs +++ b/sn_node/tests/common/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2024 MaidSafe.net limited. +// Copyright 2023 MaidSafe.net limited. // // This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. // Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed @@ -106,6 +106,7 @@ pub async fn get_all_peer_ids(node_rpc_addresses: &Vec) -> Result Result<()> { let mut rpc_client = get_safenode_rpc_client(*addr).await?; @@ -113,6 +114,7 @@ pub async fn node_restart(addr: &SocketAddr) -> Result<()> { .node_info(Request::new(NodeInfoRequest {})) .await?; let root_dir = Path::new(&response.get_ref().data_dir); + let previous_peer_id = PeerId::from_bytes(&response.get_ref().peer_id)?; debug!("Obtained root dir from node {root_dir:?}."); let record_store = root_dir.join("record_store"); @@ -141,5 +143,16 @@ pub async fn node_restart(addr: &SocketAddr) -> Result<()> { println!("Node restart requested to RPC service at {addr}"); info!("Node restart requested to RPC service at {addr}"); + tokio::time::sleep(Duration::from_secs(5)).await; + println!("Verifying if the node restarted with a different PeerId"); + info!("Verifying if the node restarted with a different PeerId"); + let response = rpc_client + .node_info(Request::new(NodeInfoRequest {})) + .await?; + let current_peer_id = PeerId::from_bytes(&response.get_ref().peer_id)?; + if current_peer_id == previous_peer_id { + bail!("The PeerIds are not the same after restart. previous: {previous_peer_id:?}, current: {current_peer_id:?}"); + } + Ok(()) }