From d56526df6521c84fcc0af24f0df1867d62bd3a21 Mon Sep 17 00:00:00 2001 From: Alex Mikhalevich <2990126+alexmikhalevich@users.noreply.github.com> Date: Mon, 8 Apr 2024 12:21:02 +0200 Subject: [PATCH 1/2] feat: implement gio endpoint --- rollup-http/rollup-http-client/src/client.rs | 24 +++++- rollup-http/rollup-http-client/src/rollup.rs | 12 +++ rollup-http/rollup-http-server/build.rs | 1 + .../rollup-http-server/src/http_service.rs | 23 +++++- .../rollup-http-server/src/rollup/bindings.rs | 0 .../rollup-http-server/src/rollup/mod.rs | 77 +++++++++++++++++++ .../rollup-http-server/src/rollup/wrapper.h | 1 - .../tests/rollup-http-server-tests.rs | 29 ++++++- 8 files changed, 163 insertions(+), 4 deletions(-) delete mode 100644 rollup-http/rollup-http-server/src/rollup/bindings.rs delete mode 100644 rollup-http/rollup-http-server/src/rollup/wrapper.h diff --git a/rollup-http/rollup-http-client/src/client.rs b/rollup-http/rollup-http-client/src/client.rs index c112d90c..72eb0b0c 100644 --- a/rollup-http/rollup-http-client/src/client.rs +++ b/rollup-http/rollup-http-client/src/client.rs @@ -14,7 +14,8 @@ // limitations under the License. // -use crate::rollup::{AdvanceRequest, Exception, IndexResponse, InspectRequest, Notice, Report, RollupRequest, RollupResponse, Voucher}; +use crate::rollup::{AdvanceRequest, Exception, IndexResponse, InspectRequest, Notice, Report, RollupRequest, RollupResponse, Voucher, GIORequest}; +use hyper::Response; use serde::{Deserialize, Serialize}; use std::io::ErrorKind; @@ -98,6 +99,27 @@ pub async fn send_report(rollup_http_server_addr: &str, report: Report) { } } +pub async fn send_gio_request(rollup_http_server_addr: &str, gio_request: GIORequest) -> Response { + log::debug!("sending gio request to {}", rollup_http_server_addr); + let client = hyper::Client::new(); + let req = hyper::Request::builder() + .method(hyper::Method::POST) + .header(hyper::header::CONTENT_TYPE, "application/json") + .uri(rollup_http_server_addr.to_string() + "/gio") + .body(hyper::Body::from(serde_json::to_string(&gio_request).unwrap())) + .expect("gio request"); + match client.request(req).await { + Ok(res) => { + log::info!("got gio response: {:?}", res); + res + } + Err(e) => { + log::error!("failed to send gio request to rollup http server: {}", e); + Response::builder().status(500).body(hyper::Body::empty()).unwrap() + } + } +} + pub async fn throw_exception(rollup_http_server_addr: &str, exception: Exception) { log::debug!( "throwing exception request to {}", diff --git a/rollup-http/rollup-http-client/src/rollup.rs b/rollup-http/rollup-http-client/src/rollup.rs index 9304b2b4..c4d503ef 100644 --- a/rollup-http/rollup-http-client/src/rollup.rs +++ b/rollup-http/rollup-http-client/src/rollup.rs @@ -64,6 +64,18 @@ pub struct IndexResponse { index: u64, } +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct GIORequest { + pub domain: u16, + pub payload: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct GIOResponse { + pub response_code: u16, + pub response: String, +} + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Exception { pub payload: String, diff --git a/rollup-http/rollup-http-server/build.rs b/rollup-http/rollup-http-server/build.rs index 9c658049..08dffeaf 100644 --- a/rollup-http/rollup-http-server/build.rs +++ b/rollup-http/rollup-http-server/build.rs @@ -55,6 +55,7 @@ fn main() { // link the libcmt shared library println!("cargo:rustc-link-search=native={}", lib_dir); + println!("cargo:rerun-if-changed={}/libcmt.a", lib_dir); println!("cargo:rustc-link-lib=static=cmt"); let bindings = bindgen::Builder::default() diff --git a/rollup-http/rollup-http-server/src/http_service.rs b/rollup-http/rollup-http-server/src/http_service.rs index 49d6924a..812d2028 100644 --- a/rollup-http/rollup-http-server/src/http_service.rs +++ b/rollup-http/rollup-http-server/src/http_service.rs @@ -21,9 +21,10 @@ use actix_web_validator::Json; use async_mutex::Mutex; use serde::{Deserialize, Serialize}; use tokio::sync::Notify; +use serde_json::json; use crate::config::Config; -use crate::rollup::{self, RollupFd}; +use crate::rollup::{self, RollupFd, GIORequest}; use crate::rollup::{ AdvanceRequest, Exception, InspectRequest, Notice, Report, RollupRequest, FinishRequest, Voucher, }; @@ -52,6 +53,7 @@ pub fn create_server( .service(voucher) .service(notice) .service(report) + .service(gio) .service(exception) .service(finish) }) @@ -148,6 +150,25 @@ async fn report(report: Json, data: Data>) -> HttpRespons }; } +/// Process gio request and return the result +#[actix_web::post("/gio")] +async fn gio(request: Json, data: Data>) -> HttpResponse { + log::debug!("received gio request {:#?}", request); + let context = data.lock().await; + // Write report to linux rollup device + return match rollup::gio_request(&*context.rollup_fd.lock().await, &request.0) { + Ok(result) => { + log::debug!("gio successfully processed, response: {:#?}", result); + HttpResponse::Accepted().body(json!(result).to_string()) + } + Err(e) => { + log::error!("unable to process gio request, error details: '{}'", e); + HttpResponse::BadRequest() + .body(format!("unable to process gio request, error details: '{}'", e)) + } + }; +} + /// The DApp should call this method when it cannot proceed with the request processing after an exception happens. /// This method should be the last method ever called by the DApp backend, and it should not expect the call to return. /// The Rollup HTTP Server will pass the exception info to the Cartesi Server Manager. diff --git a/rollup-http/rollup-http-server/src/rollup/bindings.rs b/rollup-http/rollup-http-server/src/rollup/bindings.rs deleted file mode 100644 index e69de29b..00000000 diff --git a/rollup-http/rollup-http-server/src/rollup/mod.rs b/rollup-http/rollup-http-server/src/rollup/mod.rs index fdc856a3..6c03ecfc 100644 --- a/rollup-http/rollup-http-server/src/rollup/mod.rs +++ b/rollup-http/rollup-http-server/src/rollup/mod.rs @@ -114,6 +114,19 @@ impl From<&mut RollupFinish> for cmt_rollup_finish_t { } } +#[derive(Debug, Clone, Serialize, Deserialize, Validate)] +pub struct GIORequest { + #[validate(range(min = 0x10))] // avoid overlapping with our HTIF_YIELD_MANUAL_REASON_* + pub domain: u16, + pub payload: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct GIOResponse { + pub response_code: u16, + pub response: String, +} + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct AdvanceMetadata { pub msg_sender: String, @@ -467,6 +480,70 @@ pub fn rollup_write_report(fd: &RollupFd, report: &Report) -> Result<(), Box Result> { + println!("going to do gio_request"); + let binary_payload = match hex::decode(&gio.payload[2..]) { + Ok(payload) => payload, + Err(_err) => { + return Err(Box::new(RollupError::new(&format!( + "Error decoding gio request payload, payload must be in Ethereum hex binary format" + )))); + } + }; + + let mut buffer: Vec = Vec::with_capacity(binary_payload.len()); + let data = buffer.as_mut_ptr() as *mut c_void; + unsafe { + std::ptr::copy( + binary_payload.as_ptr(), + buffer.as_mut_ptr(), + binary_payload.len(), + ); + }; + + let mut gio_request = Box::new(cmt_gio_t { + domain: gio.domain, + id_length: binary_payload.len() as u32, + id: data, + response_code: 0, + response_data_length: 0, + response_data: std::ptr::null::<::std::os::raw::c_uchar>() as *mut c_void, + }); + + let res = unsafe { + cmt_gio_request(fd.0, gio_request.as_mut()) + }; + + if res != 0 { + return Err(Box::new(RollupError::new(&format!( + "GIO request returned error {}", + res + )))); + } + + let mut gio_response: Vec = Vec::with_capacity(gio_request.response_data_length as usize); + if gio_request.response_data_length == 0 { + log::info!("read zero size response from gio request"); + } else { + unsafe { + std::ptr::copy( + gio_request.response_data, + gio_response.as_mut_ptr() as *mut c_void, + gio_request.response_data_length as usize, + ); + gio_response.set_len(gio_request.response_data_length as usize); + } + } + + let result = GIOResponse { + response_code: gio_request.response_code, + response: "0x".to_string() + &hex::encode(&gio_response), + }; + dbg!(result.clone()); + + Ok(result) +} + pub fn rollup_throw_exception( fd: &RollupFd, exception: &Exception, diff --git a/rollup-http/rollup-http-server/src/rollup/wrapper.h b/rollup-http/rollup-http-server/src/rollup/wrapper.h deleted file mode 100644 index e04f87c6..00000000 --- a/rollup-http/rollup-http-server/src/rollup/wrapper.h +++ /dev/null @@ -1 +0,0 @@ -#include 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 c23267c5..ee774017 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 @@ -20,7 +20,7 @@ extern crate rollup_http_server; use actix_server::ServerHandle; use async_mutex::Mutex; use rollup_http_client::rollup::{ - Exception, Notice, Report, RollupRequest, RollupResponse, Voucher, + Exception, Notice, Report, RollupRequest, RollupResponse, Voucher, GIORequest, }; use rollup_http_server::config::Config; use rollup_http_server::rollup::RollupFd; @@ -333,6 +333,33 @@ async fn test_write_report( Ok(()) } +#[rstest] +#[tokio::test] +async fn test_gio_request( + context_future: impl Future, +) -> Result<(), Box> { + let context = context_future.await; + // Set the global log level + println!("Sending gio request"); + let test_gio_request = GIORequest { + domain: 0x100, + payload: "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; + + //Read text file with results + let gio = + std::fs::read_to_string("none.gio-0.bin").expect("error reading test gio file"); + assert_eq!( + gio, + "gio test payload 01" + ); + std::fs::remove_file("none.gio-0.bin")?; + + Ok(()) +} + #[rstest] #[tokio::test] async fn test_exception_throw( From 30a110080b505d220ef1612639786c7770d3d053 Mon Sep 17 00:00:00 2001 From: Alex Mikhalevich <2990126+alexmikhalevich@users.noreply.github.com> Date: Mon, 8 Apr 2024 12:21:46 +0200 Subject: [PATCH 2/2] chore: apply cargo fmt --- rollup-http/rollup-http-client/src/client.rs | 32 +++++----- rollup-http/rollup-http-client/src/lib.rs | 2 +- .../rollup-http-server/src/http_service.rs | 14 +++-- .../rollup-http-server/src/rollup/mod.rs | 59 +++++++++++-------- .../tests/rollup-http-server-tests.rs | 51 ++++++++-------- 5 files changed, 87 insertions(+), 71 deletions(-) diff --git a/rollup-http/rollup-http-client/src/client.rs b/rollup-http/rollup-http-client/src/client.rs index 72eb0b0c..3fb25202 100644 --- a/rollup-http/rollup-http-client/src/client.rs +++ b/rollup-http/rollup-http-client/src/client.rs @@ -14,7 +14,10 @@ // limitations under the License. // -use crate::rollup::{AdvanceRequest, Exception, IndexResponse, InspectRequest, Notice, Report, RollupRequest, RollupResponse, Voucher, GIORequest}; +use crate::rollup::{ + AdvanceRequest, Exception, GIORequest, IndexResponse, InspectRequest, Notice, Report, + RollupRequest, RollupResponse, Voucher, +}; use hyper::Response; use serde::{Deserialize, Serialize}; use std::io::ErrorKind; @@ -23,13 +26,9 @@ use std::io::ErrorKind; #[serde(tag = "request_type")] enum RollupHttpRequest { #[serde(rename = "advance_state")] - Advance { - data: AdvanceRequest, - }, + Advance { data: AdvanceRequest }, #[serde(rename = "inspect_state")] - Inspect { - data: InspectRequest, - }, + Inspect { data: InspectRequest }, } pub async fn send_voucher(rollup_http_server_addr: &str, voucher: Voucher) { @@ -99,14 +98,19 @@ pub async fn send_report(rollup_http_server_addr: &str, report: Report) { } } -pub async fn send_gio_request(rollup_http_server_addr: &str, gio_request: GIORequest) -> Response { +pub async fn send_gio_request( + rollup_http_server_addr: &str, + gio_request: GIORequest, +) -> Response { log::debug!("sending gio request to {}", rollup_http_server_addr); let client = hyper::Client::new(); let req = hyper::Request::builder() .method(hyper::Method::POST) .header(hyper::header::CONTENT_TYPE, "application/json") .uri(rollup_http_server_addr.to_string() + "/gio") - .body(hyper::Body::from(serde_json::to_string(&gio_request).unwrap())) + .body(hyper::Body::from( + serde_json::to_string(&gio_request).unwrap(), + )) .expect("gio request"); match client.request(req).await { Ok(res) => { @@ -115,16 +119,16 @@ pub async fn send_gio_request(rollup_http_server_addr: &str, gio_request: GIOReq } Err(e) => { log::error!("failed to send gio request to rollup http server: {}", e); - Response::builder().status(500).body(hyper::Body::empty()).unwrap() + Response::builder() + .status(500) + .body(hyper::Body::empty()) + .unwrap() } } } pub async fn throw_exception(rollup_http_server_addr: &str, exception: Exception) { - log::debug!( - "throwing exception request to {}", - rollup_http_server_addr - ); + log::debug!("throwing exception request to {}", rollup_http_server_addr); let client = hyper::Client::new(); let req = hyper::Request::builder() .method(hyper::Method::POST) diff --git a/rollup-http/rollup-http-client/src/lib.rs b/rollup-http/rollup-http-client/src/lib.rs index 0bb4a0e9..2e40f68f 100644 --- a/rollup-http/rollup-http-client/src/lib.rs +++ b/rollup-http/rollup-http-client/src/lib.rs @@ -1,2 +1,2 @@ pub mod client; -pub mod rollup; \ No newline at end of file +pub mod rollup; diff --git a/rollup-http/rollup-http-server/src/http_service.rs b/rollup-http/rollup-http-server/src/http_service.rs index 812d2028..8afc64c0 100644 --- a/rollup-http/rollup-http-server/src/http_service.rs +++ b/rollup-http/rollup-http-server/src/http_service.rs @@ -20,13 +20,14 @@ use actix_web::{middleware::Logger, web::Data, App, HttpResponse, HttpServer}; use actix_web_validator::Json; use async_mutex::Mutex; use serde::{Deserialize, Serialize}; -use tokio::sync::Notify; use serde_json::json; +use tokio::sync::Notify; use crate::config::Config; -use crate::rollup::{self, RollupFd, GIORequest}; +use crate::rollup::{self, GIORequest, RollupFd}; use crate::rollup::{ - AdvanceRequest, Exception, InspectRequest, Notice, Report, RollupRequest, FinishRequest, Voucher, + AdvanceRequest, Exception, FinishRequest, InspectRequest, Notice, Report, RollupRequest, + Voucher, }; #[derive(Debug, Serialize, Deserialize)] @@ -155,7 +156,6 @@ async fn report(report: Json, data: Data>) -> HttpRespons async fn gio(request: Json, data: Data>) -> HttpResponse { log::debug!("received gio request {:#?}", request); let context = data.lock().await; - // Write report to linux rollup device return match rollup::gio_request(&*context.rollup_fd.lock().await, &request.0) { Ok(result) => { log::debug!("gio successfully processed, response: {:#?}", result); @@ -163,8 +163,10 @@ 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().body(format!( + "unable to process gio request, error details: '{}'", + e + )) } }; } diff --git a/rollup-http/rollup-http-server/src/rollup/mod.rs b/rollup-http/rollup-http-server/src/rollup/mod.rs index 6c03ecfc..646be3e3 100644 --- a/rollup-http/rollup-http-server/src/rollup/mod.rs +++ b/rollup-http/rollup-http-server/src/rollup/mod.rs @@ -20,11 +20,11 @@ use std::io::ErrorKind; +use lazy_static::lazy_static; use libc::c_void; +use regex::Regex; use serde::{Deserialize, Serialize}; use validator::Validate; -use regex::Regex; -use lazy_static::lazy_static; include!(concat!(env!("OUT_DIR"), "/bindings.rs")); @@ -116,7 +116,7 @@ impl From<&mut RollupFinish> for cmt_rollup_finish_t { #[derive(Debug, Clone, Serialize, Deserialize, Validate)] pub struct GIORequest { - #[validate(range(min = 0x10))] // avoid overlapping with our HTIF_YIELD_MANUAL_REASON_* + #[validate(range(min = 0x10))] // avoid overlapping with our HTIF_YIELD_MANUAL_REASON_* pub domain: u16, pub payload: String, } @@ -181,7 +181,7 @@ pub struct FinishRequest { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct InspectReport { - pub reports: Vec + pub reports: Vec, } #[derive(Debug, Clone, Serialize, Deserialize, Validate)] @@ -239,7 +239,6 @@ pub fn rollup_finish_request( pub fn rollup_read_advance_state_request( fd: &RollupFd, ) -> Result> { - let mut advance_request = Box::new(cmt_rollup_advance_t { chain_id: 0, msg_sender: Default::default(), @@ -251,9 +250,7 @@ pub fn rollup_read_advance_state_request( payload: std::ptr::null::<::std::os::raw::c_uchar>() as *mut c_void, }); - let res = unsafe { - cmt_rollup_read_advance_state(fd.0, advance_request.as_mut()) - }; + let res = unsafe { cmt_rollup_read_advance_state(fd.0, advance_request.as_mut()) }; if res != 0 { return Err(Box::new(RollupError::new(&format!( @@ -269,7 +266,11 @@ pub fn rollup_read_advance_state_request( let mut payload: Vec = Vec::with_capacity(advance_request.payload_length as usize); if advance_request.payload_length > 0 { unsafe { - std::ptr::copy(advance_request.payload, payload.as_mut_ptr() as *mut c_void, advance_request.payload_length as usize); + std::ptr::copy( + advance_request.payload, + payload.as_mut_ptr() as *mut c_void, + advance_request.payload_length as usize, + ); payload.set_len(advance_request.payload_length as usize); } } @@ -282,19 +283,15 @@ pub fn rollup_read_advance_state_request( Ok(result) } - pub fn rollup_read_inspect_state_request( fd: &RollupFd, ) -> Result> { - let mut inspect_request = Box::new(cmt_rollup_inspect_t { payload_length: 0, payload: 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()) - }; + let res = unsafe { cmt_rollup_read_inspect_state(fd.0, inspect_request.as_mut()) }; if res != 0 { return Err(Box::new(RollupError::new(&format!( @@ -307,11 +304,18 @@ pub fn rollup_read_inspect_state_request( log::info!("read zero size payload from inspect state request"); } - println!("inspect_request.payload_length: {}", inspect_request.payload_length); + println!( + "inspect_request.payload_length: {}", + inspect_request.payload_length + ); let mut payload: Vec = Vec::with_capacity(inspect_request.payload_length as usize); if inspect_request.payload_length > 0 { unsafe { - std::ptr::copy(inspect_request.payload, payload.as_mut_ptr() as *mut c_void, inspect_request.payload_length as usize); + std::ptr::copy( + inspect_request.payload, + payload.as_mut_ptr() as *mut c_void, + inspect_request.payload_length as usize, + ); payload.set_len(inspect_request.payload_length as usize); } } @@ -349,7 +353,12 @@ pub fn rollup_write_notice( binary_payload.len(), ); - cmt_rollup_emit_notice(fd.0, length as u32, buffer.as_mut_ptr() as *mut c_void, &mut notice_index) + cmt_rollup_emit_notice( + fd.0, + length as u32, + buffer.as_mut_ptr() as *mut c_void, + &mut notice_index, + ) }; if res != 0 { @@ -364,7 +373,6 @@ pub fn rollup_write_notice( Ok(notice_index as u64) } - pub fn rollup_write_voucher( fd: &RollupFd, voucher: &mut Voucher, @@ -442,7 +450,10 @@ pub fn rollup_write_voucher( Ok(voucher_index as u64) } -pub fn rollup_write_report(fd: &RollupFd, report: &Report) -> Result<(), Box> { +pub fn rollup_write_report( + fd: &RollupFd, + report: &Report, +) -> Result<(), Box> { print_report(report); let binary_payload = match hex::decode(&report.payload[2..]) { @@ -480,7 +491,10 @@ pub fn rollup_write_report(fd: &RollupFd, report: &Report) -> Result<(), Box Result> { +pub fn gio_request( + fd: &RollupFd, + gio: &GIORequest, +) -> Result> { println!("going to do gio_request"); let binary_payload = match hex::decode(&gio.payload[2..]) { Ok(payload) => payload, @@ -510,9 +524,7 @@ pub fn gio_request(fd: &RollupFd, gio: &GIORequest) -> Result() as *mut c_void, }); - let res = unsafe { - cmt_gio_request(fd.0, gio_request.as_mut()) - }; + let res = unsafe { cmt_gio_request(fd.0, gio_request.as_mut()) }; if res != 0 { return Err(Box::new(RollupError::new(&format!( @@ -689,7 +701,6 @@ pub fn print_notice(notice: &Notice) { ); } - pub fn print_voucher(voucher: &Voucher) { let mut voucher_request_printout = String::new(); voucher_request_printout.push_str("voucher: {{ destination: "); 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 ee774017..31ebf8c7 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 @@ -19,19 +19,19 @@ extern crate rollup_http_server; use actix_server::ServerHandle; use async_mutex::Mutex; +use rand::Rng; use rollup_http_client::rollup::{ - Exception, Notice, Report, RollupRequest, RollupResponse, Voucher, GIORequest, + Exception, GIORequest, Notice, Report, RollupRequest, RollupResponse, Voucher, }; use rollup_http_server::config::Config; use rollup_http_server::rollup::RollupFd; use rollup_http_server::*; use rstest::*; -use std::future::Future; -use std::sync::Arc; -use rand::Rng; use std::env; use std::fs::File; +use std::future::Future; use std::io::Write; +use std::sync::Arc; const HOST: &str = "127.0.0.1"; @@ -156,7 +156,10 @@ async fn test_finish_request( let mut inspect_file = File::create(inspect_path)?; inspect_file.write_all(&inspect_binary_data)?; - env::set_var("CMT_INPUTS", format!("0:{0},1:{1}", advance_path, inspect_path)); + env::set_var( + "CMT_INPUTS", + format!("0:{0},1:{1}", advance_path, inspect_path), + ); env::set_var("CMT_DEBUG", "yes"); let context = context_future.await; @@ -216,18 +219,20 @@ async fn test_finish_request( Ok(()) } -fn check_voucher_or_fail( - original_voucher: Voucher, - output_filename: &str, -) { +fn check_voucher_or_fail(original_voucher: Voucher, output_filename: &str) { // we try to decode the produced voucher with a third-party lib to see if it matches // the expected values - let data = - std::fs::read(output_filename).expect("error reading voucher file"); + let data = std::fs::read(output_filename).expect("error reading voucher file"); let decoded_voucher = ethabi::decode( - &[ethabi::ParamType::Address, ethabi::ParamType::Uint(256), ethabi::ParamType::Bytes], + &[ + ethabi::ParamType::Address, + ethabi::ParamType::Uint(256), + ethabi::ParamType::Bytes, + ], &data[4..], // skip the first 4 bytes that are the function signature - ).ok().unwrap(); + ) + .ok() + .unwrap(); assert_eq!( "0x".to_string() + &decoded_voucher[0].to_string(), @@ -292,12 +297,13 @@ async fn test_write_notice( // we try to decode the produced voucher with a third-party lib to see if it matches // the expected values - let data = - std::fs::read("none.output-0.bin").expect("error reading test notice file"); + let data = std::fs::read("none.output-0.bin").expect("error reading test notice file"); let decoded_notice = ethabi::decode( &[ethabi::ParamType::Bytes], &data[4..], // skip the first 4 bytes that are the function signature - ).ok().unwrap(); + ) + .ok() + .unwrap(); assert_eq!( "0x".to_string() + &decoded_notice[0].to_string(), @@ -324,10 +330,7 @@ async fn test_write_report( //Read text file with results let report1 = std::fs::read_to_string("none.report-0.bin").expect("error reading test report file"); - assert_eq!( - report1, - "report test payload 01" - ); + assert_eq!(report1, "report test payload 01"); std::fs::remove_file("none.report-0.bin")?; Ok(()) @@ -349,12 +352,8 @@ async fn test_gio_request( context.server_handle.stop(true).await; //Read text file with results - let gio = - std::fs::read_to_string("none.gio-0.bin").expect("error reading test gio file"); - assert_eq!( - gio, - "gio test payload 01" - ); + let gio = std::fs::read_to_string("none.gio-0.bin").expect("error reading test gio file"); + assert_eq!(gio, "gio test payload 01"); std::fs::remove_file("none.gio-0.bin")?; Ok(())