forked from ghe0/brain-to-surreal
124 lines
3.5 KiB
Rust
124 lines
3.5 KiB
Rust
use detee_shared::common_proto::Empty;
|
|
use detee_shared::general_proto::ReportNodeReq;
|
|
use detee_shared::vm_proto::brain_vm_cli_client::BrainVmCliClient;
|
|
use detee_shared::vm_proto::ListVmContractsReq;
|
|
use detee_shared::{
|
|
common_proto::Pubkey, general_proto::brain_general_cli_client::BrainGeneralCliClient,
|
|
};
|
|
mod common;
|
|
use common::prepare_test_env::{prepare_test_setup, TEST_STATE};
|
|
use common::test_utils::{get_pub_key, sign_request};
|
|
use tokio_stream::StreamExt;
|
|
|
|
#[tokio::test]
|
|
async fn test_general_balance() {
|
|
prepare_test_setup().await;
|
|
let grpc_channel = TEST_STATE.get().unwrap().clone();
|
|
|
|
let mut brain_general_cli_client = BrainGeneralCliClient::new(grpc_channel.clone());
|
|
|
|
let req_data = Pubkey { pubkey: get_pub_key().unwrap() };
|
|
|
|
let acc_bal = brain_general_cli_client
|
|
.get_balance(sign_request(req_data).unwrap())
|
|
.await
|
|
.unwrap()
|
|
.into_inner();
|
|
|
|
// verify it in db also
|
|
|
|
assert_eq!(acc_bal.balance, 0);
|
|
assert_eq!(acc_bal.tmp_locked, 0);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_report_node() {
|
|
prepare_test_setup().await;
|
|
let grpc_channel = TEST_STATE.get().unwrap().clone();
|
|
|
|
let mut brain_general_cli_client = BrainGeneralCliClient::new(grpc_channel.clone());
|
|
|
|
// TODO: create contract, node and operator in db and use it here
|
|
let req_data = ReportNodeReq {
|
|
admin_pubkey: get_pub_key().unwrap(),
|
|
node_pubkey: String::from("node_pubkey"),
|
|
contract: String::from("uuid"),
|
|
reason: String::from("reason"),
|
|
};
|
|
|
|
let report_error =
|
|
brain_general_cli_client.report_node(sign_request(req_data).unwrap()).await.err().unwrap();
|
|
|
|
assert_eq!(report_error.message(), "No contract found by this ID.");
|
|
|
|
// verify report in db
|
|
}
|
|
|
|
#[tokio::test]
|
|
// TODO: register some operators before testing this
|
|
async fn test_list_operators() {
|
|
prepare_test_setup().await;
|
|
let grpc_channel = TEST_STATE.get().unwrap().clone();
|
|
|
|
let mut brain_general_cli_client = BrainGeneralCliClient::new(grpc_channel.clone());
|
|
|
|
let mut grpc_stream = brain_general_cli_client
|
|
.list_operators(sign_request(Empty {}).unwrap())
|
|
.await
|
|
.unwrap()
|
|
.into_inner();
|
|
|
|
let mut operators = Vec::new();
|
|
while let Some(stream_update) = grpc_stream.next().await {
|
|
match stream_update {
|
|
Ok(op) => {
|
|
operators.push(op);
|
|
}
|
|
Err(e) => {
|
|
panic!("Received error instead of operators: {e:?}");
|
|
}
|
|
}
|
|
}
|
|
|
|
assert!(!operators.is_empty())
|
|
|
|
// verify report in db
|
|
}
|
|
|
|
#[tokio::test]
|
|
// TODO: create vm for this user before testing this
|
|
async fn test_list_vm_contracts() {
|
|
prepare_test_setup().await;
|
|
let grpc_channel = TEST_STATE.get().unwrap().clone();
|
|
|
|
let mut brain_general_cli_client = BrainVmCliClient::new(grpc_channel.clone());
|
|
|
|
let req_data = ListVmContractsReq {
|
|
wallet: get_pub_key().unwrap(),
|
|
uuid: String::from("uuid"),
|
|
as_operator: false,
|
|
};
|
|
|
|
let mut grpc_stream = brain_general_cli_client
|
|
.list_vm_contracts(sign_request(req_data).unwrap())
|
|
.await
|
|
.unwrap()
|
|
.into_inner();
|
|
|
|
let mut vm_contracts = Vec::new();
|
|
while let Some(stream_update) = grpc_stream.next().await {
|
|
match stream_update {
|
|
Ok(vm_c) => {
|
|
vm_contracts.push(vm_c);
|
|
}
|
|
Err(e) => {
|
|
panic!("Received error instead of vm_contracts: {e:?}");
|
|
}
|
|
}
|
|
}
|
|
|
|
assert!(vm_contracts.is_empty())
|
|
|
|
// verify report in db
|
|
}
|