diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 14d6ad8e..05fa5458 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -137,3 +137,14 @@ jobs: run: | cd rollup-http/rollup-http-server MOCK_BUILD=true cargo test -- --show-output --test-threads=1 + + - name: Test rollup-http-server api schema + run: | + sudo apt-get update + sudo apt-get install -y wait-for-it python3 python3-pip + pip3 install schemathesis + cd rollup-http/rollup-http-server + wget https://raw.githubusercontent.com/cartesi/openapi-interfaces/main/rollup.yaml + MOCK_BUILD=true cargo run -- "echo 1" & + wait-for-it localhost:5004 --timeout=30 + st run rollup.yaml --checks all --validate-schema true --hypothesis-phases explicit --base-url http://localhost:5004 diff --git a/rollup-http/rollup-http-client/src/rollup.rs b/rollup-http/rollup-http-client/src/rollup.rs index c4d503ef..3a6939bb 100644 --- a/rollup-http/rollup-http-client/src/rollup.rs +++ b/rollup-http/rollup-http-client/src/rollup.rs @@ -20,10 +20,13 @@ use std::fmt; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct AdvanceMetadata { + pub chain_id: u64, + pub app_contract: String, pub msg_sender: String, - pub input_index: u64, pub block_number: u64, pub block_timestamp: u64, + pub prev_randao: String, + pub input_index: u64, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -67,7 +70,7 @@ pub struct IndexResponse { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct GIORequest { pub domain: u16, - pub payload: String, + pub id: String, } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/rollup-http/rollup-http-server/src/http_service.rs b/rollup-http/rollup-http-server/src/http_service.rs index 80f88a43..05a9ccde 100644 --- a/rollup-http/rollup-http-server/src/http_service.rs +++ b/rollup-http/rollup-http-server/src/http_service.rs @@ -89,7 +89,9 @@ async fn voucher(mut voucher: Json, data: Data>) -> Http voucher.destination, voucher.destination.len() ); - return HttpResponse::BadRequest().body("Address not valid"); + return HttpResponse::BadRequest() + .append_header((hyper::header::CONTENT_TYPE, "text/plain")) + .body("address not valid"); } let context = data.lock().await; // Write voucher to linux rollup device @@ -106,6 +108,7 @@ async fn voucher(mut voucher: Json, data: Data>) -> Http e.to_string() ); HttpResponse::BadRequest() + .append_header((hyper::header::CONTENT_TYPE, "text/plain")) .body(format!("unable to insert voucher, error details: '{}'", e)) } }; @@ -127,7 +130,8 @@ async fn notice(mut notice: Json, data: Data>) -> HttpRes Err(e) => { log::error!("unable to insert notice, error details: '{}'", e); HttpResponse::BadRequest() - .body(format!("Unable to insert notice, error details: '{}'", e)) + .append_header((hyper::header::CONTENT_TYPE, "text/plain")) + .body(format!("unable to insert notice, error details: '{}'", e)) } }; } @@ -146,6 +150,7 @@ async fn report(report: Json, data: Data>) -> HttpRespons Err(e) => { log::error!("unable to insert report, error details: '{}'", e); HttpResponse::BadRequest() + .append_header((hyper::header::CONTENT_TYPE, "text/plain")) .body(format!("unable to insert notice, error details: '{}'", e)) } }; @@ -163,10 +168,12 @@ async fn gio(request: Json, data: Data>) -> HttpRespo } Err(e) => { log::error!("unable to process gio request, error details: '{}'", e); - HttpResponse::BadRequest().body(format!( - "unable to process gio request, error details: '{}'", - e - )) + HttpResponse::BadRequest() + .append_header((hyper::header::CONTENT_TYPE, "text/plain")) + .body(format!( + "unable to process gio request, error details: '{}'", + e + )) } }; } @@ -188,6 +195,7 @@ async fn exception(exception: Json, data: Data>) -> Ht Err(e) => { log::error!("unable to throw exception, error details: '{}'", e); HttpResponse::BadRequest() + .append_header((hyper::header::CONTENT_TYPE, "text/plain")) .body(format!("unable to throw exception, error details: '{}'", e)) } }; @@ -203,7 +211,9 @@ async fn finish(finish: Json, data: Data>) -> Http "accept" => true, "reject" => false, _ => { - return HttpResponse::BadRequest().body("status must be 'accept' or 'reject'"); + return HttpResponse::BadRequest() + .append_header((hyper::header::CONTENT_TYPE, "text/plain")) + .body("status must be 'accept' or 'reject'"); } }; log::debug!( @@ -218,7 +228,7 @@ async fn finish(finish: Json, data: Data>) -> Http Ok(finish_request) => { // Received new request, process it log::info!( - "Received new request of type {}", + "received new request of type {}", match finish_request.next_request_type { 0 => "ADVANCE", 1 => "INSPECT", @@ -233,7 +243,9 @@ async fn finish(finish: Json, data: Data>) -> Http e.to_string() ); log::error!("{}", &error_message); - return HttpResponse::BadRequest().body(error_message); + return HttpResponse::BadRequest() + .append_header((hyper::header::CONTENT_TYPE, "text/plain")) + .body(error_message); } } } @@ -243,7 +255,9 @@ async fn finish(finish: Json, data: Data>) -> Http e.to_string() ); log::error!("{}", &error_message); - return HttpResponse::BadRequest().body(error_message); + return HttpResponse::BadRequest() + .append_header((hyper::header::CONTENT_TYPE, "text/plain")) + .body(error_message); } }; diff --git a/rollup-http/rollup-http-server/src/rollup/mod.rs b/rollup-http/rollup-http-server/src/rollup/mod.rs index ffb79ce4..64b77f64 100644 --- a/rollup-http/rollup-http-server/src/rollup/mod.rs +++ b/rollup-http/rollup-http-server/src/rollup/mod.rs @@ -122,7 +122,7 @@ impl cmt_abi_u256_t { cmt_abi_encode_uint_nn( binary.len(), binary.as_mut_ptr() as *const u8, - value.data.as_mut_ptr() + value.data.as_mut_ptr(), ) }; if rc != 0 { @@ -152,7 +152,7 @@ impl cmt_abi_address_t { pub struct GIORequest { #[validate(range(min = 0x10))] // avoid overlapping with our HTIF_YIELD_MANUAL_REASON_* pub domain: u16, - pub payload: String, + pub id: String, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -185,12 +185,12 @@ impl From for AdvanceMetadata { prev_randao.push_str(&hex::encode(&other.prev_randao.data)); AdvanceMetadata { chain_id: other.chain_id, - app_contract: app_contract, - msg_sender: msg_sender, + app_contract, + msg_sender, block_timestamp: other.block_timestamp, block_number: other.block_number, input_index: other.index, - prev_randao: prev_randao, + prev_randao, } } } @@ -354,7 +354,8 @@ pub fn rollup_read_inspect_state_request( payload: cmt_abi_bytes_t { length: 0, data: std::ptr::null::<::std::os::raw::c_uchar>() as *mut c_void, - }}); + }, + }); let res = unsafe { cmt_rollup_read_inspect_state(fd.0, inspect_request.as_mut()) }; @@ -502,8 +503,7 @@ pub fn gio_request( fd: &RollupFd, gio: &GIORequest, ) -> Result> { - println!("going to do gio_request"); - let binary_payload = match hex::decode(&gio.payload[2..]) { + let binary_payload = match hex::decode(&gio.id[2..]) { Ok(payload) => payload, Err(_err) => { return Err(Box::new(RollupError::new(&format!( diff --git a/rollup-http/rollup-http-server/tests/rollup-http-server-tests.rs b/rollup-http/rollup-http-server/tests/rollup-http-server-tests.rs index aab663e3..13fe149b 100644 --- a/rollup-http/rollup-http-server/tests/rollup-http-server-tests.rs +++ b/rollup-http/rollup-http-server/tests/rollup-http-server-tests.rs @@ -348,7 +348,7 @@ async fn test_gio_request( println!("Sending gio request"); let test_gio_request = GIORequest { domain: 0x100, - payload: "0x".to_string() + &hex::encode("gio test payload 01"), + id: "0x".to_string() + &hex::encode("gio test payload 01"), }; rollup_http_client::client::send_gio_request(&context.address, test_gio_request.clone()).await; context.server_handle.stop(true).await;