Skip to content

Commit

Permalink
Use the existing docker-compose.yml for github actions tests
Browse files Browse the repository at this point in the history
  • Loading branch information
refring committed Oct 18, 2022
1 parent 59ad587 commit c7308a7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 57 deletions.
26 changes: 5 additions & 21 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
36 changes: 13 additions & 23 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Iterator<Item = Value> + Send + 'static>),
Expand All @@ -72,7 +72,7 @@ enum RpcParams {

#[derive(Clone, Debug)]
pub enum RpcAuthentication {
Credentials{username: String, password: String},
Credentials { username: String, password: String },
None,
}

Expand Down Expand Up @@ -106,7 +106,7 @@ impl From<RpcParams> for Params {
struct RemoteCaller {
http_client: reqwest::Client,
addr: String,
rpc_auth: RpcAuthentication
rpc_auth: RpcAuthentication,
}

impl RemoteCaller {
Expand All @@ -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::<response::Output>()
.await?
} else{
req.send()
.await?
.json::<response::Output>()
.await?
} else {
req.send().await?.json::<response::Output>().await?
};

trace!("Received JSON-RPC response: {:?}", rsp);
Expand All @@ -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::<T>()
.await?
} else{
req.send()
.await?
.json::<T>()
.await?
} else {
req.send().await?.json::<T>().await?
};

trace!("Received daemon RPC response: {:?}", rsp);
Expand Down Expand Up @@ -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,
})),
}
}
Expand All @@ -234,7 +224,7 @@ impl RpcClient {
inner: CallerWrapper(Arc::new(RemoteCaller {
http_client: reqwest::ClientBuilder::new().build().unwrap(),
addr,
rpc_auth
rpc_auth,
})),
}
}
Expand Down
11 changes: 7 additions & 4 deletions tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
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"
ports:
- 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:
Expand All @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions tests/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
}
Expand All @@ -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());
}
Expand All @@ -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());
}
}

0 comments on commit c7308a7

Please sign in to comment.