Split monero-harness into harness and rpc

This allows us to move `monero-harness` and `bitcoin-harness` into
`[dev-dependencies]` of `swap`.
This commit is contained in:
Thomas Eizinger 2021-02-22 12:32:15 +11:00
parent 2a3db9bd80
commit 03078f328c
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96
16 changed files with 82 additions and 54 deletions

46
Cargo.lock generated
View File

@ -439,9 +439,9 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3"
[[package]]
name = "bstr"
version = "0.2.14"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "473fc6b38233f9af7baa94fb5852dca389e3d95b8e21c8e3719301462c5d9faf"
checksum = "a40b47ad93e1a5404e6c18dec46b628214fee441c70f4ab5d6942142cc268a3d"
dependencies = [
"lazy_static",
"memchr",
@ -801,19 +801,6 @@ dependencies = [
"generic-array 0.14.4",
]
[[package]]
name = "digest_auth"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4bce617b8491dd210e3fcbc939e2c5bbeb27355f8adf7da335b87d6cc8d5482"
dependencies = [
"digest 0.8.1",
"hex 0.4.2",
"md-5",
"rand 0.7.3",
"sha2 0.8.2",
]
[[package]]
name = "directories-next"
version = "2.0.0"
@ -1876,17 +1863,6 @@ version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
[[package]]
name = "md-5"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a18af3dcaf2b0219366cdb4e2af65a6101457b415c3d1a5c71dd9c2b7c77b9c8"
dependencies = [
"block-buffer 0.7.3",
"digest 0.8.1",
"opaque-debug 0.2.3",
]
[[package]]
name = "memchr"
version = "2.3.4"
@ -1983,20 +1959,27 @@ name = "monero-harness"
version = "0.1.0"
dependencies = [
"anyhow",
"digest_auth",
"futures",
"monero-rpc",
"port_check",
"rand 0.7.3",
"reqwest",
"serde",
"serde_json",
"spectral",
"testcontainers 0.12.0",
"tokio",
"tracing",
"tracing-log",
"tracing-subscriber",
"url",
]
[[package]]
name = "monero-rpc"
version = "0.1.0"
dependencies = [
"anyhow",
"reqwest",
"serde",
"serde_json",
"tracing",
]
[[package]]
@ -3488,6 +3471,7 @@ dependencies = [
"miniscript",
"monero",
"monero-harness",
"monero-rpc",
"pem",
"port_check",
"prettytable-rs",

View File

@ -1,2 +1,2 @@
[workspace]
members = ["monero-harness", "swap"]
members = ["monero-harness", "monero-rpc", "swap"]

View File

@ -6,17 +6,13 @@ edition = "2018"
[dependencies]
anyhow = "1"
digest_auth = "0.2.3"
futures = "0.3"
monero-rpc = { path = "../monero-rpc" }
port_check = "0.1"
rand = "0.7"
reqwest = { version = "0.11", default-features = false, features = ["json", "native-tls"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
spectral = "0.6"
testcontainers = "0.12"
tokio = { version = "1.0", default-features = false, features = ["rt-multi-thread", "time", "macros"] }
tracing = "0.1"
tracing-log = "0.1"
tracing-subscriber = { version = "0.2", default-features = false, features = ["fmt", "ansi", "env-filter"] }
url = "2"

View File

@ -21,18 +21,15 @@
//!
//! Also provides standalone JSON RPC clients for monerod and monero-wallet-rpc.
pub mod image;
pub mod rpc;
use crate::{
image::{
use crate::image::{
MONEROD_DAEMON_CONTAINER_NAME, MONEROD_DEFAULT_NETWORK, MONEROD_RPC_PORT, WALLET_RPC_PORT,
},
rpc::{
monerod,
wallet::{self, GetAddress, Refreshed, Transfer},
},
};
use anyhow::{anyhow, bail, Result};
use monero_rpc::{
monerod,
wallet::{self, GetAddress, Refreshed, Transfer},
};
use std::time::Duration;
use testcontainers::{clients::Cli, core::Port, Container, Docker, RunArgs};
use tokio::time;

12
monero-rpc/Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[package]
name = "monero-rpc"
version = "0.1.0"
authors = ["CoBloX Team <team@coblox.tech>"]
edition = "2018"
[dependencies]
anyhow = "1"
reqwest = { version = "0.11", default-features = false, features = ["json", "native-tls"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tracing = "0.1"

12
monero-rpc/README.md Normal file
View File

@ -0,0 +1,12 @@
Monero Harness
==============
Provides an implementation of `testcontainers::Image` for a monero image to run
`monerod` and `monero-wallet-rpc` in a docker container.
Also provides two standalone JSON RPC clients, one each for `monerod` and `monero-wallet-rpc`.
Example Usage
-------------
Please see `tests/*` for example usage.

View File

@ -0,0 +1 @@
1.46.0

9
monero-rpc/rustfmt.toml Normal file
View File

@ -0,0 +1,9 @@
edition = "2018"
condense_wildcard_suffixes = true
format_macro_matchers = true
imports_granularity = "Crate"
use_field_init_shorthand = true
format_code_in_doc_comments = true
normalize_comments = true
wrap_comments = true
overflow_delimited_expr = true

17
monero-rpc/src/lib.rs Normal file
View File

@ -0,0 +1,17 @@
#![warn(
unused_extern_crates,
missing_debug_implementations,
missing_copy_implementations,
rust_2018_idioms,
clippy::cast_possible_truncation,
clippy::cast_sign_loss,
clippy::fallible_impl_from,
clippy::cast_precision_loss,
clippy::cast_possible_wrap,
clippy::dbg_macro
)]
#![forbid(unsafe_code)]
mod rpc;
pub use self::rpc::*;

View File

@ -39,7 +39,6 @@ struct Response<T> {
#[cfg(test)]
mod tests {
use super::*;
use spectral::prelude::*;
#[derive(Serialize, Debug, Clone)]
struct Params {
@ -58,6 +57,7 @@ mod tests {
let want =
"{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"method\":\"get_block\",\"params\":{\"val\":0}}"
.to_string();
assert_that!(got).is_equal_to(want);
assert_eq!(got, want);
}
}

View File

@ -1,5 +1,4 @@
use crate::rpc::{Request, Response};
use anyhow::Result;
use reqwest::Url;
use serde::{Deserialize, Serialize};

View File

@ -20,7 +20,6 @@ backoff = { version = "0.3", features = ["tokio"] }
base64 = "0.12"
bdk = { version = "0.4" }
bitcoin = { version = "0.26", features = ["rand", "use-serde"] }
bitcoin-harness = { git = "https://github.com/coblox/bitcoin-harness-rs" }
config = { version = "0.10", default-features = false, features = ["toml"] }
conquer-once = "0.3"
curve25519-dalek = "3"
@ -33,7 +32,7 @@ libp2p-async-await = { git = "https://github.com/comit-network/rust-libp2p-async
log = { version = "0.4", features = ["serde"] }
miniscript = { version = "5", features = ["serde"] }
monero = { version = "0.10", features = ["serde_support"] }
monero-harness = { path = "../monero-harness" }
monero-rpc = { path = "../monero-rpc" }
pem = "0.8"
prettytable-rs = "0.8"
rand = "0.7"
@ -62,8 +61,10 @@ uuid = { version = "0.8", features = ["serde", "v4"] }
void = "1"
[dev-dependencies]
bitcoin-harness = { git = "https://github.com/coblox/bitcoin-harness-rs" }
get-port = "3"
hyper = "0.14"
monero-harness = { path = "../monero-harness" }
port_check = "0.1"
serde_cbor = "0.11"
spectral = "0.6"

View File

@ -3,7 +3,7 @@ use crate::{
protocol::{bob, bob::BobState},
};
use ::bitcoin::hashes::core::fmt::Display;
use monero_harness::rpc::wallet::BlockHeight;
use monero_rpc::wallet::BlockHeight;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]

View File

@ -7,7 +7,7 @@ use anyhow::Result;
use async_trait::async_trait;
use backoff::{backoff::Constant as ConstantBackoff, future::retry};
use bitcoin::hashes::core::sync::atomic::AtomicU32;
use monero_harness::rpc::wallet;
use monero_rpc::wallet;
use std::{
str::FromStr,
sync::{atomic::Ordering, Arc},

View File

@ -21,7 +21,7 @@ use ecdsa_fun::{
nonce::Deterministic,
Signature,
};
use monero_harness::rpc::wallet::BlockHeight;
use monero_rpc::wallet::BlockHeight;
use rand::{CryptoRng, RngCore};
use serde::{Deserialize, Serialize};
use sha2::Sha256;