Skip to content

Commit

Permalink
[refactor]: Export iroha_config through iroha_client (hyperledger-iro…
Browse files Browse the repository at this point in the history
…ha#4147)

Signed-off-by: Marin Veršić <[email protected]>
  • Loading branch information
mversic authored and Asem-Abdelhady committed Jan 9, 2024
1 parent 81d93cb commit 53dbc81
Show file tree
Hide file tree
Showing 21 changed files with 716 additions and 626 deletions.
1,234 changes: 663 additions & 571 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/examples/tutorial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use std::fs::File;

use eyre::{Error, WrapErr};
use iroha_client::config::Configuration;
// #region rust_config_crates
use iroha_config::client::Configuration;
// #endregion rust_config_crates

fn main() {
Expand Down
42 changes: 27 additions & 15 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use derive_more::{DebugCustom, Display};
use eyre::{eyre, Result, WrapErr};
use futures_util::StreamExt;
use http_default::{AsyncWebSocketStream, WebSocketStream};
use iroha_config::{client::Configuration, client_api::ConfigurationDTO, torii::uri};
use iroha_logger::prelude::*;
use iroha_telemetry::metrics::Status;
use iroha_version::prelude::*;
Expand All @@ -23,6 +22,7 @@ use url::Url;

use self::{blocks_api::AsyncBlockStream, events_api::AsyncEventStream};
use crate::{
config::{api::ConfigurationDTO, Configuration},
crypto::{HashOf, KeyPair},
data_model::{
block::SignedBlock,
Expand Down Expand Up @@ -372,7 +372,7 @@ pub struct QueryRequest {
impl QueryRequest {
#[cfg(test)]
fn dummy() -> Self {
let torii_url = iroha_config::torii::uri::DEFAULT_API_ADDR;
let torii_url = crate::config::torii::DEFAULT_API_ADDR;

Self {
torii_url: format!("http://{torii_url}").parse().unwrap(),
Expand All @@ -391,7 +391,9 @@ impl QueryRequest {
fn assemble(self) -> DefaultRequestBuilder {
let builder = DefaultRequestBuilder::new(
HttpMethod::POST,
self.torii_url.join(uri::QUERY).expect("Valid URI"),
self.torii_url
.join(crate::config::torii::QUERY)
.expect("Valid URI"),
)
.headers(self.headers);

Expand Down Expand Up @@ -682,7 +684,9 @@ impl Client {
(
B::new(
HttpMethod::POST,
self.torii_url.join(uri::TRANSACTION).expect("Valid URI"),
self.torii_url
.join(crate::config::torii::TRANSACTION)
.expect("Valid URI"),
)
.headers(self.headers.clone())
.body(transaction_bytes),
Expand Down Expand Up @@ -752,7 +756,7 @@ impl Client {
///
/// ```ignore
/// use eyre::Result;
/// use iroha_client::{
/// use crate::{
/// data_model::{predicate::PredicateBox, prelude::{Account, FindAllAccounts, Pagination}},
/// client::Client,
/// http::{RequestBuilder, Response, Method},
Expand Down Expand Up @@ -951,7 +955,9 @@ impl Client {
events_api::flow::Init::new(
event_filter,
self.headers.clone(),
self.torii_url.join(uri::SUBSCRIPTION).expect("Valid URI"),
self.torii_url
.join(crate::config::torii::SUBSCRIPTION)
.expect("Valid URI"),
)
}

Expand Down Expand Up @@ -985,7 +991,9 @@ impl Client {
blocks_api::flow::Init::new(
height,
self.headers.clone(),
self.torii_url.join(uri::BLOCKS_STREAM).expect("Valid URI"),
self.torii_url
.join(crate::config::torii::BLOCKS_STREAM)
.expect("Valid URI"),
)
}

Expand Down Expand Up @@ -1018,7 +1026,7 @@ impl Client {
let response = DefaultRequestBuilder::new(
HttpMethod::GET,
self.torii_url
.join(uri::PENDING_TRANSACTIONS)
.join(crate::config::torii::PENDING_TRANSACTIONS)
.expect("Valid URI"),
)
.params(pagination.clone())
Expand Down Expand Up @@ -1079,7 +1087,9 @@ impl Client {
pub fn get_config(&self) -> Result<ConfigurationDTO> {
let resp = DefaultRequestBuilder::new(
HttpMethod::GET,
self.torii_url.join(uri::CONFIGURATION).expect("Valid URI"),
self.torii_url
.join(crate::config::torii::CONFIGURATION)
.expect("Valid URI"),
)
.header(http::header::CONTENT_TYPE, APPLICATION_JSON)
.build()?
Expand All @@ -1101,7 +1111,10 @@ impl Client {
/// If sending request or decoding fails
pub fn set_config(&self, dto: ConfigurationDTO) -> Result<()> {
let body = serde_json::to_vec(&dto).wrap_err(format!("Failed to serialize {dto:?}"))?;
let url = self.torii_url.join(uri::CONFIGURATION).expect("Valid URI");
let url = self
.torii_url
.join(crate::config::torii::CONFIGURATION)
.expect("Valid URI");
let resp = DefaultRequestBuilder::new(HttpMethod::POST, url)
.header(http::header::CONTENT_TYPE, APPLICATION_JSON)
.body(body)
Expand Down Expand Up @@ -1138,7 +1151,9 @@ impl Client {
pub fn prepare_status_request<B: RequestBuilder>(&self) -> B {
B::new(
HttpMethod::GET,
self.torii_url.join(uri::STATUS).expect("Valid URI"),
self.torii_url
.join(crate::config::torii::STATUS)
.expect("Valid URI"),
)
.headers(self.headers.clone())
}
Expand Down Expand Up @@ -1634,13 +1649,10 @@ pub mod parameter {
mod tests {
use std::str::FromStr;

use iroha_config::{
client::{BasicAuth, ConfigurationProxy, WebLogin},
torii::uri::DEFAULT_API_ADDR,
};
use iroha_primitives::small::SmallStr;

use super::*;
use crate::config::{torii::DEFAULT_API_ADDR, BasicAuth, ConfigurationProxy, WebLogin};

const LOGIN: &str = "mad_hatter";
const PASSWORD: &str = "ilovetea";
Expand Down
14 changes: 9 additions & 5 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ mod query_builder;

/// Module containing sample configurations for tests and benchmarks.
pub mod samples {
use iroha_config::{
client::{Configuration, ConfigurationProxy},
torii::uri::DEFAULT_API_ADDR,
use crate::{
config::{torii::DEFAULT_API_ADDR, Configuration, ConfigurationProxy},
crypto::KeyPair,
};

use crate::crypto::KeyPair;

/// Get sample client configuration.
pub fn get_client_config(key_pair: &KeyPair) -> Configuration {
let (public_key, private_key) = key_pair.clone().into();
Expand All @@ -39,5 +37,11 @@ pub mod samples {
}
}

pub mod config {
//! Module for client-related configuration and structs
pub use iroha_config::{client::*, client_api as api, path, torii::uri as torii};
}

pub use iroha_crypto as crypto;
pub use iroha_data_model as data_model;
3 changes: 2 additions & 1 deletion client/tests/integration/add_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::thread;

use eyre::Result;
use iroha_client::{client, data_model::prelude::*};
use iroha_config::iroha::Configuration;
use test_network::*;

#[test]
Expand All @@ -10,7 +11,7 @@ fn client_add_account_with_name_length_more_than_limit_should_not_commit_transac
let (_rt, _peer, test_client) = <PeerBuilder>::new().with_port(10_505).start_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);

let pipeline_time = super::Configuration::pipeline_time();
let pipeline_time = Configuration::pipeline_time();

let normal_account_id: AccountId = "bob@wonderland".parse().expect("Valid");
let create_account = Register::account(Account::new(normal_account_id.clone(), []));
Expand Down
3 changes: 1 addition & 2 deletions client/tests/integration/add_domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ use std::thread;

use eyre::Result;
use iroha_client::{client, data_model::prelude::*};
use iroha_config::iroha::Configuration;
use test_network::*;

use super::Configuration;

#[test]
fn client_add_domain_with_name_length_more_than_limit_should_not_commit_transaction() -> Result<()>
{
Expand Down
3 changes: 1 addition & 2 deletions client/tests/integration/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ use iroha_client::{
crypto::{KeyPair, PublicKey},
data_model::prelude::*,
};
use iroha_config::iroha::Configuration;
use iroha_primitives::fixed::Fixed;
use serde_json::json;
use test_network::*;

use super::Configuration;

#[test]
fn client_register_asset_should_add_asset_once_but_not_twice() -> Result<()> {
let (_rt, _peer, test_client) = <PeerBuilder>::new().with_port(10_620).start_with_runtime();
Expand Down
3 changes: 1 addition & 2 deletions client/tests/integration/asset_propagation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ use iroha_client::{
prelude::*,
},
};
use iroha_config::iroha::Configuration;
use test_network::*;

use super::Configuration;

#[test]
fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount_on_another_peer(
) -> Result<()> {
Expand Down
3 changes: 1 addition & 2 deletions client/tests/integration/connected_peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ use iroha_client::{
prelude::*,
},
};
use iroha_config::iroha::Configuration;
use test_network::*;

use super::Configuration;

#[ignore = "ignore, more in #2851"]
#[test]
fn connected_peers_with_f_2_1_2() -> Result<()> {
Expand Down
1 change: 0 additions & 1 deletion client/tests/integration/events/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub use super::Configuration;
mod data;
mod notification;
mod pipeline;
3 changes: 1 addition & 2 deletions client/tests/integration/events/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ use iroha_client::{
prelude::*,
},
};
use iroha_config::iroha::Configuration;
use test_network::*;

use super::Configuration;

// Needed to re-enable ignored tests.
#[allow(dead_code)]
const PEER_COUNT: usize = 7;
Expand Down
5 changes: 0 additions & 5 deletions client/tests/integration/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
pub use iroha_config::{
base::proxy::Builder,
iroha::{Configuration, ConfigurationProxy},
};

mod add_account;
mod add_domain;
mod asset;
Expand Down
3 changes: 1 addition & 2 deletions client/tests/integration/multiple_blocks_created.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ use iroha_client::{
prelude::*,
},
};
use iroha_config::iroha::Configuration;
use test_network::*;

use super::Configuration;

const N_BLOCKS: usize = 510;

#[ignore = "Takes a lot of time."]
Expand Down
3 changes: 1 addition & 2 deletions client/tests/integration/multisignature_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ use iroha_client::{
crypto::KeyPair,
data_model::prelude::*,
};
use iroha_config::iroha::Configuration;
use test_network::*;

use super::Configuration;

#[test]
fn transaction_signed_by_new_signatory_of_account_should_pass() -> Result<()> {
let (_rt, peer, client) = <PeerBuilder>::new().with_port(10_605).start_with_runtime();
Expand Down
5 changes: 2 additions & 3 deletions client/tests/integration/multisignature_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ use std::{str::FromStr as _, thread, time::Duration};
use eyre::Result;
use iroha_client::{
client::{self, Client, QueryResult},
config::Configuration as ClientConfiguration,
crypto::KeyPair,
data_model::{
parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder},
prelude::*,
},
};
use iroha_config::client::Configuration as ClientConfiguration;
use iroha_config::iroha::Configuration;
use test_network::*;

use super::Configuration;

#[allow(clippy::too_many_lines)]
#[test]
fn multisignature_transactions_should_wait_for_all_signatures() -> Result<()> {
Expand Down
3 changes: 1 addition & 2 deletions client/tests/integration/restart_peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ use iroha_client::{
client::{self, QueryResult},
data_model::prelude::*,
};
use iroha_config::iroha::Configuration;
use iroha_primitives::unique_vec;
use tempfile::TempDir;
use test_network::*;
use tokio::runtime::Runtime;

use super::Configuration;

#[test]
fn restarted_peer_should_have_the_same_asset_amount() -> Result<()> {
let temp_dir = Arc::new(TempDir::new()?);
Expand Down
3 changes: 1 addition & 2 deletions client/tests/integration/tx_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ use iroha_client::{
client::{transaction, QueryResult},
data_model::{prelude::*, query::Pagination},
};
use iroha_config::iroha::Configuration;
use test_network::*;

use super::Configuration;

#[ignore = "ignore, more in #2851"]
#[test]
fn client_has_rejected_and_acepted_txs_should_return_tx_history() -> Result<()> {
Expand Down
3 changes: 1 addition & 2 deletions client/tests/integration/unregister_peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ use iroha_client::{
prelude::*,
},
};
use iroha_config::iroha::Configuration;
use test_network::*;

use super::Configuration;

// Note the test is marked as `unstable`, not the network.
#[ignore = "ignore, more in #2851"]
#[test]
Expand Down
3 changes: 1 addition & 2 deletions client/tests/integration/unstable_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ use iroha_client::{
client::{self, Client, QueryResult},
data_model::{prelude::*, Level},
};
use iroha_config::iroha::Configuration;
use rand::seq::SliceRandom;
use test_network::*;
use tokio::runtime::Runtime;

use super::Configuration;

const MAX_TRANSACTIONS_IN_BLOCK: u32 = 5;

#[test]
Expand Down
1 change: 0 additions & 1 deletion client_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ maintenance = { status = "actively-developed" }
[dependencies]
iroha_client = { workspace = true }
iroha_primitives = { workspace = true }
iroha_config = { workspace = true }

color-eyre = { workspace = true }
# TODO: migrate to clap v4 (and use the workspace dependency)
Expand Down
2 changes: 1 addition & 1 deletion client_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use dialoguer::Confirm;
use erased_serde::Serialize;
use iroha_client::{
client::{Client, QueryResult},
config::{path::Path as ConfigPath, Configuration as ClientConfiguration},
data_model::prelude::*,
};
use iroha_config::{client::Configuration as ClientConfiguration, path::Path as ConfigPath};
use iroha_primitives::addr::SocketAddr;

/// Metadata wrapper, which can be captured from cli arguments (from user supplied file).
Expand Down

0 comments on commit 53dbc81

Please sign in to comment.