Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
gianfra-t committed Sep 14, 2023
1 parent e06bf16 commit 9d42516
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 75 deletions.
64 changes: 32 additions & 32 deletions clients/runner/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,39 @@ use url::ParseError as UrlParseError;

#[derive(Error, Debug)]
pub enum Error {
#[error("CodecError: {0}")]
CodecError(#[from] CodecError),
#[error("System I/O error: {0}")]
IoError(#[from] IoError),
#[error("System command error: {0}")]
OsError(#[from] OsError),
#[error("HTTP request error: {0}")]
HttpError(#[from] ReqwestError),
#[error("UrlParseError: {0}")]
UrlParseError(#[from] UrlParseError),
#[error("SubxtError: {0}")]
SubxtError(#[from] SubxtError),
#[error("Integer conversion error")]
IntegerConversionError,
#[error("A client release has not been downloaded")]
NoDownloadedRelease,
#[error("A child process is already running")]
ChildProcessExists,
#[error("Failed to terminate child process")]
ProcessTerminationFailure,
#[error("Failed to parse the client-type CLI argument")]
ClientTypeParsingError,
#[error("Failed to derive the release name of the vault")]
ClientNameDerivationError,
#[error("Incorrect Checksum")]
IncorrectChecksum,
#[error("CodecError: {0}")]
CodecError(#[from] CodecError),
#[error("System I/O error: {0}")]
IoError(#[from] IoError),
#[error("System command error: {0}")]
OsError(#[from] OsError),
#[error("HTTP request error: {0}")]
HttpError(#[from] ReqwestError),
#[error("UrlParseError: {0}")]
UrlParseError(#[from] UrlParseError),
#[error("SubxtError: {0}")]
SubxtError(#[from] SubxtError),
#[error("Integer conversion error")]
IntegerConversionError,
#[error("A client release has not been downloaded")]
NoDownloadedRelease,
#[error("A child process is already running")]
ChildProcessExists,
#[error("Failed to terminate child process")]
ProcessTerminationFailure,
#[error("Failed to parse the client-type CLI argument")]
ClientTypeParsingError,
#[error("Failed to derive the release name of the vault")]
ClientNameDerivationError,
#[error("Incorrect Checksum")]
IncorrectChecksum,
}

impl<E: Into<Error> + Sized> From<BackoffError<E>> for Error {
fn from(e: BackoffError<E>) -> Self {
match e {
BackoffError::Permanent(err) => err.into(),
BackoffError::Transient(err) => err.into(),
}
}
fn from(e: BackoffError<E>) -> Self {
match e {
BackoffError::Permanent(err) => err.into(),
BackoffError::Transient(err) => err.into(),
}
}
}
53 changes: 27 additions & 26 deletions clients/runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,38 @@ use crate::runner::{retry_with_log_async, subxt_api, Runner};
#[derive(Parser, Debug, Clone)]
#[clap(version, author, about, trailing_var_arg = true)]
pub struct Opts {
/// Client to run, one of: vault, oracle, faucet. Default is `vault`.
#[clap(long, default_value = "vault")]
pub client_type: ClientType,
/// Client to run, one of: vault, oracle, faucet. Default is `vault`.
#[clap(long, default_value = "vault")]
pub client_type: ClientType,

/// Parachain websocket URL.
#[clap(long)]
pub parachain_ws: String,
/// Parachain websocket URL.
#[clap(long)]
pub parachain_ws: String,

/// Download path for the client executable.
#[clap(long, default_value = ".")]
pub download_path: PathBuf,
/// Download path for the client executable.
#[clap(long, default_value = ".")]
pub download_path: PathBuf,

/// CLI arguments to pass to the client executable.
pub client_args: Vec<String>,
/// CLI arguments to pass to the client executable.
pub client_args: Vec<String>,
}

#[tokio::main]
async fn main() -> Result<(), Error> {
env_logger::init_from_env(
env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, log::LevelFilter::Info.as_str()),
);
let opts: Opts = Opts::parse();
let rpc_client = retry_with_log_async(
|| subxt_api(&opts.parachain_ws).into_future().boxed(),
"Error fetching executable".to_string(),
)
.await?;
log::info!("Connected to the parachain");

let runner = Runner::new(rpc_client, opts);
let shutdown_signals = Signals::new([SIGHUP, SIGTERM, SIGINT, SIGQUIT])?;
Runner::run(Box::new(runner), shutdown_signals).await?;
Ok(())
env_logger::init_from_env(
env_logger::Env::default()
.filter_or(env_logger::DEFAULT_FILTER_ENV, log::LevelFilter::Info.as_str()),
);
let opts: Opts = Opts::parse();
let rpc_client = retry_with_log_async(
|| subxt_api(&opts.parachain_ws).into_future().boxed(),
"Error fetching executable".to_string(),
)
.await?;
log::info!("Connected to the parachain");

let runner = Runner::new(rpc_client, opts);
let shutdown_signals = Signals::new([SIGHUP, SIGTERM, SIGINT, SIGQUIT])?;
Runner::run(Box::new(runner), shutdown_signals).await?;
Ok(())
}
19 changes: 7 additions & 12 deletions clients/runner/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use async_trait::async_trait;
/// Also used as the name of the downloaded executable.
#[derive(Debug, Clone)]
pub enum ClientType {
Vault
Vault,
}

impl FromStr for ClientType {
Expand Down Expand Up @@ -175,10 +175,7 @@ impl Runner {
Ok(downloaded_release)
}

async fn do_download_binary(
bin_path: PathBuf,
release: ClientRelease,
) -> Result<(), Error> {
async fn do_download_binary(bin_path: PathBuf, release: ClientRelease) -> Result<(), Error> {
let mut file = OpenOptions::new()
.read(true)
.write(true)
Expand Down Expand Up @@ -707,7 +704,7 @@ mod tests {
}
}

//Before running this test, ensure uri and checksum of the test file match!
//Before running this test, ensure uri and checksum of the test file match!
#[tokio::test]
async fn test_runner_download_binary() {
let mut runner = MockRunner::default();
Expand Down Expand Up @@ -758,7 +755,6 @@ mod tests {
// (`700`).
fs::Permissions::from_mode(0o0100700)
);

}

#[tokio::test]
Expand Down Expand Up @@ -792,10 +788,10 @@ mod tests {
runner.expect_download_path().return_const(mock_path.clone());
runner.expect_client_type().return_const(client.clone());
let (bin_name, bin_path) = Runner::get_bin_path(
&runner,
"https://downloads.pendulumchain.tech/spacewalk/vault-rococo",
)
.unwrap();
&runner,
"https://downloads.pendulumchain.tech/spacewalk/vault-rococo",
)
.unwrap();
assert_eq!(bin_name, "vault-rococo");
assert_eq!(bin_path, mock_path.join(bin_name));
}
Expand Down Expand Up @@ -874,7 +870,6 @@ mod tests {
.iter()
.map(|s| s.to_string())
.collect();


let mock_downloaded_release = DownloadedRelease {
checksum: H256::default(),
Expand Down
10 changes: 5 additions & 5 deletions testchain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use codec::Encode;
pub use dia_oracle::dia::*;
use frame_support::{
construct_runtime, parameter_types,
traits::{ConstU128, ConstU64, ConstU32, ConstU8, Contains},
traits::{ConstU128, ConstU32, ConstU64, ConstU8, Contains},
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, IdentityFee, Weight},
PalletId,
};
Expand Down Expand Up @@ -561,10 +561,10 @@ impl nomination::Config for Runtime {
}

impl clients_info::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = clients_info::SubstrateWeight<Runtime>;
type MaxNameLength = ConstU32<255>;
type MaxUriLength = ConstU32<255>;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = clients_info::SubstrateWeight<Runtime>;
type MaxNameLength = ConstU32<255>;
type MaxUriLength = ConstU32<255>;
}

construct_runtime! {
Expand Down

0 comments on commit 9d42516

Please sign in to comment.