Split RPCs into a separate crate (#1910)

* WIP extract RPCs into separate crate

* fmt

* Fix test

* Remove unused deps

* fix import

* WIP: Fix up errors and most tests. Start extracintg some tests/code to rpc crate

* MockRpcClient sync or async

* MockRpcClient only async but better type inference

* WIP MockRpcClient FnMuts and some test updates to use it

* Get all but one test working with new MockRpcClient

* WIP trying to debug failure

* WIP, Tests mostly fixed, need to add back oen more

* Get mock RPC tests working

* fmt

* fmt

* Clippy and comment tweak

* update CI to explicitly check subxt-rpc features

* clippy

* small tweaks after pass over

* feature flag rename

* update some docs

* Fix some examples

* fmt

* Fix features flags to work with web/wasm32

* Fix unused dep warning

* explicit targets in wasm CI

* Add better crate level docs

* fmt

* Address review comments

* Comment out flaky test for now and make more obvious how similar POlkadot and Substrate configs are

* Not a doc comment

* Remove unused imports
This commit is contained in:
James Wilson
2025-02-18 12:07:00 +00:00
committed by GitHub
parent 333de953ec
commit 816a86423b
50 changed files with 4575 additions and 1186 deletions
@@ -2,10 +2,8 @@
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
use std::collections::HashSet;
use crate::{
subxt_test, test_context, test_context_reconnecting_rpc_client,
subxt_test, test_context,
utils::{node_runtime, wait_for_blocks},
};
use codec::{Decode, Encode};
@@ -412,10 +410,20 @@ async fn partial_fee_estimate_correct() {
assert_eq!(partial_fee_1, partial_fee_2);
}
// This test runs OK locally but fails sporadically in CI eg:
//
// https://github.com/paritytech/subxt/actions/runs/13374953009/job/37353887719?pr=1910#step:7:178
// https://github.com/paritytech/subxt/actions/runs/13385878645/job/37382498200#step:6:163
//
// While those errors were timeouts, I also saw errors like "intersections size is 1".
/*
#[subxt_test(timeout = 300)]
async fn chainhead_block_subscription_reconnect() {
use std::collections::HashSet;
use crate::test_context_reconnecting_rpc_client;
let ctx = test_context_reconnecting_rpc_client().await;
let api = ctx.chainhead_backend().await;
let api = ctx.chainhead_backend().await;ccc
let chainhead_client_blocks = move |num: usize| {
let api = api.clone();
async move {
@@ -428,7 +436,7 @@ async fn chainhead_block_subscription_reconnect() {
let disconnected = match item {
Ok(_) => false,
Err(e) => {
if matches!(e, Error::Rpc(subxt::error::RpcError::DisconnectedWillReconnect(e)) if e.contains("Missed at least one block when the connection was lost")) {
if e.is_disconnected_will_reconnect() && e.to_string().contains("Missed at least one block when the connection was lost") {
missed_blocks = true;
}
e.is_disconnected_will_reconnect()
@@ -463,3 +471,4 @@ async fn chainhead_block_subscription_reconnect() {
assert!(intersection >= 3, "intersections size is {}", intersection);
}
}
*/
@@ -13,14 +13,14 @@ use assert_matches::assert_matches;
use codec::Encode;
use futures::Stream;
use subxt::{
backend::chain_head::rpc_methods::{
FollowEvent, Initialized, MethodResponse, RuntimeEvent, RuntimeVersionEvent, StorageQuery,
StorageQueryType,
},
config::Hasher,
utils::{AccountId32, MultiAddress},
SubstrateConfig,
};
use subxt_rpcs::methods::chain_head::{
FollowEvent, Initialized, MethodResponse, RuntimeEvent, RuntimeVersionEvent, StorageQuery,
StorageQueryType,
};
use subxt_signer::sr25519::dev;
@@ -293,7 +293,8 @@ async fn transactionwatch_v1_submit_and_watch() {
/// Ignore block related events and obtain the next event related to an operation.
async fn next_operation_event<
T: serde::de::DeserializeOwned,
S: Unpin + Stream<Item = Result<FollowEvent<T>, subxt::Error>>,
S: Unpin + Stream<Item = Result<FollowEvent<T>, E>>,
E: core::fmt::Debug,
>(
sub: &mut S,
) -> FollowEvent<T> {