From 09ac50aa82db110a3e34abed5340676925667a37 Mon Sep 17 00:00:00 2001 From: hanabi1224 Date: Mon, 14 Oct 2024 22:24:47 +0800 Subject: [PATCH] test(rpc): pairty test for Filecoin.F3GetECPowerTable --- src/rpc/methods/f3.rs | 18 +++++++++++------- src/tool/subcommands/api_cmd.rs | 9 +++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/rpc/methods/f3.rs b/src/rpc/methods/f3.rs index 763d966c2e86..0cb0b05c5cd3 100644 --- a/src/rpc/methods/f3.rs +++ b/src/rpc/methods/f3.rs @@ -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, @@ -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; async fn handle( ctx: Ctx, - params: Self::Params, + (ApiTipsetKey(tsk_opt),): Self::Params, ) -> Result { - 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 } } @@ -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, - (tsk,): Self::Params, + ctx: Ctx, + (ApiTipsetKey(tsk_opt),): Self::Params, ) -> Result { + 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())?; diff --git a/src/tool/subcommands/api_cmd.rs b/src/tool/subcommands/api_cmd.rs index 59135eacd15c..b23743d3890f 100644 --- a/src/tool/subcommands/api_cmd.rs +++ b/src/tool/subcommands/api_cmd.rs @@ -1614,6 +1614,14 @@ fn gas_tests_with_tipset(shared_tipset: &Tipset) -> Vec { )] } +fn f3_tests_with_tipset(tipset: &Tipset) -> anyhow::Result> { + 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( @@ -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)