Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(rpc): pairty test for Filecoin.F3GetECPowerTable #4892

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading