Skip to content

Commit

Permalink
fix: api compare test failures (#4235)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanabi1224 authored Apr 18, 2024
1 parent c4fc0b2 commit c02a97d
Show file tree
Hide file tree
Showing 35 changed files with 210 additions and 220 deletions.
1 change: 1 addition & 0 deletions src/blocks/tipset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ mod lotus_json {

use super::TipsetKey;

#[derive(Clone)]
pub struct TipsetLotusJson(Tipset);

impl JsonSchema for TipsetLotusJson {
Expand Down
12 changes: 4 additions & 8 deletions src/cli/subcommands/attach_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,7 @@ mod inner {
Address::from_str(&to)?,
humantoken::parse(&value)?, // Convert forest_shim::TokenAmount to TokenAmount3
);
Ok(
MpoolPushMessage::call(&rpc::Client::from(api), (message.into(), None))
.await?
.into_inner(),
)
Ok(MpoolPushMessage::call(&rpc::Client::from(api), (message.into(), None)).await?)
}

type SleepParams = (u64,);
Expand All @@ -300,14 +296,14 @@ mod inner {
let mut epoch = None;
loop {
let state = SyncState::call(&client, ()).await?;
if state.active_syncs.as_ref().first().stage() == SyncStage::Complete {
if state.active_syncs.first().stage() == SyncStage::Complete {
if let Some(prev) = epoch {
let curr = state.active_syncs.as_ref().first().epoch();
let curr = state.active_syncs.first().epoch();
if (curr - prev) >= epochs {
return Ok(());
}
} else {
epoch = Some(state.active_syncs.as_ref().first().epoch());
epoch = Some(state.active_syncs.first().epoch());
}
}
time::sleep(time::Duration::from_secs(1)).await;
Expand Down
8 changes: 2 additions & 6 deletions src/cli/subcommands/auth_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,14 @@ impl AuthCommands {
let perm: String = perm.parse()?;
let perms = process_perms(perm)?;
let token_exp = Duration::from_std(expire_in.into())?;
let res = AuthNew::call(&client, (AuthNewParams { perms, token_exp },))
.await?
.into_inner();
let res = AuthNew::call(&client, (AuthNewParams { perms, token_exp },)).await?;
print_rpc_res_bytes(res)
}
Self::ApiInfo { perm, expire_in } => {
let perm: String = perm.parse()?;
let perms = process_perms(perm)?;
let token_exp = Duration::from_std(expire_in.into())?;
let token = AuthNew::call(&client, (AuthNewParams { perms, token_exp },))
.await?
.into_inner();
let token = AuthNew::call(&client, (AuthNewParams { perms, token_exp },)).await?;
let new_api = api.set_token(Some(String::from_utf8(token)?));
println!("FULLNODE_API_INFO=\"{}\"", new_api);
Ok(())
Expand Down
19 changes: 7 additions & 12 deletions src/cli/subcommands/chain_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,10 @@ impl ChainCommands {
Self::Block { cid } => {
print_pretty_json(ChainGetBlock::call(&client, (cid.into(),)).await?)
}
Self::Genesis => print_pretty_json(ChainGetGenesis::call(&client, ()).await?),
Self::Head => print_rpc_res_cids(ChainHead::call(&client, ()).await?.into_inner()),
Self::Genesis => print_pretty_json(ChainGetGenesis::call_raw(&client, ()).await?),
Self::Head => print_rpc_res_cids(ChainHead::call(&client, ()).await?),
Self::Message { cid } => {
let bytes = ChainReadObj::call(&client, (cid.into(),))
.await?
.into_inner();
let bytes = ChainReadObj::call(&client, (cid.into(),)).await?;
match fvm_ipld_encoding::from_slice::<ChainMessage>(&bytes)? {
ChainMessage::Unsigned(m) => print_pretty_json(LotusJson(m)),
ChainMessage::Signed(m) => {
Expand All @@ -77,9 +75,7 @@ impl ChainCommands {
}
}
Self::ReadObj { cid } => {
let bytes = ChainReadObj::call(&client, (cid.into(),))
.await?
.into_inner();
let bytes = ChainReadObj::call(&client, (cid.into(),)).await?;
println!("{}", hex::encode(bytes));
Ok(())
}
Expand Down Expand Up @@ -122,18 +118,17 @@ async fn tipset_by_epoch_or_offset(
client: &rpc::Client,
epoch_or_offset: i64,
) -> Result<Tipset, jsonrpsee::core::ClientError> {
let current_head = ChainHead::call(client, ()).await?.into_inner();
let current_head = ChainHead::call(client, ()).await?;

let target_epoch = match epoch_or_offset.is_negative() {
true => current_head.epoch() + epoch_or_offset, // adding negative number
false => epoch_or_offset,
};
Ok(ChainGetTipSetByHeight::call(
ChainGetTipSetByHeight::call(
client,
(target_epoch, LotusJson(current_head.key().clone().into())),
)
.await?
.into_inner())
.await
}

const SET_HEAD_CONFIRMATION_MESSAGE: &str =
Expand Down
7 changes: 2 additions & 5 deletions src/cli/subcommands/info_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,13 @@ impl InfoCommand {
StartTime::call(&client, ()),
WalletDefaultAddress::call(&client, ()),
)?;
let default_wallet_address = default_wallet_address.into_inner();

let cur_duration: Duration = SystemTime::now().duration_since(UNIX_EPOCH)?;
let blocks_per_tipset_last_finality =
node_status.chain_status.blocks_per_tipset_last_finality;

let default_wallet_address_balance = if let Some(def_addr) = default_wallet_address {
let balance = WalletBalance::call(&client, (def_addr.into(),))
.await?
.into_inner();
let balance = WalletBalance::call(&client, (def_addr.into(),)).await?;
Some(balance)
} else {
None
Expand All @@ -177,7 +174,7 @@ impl InfoCommand {
let node_status_info = NodeStatusInfo::new(
cur_duration,
blocks_per_tipset_last_finality,
&head.into_inner(),
&head,
start_time,
network,
default_wallet_address,
Expand Down
16 changes: 7 additions & 9 deletions src/cli/subcommands/mpool_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,11 @@ impl MpoolCommands {
to,
from,
} => {
let messages = MpoolPending::call(&client, (LotusJson(ApiTipsetKey(None)),))
.await?
.into_inner();
let messages =
MpoolPending::call(&client, (LotusJson(ApiTipsetKey(None)),)).await?;

let local_addrs = if local {
let response = WalletList::call(&client, ()).await?.into_inner();
let response = WalletList::call(&client, ()).await?;
Some(HashSet::from_iter(response))
} else {
None
Expand All @@ -244,18 +243,17 @@ impl MpoolCommands {
basefee_lookback,
local,
} => {
let tipset = ChainHead::call(&client, ()).await?.into_inner();
let tipset = ChainHead::call(&client, ()).await?;
let curr_base_fee = tipset.block_headers().first().parent_base_fee.to_owned();

let atto_str = ChainGetMinBaseFee::call(&client, (basefee_lookback,)).await?;
let min_base_fee = TokenAmount::from_atto(atto_str.parse::<BigInt>()?);

let messages = MpoolPending::call(&client, (LotusJson(ApiTipsetKey(None)),))
.await?
.into_inner();
let messages =
MpoolPending::call(&client, (LotusJson(ApiTipsetKey(None)),)).await?;

let local_addrs = if local {
let response = WalletList::call(&client, ()).await?.into_inner();
let response = WalletList::call(&client, ()).await?;
Some(HashSet::from_iter(response))
} else {
None
Expand Down
5 changes: 1 addition & 4 deletions src/cli/subcommands/send_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ impl SendCommand {
} else {
WalletDefaultAddress::call(&client, ())
.await?
.into_inner()
.context("No default wallet address selected. Please set a default address.")?
};

Expand All @@ -58,9 +57,7 @@ impl SendCommand {
..Default::default()
};

let signed_msg = MpoolPushMessage::call(&client, (message.into(), None))
.await?
.into_inner();
let signed_msg = MpoolPushMessage::call(&client, (message.into(), None)).await?;

println!("{}", signed_msg.cid().unwrap());

Expand Down
7 changes: 3 additions & 4 deletions src/cli/subcommands/snapshot_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,15 @@ impl SnapshotCommands {
tipset,
depth,
} => {
let chain_head = ChainHead::call(&client, ()).await?.into_inner();
let chain_head = ChainHead::call(&client, ()).await?;

let epoch = tipset.unwrap_or(chain_head.epoch());

let raw_network_name = api.state_network_name().await?;
let chain_name = crate::daemon::get_actual_chain_name(&raw_network_name);

let tipset = ChainGetTipSetByHeight::call(&client, (epoch, Default::default()))
.await?
.into_inner();
let tipset =
ChainGetTipSetByHeight::call(&client, (epoch, Default::default())).await?;

let output_path = match output_path.is_dir() {
true => output_path.join(snapshot::filename(
Expand Down
4 changes: 2 additions & 2 deletions src/cli/subcommands/sync_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl SyncCommands {

for _ in ticker {
let resp = SyncState::call(&client, ()).await?;
let active_syncs = resp.active_syncs.as_ref();
let active_syncs = resp.active_syncs;
let state = active_syncs
.iter()
.rev()
Expand Down Expand Up @@ -99,7 +99,7 @@ impl SyncCommands {
}
Self::Status => {
let resp = SyncState::call(&client, ()).await?;
let state = resp.active_syncs.as_ref().first();
let state = resp.active_syncs.first();

let base = state.base();
let elapsed_time = state.get_elapsed_time();
Expand Down
2 changes: 1 addition & 1 deletion src/lotus_json/beacon_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::beacon::BeaconEntry;

use super::*;

#[derive(Serialize, Deserialize, JsonSchema)]
#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
pub struct BeaconEntryLotusJson {
round: LotusJson<u64>,
Expand Down
2 changes: 1 addition & 1 deletion src/lotus_json/block_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use serde::{Deserialize, Serialize};

use crate::blocks::{CachingBlockHeader, RawBlockHeader};

#[derive(Serialize, Deserialize, JsonSchema)]
#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
pub struct BlockHeaderLotusJson {
miner: LotusJson<Address>,
Expand Down
2 changes: 1 addition & 1 deletion src/lotus_json/cid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use super::*;

#[derive(Serialize, Deserialize, JsonSchema)]
#[derive(Clone, Serialize, Deserialize, JsonSchema)]
pub struct CidLotusJsonGeneric<const S: usize> {
#[serde(rename = "/")]
slash: Stringify<::cid::CidGeneric<S>>,
Expand Down
2 changes: 1 addition & 1 deletion src/lotus_json/key_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::*;

use crate::{key_management::KeyInfo, shim::crypto::SignatureType};

#[derive(Serialize, Deserialize, JsonSchema)]
#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
pub struct KeyInfoLotusJson {
r#type: LotusJson<SignatureType>,
Expand Down
2 changes: 1 addition & 1 deletion src/lotus_json/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::shim::{address::Address, econ::TokenAmount, message::Message};
use ::cid::Cid;
use fvm_ipld_encoding::RawBytes;

#[derive(Serialize, Deserialize, JsonSchema)]
#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
pub struct MessageLotusJson {
version: LotusJson<u64>,
Expand Down
11 changes: 8 additions & 3 deletions src/lotus_json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ use serde::{de::DeserializeOwned, Deserialize, Deserializer, Serialize, Serializ
#[cfg(test)]
use serde_json::json;
use std::{fmt::Display, str::FromStr};
use uuid::Uuid;
#[cfg(test)]
use {pretty_assertions::assert_eq, quickcheck::quickcheck};

Expand Down Expand Up @@ -416,9 +417,6 @@ impl<T> LotusJson<T> {
pub fn into_inner(self) -> T {
self.0
}
pub fn as_ref(&self) -> &T {
&self.0
}
}

impl<T> LotusJson<Option<T>> {
Expand Down Expand Up @@ -449,6 +447,12 @@ impl<T> JsonSchema for Stringify<T> {
}
}

impl<T: Clone> Clone for Stringify<T> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}

macro_rules! lotus_json_with_self {
($($domain_ty:ty),* $(,)?) => {
$(
Expand Down Expand Up @@ -482,6 +486,7 @@ lotus_json_with_self!(
bool,
DeadlineInfo,
PaddedPieceSize,
Uuid,
);

#[derive(Default, Debug, Serialize, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion src/lotus_json/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use super::*;
use crate::shim::crypto::{Signature, SignatureType};

#[derive(Serialize, Deserialize, JsonSchema)]
#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
pub struct SignatureLotusJson {
r#type: LotusJson<SignatureType>,
Expand Down
2 changes: 1 addition & 1 deletion src/lotus_json/signed_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ::cid::Cid;

use super::*;

#[derive(Serialize, Deserialize, JsonSchema)]
#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
pub struct SignedMessageLotusJson {
message: LotusJson<Message>,
Expand Down
2 changes: 1 addition & 1 deletion src/lotus_json/token_amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::*;
use crate::shim::econ::TokenAmount;
use num::BigInt;

#[derive(Serialize, Deserialize, JsonSchema)]
#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[serde(transparent)] // name the field for clarity
pub struct TokenAmountLotusJson {
attos: LotusJson<BigInt>,
Expand Down
6 changes: 6 additions & 0 deletions src/lotus_json/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ where
}
}

impl<T: Clone> Clone for VecLotusJson<T> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}

#[test]
fn shapshots() {
assert_one_snapshot(json!([{"/": "baeaaaaa"}]), vec![::cid::Cid::default()]);
Expand Down
4 changes: 2 additions & 2 deletions src/lotus_json/vec_u8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use super::*;
// This code looks odd so we can
// - use #[serde(with = "...")]
// - de/ser empty vecs as null
#[derive(Serialize, Deserialize, JsonSchema)]
#[derive(Clone, Serialize, Deserialize, JsonSchema)]
pub struct VecU8LotusJson(Option<Inner>);

#[derive(Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize)]
struct Inner(#[serde(with = "base64_standard")] Vec<u8>);

impl JsonSchema for Inner {
Expand Down
5 changes: 2 additions & 3 deletions src/rpc/methods/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0, MIT

use crate::auth::*;
use crate::lotus_json::LotusJson;
use crate::rpc::{ApiVersion, Ctx, RpcMethod, ServerError};
use anyhow::Result;
use chrono::Duration;
Expand All @@ -26,15 +25,15 @@ impl RpcMethod<1> for AuthNew {
const PARAM_NAMES: [&'static str; 1] = ["params"];
const API_VERSION: ApiVersion = ApiVersion::V0;
type Params = (AuthNewParams,);
type Ok = LotusJson<Vec<u8>>;
type Ok = Vec<u8>;
async fn handle(
ctx: Ctx<impl Blockstore>,
(params,): Self::Params,
) -> Result<Self::Ok, ServerError> {
let ks = ctx.keystore.read().await;
let ki = ks.get(JWT_IDENTIFIER)?;
let token = create_token(params.perms, ki.private_key(), params.token_exp)?;
Ok(LotusJson(token.as_bytes().to_vec()))
Ok(token.as_bytes().to_vec())
}
}

Expand Down
Loading

0 comments on commit c02a97d

Please sign in to comment.