From ab6d3a1d9b3af350d31400e1616d1c490805788d Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 3 Aug 2023 00:16:54 -0700 Subject: [PATCH] split command line into separte module --- Cargo.lock | 31 ++++---- Cargo.toml | 1 + Dockerfile | 4 +- README.md | 2 +- web3_proxy/Cargo.toml | 12 ++-- web3_proxy/src/lib.rs | 3 +- web3_proxy/src/prelude.rs | 34 +++++++++ web3_proxy/src/stats/mod.rs | 70 +++++++++++++++++++ .../{tests/common => src/test_utils}/anvil.rs | 4 +- .../create_provider_with_rpc_key.rs | 10 +++ .../common => src/test_utils}/influx.rs | 13 ++-- web3_proxy/src/test_utils/lib.rs | 3 + web3_proxy/src/test_utils/mod.rs | 8 +++ .../{tests/common => src/test_utils}/mysql.rs | 3 +- web3_proxy/tests/test_stat_buffer.rs | 68 ------------------ web3_proxy_cli/Cargo.toml | 33 +++++++++ .../examples/subscribe_blocks.rs | 5 +- .../examples/tracing.rs | 0 .../examples/watch_blocks.rs | 5 +- .../src/bin/curve_api_checks.rs | 2 + .../src/bin/wait_for_sync.rs | 25 +++---- web3_proxy_cli/src/lib.rs | 2 + .../src/main.rs | 7 +- .../src/sub_commands/change_admin_status.rs | 14 ++-- .../src/sub_commands/change_user_address.rs | 14 ++-- .../src/sub_commands/change_user_tier.rs | 12 ++-- .../change_user_tier_by_address.rs | 14 ++-- .../sub_commands/change_user_tier_by_key.rs | 16 ++--- .../src/sub_commands/check_config.rs | 9 ++- .../src/sub_commands/count_users.rs | 7 +- .../src/sub_commands/create_key.rs | 20 +++--- .../src/sub_commands/create_user.rs | 16 ++--- .../src/sub_commands/delete_user.rs | 0 .../src/sub_commands/drop_migration_lock.rs | 7 +- .../src/sub_commands/example.rs | 2 +- .../sub_commands/grant_credits_to_address.rs | 18 ++--- .../src/sub_commands/list_recent_users.rs | 0 .../src/sub_commands/mass_grant_credits.rs | 14 ++-- .../src/sub_commands/migrate_stats_to_v2.rs | 42 +++++------ .../src/sub_commands/mod.rs | 0 .../src/sub_commands/pagerduty.rs | 14 ++-- .../src/sub_commands/popularity_contest.rs | 9 ++- .../src/sub_commands/proxyd.rs | 29 ++++---- .../src/sub_commands/rpc_accounting.rs | 16 ++--- .../src/sub_commands/search_kafka.rs | 23 +++--- .../src/sub_commands/sentryd/compare.rs | 20 +++--- .../src/sub_commands/sentryd/mod.rs | 25 ++++--- .../src/sub_commands/sentryd/simple.rs | 5 +- .../src/sub_commands/stat_age.rs | 0 .../src/sub_commands/transfer_key.rs | 16 ++--- .../src/sub_commands/user_export.rs | 2 + .../src/sub_commands/user_import.rs | 20 +++--- .../src/test_utils}/admin_deposits.rs | 1 + .../test_utils}/admin_increases_balance.rs | 5 +- .../src/test_utils}/app.rs | 27 ++++--- .../src/test_utils}/create_admin.rs | 23 +++--- .../create_provider_with_rpc_key.rs | 4 +- .../src/test_utils}/create_user.rs | 17 ++--- .../src/test_utils}/mod.rs | 9 +-- .../src/test_utils}/referral.rs | 6 +- .../src/test_utils}/rpc_key.rs | 5 +- .../src/test_utils}/stats_accounting.rs | 3 +- .../src/test_utils}/user_balance.rs | 3 +- .../tests/test_admins.rs | 20 +++--- .../tests/test_multiple_proxy.rs | 30 ++++---- .../tests/test_proxy.rs | 9 ++- .../tests/test_single_proxy.rs | 28 ++++---- .../tests/test_sum_credits_used.rs | 17 +++-- .../tests/test_users.rs | 37 +++++----- 69 files changed, 551 insertions(+), 422 deletions(-) create mode 100644 web3_proxy/src/prelude.rs rename web3_proxy/{tests/common => src/test_utils}/anvil.rs (90%) create mode 100644 web3_proxy/src/test_utils/create_provider_with_rpc_key.rs rename web3_proxy/{tests/common => src/test_utils}/influx.rs (96%) create mode 100644 web3_proxy/src/test_utils/lib.rs create mode 100644 web3_proxy/src/test_utils/mod.rs rename web3_proxy/{tests/common => src/test_utils}/mysql.rs (98%) delete mode 100644 web3_proxy/tests/test_stat_buffer.rs create mode 100644 web3_proxy_cli/Cargo.toml rename {web3_proxy => web3_proxy_cli}/examples/subscribe_blocks.rs (84%) rename {web3_proxy => web3_proxy_cli}/examples/tracing.rs (100%) rename {web3_proxy => web3_proxy_cli}/examples/watch_blocks.rs (85%) rename {web3_proxy => web3_proxy_cli}/src/bin/curve_api_checks.rs (90%) rename {web3_proxy => web3_proxy_cli}/src/bin/wait_for_sync.rs (91%) create mode 100644 web3_proxy_cli/src/lib.rs rename web3_proxy/src/bin/web3_proxy_cli.rs => web3_proxy_cli/src/main.rs (99%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/change_admin_status.rs (87%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/change_user_address.rs (80%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/change_user_tier.rs (88%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/change_user_tier_by_address.rs (82%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/change_user_tier_by_key.rs (81%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/check_config.rs (94%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/count_users.rs (66%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/create_key.rs (77%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/create_user.rs (86%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/delete_user.rs (100%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/drop_migration_lock.rs (73%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/example.rs (87%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/grant_credits_to_address.rs (84%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/list_recent_users.rs (100%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/mass_grant_credits.rs (89%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/migrate_stats_to_v2.rs (91%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/mod.rs (100%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/pagerduty.rs (89%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/popularity_contest.rs (95%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/proxyd.rs (94%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/rpc_accounting.rs (95%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/search_kafka.rs (85%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/sentryd/compare.rs (94%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/sentryd/mod.rs (93%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/sentryd/simple.rs (92%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/stat_age.rs (100%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/transfer_key.rs (82%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/user_export.rs (98%) rename {web3_proxy => web3_proxy_cli}/src/sub_commands/user_import.rs (94%) rename {web3_proxy/tests/common => web3_proxy_cli/src/test_utils}/admin_deposits.rs (96%) rename {web3_proxy/tests/common => web3_proxy_cli/src/test_utils}/admin_increases_balance.rs (90%) rename {web3_proxy/tests/common => web3_proxy_cli/src/test_utils}/app.rs (94%) rename {web3_proxy/tests/common => web3_proxy_cli/src/test_utils}/create_admin.rs (87%) rename {web3_proxy/tests/common => web3_proxy_cli/src/test_utils}/create_provider_with_rpc_key.rs (82%) rename {web3_proxy/tests/common => web3_proxy_cli/src/test_utils}/create_user.rs (88%) rename {web3_proxy/tests/common => web3_proxy_cli/src/test_utils}/mod.rs (63%) rename {web3_proxy/tests/common => web3_proxy_cli/src/test_utils}/referral.rs (96%) rename {web3_proxy/tests/common => web3_proxy_cli/src/test_utils}/rpc_key.rs (95%) rename {web3_proxy/tests/common => web3_proxy_cli/src/test_utils}/stats_accounting.rs (97%) rename {web3_proxy/tests/common => web3_proxy_cli/src/test_utils}/user_balance.rs (91%) rename {web3_proxy => web3_proxy_cli}/tests/test_admins.rs (77%) rename {web3_proxy => web3_proxy_cli}/tests/test_multiple_proxy.rs (93%) rename {web3_proxy => web3_proxy_cli}/tests/test_proxy.rs (94%) rename {web3_proxy => web3_proxy_cli}/tests/test_single_proxy.rs (92%) rename {web3_proxy => web3_proxy_cli}/tests/test_sum_credits_used.rs (97%) rename {web3_proxy => web3_proxy_cli}/tests/test_users.rs (96%) diff --git a/Cargo.lock b/Cargo.lock index 115ea447..bdff027c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4348,17 +4348,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "proctitle" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "924cd8a0de90723d63fed19c5035ea129913a0bc998b37686a67f1eaf6a2aab5" -dependencies = [ - "lazy_static", - "libc", - "winapi", -] - [[package]] name = "prost" version = "0.11.9" @@ -7219,7 +7208,7 @@ dependencies = [ [[package]] name = "web3_proxy" -version = "1.42.1" +version = "1.42.2" dependencies = [ "anyhow", "arc-swap", @@ -7268,8 +7257,6 @@ dependencies = [ "pagerduty-rs", "parking_lot", "payment-contracts", - "prettytable", - "proctitle", "rdkafka", "redis-rate-limiter", "regex", @@ -7300,6 +7287,22 @@ dependencies = [ "uuid 1.4.1", ] +[[package]] +name = "web3_proxy_cli" +version = "0.1.0" +dependencies = [ + "env_logger", + "parking_lot", + "prettytable", + "serde", + "serde_json", + "test-log", + "tokio", + "tracing", + "tracing-subscriber", + "web3_proxy", +] + [[package]] name = "webpki" version = "0.22.0" diff --git a/Cargo.toml b/Cargo.toml index 02c31bf8..4b3c5dd7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ members = [ "rate-counter", "redis-rate-limiter", "web3_proxy", + "web3_proxy_cli", ] resolver = "2" diff --git a/Dockerfile b/Dockerfile index 80923a13..a9acd01c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -78,7 +78,7 @@ RUN --mount=type=cache,target=/root/.cargo/git \ FROM rust as rust_with_env # changing our features doesn't change any of the steps above -ENV WEB3_PROXY_FEATURES "deadlock_detection,rdkafka-src" +ENV WEB3_PROXY_FEATURES "rdkafka-src" # copy the app COPY . . @@ -130,7 +130,7 @@ RUN --mount=type=cache,target=/root/.cargo/git \ --frozen \ --no-default-features \ --offline \ - --path ./web3_proxy \ + --path ./web3_proxy_cli \ --root /usr/local \ ; \ /usr/local/bin/web3_proxy_cli --help | grep 'Usage: web3_proxy_cli' diff --git a/README.md b/README.md index 44f64011..3eb64195 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ RUST_LOG=web3_proxy=trace,info cargo nextest run Run more tests: ``` -RUST_LOG=web3_proxy=trace,info cargo nextest run --features tests-needing-docker +RUST_LOG=web3_proxy=trace,info cargo nextest run --features tests-needing-docker,tests_utils ``` ## Mysql diff --git a/web3_proxy/Cargo.toml b/web3_proxy/Cargo.toml index 06c91f55..086c20da 100644 --- a/web3_proxy/Cargo.toml +++ b/web3_proxy/Cargo.toml @@ -1,18 +1,17 @@ [package] name = "web3_proxy" -version = "1.42.1" +version = "1.42.2" edition = "2021" -default-run = "web3_proxy_cli" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default = ["deadlock_detection"] -deadlock_detection = ["parking_lot/deadlock_detection"] +default = [] + mimalloc = ["dep:mimalloc"] -tokio-console = ["dep:tokio-console", "dep:console-subscriber"] rdkafka-src = ["rdkafka/cmake-build", "rdkafka/libz", "rdkafka/ssl-vendored", "rdkafka/zstd-pkg-config"] tests-needing-docker = [] +tokio-console = ["dep:tokio-console", "dep:console-subscriber"] [dependencies] deferred-rate-limiter = { path = "../deferred-rate-limiter" } @@ -74,8 +73,6 @@ once_cell = { version = "1.18.0" } ordered-float = {version = "3.7.0" } pagerduty-rs = { version = "0.1.6", default-features = false, features = ["async", "rustls", "sync"] } parking_lot = { version = "0.12.1", features = ["arc_lock", "nightly"] } -prettytable = "0.10.0" -proctitle = "0.1.1" rdkafka = { version = "0.33.2", features = ["tracing"] } regex = "1.9.1" reqwest = { version = "0.11.18", default-features = false, features = ["deflate", "gzip", "json", "tokio-rustls"] } @@ -97,7 +94,6 @@ toml = "0.7.6" tower = { version = "0.4.13", features = ["timeout", "tracing"] } tower-http = { version = "0.4.3", features = ["cors", "normalize-path", "sensitive-headers", "trace"] } tracing = "0.1" -tracing-subscriber = { version = "0.3", features = ["env-filter"] } ulid = { version = "1.0.0", features = ["rand", "uuid", "serde"] } url = { version = "2.4.0" } uuid = { version = "1.4.1", default-features = false, features = ["fast-rng", "v4", "zerocopy"] } diff --git a/web3_proxy/src/lib.rs b/web3_proxy/src/lib.rs index d7476eb3..dbde96d5 100644 --- a/web3_proxy/src/lib.rs +++ b/web3_proxy/src/lib.rs @@ -16,6 +16,7 @@ pub mod globals; pub mod http_params; pub mod jsonrpc; pub mod pagerduty; +pub mod prelude; pub mod premium; pub mod prometheus; pub mod referral_code; @@ -23,5 +24,5 @@ pub mod relational_db; pub mod response_cache; pub mod rpcs; pub mod stats; -pub mod sub_commands; +pub mod test_utils; pub mod user_token; diff --git a/web3_proxy/src/prelude.rs b/web3_proxy/src/prelude.rs new file mode 100644 index 00000000..0284ca1a --- /dev/null +++ b/web3_proxy/src/prelude.rs @@ -0,0 +1,34 @@ +pub use anyhow; +pub use argh; +pub use chrono; +pub use entities; +pub use ethers; +pub use ethers::prelude::rand; +pub use fdlimit; +pub use futures; +pub use glob; +pub use hashbrown; +pub use http; +pub use influxdb2; +pub use migration; +pub use migration::sea_orm; +pub use moka; +pub use num; +pub use ordered_float; +pub use pagerduty_rs; +pub use parking_lot; +pub use rdkafka; +pub use reqwest; +pub use rmp_serde; +pub use rust_decimal; +pub use sentry; +pub use sentry_tracing; +pub use serde; +pub use serde_inline_default; +pub use serde_json; +pub use tokio; +pub use toml; +pub use tracing; +pub use ulid; +pub use url; +pub use uuid; diff --git a/web3_proxy/src/stats/mod.rs b/web3_proxy/src/stats/mod.rs index 351addf2..7830711e 100644 --- a/web3_proxy/src/stats/mod.rs +++ b/web3_proxy/src/stats/mod.rs @@ -617,3 +617,73 @@ impl RpcQueryStats { Ok(x) } } + +#[cfg(test)] +mod tests { + use crate::test_utils::TestInflux; + use crate::{caches::UserBalanceCache, stats::StatBuffer}; + use moka::future::Cache; + use tokio::sync::{broadcast, mpsc}; + + #[cfg_attr(not(feature = "tests-needing-docker"), ignore)] + #[test_log::test(tokio::test)] + async fn test_two_buffers() { + let i = TestInflux::spawn().await; + + let billing_period_seconds = 86400 * 7; + let chain_id = 999_001_999; + let db_save_interval_seconds = 60; + let influxdb_bucket = Some(i.bucket.clone()); + let influxdb_client = Some(i.client.clone()); + let rpc_secret_key_cache = Cache::builder().build(); + let tsdb_save_interval_seconds = 30; + let user_balance_cache: UserBalanceCache = Cache::builder().build().into(); + + let (shutdown_sender, shutdown_receiver_1) = broadcast::channel(1); + let shutdown_receiver_2 = shutdown_sender.subscribe(); + + let (flush_sender_1, flush_receiver_1) = mpsc::channel(1); + let (flush_sender_2, flush_receiver_2) = mpsc::channel(1); + + let buffer_1 = StatBuffer::try_spawn( + billing_period_seconds, + chain_id, + db_save_interval_seconds, + influxdb_bucket.clone(), + influxdb_client.clone(), + rpc_secret_key_cache.clone(), + user_balance_cache.clone(), + shutdown_receiver_1, + tsdb_save_interval_seconds, + flush_sender_1, + flush_receiver_1, + 1, + ) + .unwrap() + .unwrap(); + + let buffer_2 = StatBuffer::try_spawn( + billing_period_seconds, + chain_id, + db_save_interval_seconds, + influxdb_bucket, + influxdb_client, + rpc_secret_key_cache, + user_balance_cache, + shutdown_receiver_2, + tsdb_save_interval_seconds, + flush_sender_2, + flush_receiver_2, + 2, + ) + .unwrap() + .unwrap(); + + // TODO: send things to the buffers + + shutdown_sender.send(()).unwrap(); + + buffer_1.background_handle.await.unwrap().unwrap(); + buffer_2.background_handle.await.unwrap().unwrap(); + } +} diff --git a/web3_proxy/tests/common/anvil.rs b/web3_proxy/src/test_utils/anvil.rs similarity index 90% rename from web3_proxy/tests/common/anvil.rs rename to web3_proxy/src/test_utils/anvil.rs index ba396093..fc012cff 100644 --- a/web3_proxy/tests/common/anvil.rs +++ b/web3_proxy/src/test_utils/anvil.rs @@ -1,12 +1,12 @@ // TODO: option to spawn in a dedicated thread? // TODO: option to subscribe to another anvil and copy blocks +use crate::rpcs::provider::EthersHttpProvider; use ethers::{ signers::LocalWallet, utils::{Anvil, AnvilInstance}, }; use tracing::info; -use web3_proxy::rpcs::provider::EthersHttpProvider; /// on drop, the anvil instance will be shut down pub struct TestAnvil { @@ -15,7 +15,6 @@ pub struct TestAnvil { } impl TestAnvil { - #[allow(unused)] pub async fn spawn(chain_id: u64) -> Self { info!(?chain_id); @@ -30,7 +29,6 @@ impl TestAnvil { Self { instance, provider } } - #[allow(unused)] pub fn wallet(&self, id: usize) -> LocalWallet { self.instance.keys()[id].clone().into() } diff --git a/web3_proxy/src/test_utils/create_provider_with_rpc_key.rs b/web3_proxy/src/test_utils/create_provider_with_rpc_key.rs new file mode 100644 index 00000000..355319f1 --- /dev/null +++ b/web3_proxy/src/test_utils/create_provider_with_rpc_key.rs @@ -0,0 +1,10 @@ +use crate::rpcs::provider::EthersHttpProvider; +use ulid::Ulid; +use url::Url; + +pub async fn create_provider_for_user(url: &Url, user_secret_key: &Ulid) -> EthersHttpProvider { + // Then generate a provider + let proxy_endpoint = format!("{}rpc/{}", url, user_secret_key); + + EthersHttpProvider::try_from(proxy_endpoint).unwrap() +} diff --git a/web3_proxy/tests/common/influx.rs b/web3_proxy/src/test_utils/influx.rs similarity index 96% rename from web3_proxy/tests/common/influx.rs rename to web3_proxy/src/test_utils/influx.rs index 75921f8a..6ee7782d 100644 --- a/web3_proxy/tests/common/influx.rs +++ b/web3_proxy/src/test_utils/influx.rs @@ -1,12 +1,12 @@ -use ethers::prelude::rand::{self, distributions::Alphanumeric, Rng}; -use influxdb2::Client; -use std::process::Command as SyncCommand; -use std::time::Duration; -use tokio::{ +use crate::prelude::influxdb2::Client; +use crate::prelude::rand::{self, distributions::Alphanumeric, Rng}; +use crate::prelude::tokio::{ net::TcpStream, process::Command as AsyncCommand, time::{sleep, Instant}, }; +use std::process::Command as SyncCommand; +use std::time::Duration; use tracing::{info, trace}; /// on drop, the mysql docker container will be shut down @@ -21,7 +21,6 @@ pub struct TestInflux { } impl TestInflux { - #[allow(unused)] pub async fn spawn() -> Self { let random: String = rand::thread_rng() .sample_iter(&Alphanumeric) @@ -136,7 +135,7 @@ impl TestInflux { // create the TestInflux as soon as the url is known // when this is dropped, the docker container will be stopped - let mut test_influx = Self { + let test_influx = Self { host: influx_host, org: org.to_string(), token: admin_token.to_string(), diff --git a/web3_proxy/src/test_utils/lib.rs b/web3_proxy/src/test_utils/lib.rs new file mode 100644 index 00000000..e7a11a96 --- /dev/null +++ b/web3_proxy/src/test_utils/lib.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/web3_proxy/src/test_utils/mod.rs b/web3_proxy/src/test_utils/mod.rs new file mode 100644 index 00000000..42f819d8 --- /dev/null +++ b/web3_proxy/src/test_utils/mod.rs @@ -0,0 +1,8 @@ +pub mod anvil; +pub mod create_provider_with_rpc_key; +pub mod influx; +pub mod mysql; + +pub use self::anvil::TestAnvil; +pub use self::influx::TestInflux; +pub use self::mysql::TestMysql; diff --git a/web3_proxy/tests/common/mysql.rs b/web3_proxy/src/test_utils/mysql.rs similarity index 98% rename from web3_proxy/tests/common/mysql.rs rename to web3_proxy/src/test_utils/mysql.rs index 36ac0e05..e67e48f6 100644 --- a/web3_proxy/tests/common/mysql.rs +++ b/web3_proxy/src/test_utils/mysql.rs @@ -1,3 +1,4 @@ +use crate::relational_db::{connect_db, get_migrated_db}; use ethers::prelude::rand::{self, distributions::Alphanumeric, Rng}; use migration::sea_orm::DatabaseConnection; use std::process::Command as SyncCommand; @@ -8,7 +9,6 @@ use tokio::{ time::{sleep, Instant}, }; use tracing::{info, trace, warn}; -use web3_proxy::relational_db::{connect_db, get_migrated_db}; /// on drop, the mysql docker container will be shut down pub struct TestMysql { @@ -17,7 +17,6 @@ pub struct TestMysql { } impl TestMysql { - #[allow(unused)] pub async fn spawn() -> Self { let password: String = rand::thread_rng() .sample_iter(&Alphanumeric) diff --git a/web3_proxy/tests/test_stat_buffer.rs b/web3_proxy/tests/test_stat_buffer.rs deleted file mode 100644 index faf1fb79..00000000 --- a/web3_proxy/tests/test_stat_buffer.rs +++ /dev/null @@ -1,68 +0,0 @@ -mod common; - -use crate::common::influx::TestInflux; -use moka::future::Cache; -use tokio::sync::{broadcast, mpsc}; -use web3_proxy::{caches::UserBalanceCache, stats::StatBuffer}; - -#[cfg_attr(not(feature = "tests-needing-docker"), ignore)] -#[test_log::test(tokio::test)] -async fn test_two_buffers() { - let i = TestInflux::spawn().await; - - let billing_period_seconds = 86400 * 7; - let chain_id = 999_001_999; - let db_save_interval_seconds = 60; - let influxdb_bucket = Some(i.bucket.clone()); - let influxdb_client = Some(i.client.clone()); - let rpc_secret_key_cache = Cache::builder().build(); - let tsdb_save_interval_seconds = 30; - let user_balance_cache: UserBalanceCache = Cache::builder().build().into(); - - let (shutdown_sender, shutdown_receiver_1) = broadcast::channel(1); - let shutdown_receiver_2 = shutdown_sender.subscribe(); - - let (flush_sender_1, flush_receiver_1) = mpsc::channel(1); - let (flush_sender_2, flush_receiver_2) = mpsc::channel(1); - - let buffer_1 = StatBuffer::try_spawn( - billing_period_seconds, - chain_id, - db_save_interval_seconds, - influxdb_bucket.clone(), - influxdb_client.clone(), - rpc_secret_key_cache.clone(), - user_balance_cache.clone(), - shutdown_receiver_1, - tsdb_save_interval_seconds, - flush_sender_1, - flush_receiver_1, - 1, - ) - .unwrap() - .unwrap(); - - let buffer_2 = StatBuffer::try_spawn( - billing_period_seconds, - chain_id, - db_save_interval_seconds, - influxdb_bucket, - influxdb_client, - rpc_secret_key_cache, - user_balance_cache, - shutdown_receiver_2, - tsdb_save_interval_seconds, - flush_sender_2, - flush_receiver_2, - 2, - ) - .unwrap() - .unwrap(); - - // TODO: send things to the buffers - - shutdown_sender.send(()).unwrap(); - - buffer_1.background_handle.await.unwrap().unwrap(); - buffer_2.background_handle.await.unwrap().unwrap(); -} diff --git a/web3_proxy_cli/Cargo.toml b/web3_proxy_cli/Cargo.toml new file mode 100644 index 00000000..0940590f --- /dev/null +++ b/web3_proxy_cli/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "web3_proxy_cli" +version = "0.1.0" +edition = "2021" +default-run = "web3_proxy_cli" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[features] +default = [] + +deadlock_detection = ["parking_lot/deadlock_detection"] +mimalloc = ["web3_proxy/mimalloc"] +rdkafka-src = ["web3_proxy/rdkafka-src"] +tests-needing-docker = ["web3_proxy/tests-needing-docker"] +tokio-console = ["web3_proxy/tokio-console"] + +[dependencies] +web3_proxy = { path = "../web3_proxy" } + +parking_lot = { version = "0.12.1", features = ["arc_lock", "nightly"] } +prettytable = "0.10.0" +serde = { version = "1.0.180" } +serde_json = { version = "1.0.104", default-features = false, features = ["raw_value"] } +tracing = "0.1" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } + +[dev-dependencies] +env_logger = "0.10" +test-log = "0.2.12" +tokio = { version = "1.29.1", features = ["full", "test-util"] } +tracing = {version = "0.1", default-features = false} +tracing-subscriber = {version = "0.3", default-features = false, features = ["env-filter", "fmt"]} diff --git a/web3_proxy/examples/subscribe_blocks.rs b/web3_proxy_cli/examples/subscribe_blocks.rs similarity index 84% rename from web3_proxy/examples/subscribe_blocks.rs rename to web3_proxy_cli/examples/subscribe_blocks.rs index 72345209..27bee5aa 100644 --- a/web3_proxy/examples/subscribe_blocks.rs +++ b/web3_proxy_cli/examples/subscribe_blocks.rs @@ -1,6 +1,9 @@ /// subscribe to a websocket rpc -use ethers::prelude::*; use std::time::Duration; +use web3_proxy::prelude::anyhow; +use web3_proxy::prelude::ethers::prelude::*; +use web3_proxy::prelude::fdlimit; +use web3_proxy::prelude::tokio; #[tokio::main] async fn main() -> anyhow::Result<()> { diff --git a/web3_proxy/examples/tracing.rs b/web3_proxy_cli/examples/tracing.rs similarity index 100% rename from web3_proxy/examples/tracing.rs rename to web3_proxy_cli/examples/tracing.rs diff --git a/web3_proxy/examples/watch_blocks.rs b/web3_proxy_cli/examples/watch_blocks.rs similarity index 85% rename from web3_proxy/examples/watch_blocks.rs rename to web3_proxy_cli/examples/watch_blocks.rs index 04595975..012235a9 100644 --- a/web3_proxy/examples/watch_blocks.rs +++ b/web3_proxy_cli/examples/watch_blocks.rs @@ -1,6 +1,9 @@ /// poll an http rpc -use ethers::prelude::*; use std::{str::FromStr, time::Duration}; +use web3_proxy::prelude::anyhow; +use web3_proxy::prelude::ethers::prelude::*; +use web3_proxy::prelude::fdlimit; +use web3_proxy::prelude::tokio; #[tokio::main] async fn main() -> anyhow::Result<()> { diff --git a/web3_proxy/src/bin/curve_api_checks.rs b/web3_proxy_cli/src/bin/curve_api_checks.rs similarity index 90% rename from web3_proxy/src/bin/curve_api_checks.rs rename to web3_proxy_cli/src/bin/curve_api_checks.rs index 25f47375..6d29d29e 100644 --- a/web3_proxy/src/bin/curve_api_checks.rs +++ b/web3_proxy_cli/src/bin/curve_api_checks.rs @@ -1,3 +1,5 @@ +use web3_proxy::prelude::anyhow; + fn main() -> anyhow::Result<()> { // get curve-api and rpc endpoints from cli flags // do simple checks for proxy version, blockNum, a simple balance call diff --git a/web3_proxy/src/bin/wait_for_sync.rs b/web3_proxy_cli/src/bin/wait_for_sync.rs similarity index 91% rename from web3_proxy/src/bin/wait_for_sync.rs rename to web3_proxy_cli/src/bin/wait_for_sync.rs index 95165e87..bc53132f 100644 --- a/web3_proxy/src/bin/wait_for_sync.rs +++ b/web3_proxy_cli/src/bin/wait_for_sync.rs @@ -1,18 +1,19 @@ // TODO: support websockets -use anyhow::Context; -use argh::FromArgs; -use chrono::Utc; -use ethers::types::U64; -use ethers::types::{Block, TxHash}; -use reqwest::Client; -use serde::Deserialize; -use serde_json::json; use std::sync::atomic::{AtomicU32, Ordering}; -use tokio::time::sleep; -use tokio::time::Duration; -use tracing::info; -use tracing::warn; +use tracing::{info, warn}; +use web3_proxy::prelude::anyhow::{self, Context}; +use web3_proxy::prelude::argh::{self, FromArgs}; +use web3_proxy::prelude::chrono::Utc; +use web3_proxy::prelude::ethers::types::{Block, TxHash, U64}; +use web3_proxy::prelude::fdlimit; +use web3_proxy::prelude::reqwest; +use web3_proxy::prelude::reqwest::Client; +use web3_proxy::prelude::serde::Deserialize; +use web3_proxy::prelude::serde_json::json; +use web3_proxy::prelude::tokio; +use web3_proxy::prelude::tokio::time::sleep; +use web3_proxy::prelude::tokio::time::Duration; #[derive(Debug, FromArgs)] /// Command line interface for admins to interact with web3_proxy diff --git a/web3_proxy_cli/src/lib.rs b/web3_proxy_cli/src/lib.rs new file mode 100644 index 00000000..cdc87a30 --- /dev/null +++ b/web3_proxy_cli/src/lib.rs @@ -0,0 +1,2 @@ +pub mod sub_commands; +pub mod test_utils; diff --git a/web3_proxy/src/bin/web3_proxy_cli.rs b/web3_proxy_cli/src/main.rs similarity index 99% rename from web3_proxy/src/bin/web3_proxy_cli.rs rename to web3_proxy_cli/src/main.rs index 15d7fb81..eb3942c2 100644 --- a/web3_proxy/src/bin/web3_proxy_cli.rs +++ b/web3_proxy_cli/src/main.rs @@ -1,3 +1,5 @@ +use web3_proxy::prelude::*; + use anyhow::Context; use argh::FromArgs; use ethers::types::U256; @@ -14,12 +16,12 @@ use tokio::runtime; use tracing::{info, warn}; use tracing_subscriber::{prelude::*, EnvFilter}; use web3_proxy::pagerduty::panic_handler; -use web3_proxy::sub_commands; use web3_proxy::{ app::APP_USER_AGENT, config::TopConfig, relational_db::{connect_db, get_migrated_db}, }; +use web3_proxy_cli::sub_commands; #[cfg(feature = "mimalloc")] use mimalloc::MiMalloc; @@ -177,9 +179,6 @@ fn main() -> anyhow::Result<()> { let mut top_config: TopConfig = toml::from_str(&top_config)?; - // TODO: this doesn't seem to do anything - proctitle::set_title(format!("web3_proxy-{}", top_config.app.chain_id)); - if cli_config.db_url.is_none() { cli_config.db_url = top_config.app.db_url.clone(); } diff --git a/web3_proxy/src/sub_commands/change_admin_status.rs b/web3_proxy_cli/src/sub_commands/change_admin_status.rs similarity index 87% rename from web3_proxy/src/sub_commands/change_admin_status.rs rename to web3_proxy_cli/src/sub_commands/change_admin_status.rs index 44322cbb..b7d0399e 100644 --- a/web3_proxy/src/sub_commands/change_admin_status.rs +++ b/web3_proxy_cli/src/sub_commands/change_admin_status.rs @@ -1,12 +1,12 @@ -use anyhow::Context; -use argh::FromArgs; -use entities::{admin, login, user}; -use ethers::types::Address; -use migration::sea_orm::{ +use web3_proxy::prelude::anyhow::{self, Context}; +use web3_proxy::prelude::argh::{self, FromArgs}; +use web3_proxy::prelude::entities::{admin, login, user}; +use web3_proxy::prelude::ethers::types::Address; +use web3_proxy::prelude::migration::sea_orm::{ self, ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, ModelTrait, QueryFilter, }; -use serde_json::json; -use tracing::{debug, info}; +use web3_proxy::prelude::serde_json::json; +use web3_proxy::prelude::tracing::{debug, info}; /// change a user's admin status. eiter they are an admin, or they aren't #[derive(FromArgs, PartialEq, Eq, Debug)] diff --git a/web3_proxy/src/sub_commands/change_user_address.rs b/web3_proxy_cli/src/sub_commands/change_user_address.rs similarity index 80% rename from web3_proxy/src/sub_commands/change_user_address.rs rename to web3_proxy_cli/src/sub_commands/change_user_address.rs index a389c293..365acb20 100644 --- a/web3_proxy/src/sub_commands/change_user_address.rs +++ b/web3_proxy_cli/src/sub_commands/change_user_address.rs @@ -1,13 +1,13 @@ -use anyhow::Context; -use argh::FromArgs; -use entities::user; -use ethers::types::Address; -use migration::sea_orm::{ +use web3_proxy::prelude::anyhow::{self, Context}; +use web3_proxy::prelude::argh::{self, FromArgs}; +use web3_proxy::prelude::entities::user; +use web3_proxy::prelude::ethers::types::Address; +use web3_proxy::prelude::migration::sea_orm::{ self, ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, QueryFilter, }; -use serde_json::json; -use tracing::{debug, info}; +use web3_proxy::prelude::serde_json::json; +use web3_proxy::prelude::tracing::{debug, info}; /// change a user's address. #[derive(FromArgs, PartialEq, Eq, Debug)] diff --git a/web3_proxy/src/sub_commands/change_user_tier.rs b/web3_proxy_cli/src/sub_commands/change_user_tier.rs similarity index 88% rename from web3_proxy/src/sub_commands/change_user_tier.rs rename to web3_proxy_cli/src/sub_commands/change_user_tier.rs index f278b8f9..7d5db9e3 100644 --- a/web3_proxy/src/sub_commands/change_user_tier.rs +++ b/web3_proxy_cli/src/sub_commands/change_user_tier.rs @@ -1,12 +1,12 @@ -use anyhow::Context; -use argh::FromArgs; -use entities::user_tier; -use migration::sea_orm::{ +use web3_proxy::prelude::anyhow::{self, Context}; +use web3_proxy::prelude::argh::{self, FromArgs}; +use web3_proxy::prelude::entities::user_tier; +use web3_proxy::prelude::migration::sea_orm::{ self, ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, QueryFilter, }; -use serde_json::json; -use tracing::{debug, info}; +use web3_proxy::prelude::serde_json::json; +use web3_proxy::prelude::tracing::{debug, info}; /// change a user's tier. #[derive(FromArgs, PartialEq, Eq, Debug)] diff --git a/web3_proxy/src/sub_commands/change_user_tier_by_address.rs b/web3_proxy_cli/src/sub_commands/change_user_tier_by_address.rs similarity index 82% rename from web3_proxy/src/sub_commands/change_user_tier_by_address.rs rename to web3_proxy_cli/src/sub_commands/change_user_tier_by_address.rs index 3ec58b54..1745e482 100644 --- a/web3_proxy/src/sub_commands/change_user_tier_by_address.rs +++ b/web3_proxy_cli/src/sub_commands/change_user_tier_by_address.rs @@ -1,13 +1,13 @@ -use anyhow::Context; -use argh::FromArgs; -use entities::{user, user_tier}; -use ethers::types::Address; -use migration::sea_orm::{ +use web3_proxy::prelude::anyhow::{self, Context}; +use web3_proxy::prelude::argh::{self, FromArgs}; +use web3_proxy::prelude::entities::{user, user_tier}; +use web3_proxy::prelude::ethers::types::Address; +use web3_proxy::prelude::migration::sea_orm::{ self, ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, QueryFilter, }; -use serde_json::json; -use tracing::{debug, info}; +use web3_proxy::prelude::serde_json::json; +use web3_proxy::prelude::tracing::{debug, info}; /// change a user's tier. #[derive(FromArgs, PartialEq, Eq, Debug)] diff --git a/web3_proxy/src/sub_commands/change_user_tier_by_key.rs b/web3_proxy_cli/src/sub_commands/change_user_tier_by_key.rs similarity index 81% rename from web3_proxy/src/sub_commands/change_user_tier_by_key.rs rename to web3_proxy_cli/src/sub_commands/change_user_tier_by_key.rs index c6106aa8..24f9e144 100644 --- a/web3_proxy/src/sub_commands/change_user_tier_by_key.rs +++ b/web3_proxy_cli/src/sub_commands/change_user_tier_by_key.rs @@ -1,14 +1,14 @@ -use crate::frontend::authorization::RpcSecretKey; -use anyhow::Context; -use argh::FromArgs; -use entities::{rpc_key, user, user_tier}; -use migration::sea_orm::{ +use web3_proxy::frontend::authorization::RpcSecretKey; +use web3_proxy::prelude::anyhow::{self, Context}; +use web3_proxy::prelude::argh::{self, FromArgs}; +use web3_proxy::prelude::entities::{rpc_key, user, user_tier}; +use web3_proxy::prelude::migration::sea_orm::{ self, ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, QueryFilter, }; -use serde_json::json; -use tracing::{debug, info}; -use uuid::Uuid; +use web3_proxy::prelude::serde_json::json; +use web3_proxy::prelude::tracing::{debug, info}; +use web3_proxy::prelude::uuid::Uuid; /// change a user's tier. #[derive(FromArgs, PartialEq, Eq, Debug)] diff --git a/web3_proxy/src/sub_commands/check_config.rs b/web3_proxy_cli/src/sub_commands/check_config.rs similarity index 94% rename from web3_proxy/src/sub_commands/check_config.rs rename to web3_proxy_cli/src/sub_commands/check_config.rs index 6e6721eb..dc976a3b 100644 --- a/web3_proxy/src/sub_commands/check_config.rs +++ b/web3_proxy_cli/src/sub_commands/check_config.rs @@ -1,7 +1,9 @@ -use crate::config::TopConfig; -use argh::FromArgs; use std::fs; -use tracing::{error, info, warn}; +use web3_proxy::config::TopConfig; +use web3_proxy::prelude::anyhow; +use web3_proxy::prelude::argh::{self, FromArgs}; +use web3_proxy::prelude::toml; +use web3_proxy::prelude::tracing::{error, info, warn}; #[derive(FromArgs, PartialEq, Eq, Debug)] /// Check the config for any problems. @@ -93,6 +95,7 @@ impl CheckConfigSubCommand { #[cfg(test)] mod tests { use std::env; + use web3_proxy::prelude::tokio; use super::*; diff --git a/web3_proxy/src/sub_commands/count_users.rs b/web3_proxy_cli/src/sub_commands/count_users.rs similarity index 66% rename from web3_proxy/src/sub_commands/count_users.rs rename to web3_proxy_cli/src/sub_commands/count_users.rs index 0bfa3e57..b920c570 100644 --- a/web3_proxy/src/sub_commands/count_users.rs +++ b/web3_proxy_cli/src/sub_commands/count_users.rs @@ -1,7 +1,8 @@ -use argh::FromArgs; -use entities::user; -use migration::sea_orm::{self, EntityTrait, PaginatorTrait}; use tracing::info; +use web3_proxy::prelude::anyhow; +use web3_proxy::prelude::argh::{self, FromArgs}; +use web3_proxy::prelude::entities::user; +use web3_proxy::prelude::migration::sea_orm::{self, EntityTrait, PaginatorTrait}; #[derive(FromArgs, PartialEq, Debug, Eq)] /// Create a new user and api key diff --git a/web3_proxy/src/sub_commands/create_key.rs b/web3_proxy_cli/src/sub_commands/create_key.rs similarity index 77% rename from web3_proxy/src/sub_commands/create_key.rs rename to web3_proxy_cli/src/sub_commands/create_key.rs index cfe10f6a..e91d3ac5 100644 --- a/web3_proxy/src/sub_commands/create_key.rs +++ b/web3_proxy_cli/src/sub_commands/create_key.rs @@ -1,12 +1,14 @@ -use crate::frontend::authorization::RpcSecretKey; -use anyhow::Context; -use argh::FromArgs; -use entities::{rpc_key, user}; -use ethers::prelude::Address; -use migration::sea_orm::{self, ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter}; -use tracing::info; -use ulid::Ulid; -use uuid::Uuid; +use web3_proxy::frontend::authorization::RpcSecretKey; +use web3_proxy::prelude::anyhow::{self, Context}; +use web3_proxy::prelude::argh::{self, FromArgs}; +use web3_proxy::prelude::entities::{rpc_key, user}; +use web3_proxy::prelude::ethers::prelude::Address; +use web3_proxy::prelude::migration::sea_orm::{ + self, ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter, +}; +use web3_proxy::prelude::tracing::info; +use web3_proxy::prelude::ulid::Ulid; +use web3_proxy::prelude::uuid::Uuid; #[derive(FromArgs, PartialEq, Debug, Eq)] /// Create a new user and api key diff --git a/web3_proxy/src/sub_commands/create_user.rs b/web3_proxy_cli/src/sub_commands/create_user.rs similarity index 86% rename from web3_proxy/src/sub_commands/create_user.rs rename to web3_proxy_cli/src/sub_commands/create_user.rs index 3020d479..d7e553e5 100644 --- a/web3_proxy/src/sub_commands/create_user.rs +++ b/web3_proxy_cli/src/sub_commands/create_user.rs @@ -1,12 +1,12 @@ -use crate::frontend::authorization::RpcSecretKey; -use anyhow::Context; -use argh::FromArgs; -use entities::{rpc_key, user}; -use ethers::prelude::Address; -use migration::sea_orm::{self, ActiveModelTrait, TransactionTrait}; use tracing::info; -use ulid::Ulid; -use uuid::Uuid; +use web3_proxy::frontend::authorization::RpcSecretKey; +use web3_proxy::prelude::anyhow::{self, Context}; +use web3_proxy::prelude::argh::{self, FromArgs}; +use web3_proxy::prelude::entities::{rpc_key, user}; +use web3_proxy::prelude::ethers::prelude::Address; +use web3_proxy::prelude::migration::sea_orm::{self, ActiveModelTrait, TransactionTrait}; +use web3_proxy::prelude::ulid::Ulid; +use web3_proxy::prelude::uuid::Uuid; #[derive(FromArgs, PartialEq, Debug, Eq)] /// Create a new user and api key diff --git a/web3_proxy/src/sub_commands/delete_user.rs b/web3_proxy_cli/src/sub_commands/delete_user.rs similarity index 100% rename from web3_proxy/src/sub_commands/delete_user.rs rename to web3_proxy_cli/src/sub_commands/delete_user.rs diff --git a/web3_proxy/src/sub_commands/drop_migration_lock.rs b/web3_proxy_cli/src/sub_commands/drop_migration_lock.rs similarity index 73% rename from web3_proxy/src/sub_commands/drop_migration_lock.rs rename to web3_proxy_cli/src/sub_commands/drop_migration_lock.rs index 72bd3a6b..8a25a67b 100644 --- a/web3_proxy/src/sub_commands/drop_migration_lock.rs +++ b/web3_proxy_cli/src/sub_commands/drop_migration_lock.rs @@ -1,6 +1,7 @@ -use crate::relational_db::{drop_migration_lock, migrate_db}; -use argh::FromArgs; -use migration::sea_orm::DatabaseConnection; +use web3_proxy::prelude::anyhow; +use web3_proxy::prelude::argh::{self, FromArgs}; +use web3_proxy::prelude::migration::sea_orm::DatabaseConnection; +use web3_proxy::relational_db::{drop_migration_lock, migrate_db}; #[derive(FromArgs, PartialEq, Debug, Eq)] /// In case of emergency, break glass. diff --git a/web3_proxy/src/sub_commands/example.rs b/web3_proxy_cli/src/sub_commands/example.rs similarity index 87% rename from web3_proxy/src/sub_commands/example.rs rename to web3_proxy_cli/src/sub_commands/example.rs index 51e2fa64..9080bf31 100644 --- a/web3_proxy/src/sub_commands/example.rs +++ b/web3_proxy_cli/src/sub_commands/example.rs @@ -1,4 +1,4 @@ -use argh::FromArgs; +use web3_proxy::prelude::argh::{self, FromArgs}; #[derive(FromArgs, PartialEq, Debug)] /// An example subcommand. Copy paste this into a new file. diff --git a/web3_proxy/src/sub_commands/grant_credits_to_address.rs b/web3_proxy_cli/src/sub_commands/grant_credits_to_address.rs similarity index 84% rename from web3_proxy/src/sub_commands/grant_credits_to_address.rs rename to web3_proxy_cli/src/sub_commands/grant_credits_to_address.rs index 89ad1228..bdc0f271 100644 --- a/web3_proxy/src/sub_commands/grant_credits_to_address.rs +++ b/web3_proxy_cli/src/sub_commands/grant_credits_to_address.rs @@ -2,18 +2,18 @@ // that's easier than refactoring right now. // it could be cleaned up, but this is a script that runs once so isn't worth spending tons of time on. -use crate::balance::Balance; -use anyhow::Context; -use argh::FromArgs; -use entities::{admin_increase_balance_receipt, user, user_tier}; -use ethers::types::Address; -use migration::sea_orm::{ +use web3_proxy::balance::Balance; +use web3_proxy::prelude::anyhow::{self, Context}; +use web3_proxy::prelude::argh::{self, FromArgs}; +use web3_proxy::prelude::entities::{admin_increase_balance_receipt, user, user_tier}; +use web3_proxy::prelude::ethers::types::Address; +use web3_proxy::prelude::migration::sea_orm::{ self, ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, QueryFilter, TransactionTrait, }; -use rust_decimal::Decimal; -use serde_json::json; -use tracing::info; +use web3_proxy::prelude::rust_decimal::Decimal; +use web3_proxy::prelude::serde_json::json; +use web3_proxy::prelude::tracing::info; #[derive(FromArgs, PartialEq, Debug)] /// Grant credits to all the users in a tier (and change their tier to premium). diff --git a/web3_proxy/src/sub_commands/list_recent_users.rs b/web3_proxy_cli/src/sub_commands/list_recent_users.rs similarity index 100% rename from web3_proxy/src/sub_commands/list_recent_users.rs rename to web3_proxy_cli/src/sub_commands/list_recent_users.rs diff --git a/web3_proxy/src/sub_commands/mass_grant_credits.rs b/web3_proxy_cli/src/sub_commands/mass_grant_credits.rs similarity index 89% rename from web3_proxy/src/sub_commands/mass_grant_credits.rs rename to web3_proxy_cli/src/sub_commands/mass_grant_credits.rs index 658f7c53..288798e2 100644 --- a/web3_proxy/src/sub_commands/mass_grant_credits.rs +++ b/web3_proxy_cli/src/sub_commands/mass_grant_credits.rs @@ -2,16 +2,16 @@ // that's easier than refactoring right now. // it could be cleaned up, but this is a script that runs once so isn't worth spending tons of time on. -use anyhow::Context; -use argh::FromArgs; -use entities::{admin_increase_balance_receipt, user, user_tier}; -use futures::TryStreamExt; -use migration::sea_orm::{ +use tracing::info; +use web3_proxy::prelude::anyhow::{self, Context}; +use web3_proxy::prelude::argh::{self, FromArgs}; +use web3_proxy::prelude::entities::{admin_increase_balance_receipt, user, user_tier}; +use web3_proxy::prelude::futures::TryStreamExt; +use web3_proxy::prelude::migration::sea_orm::{ self, ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, PaginatorTrait, QueryFilter, QueryOrder, TransactionTrait, }; -use rust_decimal::Decimal; -use tracing::info; +use web3_proxy::prelude::rust_decimal::Decimal; #[derive(FromArgs, PartialEq, Debug)] /// Grant credits to all the users in a tier (and change their tier to premium). diff --git a/web3_proxy/src/sub_commands/migrate_stats_to_v2.rs b/web3_proxy_cli/src/sub_commands/migrate_stats_to_v2.rs similarity index 91% rename from web3_proxy/src/sub_commands/migrate_stats_to_v2.rs rename to web3_proxy_cli/src/sub_commands/migrate_stats_to_v2.rs index 7d5afb11..75f708cc 100644 --- a/web3_proxy/src/sub_commands/migrate_stats_to_v2.rs +++ b/web3_proxy_cli/src/sub_commands/migrate_stats_to_v2.rs @@ -1,26 +1,28 @@ -use crate::app::BILLING_PERIOD_SECONDS; -use crate::config::TopConfig; -use crate::frontend::authorization::{Authorization, RequestMetadata, RpcSecretKey}; -use crate::rpcs::one::Web3Rpc; -use crate::stats::StatBuffer; -use anyhow::Context; -use argh::FromArgs; -use entities::{rpc_accounting, rpc_key}; -use futures::stream::FuturesUnordered; -use futures::StreamExt; -use migration::sea_orm::QueryOrder; -use migration::sea_orm::{ - ColumnTrait, DatabaseConnection, EntityTrait, QueryFilter, QuerySelect, UpdateResult, -}; -use migration::{Expr, Value}; -use moka::future::Cache; -use parking_lot::Mutex; use std::num::NonZeroU64; use std::sync::Arc; -use tokio::sync::{broadcast, mpsc}; -use tokio::time::Instant; use tracing::{error, info}; -use ulid::Ulid; +use web3_proxy::app::BILLING_PERIOD_SECONDS; +use web3_proxy::config::TopConfig; +use web3_proxy::frontend::authorization::{Authorization, RequestMetadata, RpcSecretKey}; +use web3_proxy::prelude::anyhow::{self, Context}; +use web3_proxy::prelude::argh::{self, FromArgs}; +use web3_proxy::prelude::chrono; +use web3_proxy::prelude::entities::{rpc_accounting, rpc_key}; +use web3_proxy::prelude::futures::stream::FuturesUnordered; +use web3_proxy::prelude::futures::StreamExt; +use web3_proxy::prelude::influxdb2; +use web3_proxy::prelude::migration::sea_orm::{ + ColumnTrait, DatabaseConnection, EntityTrait, QueryFilter, QueryOrder, QuerySelect, + UpdateResult, +}; +use web3_proxy::prelude::migration::{Expr, Value}; +use web3_proxy::prelude::moka::future::Cache; +use web3_proxy::prelude::parking_lot::Mutex; +use web3_proxy::prelude::tokio::sync::{broadcast, mpsc}; +use web3_proxy::prelude::tokio::time::Instant; +use web3_proxy::prelude::ulid::Ulid; +use web3_proxy::rpcs::one::Web3Rpc; +use web3_proxy::stats::StatBuffer; #[derive(FromArgs, PartialEq, Eq, Debug)] /// Migrate towards influxdb and rpc_accounting_v2 from rpc_accounting diff --git a/web3_proxy/src/sub_commands/mod.rs b/web3_proxy_cli/src/sub_commands/mod.rs similarity index 100% rename from web3_proxy/src/sub_commands/mod.rs rename to web3_proxy_cli/src/sub_commands/mod.rs diff --git a/web3_proxy/src/sub_commands/pagerduty.rs b/web3_proxy_cli/src/sub_commands/pagerduty.rs similarity index 89% rename from web3_proxy/src/sub_commands/pagerduty.rs rename to web3_proxy_cli/src/sub_commands/pagerduty.rs index 400b7ed6..d8a21e2e 100644 --- a/web3_proxy/src/sub_commands/pagerduty.rs +++ b/web3_proxy_cli/src/sub_commands/pagerduty.rs @@ -1,11 +1,15 @@ -use crate::{ +use tracing::{error, info}; +use web3_proxy::prelude::anyhow; +use web3_proxy::prelude::argh::{self, FromArgs}; +use web3_proxy::prelude::pagerduty_rs; +use web3_proxy::prelude::pagerduty_rs::{ + eventsv2async::EventsV2 as PagerdutyAsyncEventsV2, types::Event, +}; +use web3_proxy::prelude::serde_json::json; +use web3_proxy::{ config::TopConfig, pagerduty::{pagerduty_alert, pagerduty_alert_for_config}, }; -use argh::FromArgs; -use pagerduty_rs::{eventsv2async::EventsV2 as PagerdutyAsyncEventsV2, types::Event}; -use serde_json::json; -use tracing::{error, info}; #[derive(FromArgs, PartialEq, Debug, Eq)] /// Quickly create a pagerduty alert diff --git a/web3_proxy/src/sub_commands/popularity_contest.rs b/web3_proxy_cli/src/sub_commands/popularity_contest.rs similarity index 95% rename from web3_proxy/src/sub_commands/popularity_contest.rs rename to web3_proxy_cli/src/sub_commands/popularity_contest.rs index b94a09b7..a0ab52c9 100644 --- a/web3_proxy/src/sub_commands/popularity_contest.rs +++ b/web3_proxy_cli/src/sub_commands/popularity_contest.rs @@ -1,8 +1,11 @@ -use argh::FromArgs; -use ethers::types::U64; -use ordered_float::OrderedFloat; use prettytable::{row, Table}; use std::{cmp::Reverse, str::FromStr}; +use web3_proxy::prelude::anyhow; +use web3_proxy::prelude::argh::{self, FromArgs}; +use web3_proxy::prelude::ethers::types::U64; +use web3_proxy::prelude::ordered_float::OrderedFloat; +use web3_proxy::prelude::reqwest; +use web3_proxy::prelude::serde_json; #[derive(FromArgs, PartialEq, Debug)] /// show what nodes are used most often diff --git a/web3_proxy/src/sub_commands/proxyd.rs b/web3_proxy_cli/src/sub_commands/proxyd.rs similarity index 94% rename from web3_proxy/src/sub_commands/proxyd.rs rename to web3_proxy_cli/src/sub_commands/proxyd.rs index d1b00b13..aef14eda 100644 --- a/web3_proxy/src/sub_commands/proxyd.rs +++ b/web3_proxy_cli/src/sub_commands/proxyd.rs @@ -1,22 +1,25 @@ -use crate::app::{flatten_handle, flatten_handles, Web3ProxyApp}; -use crate::compute_units::default_usd_per_cu; -use crate::config::TopConfig; -use crate::globals::global_db_conn; -use crate::stats::FlushedStats; -use crate::{frontend, prometheus}; -use argh::FromArgs; -use futures::StreamExt; -use num::Zero; use std::path::PathBuf; use std::sync::atomic::AtomicU16; use std::sync::Arc; use std::time::Duration; use std::{fs, thread}; -use tokio::signal::unix::SignalKind; -use tokio::sync::{broadcast, mpsc, oneshot}; -use tokio::time::{sleep_until, Instant}; -use tokio::{select, signal}; use tracing::{error, info, trace, warn}; +use web3_proxy::app::{flatten_handle, flatten_handles, Web3ProxyApp}; +use web3_proxy::compute_units::default_usd_per_cu; +use web3_proxy::config::TopConfig; +use web3_proxy::globals::global_db_conn; +use web3_proxy::prelude::anyhow; +use web3_proxy::prelude::argh::{self, FromArgs}; +use web3_proxy::prelude::futures::StreamExt; +use web3_proxy::prelude::num::Zero; +use web3_proxy::prelude::tokio; +use web3_proxy::prelude::tokio::signal::unix::SignalKind; +use web3_proxy::prelude::tokio::sync::{broadcast, mpsc, oneshot}; +use web3_proxy::prelude::tokio::time::{sleep_until, Instant}; +use web3_proxy::prelude::tokio::{select, signal}; +use web3_proxy::prelude::toml; +use web3_proxy::stats::FlushedStats; +use web3_proxy::{frontend, prometheus}; /// start the main proxy daemon #[derive(FromArgs, PartialEq, Debug, Eq)] diff --git a/web3_proxy/src/sub_commands/rpc_accounting.rs b/web3_proxy_cli/src/sub_commands/rpc_accounting.rs similarity index 95% rename from web3_proxy/src/sub_commands/rpc_accounting.rs rename to web3_proxy_cli/src/sub_commands/rpc_accounting.rs index cdd14051..cc19e7fb 100644 --- a/web3_proxy/src/sub_commands/rpc_accounting.rs +++ b/web3_proxy_cli/src/sub_commands/rpc_accounting.rs @@ -1,9 +1,12 @@ // select all requests for a timeline. sum bandwidth and request count. give `cost / byte` and `cost / request`. -use anyhow::Context; -use argh::FromArgs; -use entities::{rpc_accounting, rpc_key, user}; -use ethers::types::Address; -use migration::{ +use serde::Serialize; +use serde_json::json; +use tracing::info; +use web3_proxy::prelude::anyhow::{self, Context}; +use web3_proxy::prelude::argh::{self, FromArgs}; +use web3_proxy::prelude::entities::{rpc_accounting, rpc_key, user}; +use web3_proxy::prelude::ethers::types::Address; +use web3_proxy::prelude::migration::{ sea_orm::{ self, prelude::{DateTimeUtc, Decimal}, @@ -11,9 +14,6 @@ use migration::{ }, Condition, }; -use serde::Serialize; -use serde_json::json; -use tracing::info; /// count requests #[derive(FromArgs, PartialEq, Debug, Eq)] diff --git a/web3_proxy/src/sub_commands/search_kafka.rs b/web3_proxy_cli/src/sub_commands/search_kafka.rs similarity index 85% rename from web3_proxy/src/sub_commands/search_kafka.rs rename to web3_proxy_cli/src/sub_commands/search_kafka.rs index f0445195..cdfd9e29 100644 --- a/web3_proxy/src/sub_commands/search_kafka.rs +++ b/web3_proxy_cli/src/sub_commands/search_kafka.rs @@ -1,16 +1,19 @@ -use crate::{config::TopConfig, frontend::authorization::RpcSecretKey, relational_db::connect_db}; -use anyhow::Context; -use argh::FromArgs; -use entities::rpc_key; -use futures::TryStreamExt; -use migration::sea_orm::{ColumnTrait, EntityTrait, QueryFilter}; -use rdkafka::{ +use std::num::NonZeroU64; +use tracing::info; +use web3_proxy::prelude::anyhow::{self, Context}; +use web3_proxy::prelude::argh::{self, FromArgs}; +use web3_proxy::prelude::entities::rpc_key; +use web3_proxy::prelude::futures::TryStreamExt; +use web3_proxy::prelude::migration::sea_orm::{ColumnTrait, EntityTrait, QueryFilter}; +use web3_proxy::prelude::rdkafka::{ consumer::{Consumer, StreamConsumer}, ClientConfig, Message, }; -use std::num::NonZeroU64; -use tracing::info; -use uuid::Uuid; +use web3_proxy::prelude::rmp_serde; +use web3_proxy::prelude::uuid::Uuid; +use web3_proxy::{ + config::TopConfig, frontend::authorization::RpcSecretKey, relational_db::connect_db, +}; /// Second subcommand. #[derive(FromArgs, PartialEq, Debug, Eq)] diff --git a/web3_proxy/src/sub_commands/sentryd/compare.rs b/web3_proxy_cli/src/sub_commands/sentryd/compare.rs similarity index 94% rename from web3_proxy/src/sub_commands/sentryd/compare.rs rename to web3_proxy_cli/src/sub_commands/sentryd/compare.rs index 2416e159..54889d37 100644 --- a/web3_proxy/src/sub_commands/sentryd/compare.rs +++ b/web3_proxy_cli/src/sub_commands/sentryd/compare.rs @@ -1,13 +1,15 @@ -use crate::jsonrpc::JsonRpcErrorData; -use anyhow::{anyhow, Context}; -use chrono::{DateTime, Utc}; -use ethers::types::{Block, TxHash, H256}; -use futures::{stream::FuturesUnordered, StreamExt}; -use serde::{Deserialize, Serialize}; -use serde_json::json; -use tracing::{debug, warn}; - use super::{SentrydErrorBuilder, SentrydResult}; +use tracing::{debug, warn}; +use web3_proxy::jsonrpc::JsonRpcErrorData; +use web3_proxy::prelude::anyhow; +use web3_proxy::prelude::anyhow::{anyhow, Context}; +use web3_proxy::prelude::chrono::{DateTime, Utc}; +use web3_proxy::prelude::ethers::types::{Block, TxHash, H256}; +use web3_proxy::prelude::futures::{stream::FuturesUnordered, StreamExt}; +use web3_proxy::prelude::reqwest; +use web3_proxy::prelude::serde::{Deserialize, Serialize}; +use web3_proxy::prelude::serde_json::json; +use web3_proxy::prelude::tokio; #[derive(Debug, Deserialize, Serialize)] struct JsonRpcResponse { diff --git a/web3_proxy/src/sub_commands/sentryd/mod.rs b/web3_proxy_cli/src/sub_commands/sentryd/mod.rs similarity index 93% rename from web3_proxy/src/sub_commands/sentryd/mod.rs rename to web3_proxy_cli/src/sub_commands/sentryd/mod.rs index 62750590..66fbf09e 100644 --- a/web3_proxy/src/sub_commands/sentryd/mod.rs +++ b/web3_proxy_cli/src/sub_commands/sentryd/mod.rs @@ -1,19 +1,24 @@ mod compare; mod simple; -use crate::{config::TopConfig, pagerduty::pagerduty_alert}; -use anyhow::Context; -use argh::FromArgs; -use futures::{ +use std::time::Duration; +use tracing::{debug, error, info, warn, Level}; +use web3_proxy::prelude::anyhow::{self, Context}; +use web3_proxy::prelude::argh::{self, FromArgs}; +use web3_proxy::prelude::futures::{ stream::{FuturesUnordered, StreamExt}, Future, }; -use pagerduty_rs::{eventsv2async::EventsV2 as PagerdutyAsyncEventsV2, types::Event}; -use serde_json::json; -use std::time::Duration; -use tokio::sync::mpsc; -use tokio::time::{interval, MissedTickBehavior}; -use tracing::{debug, error, info, warn, Level}; +use web3_proxy::prelude::pagerduty_rs; +use web3_proxy::prelude::pagerduty_rs::{ + eventsv2async::EventsV2 as PagerdutyAsyncEventsV2, types::Event, +}; +use web3_proxy::prelude::serde_json; +use web3_proxy::prelude::serde_json::json; +use web3_proxy::prelude::tokio; +use web3_proxy::prelude::tokio::sync::mpsc; +use web3_proxy::prelude::tokio::time::{interval, MissedTickBehavior}; +use web3_proxy::{config::TopConfig, pagerduty::pagerduty_alert}; #[derive(FromArgs, PartialEq, Debug, Eq)] /// Loop healthchecks and send pager duty alerts if any fail diff --git a/web3_proxy/src/sub_commands/sentryd/simple.rs b/web3_proxy_cli/src/sub_commands/sentryd/simple.rs similarity index 92% rename from web3_proxy/src/sub_commands/sentryd/simple.rs rename to web3_proxy_cli/src/sub_commands/sentryd/simple.rs index fa0f8668..f2ca0583 100644 --- a/web3_proxy/src/sub_commands/sentryd/simple.rs +++ b/web3_proxy_cli/src/sub_commands/sentryd/simple.rs @@ -1,9 +1,10 @@ use std::time::Duration; use super::{SentrydErrorBuilder, SentrydResult}; -use anyhow::Context; -use tokio::time::Instant; use tracing::{debug, trace}; +use web3_proxy::prelude::anyhow::{self, Context}; +use web3_proxy::prelude::reqwest; +use web3_proxy::prelude::tokio::time::Instant; /// GET the url and return an error if it wasn't a success pub async fn main( diff --git a/web3_proxy/src/sub_commands/stat_age.rs b/web3_proxy_cli/src/sub_commands/stat_age.rs similarity index 100% rename from web3_proxy/src/sub_commands/stat_age.rs rename to web3_proxy_cli/src/sub_commands/stat_age.rs diff --git a/web3_proxy/src/sub_commands/transfer_key.rs b/web3_proxy_cli/src/sub_commands/transfer_key.rs similarity index 82% rename from web3_proxy/src/sub_commands/transfer_key.rs rename to web3_proxy_cli/src/sub_commands/transfer_key.rs index 9b4b9c72..f7b7ea48 100644 --- a/web3_proxy/src/sub_commands/transfer_key.rs +++ b/web3_proxy_cli/src/sub_commands/transfer_key.rs @@ -1,14 +1,14 @@ -use crate::frontend::authorization::RpcSecretKey; -use anyhow::Context; -use argh::FromArgs; -use entities::{rpc_key, user}; -use ethers::types::Address; -use migration::sea_orm::{ +use tracing::{debug, info}; +use web3_proxy::frontend::authorization::RpcSecretKey; +use web3_proxy::prelude::anyhow::{self, Context}; +use web3_proxy::prelude::argh::{self, FromArgs}; +use web3_proxy::prelude::entities::{rpc_key, user}; +use web3_proxy::prelude::ethers::types::Address; +use web3_proxy::prelude::sea_orm::{ self, ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, QueryFilter, }; -use sea_orm::prelude::Uuid; -use tracing::{debug, info}; +use web3_proxy::prelude::uuid::Uuid; /// change a key's owner. #[derive(FromArgs, PartialEq, Eq, Debug)] diff --git a/web3_proxy/src/sub_commands/user_export.rs b/web3_proxy_cli/src/sub_commands/user_export.rs similarity index 98% rename from web3_proxy/src/sub_commands/user_export.rs rename to web3_proxy_cli/src/sub_commands/user_export.rs index fff3020b..2c6f6351 100644 --- a/web3_proxy/src/sub_commands/user_export.rs +++ b/web3_proxy_cli/src/sub_commands/user_export.rs @@ -5,6 +5,8 @@ use std::fs::{self, create_dir_all}; use std::path::Path; use tracing::info; +use web3_proxy::prelude::*; + #[derive(FromArgs, PartialEq, Eq, Debug)] /// Export users from the database. #[argh(subcommand, name = "user_export")] diff --git a/web3_proxy/src/sub_commands/user_import.rs b/web3_proxy_cli/src/sub_commands/user_import.rs similarity index 94% rename from web3_proxy/src/sub_commands/user_import.rs rename to web3_proxy_cli/src/sub_commands/user_import.rs index f04f3a63..7283b462 100644 --- a/web3_proxy/src/sub_commands/user_import.rs +++ b/web3_proxy_cli/src/sub_commands/user_import.rs @@ -1,16 +1,16 @@ -use anyhow::Context; -use argh::FromArgs; -use entities::{rpc_key, user}; -use glob::glob; -use hashbrown::HashMap; -use migration::sea_orm::ActiveValue::NotSet; -use migration::sea_orm::{ - ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, QueryFilter, - Set, -}; use std::path::{Path, PathBuf}; use std::{fs::File, io::BufReader}; use tracing::info; +use web3_proxy::prelude::anyhow::{self, Context}; +use web3_proxy::prelude::argh::{self, FromArgs}; +use web3_proxy::prelude::entities::{rpc_key, user}; +use web3_proxy::prelude::glob::glob; +use web3_proxy::prelude::hashbrown::HashMap; +use web3_proxy::prelude::migration::sea_orm::ActiveValue::NotSet; +use web3_proxy::prelude::migration::sea_orm::{ + ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, QueryFilter, + Set, +}; #[derive(FromArgs, PartialEq, Eq, Debug)] /// Import users from another database. diff --git a/web3_proxy/tests/common/admin_deposits.rs b/web3_proxy_cli/src/test_utils/admin_deposits.rs similarity index 96% rename from web3_proxy/tests/common/admin_deposits.rs rename to web3_proxy_cli/src/test_utils/admin_deposits.rs index 3ade8d2e..6d83ba4b 100644 --- a/web3_proxy/tests/common/admin_deposits.rs +++ b/web3_proxy_cli/src/test_utils/admin_deposits.rs @@ -1,6 +1,7 @@ use super::TestApp; use tracing::trace; use web3_proxy::frontend::users::authentication::LoginPostResponse; +use web3_proxy::prelude::reqwest; /// Helper function to increase the balance of a user, from an admin #[allow(unused)] diff --git a/web3_proxy/tests/common/admin_increases_balance.rs b/web3_proxy_cli/src/test_utils/admin_increases_balance.rs similarity index 90% rename from web3_proxy/tests/common/admin_increases_balance.rs rename to web3_proxy_cli/src/test_utils/admin_increases_balance.rs index 0e3b0624..c34bbc34 100644 --- a/web3_proxy/tests/common/admin_increases_balance.rs +++ b/web3_proxy_cli/src/test_utils/admin_increases_balance.rs @@ -1,9 +1,10 @@ use super::TestApp; -use ethers::prelude::{LocalWallet, Signer}; -use migration::sea_orm::prelude::Decimal; use tracing::info; use web3_proxy::frontend::admin::AdminIncreaseBalancePost; use web3_proxy::frontend::users::authentication::LoginPostResponse; +use web3_proxy::prelude::ethers::prelude::{LocalWallet, Signer}; +use web3_proxy::prelude::migration::sea_orm::prelude::Decimal; +use web3_proxy::prelude::reqwest; /// Helper function to increase the balance of a user, from an admin #[allow(unused)] diff --git a/web3_proxy/tests/common/app.rs b/web3_proxy_cli/src/test_utils/app.rs similarity index 94% rename from web3_proxy/tests/common/app.rs rename to web3_proxy_cli/src/test_utils/app.rs index 1bf1ce96..241fbc21 100644 --- a/web3_proxy/tests/common/app.rs +++ b/web3_proxy_cli/src/test_utils/app.rs @@ -1,11 +1,4 @@ -use super::{anvil::TestAnvil, mysql::TestMysql}; -use crate::common::influx::TestInflux; -use ethers::{ - prelude::{Http, Provider}, - types::Address, -}; -use hashbrown::HashMap; -use serde_json::json; +use crate::sub_commands::ProxydSubCommand; use std::{ env, str::FromStr, @@ -13,7 +6,15 @@ use std::{ thread, }; use std::{sync::Arc, time::Duration}; -use tokio::{ +use tracing::info; +use web3_proxy::prelude::anyhow; +use web3_proxy::prelude::ethers::{ + prelude::{Http, Provider}, + types::Address, +}; +use web3_proxy::prelude::hashbrown::HashMap; +use web3_proxy::prelude::serde_json::json; +use web3_proxy::prelude::tokio::{ runtime::Builder, sync::{ broadcast::{self, error::SendError}, @@ -21,11 +22,10 @@ use tokio::{ }, time::{sleep, Instant}, }; -use tracing::info; +use web3_proxy::test_utils::{TestAnvil, TestInflux, TestMysql}; use web3_proxy::{ config::{AppConfig, TopConfig, Web3RpcConfig}, stats::FlushedStats, - sub_commands::ProxydSubCommand, }; pub struct TestApp { @@ -44,7 +44,6 @@ pub struct TestApp { } impl TestApp { - #[allow(unused)] pub async fn spawn( anvil: &TestAnvil, db: Option<&TestMysql>, @@ -171,7 +170,6 @@ impl TestApp { } } - #[allow(unused)] pub async fn flush_stats(&self) -> anyhow::Result { let (tx, rx) = oneshot::channel(); @@ -186,12 +184,11 @@ impl TestApp { self.shutdown_sender.send(()) } - #[allow(unused)] pub fn wait_for_stop(mut self) { let _ = self.stop(); if let Some(handle) = self.proxy_handle.take() { - handle.join().unwrap(); + handle.join().unwrap().unwrap(); } } } diff --git a/web3_proxy/tests/common/create_admin.rs b/web3_proxy_cli/src/test_utils/create_admin.rs similarity index 87% rename from web3_proxy/tests/common/create_admin.rs rename to web3_proxy_cli/src/test_utils/create_admin.rs index 8039a052..376f9a69 100644 --- a/web3_proxy/tests/common/create_admin.rs +++ b/web3_proxy_cli/src/test_utils/create_admin.rs @@ -1,12 +1,11 @@ -use super::TestApp; -use ethers::prelude::{LocalWallet, Signer}; -use ethers::types::Signature; -use http::StatusCode; +use super::{TestApp, TestMysql}; +use crate::sub_commands::ChangeAdminStatusSubCommand; use tracing::info; use web3_proxy::frontend::users::authentication::{LoginPostResponse, PostLogin}; -use web3_proxy::sub_commands::ChangeAdminStatusSubCommand; - -use super::mysql::TestMysql; +use web3_proxy::prelude::ethers::prelude::{LocalWallet, Signer}; +use web3_proxy::prelude::ethers::types::Signature; +use web3_proxy::prelude::http::StatusCode; +use web3_proxy::prelude::reqwest; /// Helper function to create admin @@ -86,9 +85,13 @@ pub async fn create_user_as_admin( x.proxy_provider.url(), admin_wallet.address() ); - let admin_login_message = r.get(admin_login_get_url).send().await.unwrap() - .error_for_status() - .unwrap(); + let admin_login_message = r + .get(admin_login_get_url) + .send() + .await + .unwrap() + .error_for_status() + .unwrap(); assert_eq!(admin_login_message.status(), StatusCode::OK); diff --git a/web3_proxy/tests/common/create_provider_with_rpc_key.rs b/web3_proxy_cli/src/test_utils/create_provider_with_rpc_key.rs similarity index 82% rename from web3_proxy/tests/common/create_provider_with_rpc_key.rs rename to web3_proxy_cli/src/test_utils/create_provider_with_rpc_key.rs index 1d815787..94f8018c 100644 --- a/web3_proxy/tests/common/create_provider_with_rpc_key.rs +++ b/web3_proxy_cli/src/test_utils/create_provider_with_rpc_key.rs @@ -1,5 +1,5 @@ -use ulid::Ulid; -use url::Url; +use web3_proxy::prelude::ulid::Ulid; +use web3_proxy::prelude::url::Url; use web3_proxy::rpcs::provider::EthersHttpProvider; #[allow(unused)] diff --git a/web3_proxy/tests/common/create_user.rs b/web3_proxy_cli/src/test_utils/create_user.rs similarity index 88% rename from web3_proxy/tests/common/create_user.rs rename to web3_proxy_cli/src/test_utils/create_user.rs index d7a0f605..ca6500c3 100644 --- a/web3_proxy/tests/common/create_user.rs +++ b/web3_proxy_cli/src/test_utils/create_user.rs @@ -1,15 +1,16 @@ use super::TestApp; -use entities::{user, user_tier}; -use ethers::prelude::{LocalWallet, Signer}; -use ethers::types::Signature; -use http::StatusCode; -use migration::sea_orm::{ - self, ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, - QueryFilter, -}; use tracing::{info, trace}; use web3_proxy::errors::Web3ProxyResult; use web3_proxy::frontend::users::authentication::{LoginPostResponse, PostLogin}; +use web3_proxy::prelude::entities::{user, user_tier}; +use web3_proxy::prelude::ethers::prelude::{LocalWallet, Signer}; +use web3_proxy::prelude::ethers::types::Signature; +use web3_proxy::prelude::http::StatusCode; +use web3_proxy::prelude::migration::sea_orm::{ + self, ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, + QueryFilter, +}; +use web3_proxy::prelude::reqwest; /// Helper function to create an "ordinary" user #[allow(unused)] diff --git a/web3_proxy/tests/common/mod.rs b/web3_proxy_cli/src/test_utils/mod.rs similarity index 63% rename from web3_proxy/tests/common/mod.rs rename to web3_proxy_cli/src/test_utils/mod.rs index 7f3ef0db..f62dfd27 100644 --- a/web3_proxy/tests/common/mod.rs +++ b/web3_proxy_cli/src/test_utils/mod.rs @@ -1,18 +1,15 @@ pub mod admin_deposits; pub mod admin_increases_balance; -pub mod anvil; pub mod app; pub mod create_admin; pub mod create_provider_with_rpc_key; pub mod create_user; -pub mod influx; -pub mod mysql; pub mod referral; pub mod rpc_key; pub mod stats_accounting; pub mod user_balance; -pub use self::anvil::TestAnvil; pub use self::app::TestApp; -pub use self::influx::TestInflux; -pub use self::mysql::TestMysql; +pub use web3_proxy::test_utils::anvil::TestAnvil; +pub use web3_proxy::test_utils::influx::TestInflux; +pub use web3_proxy::test_utils::mysql::TestMysql; diff --git a/web3_proxy/tests/common/referral.rs b/web3_proxy_cli/src/test_utils/referral.rs similarity index 96% rename from web3_proxy/tests/common/referral.rs rename to web3_proxy_cli/src/test_utils/referral.rs index dc1d5ac3..472f48d7 100644 --- a/web3_proxy/tests/common/referral.rs +++ b/web3_proxy_cli/src/test_utils/referral.rs @@ -4,10 +4,10 @@ /// - getting code for referral (shared and used) use super::TestApp; use tracing::info; -use ulid::Ulid; use web3_proxy::frontend::users::authentication::LoginPostResponse; - -use serde::{Deserialize, Serialize}; +use web3_proxy::prelude::reqwest; +use web3_proxy::prelude::serde::{Deserialize, Serialize}; +use web3_proxy::prelude::ulid::Ulid; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct UserSharedReferralInfo { diff --git a/web3_proxy/tests/common/rpc_key.rs b/web3_proxy_cli/src/test_utils/rpc_key.rs similarity index 95% rename from web3_proxy/tests/common/rpc_key.rs rename to web3_proxy_cli/src/test_utils/rpc_key.rs index 1367efae..946c4d99 100644 --- a/web3_proxy/tests/common/rpc_key.rs +++ b/web3_proxy_cli/src/test_utils/rpc_key.rs @@ -1,8 +1,9 @@ use super::TestApp; -use serde::Deserialize; use std::time::Duration; use tracing::info; -use ulid::Ulid; +use web3_proxy::prelude::reqwest; +use web3_proxy::prelude::serde::Deserialize; +use web3_proxy::prelude::ulid::Ulid; use web3_proxy::{ errors::Web3ProxyResult, frontend::users::authentication::LoginPostResponse, diff --git a/web3_proxy/tests/common/stats_accounting.rs b/web3_proxy_cli/src/test_utils/stats_accounting.rs similarity index 97% rename from web3_proxy/tests/common/stats_accounting.rs rename to web3_proxy_cli/src/test_utils/stats_accounting.rs index ab437539..796d5712 100644 --- a/web3_proxy/tests/common/stats_accounting.rs +++ b/web3_proxy_cli/src/test_utils/stats_accounting.rs @@ -1,8 +1,9 @@ use super::TestApp; -use serde_json::json; use std::time::{SystemTime, UNIX_EPOCH}; use tracing::{info, trace}; use web3_proxy::frontend::users::authentication::LoginPostResponse; +use web3_proxy::prelude::reqwest; +use web3_proxy::prelude::serde_json::json; /// Get the user stats accounting diff --git a/web3_proxy/tests/common/user_balance.rs b/web3_proxy_cli/src/test_utils/user_balance.rs similarity index 91% rename from web3_proxy/tests/common/user_balance.rs rename to web3_proxy_cli/src/test_utils/user_balance.rs index 0ebe3377..119c9ecb 100644 --- a/web3_proxy/tests/common/user_balance.rs +++ b/web3_proxy_cli/src/test_utils/user_balance.rs @@ -1,8 +1,9 @@ use super::TestApp; -use serde_json::json; use tracing::{info, trace}; use web3_proxy::balance::Balance; use web3_proxy::frontend::users::authentication::LoginPostResponse; +use web3_proxy::prelude::reqwest; +use web3_proxy::prelude::serde_json::json; /// Helper function to get the user's balance #[allow(unused)] diff --git a/web3_proxy/tests/test_admins.rs b/web3_proxy_cli/tests/test_admins.rs similarity index 77% rename from web3_proxy/tests/test_admins.rs rename to web3_proxy_cli/tests/test_admins.rs index b29d70d4..6bd0cf95 100644 --- a/web3_proxy/tests/test_admins.rs +++ b/web3_proxy_cli/tests/test_admins.rs @@ -1,17 +1,15 @@ -mod common; - use std::str::FromStr; use std::time::Duration; - -use crate::common::admin_increases_balance::admin_increase_balance; -use crate::common::anvil::TestAnvil; -use crate::common::create_admin::create_user_as_admin; -use crate::common::create_user::create_user; -use crate::common::mysql::TestMysql; -use crate::common::user_balance::user_get_balance; -use crate::common::TestApp; -use migration::sea_orm::prelude::Decimal; use tracing::info; +use web3_proxy::prelude::migration::sea_orm::prelude::Decimal; +use web3_proxy::prelude::reqwest; +use web3_proxy::test_utils::mysql::TestMysql; +use web3_proxy::test_utils::TestAnvil; +use web3_proxy_cli::test_utils::admin_increases_balance::admin_increase_balance; +use web3_proxy_cli::test_utils::create_admin::create_user_as_admin; +use web3_proxy_cli::test_utils::create_user::create_user; +use web3_proxy_cli::test_utils::user_balance::user_get_balance; +use web3_proxy_cli::test_utils::TestApp; // #[cfg_attr(not(feature = "tests-needing-docker"), ignore)] #[ignore = "under construction"] diff --git a/web3_proxy/tests/test_multiple_proxy.rs b/web3_proxy_cli/tests/test_multiple_proxy.rs similarity index 93% rename from web3_proxy/tests/test_multiple_proxy.rs rename to web3_proxy_cli/tests/test_multiple_proxy.rs index 531a956e..3146bf13 100644 --- a/web3_proxy/tests/test_multiple_proxy.rs +++ b/web3_proxy_cli/tests/test_multiple_proxy.rs @@ -1,22 +1,24 @@ -mod common; - -use crate::common::create_provider_with_rpc_key::create_provider_for_user; -use crate::common::influx::TestInflux; -use crate::common::rpc_key::user_get_first_rpc_key; -use crate::common::stats_accounting::{user_get_influx_stats_aggregated, user_get_mysql_stats}; -use crate::common::user_balance::user_get_balance; -use crate::common::{ - admin_increases_balance::admin_increase_balance, anvil::TestAnvil, - create_admin::create_user_as_admin, create_user::create_user, mysql::TestMysql, TestApp, -}; -use futures::future::try_join_all; -use rust_decimal::Decimal; use std::str::FromStr; use std::sync::Arc; use std::time::Duration; -use tokio::time::sleep; use tracing::{info, warn}; +use web3_proxy::prelude::futures::future::try_join_all; +use web3_proxy::prelude::reqwest; +use web3_proxy::prelude::rust_decimal::Decimal; +use web3_proxy::prelude::tokio::time::sleep; use web3_proxy::rpcs::blockchain::ArcBlock; +use web3_proxy::test_utils::TestInflux; +use web3_proxy::test_utils::{TestAnvil, TestMysql}; +use web3_proxy_cli::test_utils::create_provider_with_rpc_key::create_provider_for_user; +use web3_proxy_cli::test_utils::rpc_key::user_get_first_rpc_key; +use web3_proxy_cli::test_utils::stats_accounting::{ + user_get_influx_stats_aggregated, user_get_mysql_stats, +}; +use web3_proxy_cli::test_utils::user_balance::user_get_balance; +use web3_proxy_cli::test_utils::{ + admin_increases_balance::admin_increase_balance, create_admin::create_user_as_admin, + create_user::create_user, TestApp, +}; #[cfg_attr(not(feature = "tests-needing-docker"), ignore)] #[test_log::test(tokio::test)] diff --git a/web3_proxy/tests/test_proxy.rs b/web3_proxy_cli/tests/test_proxy.rs similarity index 94% rename from web3_proxy/tests/test_proxy.rs rename to web3_proxy_cli/tests/test_proxy.rs index 76a7f165..bd926875 100644 --- a/web3_proxy/tests/test_proxy.rs +++ b/web3_proxy_cli/tests/test_proxy.rs @@ -1,14 +1,13 @@ -mod common; - -use crate::common::{anvil::TestAnvil, mysql::TestMysql, TestApp}; -use ethers::prelude::U256; -use http::StatusCode; use std::time::Duration; use tokio::{ task::yield_now, time::{sleep, Instant}, }; +use web3_proxy::prelude::ethers::prelude::U256; +use web3_proxy::prelude::http::StatusCode; +use web3_proxy::prelude::reqwest; use web3_proxy::rpcs::blockchain::ArcBlock; +use web3_proxy_cli::test_utils::{TestAnvil, TestApp, TestMysql}; #[cfg_attr(not(feature = "tests-needing-docker"), ignore)] #[test_log::test(tokio::test)] diff --git a/web3_proxy/tests/test_single_proxy.rs b/web3_proxy_cli/tests/test_single_proxy.rs similarity index 92% rename from web3_proxy/tests/test_single_proxy.rs rename to web3_proxy_cli/tests/test_single_proxy.rs index a3f6321c..bbd1dca6 100644 --- a/web3_proxy/tests/test_single_proxy.rs +++ b/web3_proxy_cli/tests/test_single_proxy.rs @@ -1,22 +1,22 @@ -mod common; - -use crate::common::create_provider_with_rpc_key::create_provider_for_user; -use crate::common::influx::TestInflux; -use crate::common::rpc_key::user_get_first_rpc_key; -use crate::common::stats_accounting::{user_get_influx_stats_aggregated, user_get_mysql_stats}; -use crate::common::user_balance::user_get_balance; -use crate::common::{ - admin_increases_balance::admin_increase_balance, anvil::TestAnvil, - create_admin::create_user_as_admin, create_user::create_user, mysql::TestMysql, TestApp, -}; -use futures::future::try_join_all; -use rust_decimal::Decimal; use std::str::FromStr; use std::sync::Arc; use std::time::Duration; -use tokio::time::sleep; use tracing::{info, warn}; +use web3_proxy::prelude::futures::future::try_join_all; +use web3_proxy::prelude::reqwest; +use web3_proxy::prelude::rust_decimal::Decimal; +use web3_proxy::prelude::tokio::time::sleep; use web3_proxy::rpcs::blockchain::ArcBlock; +use web3_proxy_cli::test_utils::create_provider_with_rpc_key::create_provider_for_user; +use web3_proxy_cli::test_utils::rpc_key::user_get_first_rpc_key; +use web3_proxy_cli::test_utils::stats_accounting::{ + user_get_influx_stats_aggregated, user_get_mysql_stats, +}; +use web3_proxy_cli::test_utils::user_balance::user_get_balance; +use web3_proxy_cli::test_utils::{ + admin_increases_balance::admin_increase_balance, create_admin::create_user_as_admin, + create_user::create_user, TestAnvil, TestApp, TestInflux, TestMysql, +}; #[cfg_attr(not(feature = "tests-needing-docker"), ignore)] #[test_log::test(tokio::test)] diff --git a/web3_proxy/tests/test_sum_credits_used.rs b/web3_proxy_cli/tests/test_sum_credits_used.rs similarity index 97% rename from web3_proxy/tests/test_sum_credits_used.rs rename to web3_proxy_cli/tests/test_sum_credits_used.rs index 9cebcbab..15e49fb1 100644 --- a/web3_proxy/tests/test_sum_credits_used.rs +++ b/web3_proxy_cli/tests/test_sum_credits_used.rs @@ -1,6 +1,11 @@ -mod common; - -use crate::common::{ +use std::time::Duration; +use tracing::info; +use web3_proxy::balance::Balance; +use web3_proxy::prelude::ethers::prelude::U64; +use web3_proxy::prelude::migration::sea_orm::prelude::Decimal; +use web3_proxy::prelude::reqwest; +use web3_proxy::prelude::tokio::time::sleep; +use web3_proxy_cli::test_utils::{ admin_increases_balance::admin_increase_balance, create_admin::create_user_as_admin, create_user::{create_user, set_user_tier}, @@ -8,12 +13,6 @@ use crate::common::{ user_balance::user_get_balance, TestAnvil, TestApp, TestInflux, TestMysql, }; -use ethers::prelude::U64; -use migration::sea_orm::prelude::Decimal; -use std::time::Duration; -use tokio::time::sleep; -use tracing::info; -use web3_proxy::balance::Balance; #[cfg_attr(not(feature = "tests-needing-docker"), ignore)] #[test_log::test(tokio::test)] diff --git a/web3_proxy/tests/test_users.rs b/web3_proxy_cli/tests/test_users.rs similarity index 96% rename from web3_proxy/tests/test_users.rs rename to web3_proxy_cli/tests/test_users.rs index 691d97f1..3be6547b 100644 --- a/web3_proxy/tests/test_users.rs +++ b/web3_proxy_cli/tests/test_users.rs @@ -1,28 +1,27 @@ -mod common; - -use crate::common::admin_deposits::get_admin_deposits; -use crate::common::admin_increases_balance::admin_increase_balance; -use crate::common::anvil::TestAnvil; -use crate::common::create_admin::create_user_as_admin; -use crate::common::create_user::create_user; -use crate::common::mysql::TestMysql; -use crate::common::referral::{ - get_referral_code, get_shared_referral_codes, get_used_referral_codes, UserSharedReferralInfo, - UserUsedReferralInfo, -}; -use crate::common::rpc_key::{user_get_first_rpc_key, RpcKey}; -use crate::common::user_balance::user_get_balance; -use crate::common::TestApp; -use ethers::prelude::{Http, Provider}; -use ethers::{signers::Signer, types::Signature}; -use migration::sea_orm::prelude::Decimal; use serde::Deserialize; use std::str::FromStr; use std::time::Duration; use tracing::{debug, info, trace}; -use ulid::Ulid; use web3_proxy::frontend::users::authentication::PostLogin; +use web3_proxy::prelude::ethers::prelude::{Http, Provider}; +use web3_proxy::prelude::ethers::{signers::Signer, types::Signature}; +use web3_proxy::prelude::migration::sea_orm::prelude::Decimal; +use web3_proxy::prelude::reqwest; +use web3_proxy::prelude::ulid::Ulid; use web3_proxy::rpcs::blockchain::ArcBlock; +use web3_proxy_cli::test_utils::admin_deposits::get_admin_deposits; +use web3_proxy_cli::test_utils::admin_increases_balance::admin_increase_balance; +use web3_proxy_cli::test_utils::create_admin::create_user_as_admin; +use web3_proxy_cli::test_utils::create_user::create_user; +use web3_proxy_cli::test_utils::referral::{ + get_referral_code, get_shared_referral_codes, get_used_referral_codes, UserSharedReferralInfo, + UserUsedReferralInfo, +}; +use web3_proxy_cli::test_utils::rpc_key::{user_get_first_rpc_key, RpcKey}; +use web3_proxy_cli::test_utils::user_balance::user_get_balance; +use web3_proxy_cli::test_utils::TestAnvil; +use web3_proxy_cli::test_utils::TestApp; +use web3_proxy_cli::test_utils::TestMysql; /// TODO: use this type in the frontend #[derive(Debug, Deserialize)]