diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f08fbae..f296fd1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,30 +12,14 @@ jobs: matrix: monero: [ 0.17.3.0, 0.17.3.2, 0.18.0.0 ] - services: - monerod: - image: ghcr.io/farcaster-project/containers/monerod:${{ matrix.monero }} - env: - NETWORK: regtest - MONEROD_RPC_PORT: 18081 - MONEROD_ZMQ_PORT: 18082 - OFFLINE: --offline - DIFFICULTY: 1 - ports: - - 18081:18081 - - 18082:18082 - monero-wallet-rpc: - image: ghcr.io/farcaster-project/containers/monero-wallet-rpc:${{ matrix.monero }} - env: - MONERO_DAEMON_ADDRESS: monerod:18081 - MONERO_DAEMON_HOST: monerod:18081 - WALLET_RPC_PORT: 18083 - ports: - - 18083:18083 - steps: - uses: actions/checkout@v3 + - name: Spin up containers + run: docker-compose -f tests/docker-compose.yml up -d + env: + MONERO_VERSION: ${{ matrix.monero }} + - name: Install Rust Stable uses: actions-rs/toolchain@v1 with: diff --git a/Cargo.toml b/Cargo.toml index f640549..ec656d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ description = "RPC client for Monero daemon and wallet" [dependencies] anyhow = "1" chrono = { version = "0.4", features = ["serde"] } +diqwest = "1.1" fixed-hash = "0.7" hex = "0.4" http = "0.2" @@ -23,7 +24,6 @@ serde = { version = "1", features = ["derive"] } serde_json = "1" tracing = "0.1" uuid = { version = "1.1", features = ["v4"] } -diqwest = "1.1" [dev-dependencies] # Async diff --git a/src/lib.rs b/src/lib.rs index 376bf70..157c8dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,8 +61,8 @@ use std::{ use tracing::*; use uuid::Uuid; -use diqwest::WithDigestAuth; use crate::RpcAuthentication::Credentials; +use diqwest::WithDigestAuth; enum RpcParams { Array(Box + Send + 'static>), @@ -72,7 +72,7 @@ enum RpcParams { #[derive(Clone, Debug)] pub enum RpcAuthentication { - Credentials{username: String, password: String}, + Credentials { username: String, password: String }, None, } @@ -106,7 +106,7 @@ impl From for Params { struct RemoteCaller { http_client: reqwest::Client, addr: String, - rpc_auth: RpcAuthentication + rpc_auth: RpcAuthentication, } impl RemoteCaller { @@ -127,20 +127,15 @@ impl RemoteCaller { trace!("Sending JSON-RPC method call: {:?}", method_call); - let req = client - .post(&uri) - .json(&method_call); + let req = client.post(&uri).json(&method_call); - let rsp = if let Credentials{username, password} = &self.rpc_auth { + let rsp = if let Credentials { username, password } = &self.rpc_auth { req.send_with_digest_auth(username, password) .await? .json::() .await? - } else{ - req.send() - .await? - .json::() - .await? + } else { + req.send().await?.json::().await? }; trace!("Received JSON-RPC response: {:?}", rsp); @@ -163,20 +158,15 @@ impl RemoteCaller { json_params ); - let req = client - .post(uri) - .json(&json_params); + let req = client.post(uri).json(&json_params); - let rsp = if let Credentials{username, password} = &self.rpc_auth { + let rsp = if let Credentials { username, password } = &self.rpc_auth { req.send_with_digest_auth(username, password) .await? .json::() .await? - } else{ - req.send() - .await? - .json::() - .await? + } else { + req.send().await?.json::().await? }; trace!("Received daemon RPC response: {:?}", rsp); @@ -224,7 +214,7 @@ impl RpcClient { inner: CallerWrapper(Arc::new(RemoteCaller { http_client: reqwest::ClientBuilder::new().build().unwrap(), addr, - rpc_auth: RpcAuthentication::None + rpc_auth: RpcAuthentication::None, })), } } @@ -234,7 +224,7 @@ impl RpcClient { inner: CallerWrapper(Arc::new(RemoteCaller { http_client: reqwest::ClientBuilder::new().build().unwrap(), addr, - rpc_auth + rpc_auth, })), } } diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index 2bec3e7..83f5bea 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -1,18 +1,21 @@ version: "3.7" services: monerod: - image: ghcr.io/farcaster-project/containers/monerod:0.18.0.0 + image: ghcr.io/farcaster-project/containers/monerod:${MONERO_VERSION:-0.18.1.2} environment: NETWORK: regtest + MONEROD_RPC_PORT: 18081 + MONEROD_ZMQ_PORT: 18082 OFFLINE: --offline DIFFICULTY: 1 ports: - 18081:18081 monero-wallet-rpc: - image: ghcr.io/farcaster-project/containers/monero-wallet-rpc:0.18.0.0 + image: ghcr.io/farcaster-project/containers/monero-wallet-rpc:${MONERO_VERSION:-0.18.1.2} environment: MONERO_DAEMON_ADDRESS: monerod:18081 + MONERO_DAEMON_HOST: monerod:18081 WALLET_RPC_PORT: 18083 depends_on: - "monerod" @@ -20,7 +23,7 @@ services: - 18083:18083 monerod-rpc-authentication: - image: ghcr.io/farcaster-project/containers/monerod:0.18.0.0 + image: ghcr.io/farcaster-project/containers/monerod:${MONERO_VERSION:-0.18.1.2} depends_on: - "monerod" ports: @@ -36,7 +39,7 @@ services: --fixed-difficulty 1 monero-wallet-rpc-authentication: - image: ghcr.io/farcaster-project/containers/monero-wallet-rpc:0.18.0.0 + image: ghcr.io/farcaster-project/containers/monero-wallet-rpc:${MONERO_VERSION:-0.18.1.2} depends_on: - "monerod" ports: diff --git a/tests/rpc.rs b/tests/rpc.rs index 8dda416..59e8498 100644 --- a/tests/rpc.rs +++ b/tests/rpc.rs @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::env; use monero::Hash; use monero_rpc::{RpcAuthentication, RpcClient}; +use std::env; mod clients_tests; @@ -63,16 +63,14 @@ async fn main_functional_test() { clients_tests::all_clients_interaction::run().await; } - fn setup_rpc_auth_client(username: &str, password: &str, port: u32) -> RpcClient { let whost = env::var("MONERO_WALLET_HOST_1").unwrap_or_else(|_| "localhost".into()); let rpc_credentials = RpcAuthentication::Credentials { username: username.into(), - password: password.into() + password: password.into(), }; - let rpc_client = RpcClient::with_authentication( - format!("http://{}:{}", whost, port), - rpc_credentials); + let rpc_client = + RpcClient::with_authentication(format!("http://{}:{}", whost, port), rpc_credentials); rpc_client } @@ -97,7 +95,9 @@ async fn test_daemon_rpc_auth_fail() { async fn test_daemon_rpc_rpc_auth() { let rpc_client = setup_rpc_auth_client("foo", "bar", 18085).daemon_rpc(); let transactions = vec![Hash::from_low_u64_be(1)]; - let daemon_transactions = rpc_client.get_transactions(transactions, Some(true), Some(true)).await; + let daemon_transactions = rpc_client + .get_transactions(transactions, Some(true), Some(true)) + .await; assert!(daemon_transactions.is_ok()); } @@ -116,4 +116,4 @@ async fn test_rpc_auth_fail() { let rpc_client = setup_rpc_auth_client("invalid", "auth", 18084).wallet(); assert!(rpc_client.get_version().await.is_err()); -} \ No newline at end of file +}