From 55549ba10ddd22acea0fed03bd2d9b58414e13ff Mon Sep 17 00:00:00 2001 From: Noor Date: Fri, 25 Apr 2025 00:00:05 +0530 Subject: [PATCH] test listing operators and list vm contracts --- tests/grpcs_test.rs | 72 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/tests/grpcs_test.rs b/tests/grpcs_test.rs index 270cb7d..3990b6a 100644 --- a/tests/grpcs_test.rs +++ b/tests/grpcs_test.rs @@ -1,10 +1,14 @@ +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() { @@ -49,3 +53,71 @@ async fn test_report_node() { // 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 +}