Skip to content

Commit

Permalink
Fix PR.
Browse files Browse the repository at this point in the history
  • Loading branch information
yoavGrs committed Jul 19, 2023
1 parent cb253a3 commit 2cfd345
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
21 changes: 18 additions & 3 deletions crates/papyrus_common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
use serde::ser::Serializer;
use serde::{Deserialize, Serialize};
use starknet_api::block::{BlockHash, BlockNumber};

#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq)]
pub enum SyncingState {
Synced(bool),
Synced,
SyncStatus(SyncStatus),
}

// TODO(yoav): add a test that verifies that the serialization conforms to the spec.
impl serde::Serialize for SyncingState {
// Serializes Synced variant into false (not syncing), and SyncStatus into its content.
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match self {
Self::Synced => serializer.serialize_bool(false),
Self::SyncStatus(sync_status) => sync_status.serialize(serializer),
}
}
}

// TODO(yoav): Add a test that verifies that the serialization conforms to the spec.

/// The status of the synchronization progress. The hash and the number of:
/// * the block from which the synchronization started,
/// * the currently syncing block,
Expand Down
2 changes: 1 addition & 1 deletion crates/papyrus_gateway/src/v0_3_0/api/api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ impl JsonRpcV0_3_0Server for JsonRpcServerV0_3_0Impl {
#[instrument(skip(self), level = "debug", err, ret)]
fn syncing(&self) -> RpcResult<SyncingState> {
// TODO(omri): This is temporary. Implement syncing logic.
Ok(SyncingState::Synced(false))
Ok(SyncingState::Synced)
}
}

Expand Down
9 changes: 2 additions & 7 deletions crates/papyrus_gateway/src/v0_3_0/api/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use jsonrpsee::core::params::ObjectParams;
use jsonrpsee::core::Error;
use jsonrpsee::types::ErrorObjectOwned;
use jsonschema::JSONSchema;
use papyrus_common::SyncingState;
use papyrus_storage::base_layer::BaseLayerStorageWriter;
use papyrus_storage::body::events::EventIndex;
use papyrus_storage::body::{BodyStorageWriter, TransactionIndex};
Expand Down Expand Up @@ -130,12 +129,8 @@ async fn block_number() {
#[tokio::test]
async fn syncing() {
let (module, _) = get_test_rpc_server_and_storage_writer::<JsonRpcServerV0_3_0Impl>();

let res = module
.call::<_, SyncingState>("starknet_V0_3_0_syncing", ObjectParams::new())
.await
.unwrap();
assert_eq!(res, SyncingState::Synced(false));
let res = module.call::<_, bool>("starknet_V0_3_0_syncing", ObjectParams::new()).await.unwrap();
assert_eq!(res, false);
}

#[tokio::test]
Expand Down

0 comments on commit 2cfd345

Please sign in to comment.