Skip to content

Commit

Permalink
Asserts that addresses parse into SocketAddr
Browse files Browse the repository at this point in the history
  • Loading branch information
arya2 committed Jan 17, 2023
1 parent 7b72395 commit 493412f
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions zebrad/tests/common/get_block_template_rpcs/get_peer_info.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
//! Tests that `getpeerinfo` RPC method responds with info about at least 1 peer.
use std::net::SocketAddr;

use color_eyre::eyre::{Context, Result};

use zebra_chain::parameters::Network;
use zebra_rpc::methods::get_block_template_rpcs::types::peer_info::PeerInfo;
use zebra_test::args;

use crate::common::{
Expand Down Expand Up @@ -35,26 +38,28 @@ pub(crate) async fn run() -> Result<()> {
tracing::info!(?rpc_address, "zebrad opened its RPC port",);

// call `getpeerinfo` RPC method
let res = RPCRequestClient::new(rpc_address)
.call("getpeerinfo", "[]".to_string())
let peer_info_result: Vec<PeerInfo> = RPCRequestClient::new(rpc_address)
.json_result_from_call("getpeerinfo", "[]".to_string())
.await?;

// Test rpc endpoint response
assert!(res.status().is_success());
assert!(
!peer_info_result.is_empty(),
"getpeerinfo should return info for at least 1 peer"
);

// Assert that PeerInfo addresses successfully parse into [`SocketAddr`]
for peer_info in peer_info_result {
assert!(
peer_info.addr.parse::<SocketAddr>().is_ok(),
"peer info addr should be a valid SocketAddr",
);
}

child.kill(false)?;

let output = child.wait_with_output()?;
let output = output.assert_failure()?;

// Assert that PeerInfo addresses successfully parse into [`SocketAddr`]
// for peer_info in peer_info_result {
// assert!(
// peer_info.addr.parse::<SocketAddr>().is_ok(),
// "peer info addr should be a valid SocketAddr",
// );
// }

// [Note on port conflict](#Note on port conflict)
output
.assert_was_killed()
Expand Down

0 comments on commit 493412f

Please sign in to comment.