From 458f7d65141696e94a913b0098abea5d182081fd Mon Sep 17 00:00:00 2001 From: yenicelik Date: Sat, 1 Jul 2023 15:26:42 -0400 Subject: [PATCH] could call subcommand --- .../src/sub_commands/change_admin_status.rs | 4 +- web3_proxy/tests/common/app.rs | 5 +- web3_proxy/tests/test_admins.rs | 71 ++++++++++++++----- 3 files changed, 57 insertions(+), 23 deletions(-) diff --git a/web3_proxy/src/sub_commands/change_admin_status.rs b/web3_proxy/src/sub_commands/change_admin_status.rs index 9c6cbbf0..44322cbb 100644 --- a/web3_proxy/src/sub_commands/change_admin_status.rs +++ b/web3_proxy/src/sub_commands/change_admin_status.rs @@ -14,11 +14,11 @@ use tracing::{debug, info}; pub struct ChangeAdminStatusSubCommand { /// the address of the user whose admin status you want to modify #[argh(positional)] - address: String, + pub address: String, /// true if the user should be an admin, false otherwise #[argh(positional)] - should_be_admin: bool, + pub should_be_admin: bool, } impl ChangeAdminStatusSubCommand { diff --git a/web3_proxy/tests/common/app.rs b/web3_proxy/tests/common/app.rs index 0c547a00..ed60ab07 100644 --- a/web3_proxy/tests/common/app.rs +++ b/web3_proxy/tests/common/app.rs @@ -30,9 +30,10 @@ use web3_proxy::{ sub_commands::ProxydSubCommand, }; +#[derive(Clone)] pub struct DbData { - container_name: String, - url: Option, + pub container_name: String, + pub url: Option, } pub struct TestApp { diff --git a/web3_proxy/tests/test_admins.rs b/web3_proxy/tests/test_admins.rs index 0a7e5455..f3cb2581 100644 --- a/web3_proxy/tests/test_admins.rs +++ b/web3_proxy/tests/test_admins.rs @@ -1,6 +1,7 @@ mod common; use crate::common::TestApp; +use ethers::abi::AbiEncode; use ethers::prelude::Signer; use ethers::types::Signature; use rust_decimal::Decimal; @@ -8,6 +9,8 @@ use std::str::FromStr; use tracing::{debug, info, trace, warn}; use web3_proxy::frontend::admin::AdminIncreaseBalancePost; use web3_proxy::frontend::users::authentication::{LoginPostResponse, PostLogin}; +use web3_proxy::relational_db::get_db; +use web3_proxy::sub_commands::ChangeAdminStatusSubCommand; // #[cfg_attr(not(feature = "tests-needing-docker"), ignore)] #[ignore = "under construction"] @@ -21,6 +24,7 @@ async fn test_admin_imitate_user() { #[cfg_attr(not(feature = "tests-needing-docker"), ignore)] #[test_log::test(tokio::test)] async fn test_admin_grant_credits() { + info!("Starting admin grant credits test"); let x = TestApp::spawn(true).await; let r = reqwest::Client::new(); @@ -45,13 +49,13 @@ async fn test_admin_grant_credits() { .sign_message(&admin_login_message) .await .unwrap(); - debug!(?admin_signed); + info!(?admin_signed); let admin_post_login_data = PostLogin { msg: admin_login_message, sig: admin_signed.to_string(), referral_code: None, }; - debug!(?admin_post_login_data); + info!(?admin_post_login_data); let admin_login_response = r .post(&login_post_url) .json(&admin_post_login_data) @@ -61,7 +65,7 @@ async fn test_admin_grant_credits() { .json::() .await .unwrap(); - debug!(?admin_login_response); + info!(?admin_login_response); // Also login the user (to create the user) let user_login_get_url = format!( @@ -74,13 +78,13 @@ async fn test_admin_grant_credits() { // Sign the message and POST it to login as admin let user_signed: Signature = user_wallet.sign_message(&user_login_message).await.unwrap(); - debug!(?user_signed); + info!(?user_signed); let user_post_login_data = PostLogin { msg: user_login_message, sig: user_signed.to_string(), referral_code: None, }; - debug!(?user_post_login_data); + info!(?user_post_login_data); let user_login_response = r .post(login_post_url) .json(&user_post_login_data) @@ -90,10 +94,37 @@ async fn test_admin_grant_credits() { .json::() .await .unwrap(); - debug!(?user_login_response); + info!(?user_login_response); // Now I need to make the user an admin ... + info!("Make the user an admin ..."); + // Change Admin SubCommand struct + let admin_status_changer = ChangeAdminStatusSubCommand { + address: format!("{:?}", admin_wallet.address()), + should_be_admin: true, + }; + info!("Admin status changer object is: "); + info!(?admin_status_changer); + + // I suppose I gotta create a new database connection + // Connect to the database using the connection getter + info!("Establishing the database connection"); + let db_conn = get_db( + x.db.as_ref().unwrap().url.as_ref().unwrap().to_string(), + 1, + 1, + ) + .await + .unwrap(); + + info!("Changing the status of the admin_wallet to be an admin"); + // Pass on the database into it ... + let _ = admin_status_changer.main(&db_conn).await.unwrap(); + + // Make the admin user an admin + + info!("Increasing balance"); // Login the user // Use the bearer token of admin to increase user balance let increase_balance_data = AdminIncreaseBalancePost { @@ -107,21 +138,23 @@ async fn test_admin_grant_credits() { .bearer_auth(admin_login_response.bearer_token) .send() .await - .unwrap() - .json::() - .await .unwrap(); + info!("Passed second checkpoint"); + info!(?increase_balance_response); + // let increase_balance_response = increase_balance_response + // .json::() + // .await + // .unwrap(); + // info!(?increase_balance_response); - debug!(?increase_balance_response); - - // Check if the response is as expected - // assert_eq!(increase_balance_response["user"], user_wallet.address()); - assert_eq!( - Decimal::from_str(increase_balance_response["amount"].as_str().unwrap()).unwrap(), - Decimal::from(100) - ); - - x.wait().await; + // // Check if the response is as expected + // // assert_eq!(increase_balance_response["user"], user_wallet.address()); + // assert_eq!( + // Decimal::from_str(increase_balance_response["amount"].as_str().unwrap()).unwrap(), + // Decimal::from(100) + // ); + // + // x.wait().await; } // #[cfg_attr(not(feature = "tests-needing-docker"), ignore)]