diff --git a/src/db/app.rs b/src/db/app.rs index 7e445a6..987b768 100644 --- a/src/db/app.rs +++ b/src/db/app.rs @@ -86,6 +86,12 @@ impl NewAppReq { let new_app_req: Option = db.select((NEW_APP_REQ, id)).await?; Ok(new_app_req) } + + pub async fn delete(db: &Surreal, id: &str) -> Result<(), Error> { + let _: Option = db.delete((NEW_APP_REQ, id)).await?; + Ok(()) + } + pub async fn submit_error(db: &Surreal, id: &str, error: String) -> Result<(), Error> { let tx_query = String::from( " @@ -361,7 +367,7 @@ impl ActiveApp { let locked_nano = active_app.locked_nano; let _: Vec = db.insert(()).relation(active_app).await?; - db.delete::>((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};")) .await?; @@ -468,7 +474,6 @@ impl WrappedAppResp { match active_app_notif { Ok(active_app_notif) =>{ if active_app_notif.action == surrealdb::Action::Create { - let _: Option = db.delete((NEW_APP_REQ, app_id)).await?; return Ok(Self::NewAppRes(active_app_notif.data.into())); } } diff --git a/src/grpc/app.rs b/src/grpc/app.rs index 8a595a6..bbd22ac 100644 --- a/src/grpc/app.rs +++ b/src/grpc/app.rs @@ -228,7 +228,9 @@ impl BrainAppCli for AppCliServer { )) } 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( "Unknown error. Please try again or contact the DeTEE devs team.", )) diff --git a/tests/db_tx_new_app_test.rs b/tests/db_tx_new_app_test.rs new file mode 100644 index 0000000..b87e484 --- /dev/null +++ b/tests/db_tx_new_app_test.rs @@ -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(); +}