brain/tests/grpc_vm_daemon_test.rs
Noor ea50603a88
refactor tests
modularizing report node into reusable method
improved error handling unwraping only on top level method
utils methods accepts refs to remove clone() on top level methods
2025-05-08 03:04:14 +03:00

55 lines
1.8 KiB
Rust

use common::prepare_test_env::{
prepare_test_db, run_service_for_stream, run_service_in_background,
};
use common::test_utils::Key;
use common::vm_daemon_utils::{mock_vm_daemon, register_vm_node};
use detee_shared::vm_proto;
use detee_shared::vm_proto::brain_vm_cli_client::BrainVmCliClient;
use detee_shared::vm_proto::brain_vm_daemon_client::BrainVmDaemonClient;
mod common;
#[tokio::test]
async fn test_reg_vm_node() {
prepare_test_db().await.unwrap();
let addr = run_service_in_background().await.unwrap();
let mut client = BrainVmDaemonClient::connect(format!("http://{}", addr)).await.unwrap();
let vm_contracts =
register_vm_node(&mut client, &Key::new(), &Key::new().pubkey).await.unwrap();
assert!(vm_contracts.is_empty())
}
#[tokio::test]
async fn test_brain_message() {
env_logger::builder().filter_level(log::LevelFilter::Error).init();
let db = prepare_test_db().await.unwrap();
let brain_channel = run_service_for_stream().await.unwrap();
let daemon_key = mock_vm_daemon(&brain_channel).await.unwrap();
let mut cli_client = BrainVmCliClient::new(brain_channel);
let cli_key = Key::new();
let req = vm_proto::NewVmReq {
admin_pubkey: cli_key.pubkey.clone(),
node_pubkey: daemon_key,
price_per_unit: 1200,
extra_ports: vec![8080, 8081],
locked_nano: 0,
..Default::default()
};
let new_vm_resp =
cli_client.new_vm(cli_key.sign_request(req).unwrap()).await.unwrap().into_inner();
assert!(new_vm_resp.error.is_empty());
assert!(new_vm_resp.uuid.len() == 40);
let id = ("measurement_args", new_vm_resp.uuid);
let data_in_db: detee_shared::vm_proto::MeasurementArgs = db.select(id).await.unwrap().unwrap();
assert_eq!(data_in_db, new_vm_resp.args.unwrap());
}