Skip to content

Commit

Permalink
style: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-melnychuk committed Mar 1, 2024
1 parent bc4f124 commit 29f32fb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
28 changes: 22 additions & 6 deletions crates/api/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,19 @@ fn serve_on(url: &str, listener: TcpListener) -> Server {
.build()
.unwrap();

let ctx = Context { client: Arc::new(gen::client::Client::with_client(url, client)) };
let ctx = Context {
client: Arc::new(gen::client::Client::with_client(url, client)),
};

let app = Router::new().route("/rpc", post(handle_request)).with_state(ctx);

let (tx, rx) = oneshot::channel::<()>();
let port = listener.local_addr().unwrap().port();
let jh = tokio::spawn(async move {
axum::serve(listener, app.into_make_service())
.with_graceful_shutdown(async move { let _ = rx.await; })
.with_graceful_shutdown(async move {
let _ = rx.await;
})
.await
.unwrap();
});
Expand Down Expand Up @@ -260,13 +264,25 @@ impl gen::Rpc for Context {
key: StorageKey,
block_id: BlockId,
) -> std::result::Result<Felt, jsonrpc::Error> {
let result = self.client
.getStorageAt(contract_address.clone(), key.clone(), block_id.clone())
let result = self
.client
.getStorageAt(
contract_address.clone(),
key.clone(),
block_id.clone(),
)
.await?;
tracing::info!(?contract_address, ?key, ?block_id, ?result, "getStorageAt");
tracing::info!(
?contract_address,
?key,
?block_id,
?result,
"getStorageAt"
);
let felt = Felt::try_new(key.as_ref())?;
let keys = vec![Address(felt)];
let proof = self.client.getProof(block_id, contract_address, keys).await?;
let proof =
self.client.getProof(block_id, contract_address, keys).await?;
tracing::info!(?proof, "getStorageAt");
// TODO: validate proof
Ok(result)
Expand Down
11 changes: 8 additions & 3 deletions crates/api/tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use beerus_api::{gen::client::Client, rpc::{serve, Server}};
use beerus_api::{
gen::client::Client,
rpc::{serve, Server},
};

use async_once_cell::OnceCell;

Expand All @@ -8,7 +11,9 @@ pub enum Error {
}

impl From<iamgroot::jsonrpc::Error> for Error {
fn from(error: iamgroot::jsonrpc::Error) -> Self { Self::Rpc(error) }
fn from(error: iamgroot::jsonrpc::Error) -> Self {
Self::Rpc(error)
}
}

pub struct Context {
Expand All @@ -21,7 +26,7 @@ async fn setup() -> Option<Context> {

let url = std::env::var("TEST_URL").ok()?;
let server = serve(&url, "127.0.0.1:0").await;
tracing::info!(port=server.port(), "test server is up");
tracing::info!(port = server.port(), "test server is up");

let url = format!("http://localhost:{}/rpc", server.port());
let client = Client::new(&url);
Expand Down
4 changes: 3 additions & 1 deletion crates/api/tests/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ mod common;
#[tokio::test]
#[allow(non_snake_case)]
async fn test_specVersion() -> Result<(), common::Error> {
let Some(ctx) = common::ctx().await else { return Ok(()); };
let Some(ctx) = common::ctx().await else {
return Ok(());
};
assert_eq!(ctx.client.specVersion().await?, "0.6.0");
Ok(())
}

0 comments on commit 29f32fb

Please sign in to comment.