could call subcommand
This commit is contained in:
parent
17c42243d0
commit
458f7d6514
@ -14,11 +14,11 @@ use tracing::{debug, info};
|
|||||||
pub struct ChangeAdminStatusSubCommand {
|
pub struct ChangeAdminStatusSubCommand {
|
||||||
/// the address of the user whose admin status you want to modify
|
/// the address of the user whose admin status you want to modify
|
||||||
#[argh(positional)]
|
#[argh(positional)]
|
||||||
address: String,
|
pub address: String,
|
||||||
|
|
||||||
/// true if the user should be an admin, false otherwise
|
/// true if the user should be an admin, false otherwise
|
||||||
#[argh(positional)]
|
#[argh(positional)]
|
||||||
should_be_admin: bool,
|
pub should_be_admin: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChangeAdminStatusSubCommand {
|
impl ChangeAdminStatusSubCommand {
|
||||||
|
@ -30,9 +30,10 @@ use web3_proxy::{
|
|||||||
sub_commands::ProxydSubCommand,
|
sub_commands::ProxydSubCommand,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct DbData {
|
pub struct DbData {
|
||||||
container_name: String,
|
pub container_name: String,
|
||||||
url: Option<String>,
|
pub url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TestApp {
|
pub struct TestApp {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
use crate::common::TestApp;
|
use crate::common::TestApp;
|
||||||
|
use ethers::abi::AbiEncode;
|
||||||
use ethers::prelude::Signer;
|
use ethers::prelude::Signer;
|
||||||
use ethers::types::Signature;
|
use ethers::types::Signature;
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
@ -8,6 +9,8 @@ use std::str::FromStr;
|
|||||||
use tracing::{debug, info, trace, warn};
|
use tracing::{debug, info, trace, warn};
|
||||||
use web3_proxy::frontend::admin::AdminIncreaseBalancePost;
|
use web3_proxy::frontend::admin::AdminIncreaseBalancePost;
|
||||||
use web3_proxy::frontend::users::authentication::{LoginPostResponse, PostLogin};
|
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)]
|
// #[cfg_attr(not(feature = "tests-needing-docker"), ignore)]
|
||||||
#[ignore = "under construction"]
|
#[ignore = "under construction"]
|
||||||
@ -21,6 +24,7 @@ async fn test_admin_imitate_user() {
|
|||||||
#[cfg_attr(not(feature = "tests-needing-docker"), ignore)]
|
#[cfg_attr(not(feature = "tests-needing-docker"), ignore)]
|
||||||
#[test_log::test(tokio::test)]
|
#[test_log::test(tokio::test)]
|
||||||
async fn test_admin_grant_credits() {
|
async fn test_admin_grant_credits() {
|
||||||
|
info!("Starting admin grant credits test");
|
||||||
let x = TestApp::spawn(true).await;
|
let x = TestApp::spawn(true).await;
|
||||||
let r = reqwest::Client::new();
|
let r = reqwest::Client::new();
|
||||||
|
|
||||||
@ -45,13 +49,13 @@ async fn test_admin_grant_credits() {
|
|||||||
.sign_message(&admin_login_message)
|
.sign_message(&admin_login_message)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
debug!(?admin_signed);
|
info!(?admin_signed);
|
||||||
let admin_post_login_data = PostLogin {
|
let admin_post_login_data = PostLogin {
|
||||||
msg: admin_login_message,
|
msg: admin_login_message,
|
||||||
sig: admin_signed.to_string(),
|
sig: admin_signed.to_string(),
|
||||||
referral_code: None,
|
referral_code: None,
|
||||||
};
|
};
|
||||||
debug!(?admin_post_login_data);
|
info!(?admin_post_login_data);
|
||||||
let admin_login_response = r
|
let admin_login_response = r
|
||||||
.post(&login_post_url)
|
.post(&login_post_url)
|
||||||
.json(&admin_post_login_data)
|
.json(&admin_post_login_data)
|
||||||
@ -61,7 +65,7 @@ async fn test_admin_grant_credits() {
|
|||||||
.json::<LoginPostResponse>()
|
.json::<LoginPostResponse>()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
debug!(?admin_login_response);
|
info!(?admin_login_response);
|
||||||
|
|
||||||
// Also login the user (to create the user)
|
// Also login the user (to create the user)
|
||||||
let user_login_get_url = format!(
|
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
|
// Sign the message and POST it to login as admin
|
||||||
let user_signed: Signature = user_wallet.sign_message(&user_login_message).await.unwrap();
|
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 {
|
let user_post_login_data = PostLogin {
|
||||||
msg: user_login_message,
|
msg: user_login_message,
|
||||||
sig: user_signed.to_string(),
|
sig: user_signed.to_string(),
|
||||||
referral_code: None,
|
referral_code: None,
|
||||||
};
|
};
|
||||||
debug!(?user_post_login_data);
|
info!(?user_post_login_data);
|
||||||
let user_login_response = r
|
let user_login_response = r
|
||||||
.post(login_post_url)
|
.post(login_post_url)
|
||||||
.json(&user_post_login_data)
|
.json(&user_post_login_data)
|
||||||
@ -90,10 +94,37 @@ async fn test_admin_grant_credits() {
|
|||||||
.json::<LoginPostResponse>()
|
.json::<LoginPostResponse>()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
debug!(?user_login_response);
|
info!(?user_login_response);
|
||||||
|
|
||||||
// Now I need to make the user an admin ...
|
// 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
|
// Login the user
|
||||||
// Use the bearer token of admin to increase user balance
|
// Use the bearer token of admin to increase user balance
|
||||||
let increase_balance_data = AdminIncreaseBalancePost {
|
let increase_balance_data = AdminIncreaseBalancePost {
|
||||||
@ -107,21 +138,23 @@ async fn test_admin_grant_credits() {
|
|||||||
.bearer_auth(admin_login_response.bearer_token)
|
.bearer_auth(admin_login_response.bearer_token)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
|
||||||
.json::<serde_json::Value>()
|
|
||||||
.await
|
|
||||||
.unwrap();
|
.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());
|
||||||
// Check if the response is as expected
|
// assert_eq!(
|
||||||
// assert_eq!(increase_balance_response["user"], user_wallet.address());
|
// Decimal::from_str(increase_balance_response["amount"].as_str().unwrap()).unwrap(),
|
||||||
assert_eq!(
|
// Decimal::from(100)
|
||||||
Decimal::from_str(increase_balance_response["amount"].as_str().unwrap()).unwrap(),
|
// );
|
||||||
Decimal::from(100)
|
//
|
||||||
);
|
// x.wait().await;
|
||||||
|
|
||||||
x.wait().await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[cfg_attr(not(feature = "tests-needing-docker"), ignore)]
|
// #[cfg_attr(not(feature = "tests-needing-docker"), ignore)]
|
||||||
|
Loading…
Reference in New Issue
Block a user