testing: Prepare light client testing with substrate binary and add subxt-test macro (#1507)

* testing: Add long running light client flag and cfg aliases

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* testing: Expose clients depending on feature flags

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* subxt: Use unstable backend for light client

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* testing: Disable flaky lightclient tests

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* ci: Add long runnnig step

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Revert "subxt: Use unstable backend for light client"

This reverts commit ea6f3cc58b.

* ci: Long running tests for 60 mins

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* ci: Use 16 cores for light-client testing

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* ci: Isolate light-client testing to save CI minutes

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* testing: Retry on Tx::Dropped for lightclinet only

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* testing: Wait for more blocks for the lightclient init

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* subxt: Use unstable backend for light client

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* testing: Disable legacy RPC tests

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* testing: Disable sudo and contracts tests

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* testing: Retry constructing lightclient on read-proof errors

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* testing: Disable tx dynamic test

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* proc-macro: Timeout for tests

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* testing: Add timeout 800 seconds

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* proc-macro/tests: Adjust subxt-test proc-macro

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* proc-macro: Rename crate to subxt-test-proc-macro

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Use default subxt-proc-macro timeout

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* light-client: Remove println

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* subxt: Remove tokio as dependency, use it only for testing

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* testing: Chagne default timeout to 6 seconds

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* proc-macro: Add env timeout variable

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* ci: Add subxt env var for controling test timeouts

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* tests/tx-retries: Retry on `Non node available` error

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* testing: Use unstable backend for testing lightclient

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* testing: Remove old lightclient object

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* testing: Adjust for the new interface

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* backend/rpc: Allow older version of the initialized event

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/tests: Check initialized decodes correctly

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* ci: Reset workflow

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Apply cargo fmt

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Remove unused dep

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Remove gitmerge old file

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Remove unused dep

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rename proc-macro to subxt-test-macro

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* tests: Remove txretries for lightclient

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* tests: Wait for 5 blocks for the lightclient full testing suite

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* tests: Group imports

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* macro: Rename const value

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
Alexandru Vasile
2024-04-08 11:34:20 +03:00
committed by GitHub
parent 827a35de34
commit b31131d21d
26 changed files with 555 additions and 182 deletions
@@ -4,6 +4,7 @@
pub(crate) use crate::{node_runtime, utils::TestNodeProcess};
use subxt::client::OnlineClient;
use subxt::SubstrateConfig;
/// `substrate-node` should be installed on the $PATH. We fall back
@@ -20,8 +21,12 @@ pub async fn test_context_with(authority: String) -> TestContext {
proc.spawn::<SubstrateConfig>().await.unwrap()
}
pub type TestConfig = SubstrateConfig;
pub type TestContext = TestNodeProcess<SubstrateConfig>;
pub type TestClient = OnlineClient<SubstrateConfig>;
pub async fn test_context() -> TestContext {
test_context_with("alice".to_string()).await
}
+12 -1
View File
@@ -8,4 +8,15 @@ mod wait_for_blocks;
pub use context::*;
pub use node_proc::TestNodeProcess;
pub use wait_for_blocks::wait_for_blocks;
pub use wait_for_blocks::*;
pub use subxt_test_macro::subxt_test;
/// The test timeout is set to 1 second.
/// However, the test is sleeping for 5 seconds.
/// This must cause the test to panic.
#[subxt_test(timeout = 1)]
#[should_panic]
async fn test_subxt_macro() {
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
}
@@ -145,7 +145,7 @@ impl TestNodeProcessBuilder {
#[allow(unused_assignments, unused_mut)]
let mut legacy_client = None;
#[cfg(feature = "unstable-light-client")]
#[cfg(lightclient)]
let client = build_light_client(&proc).await?;
#[cfg(feature = "unstable-backend-client")]
@@ -155,10 +155,7 @@ impl TestNodeProcessBuilder {
client
};
#[cfg(all(
not(feature = "unstable-light-client"),
not(feature = "unstable-backend-client")
))]
#[cfg(all(not(lightclient), not(feature = "unstable-backend-client")))]
let client = {
let client = build_legacy_client(rpc_client.clone()).await?;
legacy_client = Some(client.clone());
@@ -219,7 +216,7 @@ async fn build_unstable_client<T: Config>(
Ok(client)
}
#[cfg(feature = "unstable-light-client")]
#[cfg(lightclient)]
async fn build_light_client<T: Config>(proc: &SubstrateNode) -> Result<OnlineClient<T>, String> {
use subxt::lightclient::{ChainConfig, LightClient};
@@ -230,7 +227,11 @@ async fn build_light_client<T: Config>(proc: &SubstrateNode) -> Result<OnlineCli
let client = OnlineClient::<T>::from_url(ws_url.clone())
.await
.map_err(|err| format!("Failed to connect to node rpc at {ws_url}: {err}"))?;
super::wait_for_blocks(&client).await;
// Wait for at least a few blocks before starting the light client.
// Otherwise, the lightclient might error with
// `"Error when retrieving the call proof: No node available for call proof query"`.
super::wait_for_number_of_blocks(&client, 5).await;
// Now, configure a light client; fetch the chain spec and modify the bootnodes.
let bootnode = format!(
@@ -252,9 +253,5 @@ async fn build_light_client<T: Config>(proc: &SubstrateNode) -> Result<OnlineCli
.map_err(|e| format!("Light client: cannot add relay chain: {e}"))?;
// Instantiate subxt client from this.
let api = OnlineClient::from_rpc_client(rpc)
.await
.map_err(|e| format!("Failed to build OnlineClient from light client RPC: {e}"))?;
Ok(api)
build_unstable_client(rpc.into()).await
}
@@ -8,9 +8,18 @@ use subxt::{client::OnlineClientT, Config};
/// wait for one more finalized block to be produced, which is important because
/// the first finalized block doesn't have much state etc associated with it.
pub async fn wait_for_blocks<C: Config>(api: &impl OnlineClientT<C>) {
let mut sub = api.blocks().subscribe_finalized().await.unwrap();
// The current finalized block:
sub.next().await;
// The next one:
sub.next().await;
// The current finalized block and the next block.
wait_for_number_of_blocks(api, 2).await;
}
/// Wait for a number of blocks to be produced.
pub async fn wait_for_number_of_blocks<C: Config>(
api: &impl OnlineClientT<C>,
number_of_blocks: usize,
) {
let mut sub = api.blocks().subscribe_finalized().await.unwrap();
for _ in 0..number_of_blocks {
sub.next().await;
}
}