Production grade kick contract code for financial transaction tested for both vm and app modified schema to include node in kick, default time for deleted_app and removed unwanted fields app data migration for testing kick contract for active_app fixed some tests register operator Reviewed-on: #2 Co-authored-by: Noor <noormohammedb@protonmail.com> Co-committed-by: Noor <noormohammedb@protonmail.com> Signed-off-by: Noor <noormohammedb@protonmail.com>
80 lines
2.6 KiB
Rust
80 lines
2.6 KiB
Rust
use super::test_utils::{admin_keys, Key};
|
|
use anyhow::{anyhow, Result};
|
|
use detee_shared::common_proto::Empty;
|
|
use detee_shared::general_proto::brain_general_cli_client::BrainGeneralCliClient;
|
|
use detee_shared::general_proto::{AirdropReq, ReportNodeReq};
|
|
use detee_shared::vm_proto;
|
|
use detee_shared::vm_proto::brain_vm_cli_client::BrainVmCliClient;
|
|
use surreal_brain::constants::{ACTIVE_VM, NEW_VM_REQ};
|
|
use surreal_brain::db::prelude as db;
|
|
use surrealdb::engine::remote::ws::Client;
|
|
use surrealdb::Surreal;
|
|
use tonic::transport::Channel;
|
|
|
|
pub async fn airdrop(brain_channel: &Channel, wallet: &str, amount: u64) -> Result<()> {
|
|
let mut client = BrainGeneralCliClient::new(brain_channel.clone());
|
|
let airdrop_req = AirdropReq { pubkey: wallet.to_string(), tokens: amount };
|
|
|
|
let admin_key = admin_keys()[0].clone();
|
|
|
|
client.airdrop(admin_key.sign_request(airdrop_req.clone())?).await?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
pub async fn create_new_vm(
|
|
db: &Surreal<Client>,
|
|
key: &Key,
|
|
node_pubkey: &str,
|
|
brain_channel: &Channel,
|
|
) -> Result<String> {
|
|
let new_vm_req = vm_proto::NewVmReq {
|
|
admin_pubkey: key.pubkey.clone(),
|
|
node_pubkey: node_pubkey.to_string(),
|
|
price_per_unit: 1200,
|
|
extra_ports: vec![8080, 8081],
|
|
locked_nano: 0,
|
|
..Default::default()
|
|
};
|
|
|
|
let mut client_vm_cli = BrainVmCliClient::new(brain_channel.clone());
|
|
let new_vm_resp = client_vm_cli.new_vm(key.sign_request(new_vm_req)?).await?.into_inner();
|
|
|
|
assert!(new_vm_resp.error.is_empty());
|
|
assert!(new_vm_resp.uuid.len() == 40);
|
|
|
|
// wait for update db
|
|
tokio::time::sleep(tokio::time::Duration::from_millis(700)).await;
|
|
|
|
let vm_req_db: Option<db::NewVmReq> = db.select((NEW_VM_REQ, new_vm_resp.uuid.clone())).await?;
|
|
|
|
if let Some(new_vm_req) = vm_req_db {
|
|
panic!("New VM request found in DB: {:?}", new_vm_req);
|
|
}
|
|
|
|
let active_vm_op: Option<db::ActiveVm> =
|
|
db.select((ACTIVE_VM, new_vm_resp.uuid.clone())).await?;
|
|
let active_vm = active_vm_op.ok_or(anyhow!("Not found active vm in db"))?;
|
|
|
|
Ok(active_vm.id.key().to_string())
|
|
}
|
|
|
|
pub async fn report_node(
|
|
key: &Key,
|
|
brain_channel: &Channel,
|
|
node_pubkey: &str,
|
|
contract: &str,
|
|
reason: &str,
|
|
) -> Result<tonic::Response<Empty>> {
|
|
let mut client_gen_cli = BrainGeneralCliClient::new(brain_channel.clone());
|
|
|
|
let report_req = ReportNodeReq {
|
|
admin_pubkey: key.pubkey.clone(),
|
|
node_pubkey: node_pubkey.to_string(),
|
|
contract: contract.to_string(),
|
|
reason: reason.to_string(),
|
|
};
|
|
|
|
Ok(client_gen_cli.report_node(key.sign_request(report_req)?).await?)
|
|
}
|