Skip to content

Commit

Permalink
test(rpc): pairty test for Filecoin.F3GetECPowerTable
Browse files Browse the repository at this point in the history
  • Loading branch information
hanabi1224 committed Oct 14, 2024
1 parent 41fd952 commit 09ac50a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/rpc/methods/f3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
chain::index::ResolveNullTipset,
libp2p::{NetRPCMethods, NetworkMessage},
lotus_json::HasLotusJson as _,
rpc::{ApiPaths, Ctx, Permission, RpcMethod, ServerError},
rpc::{types::ApiTipsetKey, ApiPaths, Ctx, Permission, RpcMethod, ServerError},
shim::{
address::{Address, Protocol},
clock::ChainEpoch,
Expand Down Expand Up @@ -539,14 +539,15 @@ impl RpcMethod<1> for F3GetECPowerTable {
const API_PATHS: ApiPaths = ApiPaths::V1;
const PERMISSION: Permission = Permission::Read;

type Params = (F3TipSetKey,);
type Params = (ApiTipsetKey,);
type Ok = Vec<F3PowerEntry>;

async fn handle(
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
params: Self::Params,
(ApiTipsetKey(tsk_opt),): Self::Params,
) -> Result<Self::Ok, ServerError> {
GetPowerTable::handle(ctx, params).await
let tsk = tsk_opt.unwrap_or_else(|| ctx.chain_store().heaviest_tipset().key().clone());
GetPowerTable::handle(ctx, (tsk.into(),)).await
}
}

Expand All @@ -557,13 +558,16 @@ impl RpcMethod<1> for F3GetF3PowerTable {
const API_PATHS: ApiPaths = ApiPaths::V1;
const PERMISSION: Permission = Permission::Read;

type Params = (F3TipSetKey,);
type Params = (ApiTipsetKey,);
type Ok = serde_json::Value;

async fn handle(
_: Ctx<impl Blockstore>,
(tsk,): Self::Params,
ctx: Ctx<impl Blockstore>,
(ApiTipsetKey(tsk_opt),): Self::Params,
) -> Result<Self::Ok, ServerError> {
let tsk: F3TipSetKey = tsk_opt
.unwrap_or_else(|| ctx.chain_store().heaviest_tipset().key().clone())
.into();
let client = get_rpc_http_client()?;
let mut params = ArrayParams::new();
params.insert(tsk.into_lotus_json())?;
Expand Down
9 changes: 9 additions & 0 deletions src/tool/subcommands/api_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,14 @@ fn gas_tests_with_tipset(shared_tipset: &Tipset) -> Vec<RpcTest> {
)]
}

fn f3_tests_with_tipset(tipset: &Tipset) -> anyhow::Result<Vec<RpcTest>> {
Ok(vec![
// using basic because 2 nodes are not garanteed to be at the same head
RpcTest::basic(F3GetECPowerTable::request((None.into(),))?),
RpcTest::identity(F3GetECPowerTable::request((tipset.key().into(),))?),
])
}

// Extract tests that use chain-specific data such as block CIDs or message
// CIDs. Right now, only the last `n_tipsets` tipsets are used.
fn snapshot_tests(
Expand All @@ -1640,6 +1648,7 @@ fn snapshot_tests(
tests.extend(gas_tests_with_tipset(&tipset));
tests.extend(mpool_tests_with_tipset(&tipset));
tests.extend(eth_state_tests_with_tipset(&store, &tipset, eth_chain_id)?);
tests.extend(f3_tests_with_tipset(&tipset)?);
}

Ok(tests)
Expand Down

0 comments on commit 09ac50a

Please sign in to comment.