could call subcommand

This commit is contained in:
yenicelik 2023-07-01 15:26:42 -04:00
parent 17c42243d0
commit 458f7d6514
3 changed files with 57 additions and 23 deletions

View File

@ -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 {

View File

@ -30,9 +30,10 @@ use web3_proxy::{
sub_commands::ProxydSubCommand,
};
#[derive(Clone)]
pub struct DbData {
container_name: String,
url: Option<String>,
pub container_name: String,
pub url: Option<String>,
}
pub struct TestApp {

View File

@ -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::<LoginPostResponse>()
.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::<LoginPostResponse>()
.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::<serde_json::Value>()
.await
.unwrap();
info!("Passed second checkpoint");
info!(?increase_balance_response);
// let increase_balance_response = increase_balance_response
// .json::<serde_json::Value>()
// .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)]