diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 22970e612e..9e186f1106 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -189,4 +189,4 @@ jobs: wasm-pack test --headless --firefox wasm-pack test --headless --chrome pkill substrate - working-directory: wasm-tests + working-directory: tests/wasm-tests diff --git a/Cargo.toml b/Cargo.toml index c89a3fd251..a6a1154e56 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,18 +1,18 @@ [workspace] members = [ - "examples", "benches", - "server", - "test-utils", - "jsonrpsee", - "tests", - "types", - "core", - "client/ws-client", "client/http-client", "client/transport", "client/wasm-client", + "client/ws-client", + "core", + "examples", + "jsonrpsee", "proc-macros", - "wasm-tests", + "server", + "test-utils", + "tests", + "tests/wasm-tests", + "types", ] resolver = "2" diff --git a/client/http-client/src/client.rs b/client/http-client/src/client.rs index fdcc0495a7..2f92a98f6f 100644 --- a/client/http-client/src/client.rs +++ b/client/http-client/src/client.rs @@ -129,18 +129,23 @@ impl HttpClientBuilder { /// Build the HTTP client with target to connect to. pub fn build(self, target: impl AsRef) -> Result { - let transport = HttpTransportClient::new( - target, - self.max_request_body_size, - self.certificate_store, - self.max_log_length, - self.headers, - ) - .map_err(|e| Error::Transport(e.into()))?; + let Self { + max_request_body_size, + max_concurrent_requests, + request_timeout, + certificate_store, + id_kind, + headers, + max_log_length, + } = self; + + let transport = + HttpTransportClient::new(target, max_request_body_size, certificate_store, max_log_length, headers) + .map_err(|e| Error::Transport(e.into()))?; Ok(HttpClient { transport, - id_manager: Arc::new(RequestIdManager::new(self.max_concurrent_requests, self.id_kind)), - request_timeout: self.request_timeout, + id_manager: Arc::new(RequestIdManager::new(max_concurrent_requests, id_kind)), + request_timeout, }) } } diff --git a/client/wasm-client/src/lib.rs b/client/wasm-client/src/lib.rs index 73f68ffe36..f5322b7110 100644 --- a/client/wasm-client/src/lib.rs +++ b/client/wasm-client/src/lib.rs @@ -37,7 +37,7 @@ use std::time::Duration; use jsonrpsee_client_transport::web; use jsonrpsee_core::client::{ClientBuilder, IdKind}; -use jsonrpsee_core::{Error, TEN_MB_SIZE_BYTES}; +use jsonrpsee_core::Error; /// Builder for [`Client`]. /// @@ -59,34 +59,28 @@ use jsonrpsee_core::{Error, TEN_MB_SIZE_BYTES}; /// } /// /// ``` -#[derive(Clone, Debug)] +#[derive(Copy, Clone, Debug)] pub struct WasmClientBuilder { - max_request_body_size: u32, - request_timeout: Duration, + id_kind: IdKind, max_concurrent_requests: usize, max_notifs_per_subscription: usize, - id_kind: IdKind, + max_log_length: u32, + request_timeout: Duration, } impl Default for WasmClientBuilder { fn default() -> Self { Self { - max_request_body_size: TEN_MB_SIZE_BYTES, - request_timeout: Duration::from_secs(60), + id_kind: IdKind::Number, + max_log_length: 4096, max_concurrent_requests: 256, max_notifs_per_subscription: 1024, - id_kind: IdKind::Number, + request_timeout: Duration::from_secs(60), } } } impl WasmClientBuilder { - /// Max request body size. - pub fn max_request_body_size(mut self, size: u32) -> Self { - self.max_request_body_size = size; - self - } - /// See documentation [`ClientBuilder::request_timeout`] (default is 60 seconds). pub fn request_timeout(mut self, timeout: Duration) -> Self { self.request_timeout = timeout; @@ -111,11 +105,26 @@ impl WasmClientBuilder { self } + /// Set maximum length for logging calls and responses. + /// + /// Logs bigger than this limit will be truncated. + pub fn set_max_logging_length(mut self, max: u32) -> Self { + self.max_log_length = max; + self + } + /// Build the client with specified URL to connect to. pub async fn build(self, url: impl AsRef) -> Result { + let Self { max_log_length, id_kind, request_timeout, max_concurrent_requests, max_notifs_per_subscription } = + self; let (sender, receiver) = web::connect(url).await.map_err(|e| Error::Transport(e.into()))?; - let builder = ClientBuilder::default(); + let builder = ClientBuilder::default() + .set_max_logging_length(max_log_length) + .request_timeout(request_timeout) + .id_format(id_kind) + .max_notifs_per_subscription(max_notifs_per_subscription) + .max_concurrent_requests(max_concurrent_requests); Ok(builder.build_with_wasm(sender, receiver)) } diff --git a/client/ws-client/src/lib.rs b/client/ws-client/src/lib.rs index e694d06918..ab9d629926 100644 --- a/client/ws-client/src/lib.rs +++ b/client/ws-client/src/lib.rs @@ -85,6 +85,7 @@ pub struct WsClientBuilder { max_notifs_per_subscription: usize, max_redirections: usize, id_kind: IdKind, + max_log_length: u32, } impl Default for WsClientBuilder { @@ -100,6 +101,7 @@ impl Default for WsClientBuilder { max_notifs_per_subscription: 1024, max_redirections: 5, id_kind: IdKind::Number, + max_log_length: 4096, } } } @@ -165,6 +167,14 @@ impl WsClientBuilder { self } + /// Set maximum length for logging calls and responses. + /// + /// Logs bigger than this limit will be truncated. + pub fn set_max_logging_length(mut self, max: u32) -> Self { + self.max_log_length = max; + self + } + /// Build the client with specified URL to connect to. /// You must provide the port number in the URL. /// @@ -172,24 +182,39 @@ impl WsClientBuilder { /// /// Panics if being called outside of `tokio` runtime context. pub async fn build(self, url: impl AsRef) -> Result { + let Self { + certificate_store, + max_concurrent_requests, + max_request_body_size, + request_timeout, + connection_timeout, + ping_interval, + headers, + max_redirections, + max_notifs_per_subscription, + id_kind, + max_log_length, + } = self; + let transport_builder = WsTransportClientBuilder { - certificate_store: self.certificate_store, - connection_timeout: self.connection_timeout, - headers: self.headers, - max_request_body_size: self.max_request_body_size, - max_redirections: self.max_redirections, + certificate_store, + connection_timeout, + headers, + max_request_body_size, + max_redirections, }; let uri: Uri = url.as_ref().parse().map_err(|e: InvalidUri| Error::Transport(e.into()))?; let (sender, receiver) = transport_builder.build(uri).await.map_err(|e| Error::Transport(e.into()))?; let mut client = ClientBuilder::default() - .max_notifs_per_subscription(self.max_notifs_per_subscription) - .request_timeout(self.request_timeout) - .max_concurrent_requests(self.max_concurrent_requests) - .id_format(self.id_kind); + .max_notifs_per_subscription(max_notifs_per_subscription) + .request_timeout(request_timeout) + .max_concurrent_requests(max_concurrent_requests) + .id_format(id_kind) + .set_max_logging_length(max_log_length); - if let Some(interval) = self.ping_interval { + if let Some(interval) = ping_interval { client = client.ping_interval(interval); } diff --git a/core/src/client/async_client/mod.rs b/core/src/client/async_client/mod.rs index 10d842f934..26856fb94a 100644 --- a/core/src/client/async_client/mod.rs +++ b/core/src/client/async_client/mod.rs @@ -135,6 +135,7 @@ impl ClientBuilder { self.max_log_length = max; self } + /// Set the interval at which pings frames are submitted (disabled by default). /// /// Periodically submitting pings at a defined interval has mainly two benefits: diff --git a/server/src/server.rs b/server/src/server.rs index 91d26dba07..723de37957 100644 --- a/server/src/server.rs +++ b/server/src/server.rs @@ -453,6 +453,14 @@ impl Builder { self } + /// Set maximum length for logging calls and responses. + /// + /// Logs bigger than this limit will be truncated. + pub fn set_max_logging_length(mut self, max: u32) -> Self { + self.settings.max_log_length = max; + self + } + /// Finalize the configuration of the server. Consumes the [`Builder`]. /// /// ```rust diff --git a/tests/wasm-tests/Cargo.toml b/tests/wasm-tests/Cargo.toml new file mode 100644 index 0000000000..cdb3bcbd9b --- /dev/null +++ b/tests/wasm-tests/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "wasm-test" +version = "0.1.0" +edition = "2021" + +[dev-dependencies] +wasm-bindgen-test = "0.3.24" +tracing-wasm = "0.2.1" +console_error_panic_hook = "0.1.7" +serde_json = "1.0.57" +jsonrpsee-wasm-client = { path = "../../client/wasm-client" } +jsonrpsee-core = { path = "../../core" , features = ["client"] } +jsonrpsee-client-transport = { path = "../../client/transport", features = ["web"] } diff --git a/wasm-tests/tests/wasm.rs b/tests/wasm-tests/tests/wasm.rs similarity index 100% rename from wasm-tests/tests/wasm.rs rename to tests/wasm-tests/tests/wasm.rs diff --git a/wasm-tests/Cargo.toml b/wasm-tests/Cargo.toml deleted file mode 100644 index 06ca032430..0000000000 --- a/wasm-tests/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "wasm-test" -version = "0.1.0" -edition = "2021" - -[dev-dependencies] -wasm-bindgen-test = "0.3.24" -tracing-wasm = "0.2.1" -console_error_panic_hook = "0.1.7" -serde_json = "1.0.57" -jsonrpsee-wasm-client = { path = "../client/wasm-client" } -jsonrpsee-core = { path = "../core" , features = ["client"] } -jsonrpsee-client-transport = { path = "../client/transport", features = ["web"] }