mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 05:17:58 +00:00
cargo fmt with stable defaults (#876)
This commit is contained in:
@@ -2,17 +2,11 @@
|
||||
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
|
||||
// see LICENSE for license details.
|
||||
|
||||
pub(crate) use crate::{
|
||||
node_runtime,
|
||||
TestNodeProcess,
|
||||
};
|
||||
pub(crate) use crate::{node_runtime, TestNodeProcess};
|
||||
|
||||
use sp_core::sr25519::Pair;
|
||||
use sp_keyring::AccountKeyring;
|
||||
use subxt::{
|
||||
tx::PairSigner,
|
||||
SubstrateConfig,
|
||||
};
|
||||
use subxt::{tx::PairSigner, SubstrateConfig};
|
||||
|
||||
/// substrate node should be installed on the $PATH
|
||||
const SUBSTRATE_NODE_PATH: &str = "substrate";
|
||||
@@ -20,8 +14,10 @@ const SUBSTRATE_NODE_PATH: &str = "substrate";
|
||||
pub async fn test_context_with(key: AccountKeyring) -> TestContext {
|
||||
let path = std::env::var("SUBSTRATE_NODE_PATH").unwrap_or_else(|_| {
|
||||
if which::which(SUBSTRATE_NODE_PATH).is_err() {
|
||||
panic!("A substrate binary should be installed on your path for integration tests. \
|
||||
See https://github.com/paritytech/subxt/tree/master#integration-testing")
|
||||
panic!(
|
||||
"A substrate binary should be installed on your path for integration tests. \
|
||||
See https://github.com/paritytech/subxt/tree/master#integration-testing"
|
||||
)
|
||||
}
|
||||
SUBSTRATE_NODE_PATH.to_string()
|
||||
});
|
||||
|
||||
@@ -4,21 +4,11 @@
|
||||
|
||||
use sp_keyring::AccountKeyring;
|
||||
use std::{
|
||||
ffi::{
|
||||
OsStr,
|
||||
OsString,
|
||||
},
|
||||
io::{
|
||||
BufRead,
|
||||
BufReader,
|
||||
Read,
|
||||
},
|
||||
ffi::{OsStr, OsString},
|
||||
io::{BufRead, BufReader, Read},
|
||||
process,
|
||||
};
|
||||
use subxt::{
|
||||
Config,
|
||||
OnlineClient,
|
||||
};
|
||||
use subxt::{Config, OnlineClient};
|
||||
|
||||
/// Spawn a local substrate node for testing subxt.
|
||||
pub struct TestNodeProcess<R: Config> {
|
||||
@@ -53,7 +43,7 @@ where
|
||||
if let Err(err) = self.proc.kill() {
|
||||
let err = format!("Error killing node process {}: {}", self.proc.id(), err);
|
||||
tracing::error!("{}", err);
|
||||
return Err(err)
|
||||
return Err(err);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -143,24 +133,21 @@ fn find_substrate_port_from_output(r: impl Read + Send + 'static) -> u16 {
|
||||
BufReader::new(r)
|
||||
.lines()
|
||||
.find_map(|line| {
|
||||
let line =
|
||||
line.expect("failed to obtain next line from stdout for port discovery");
|
||||
let line = line.expect("failed to obtain next line from stdout for port discovery");
|
||||
|
||||
// does the line contain our port (we expect this specific output from substrate).
|
||||
let line_end = line
|
||||
.rsplit_once("Listening for new connections on 127.0.0.1:")
|
||||
.or_else(|| {
|
||||
line.rsplit_once("Running JSON-RPC WS server: addr=127.0.0.1:")
|
||||
})
|
||||
.or_else(|| line.rsplit_once("Running JSON-RPC WS server: addr=127.0.0.1:"))
|
||||
.map(|(_, port_str)| port_str)?;
|
||||
|
||||
// trim non-numeric chars from the end of the port part of the line.
|
||||
let port_str = line_end.trim_end_matches(|b: char| !b.is_ascii_digit());
|
||||
|
||||
// expect to have a number here (the chars after '127.0.0.1:') and parse them into a u16.
|
||||
let port_num = port_str.parse().unwrap_or_else(|_| {
|
||||
panic!("valid port expected for log line, got '{port_str}'")
|
||||
});
|
||||
let port_num = port_str
|
||||
.parse()
|
||||
.unwrap_or_else(|_| panic!("valid port expected for log line, got '{port_str}'"));
|
||||
|
||||
Some(port_num)
|
||||
})
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
|
||||
// see LICENSE for license details.
|
||||
|
||||
use subxt::{
|
||||
client::OnlineClientT,
|
||||
Config,
|
||||
};
|
||||
use subxt::{client::OnlineClientT, Config};
|
||||
|
||||
/// Wait for blocks to be produced before running tests. Waiting for two blocks
|
||||
/// (the genesis block and another one) seems to be enough to allow tests
|
||||
|
||||
Reference in New Issue
Block a user