48 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
| use super::test_utils::Key;
 | |
| 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;
 | |
| use surrealdb::engine::remote::ws::Client;
 | |
| use surrealdb::Surreal;
 | |
| use tonic::transport::Channel;
 | |
| 
 | |
| pub async fn create_new_vm(
 | |
|     db: &Surreal<Client>,
 | |
|     key: Key,
 | |
|     node_pubkey: String,
 | |
|     brain_channel: Channel,
 | |
| ) -> String {
 | |
|     let new_vm_req = vm_proto::NewVmReq {
 | |
|         admin_pubkey: key.pubkey.clone(),
 | |
|         node_pubkey,
 | |
|         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).unwrap()).await.unwrap().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.unwrap();
 | |
| 
 | |
|     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.unwrap();
 | |
|     let active_vm = active_vm_op.unwrap();
 | |
| 
 | |
|     active_vm.id.key().to_string()
 | |
| }
 |