Compare commits
	
		
			1 Commits
		
	
	
		
			d4e499126d
			...
			f74fc94851
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| f74fc94851 | 
| @ -86,6 +86,12 @@ impl NewAppReq { | |||||||
|         let new_app_req: Option<Self> = db.select((NEW_APP_REQ, id)).await?; |         let new_app_req: Option<Self> = db.select((NEW_APP_REQ, id)).await?; | ||||||
|         Ok(new_app_req) |         Ok(new_app_req) | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     pub async fn delete(db: &Surreal<Client>, id: &str) -> Result<(), Error> { | ||||||
|  |         let _: Option<Self> = db.delete((NEW_APP_REQ, id)).await?; | ||||||
|  |         Ok(()) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     pub async fn submit_error(db: &Surreal<Client>, id: &str, error: String) -> Result<(), Error> { |     pub async fn submit_error(db: &Surreal<Client>, id: &str, error: String) -> Result<(), Error> { | ||||||
|         let tx_query = String::from( |         let tx_query = String::from( | ||||||
|             " |             " | ||||||
| @ -361,7 +367,7 @@ impl ActiveApp { | |||||||
|         let locked_nano = active_app.locked_nano; |         let locked_nano = active_app.locked_nano; | ||||||
| 
 | 
 | ||||||
|         let _: Vec<ActiveApp> = db.insert(()).relation(active_app).await?; |         let _: Vec<ActiveApp> = db.insert(()).relation(active_app).await?; | ||||||
|         db.delete::<Option<NewAppReq>>((NEW_APP_REQ, &new_app_res.uuid)).await?; |         NewAppReq::delete(&db, &new_app_res.uuid).await?; | ||||||
|         db.query(format!("UPDATE {ACCOUNT}:{admin_account} SET tmp_locked -= {locked_nano};")) |         db.query(format!("UPDATE {ACCOUNT}:{admin_account} SET tmp_locked -= {locked_nano};")) | ||||||
|             .await?; |             .await?; | ||||||
| 
 | 
 | ||||||
| @ -468,7 +474,6 @@ impl WrappedAppResp { | |||||||
|                         match active_app_notif { |                         match active_app_notif { | ||||||
|                             Ok(active_app_notif) =>{ |                             Ok(active_app_notif) =>{ | ||||||
|                                 if active_app_notif.action == surrealdb::Action::Create { |                                 if active_app_notif.action == surrealdb::Action::Create { | ||||||
|                                     let _: Option<NewAppReq> = db.delete((NEW_APP_REQ, app_id)).await?; |  | ||||||
|                                     return Ok(Self::NewAppRes(active_app_notif.data.into())); |                                     return Ok(Self::NewAppRes(active_app_notif.data.into())); | ||||||
|                                 } |                                 } | ||||||
|                             } |                             } | ||||||
|  | |||||||
| @ -228,7 +228,9 @@ impl BrainAppCli for AppCliServer { | |||||||
|                 )) |                 )) | ||||||
|             } |             } | ||||||
|             Err(e) => { |             Err(e) => { | ||||||
|                 log::error!("Something weird happened during CLI NewAppReq. Reached error {e:?}"); |                 log::error!( | ||||||
|  |                     "Something wrong happened on channel during CLI NewAppReq. Reached error {e:?}" | ||||||
|  |                 ); | ||||||
|                 Err(Status::unknown( |                 Err(Status::unknown( | ||||||
|                     "Unknown error. Please try again or contact the DeTEE devs team.", |                     "Unknown error. Please try again or contact the DeTEE devs team.", | ||||||
|                 )) |                 )) | ||||||
|  | |||||||
							
								
								
									
										35
									
								
								tests/db_tx_new_app_test.rs
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										35
									
								
								tests/db_tx_new_app_test.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,35 @@ | |||||||
|  | use common::prepare_test_env::prepare_test_db; | ||||||
|  | use detee_shared::app_proto::{AppResource, NewAppReq}; | ||||||
|  | use surreal_brain::db::prelude as db; | ||||||
|  | 
 | ||||||
|  | mod common; | ||||||
|  | 
 | ||||||
|  | #[tokio::test] | ||||||
|  | async fn test_new_app_db_tx() { | ||||||
|  |     let db = prepare_test_db().await.unwrap(); | ||||||
|  | 
 | ||||||
|  |     let req = NewAppReq { | ||||||
|  |       package_url: "https://registry.detee.ltd/sgx/packages/actix-app-info_package_2025-04-16_21-59-38.tar.gz".to_string(), | ||||||
|  |       node_pubkey: "AH3SpV6ZjXMGSSe6xGH2ekUZxyUhnesAFz4LjX7PnvVn".to_string(), | ||||||
|  |       resource: Some( | ||||||
|  |           AppResource { | ||||||
|  |               memory_mb: 1500, | ||||||
|  |               disk_size_gb: 2, | ||||||
|  |               vcpus: 1, | ||||||
|  |               ports: vec![ 8080 ], | ||||||
|  |           }, | ||||||
|  |       ), | ||||||
|  |       uuid: "".to_string(), | ||||||
|  |       admin_pubkey: "H21Shi4iE7vgfjWEQNvzmpmBMJSaiZ17PYUcdNoAoKNc".to_string(), | ||||||
|  |       price_per_unit: 200000, | ||||||
|  |       locked_nano: 152400000, | ||||||
|  |       hratls_pubkey: "7E0F887AA6BB9104EEC1066F454D4C2D9063D676715F55F919D3FBCEDC63240B".to_string(), | ||||||
|  |       public_package_mr_enclave: Some( | ||||||
|  |           vec![ 128, 0, 97, 103, 165, 103, 68, 203, 240, 145, 153, 254, 34, 129, 75, 140, 8, 186, 63, 226, 144, 129, 201, 187, 175, 66, 80, 1, 151, 114, 183, 159, ], | ||||||
|  |       ), | ||||||
|  |       app_name: "lively-ferret".to_string(), | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     let db_req: db::NewAppReq = req.into(); | ||||||
|  |     db_req.submit(&db).await.unwrap(); | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user