From 34e92229590ee68405e90a74138aa3dd389375e9 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 29 Feb 2024 15:24:20 +0200 Subject: [PATCH 01/42] testing: Add long running light client flag and cfg aliases Signed-off-by: Alexandru Vasile --- testing/integration-tests/Cargo.toml | 6 ++++++ testing/integration-tests/build.rs | 9 +++++++++ 2 files changed, 15 insertions(+) create mode 100644 testing/integration-tests/build.rs diff --git a/testing/integration-tests/Cargo.toml b/testing/integration-tests/Cargo.toml index 27a2c83d9f..d52ceaa17a 100644 --- a/testing/integration-tests/Cargo.toml +++ b/testing/integration-tests/Cargo.toml @@ -18,6 +18,9 @@ default = [] # Enable to run the tests with Light Client support. unstable-light-client = ["subxt/unstable-light-client"] +# Enable to run the full-client tests with Light Client support. +unstable-light-client-long-running = ["subxt/unstable-light-client"] + # Enable this to use the unstable backend in tests _instead of_ # the default one which relies on the "old" RPC methods. unstable-backend-client = [] @@ -43,3 +46,6 @@ tracing = { workspace = true } tracing-subscriber = { workspace = true } wabt = { workspace = true } substrate-runner = { workspace = true } + +[build-dependencies] +cfg_aliases = "0.2.0" diff --git a/testing/integration-tests/build.rs b/testing/integration-tests/build.rs new file mode 100644 index 0000000000..992c3b3e81 --- /dev/null +++ b/testing/integration-tests/build.rs @@ -0,0 +1,9 @@ +use cfg_aliases::cfg_aliases; + +fn main() { + // Setup cfg aliases + cfg_aliases! { + lightclient: { any(feature = "unstable-light-client", feature = "unstable-light-client-long-running") }, + fullclient: { all(not(feature = "unstable-light-client"), not(feature = "unstable-light-client-long-running")) }, + } +} From 518aa8e24aa98e9b676bf30c9488e12076ea1170 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 29 Feb 2024 15:24:59 +0200 Subject: [PATCH 02/42] testing: Expose clients depending on feature flags Signed-off-by: Alexandru Vasile --- .../integration-tests/src/utils/context.rs | 14 ++++++++++++++ .../integration-tests/src/utils/node_proc.rs | 19 ++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/testing/integration-tests/src/utils/context.rs b/testing/integration-tests/src/utils/context.rs index f572cb5b5e..2ad0d8edfb 100644 --- a/testing/integration-tests/src/utils/context.rs +++ b/testing/integration-tests/src/utils/context.rs @@ -6,6 +6,12 @@ pub(crate) use crate::{node_runtime, utils::TestNodeProcess}; use subxt::SubstrateConfig; +#[cfg(lightclient)] +use subxt::client::LightClient; + +#[cfg(fullclient)] +use subxt::client::OnlineClient; + /// `substrate-node` should be installed on the $PATH. We fall back /// to also checking for an older `substrate` binary. const SUBSTRATE_NODE_PATHS: &str = "substrate-node,substrate"; @@ -20,8 +26,16 @@ pub async fn test_context_with(authority: String) -> TestContext { proc.spawn::().await.unwrap() } +pub type TestConfig = SubstrateConfig; + pub type TestContext = TestNodeProcess; +#[cfg(fullclient)] +pub type TestClient = OnlineClient; + +#[cfg(lightclient)] +pub type TestClient = LightClient; + pub async fn test_context() -> TestContext { test_context_with("alice".to_string()).await } diff --git a/testing/integration-tests/src/utils/node_proc.rs b/testing/integration-tests/src/utils/node_proc.rs index d3ac752fec..419ce50b57 100644 --- a/testing/integration-tests/src/utils/node_proc.rs +++ b/testing/integration-tests/src/utils/node_proc.rs @@ -11,7 +11,7 @@ use subxt::{ Config, OnlineClient, }; -#[cfg(feature = "unstable-light-client")] +#[cfg(lightclient)] use subxt::client::{LightClient, LightClientBuilder}; /// Spawn a local substrate node for testing subxt. @@ -25,10 +25,10 @@ pub struct TestNodeProcess { rpc_client: rpc::RpcClient, - #[cfg(not(feature = "unstable-light-client"))] + #[cfg(fullclient)] client: OnlineClient, - #[cfg(feature = "unstable-light-client")] + #[cfg(lightclient)] client: LightClient, } @@ -92,13 +92,13 @@ where /// will use the legacy backend by default or the unstable backend if the /// "unstable-backend-client" feature is enabled, so that we can run each /// test against both. - #[cfg(not(feature = "unstable-light-client"))] + #[cfg(fullclient)] pub fn client(&self) -> OnlineClient { self.client.clone() } /// Returns the subxt client connected to the running node. - #[cfg(feature = "unstable-light-client")] + #[cfg(lightclient)] pub fn client(&self) -> LightClient { self.client.clone() } @@ -160,7 +160,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")] @@ -170,10 +170,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()); @@ -234,7 +231,7 @@ async fn build_unstable_client( Ok(client) } -#[cfg(feature = "unstable-light-client")] +#[cfg(lightclient)] async fn build_light_client(proc: &SubstrateNode) -> Result, String> { // RPC endpoint. let ws_url = format!("ws://127.0.0.1:{}", proc.ws_port()); From ea6f3cc58b43cbd568c981aa131e0e119684a7df Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 29 Feb 2024 15:51:04 +0200 Subject: [PATCH 03/42] subxt: Use unstable backend for light client Signed-off-by: Alexandru Vasile --- subxt/Cargo.toml | 3 ++- subxt/src/client/light_client/mod.rs | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/subxt/Cargo.toml b/subxt/Cargo.toml index 4a18bb2b41..f06bd9dd63 100644 --- a/subxt/Cargo.toml +++ b/subxt/Cargo.toml @@ -61,7 +61,7 @@ unstable-metadata = [] # Activate this to expose the Light Client functionality. # Note that this feature is experimental and things may break or not work as expected. -unstable-light-client = ["subxt-lightclient", "tokio-stream"] +unstable-light-client = ["subxt-lightclient", "tokio-stream", "tokio"] [dependencies] async-trait = { workspace = true } @@ -117,6 +117,7 @@ getrandom = { workspace = true, optional = true } # Included if "native" feature is enabled tokio-util = { workspace = true, features = ["compat"], optional = true } +tokio = { workspace = true, features = ["macros", "time", "rt-multi-thread"], optional = true } [dev-dependencies] bitvec = { workspace = true } diff --git a/subxt/src/client/light_client/mod.rs b/subxt/src/client/light_client/mod.rs index a4b116652e..6881e6ac76 100644 --- a/subxt/src/client/light_client/mod.rs +++ b/subxt/src/client/light_client/mod.rs @@ -93,7 +93,29 @@ impl RawLightClient { ) -> Result, crate::Error> { let raw_rpc = self.raw_rpc.for_chain(chain_id); let rpc_client = RpcClient::new(raw_rpc.clone()); - let client = OnlineClient::::from_rpc_client(rpc_client).await?; + + use crate::backend::unstable::UnstableBackend; + use std::sync::Arc; + let (backend, mut driver) = UnstableBackend::builder().build(rpc_client); + let future = async move { + use futures::StreamExt; + while let Some(val) = driver.next().await { + if let Err(e) = val { + // This is a test; bail if something does wrong and try to + // ensure that the message makes it to some logs. + eprintln!("Error driving unstable backend in tests (will panic): {e}"); + panic!("Error driving unstable backend in tests: {e}"); + } + } + }; + // The unstable backend needs driving: + #[cfg(feature = "native")] + tokio::spawn(future); + #[cfg(feature = "web")] + wasm_bindgen_futures::spawn_local(future); + let client = OnlineClient::from_backend(Arc::new(backend)) + .await + .map_err(|e| format!("Cannot construct OnlineClient from backend: {e}"))?; Ok(LightClient { client, chain_id }) } From ca36ef6643de3b910d5b09763672a4e1d556839d Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 29 Feb 2024 15:51:24 +0200 Subject: [PATCH 04/42] testing: Disable flaky lightclient tests Signed-off-by: Alexandru Vasile --- Cargo.lock | 7 +++++++ .../integration-tests/src/full_client/blocks/mod.rs | 12 ++++++++++++ .../integration-tests/src/full_client/client/mod.rs | 10 ++++++++++ .../src/full_client/client/unstable_rpcs.rs | 8 ++++++++ .../src/full_client/frame/balances.rs | 3 +++ .../src/full_client/frame/contracts.rs | 12 ++++++------ .../src/full_client/metadata/validation.rs | 3 +++ .../integration-tests/src/full_client/storage/mod.rs | 2 ++ testing/integration-tests/src/lib.rs | 5 ++++- 9 files changed, 55 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 502183c315..f34d4ae4b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -780,6 +780,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e53693616d3075149f4ead59bdeecd204ac6b8192d8969757601b74bddf00f" + [[package]] name = "chacha20" version = "0.9.1" @@ -2256,6 +2262,7 @@ name = "integration-tests" version = "0.34.0" dependencies = [ "assert_matches", + "cfg_aliases", "frame-metadata 16.0.0", "futures", "hex", diff --git a/testing/integration-tests/src/full_client/blocks/mod.rs b/testing/integration-tests/src/full_client/blocks/mod.rs index 0cb40404b7..f513d9a738 100644 --- a/testing/integration-tests/src/full_client/blocks/mod.rs +++ b/testing/integration-tests/src/full_client/blocks/mod.rs @@ -5,13 +5,23 @@ use crate::{test_context, utils::node_runtime}; use codec::{Compact, Encode}; use futures::StreamExt; + +#[cfg(lightclient)] +use subxt::client::OnlineClientT; + +#[cfg(fullclient)] use subxt::config::signed_extensions::{ChargeAssetTxPayment, CheckMortality, CheckNonce}; +#[cfg(fullclient)] use subxt::config::DefaultExtrinsicParamsBuilder; +#[cfg(fullclient)] use subxt::config::SubstrateConfig; +#[cfg(fullclient)] use subxt::utils::Era; + use subxt_metadata::Metadata; use subxt_signer::sr25519::dev; +#[cfg(fullclient)] #[tokio::test] async fn block_subscriptions_are_consistent_with_eachother() -> Result<(), subxt::Error> { let ctx = test_context().await; @@ -163,6 +173,7 @@ async fn runtime_api_call() -> Result<(), subxt::Error> { Ok(()) } +#[cfg(fullclient)] #[tokio::test] async fn fetch_block_and_decode_extrinsic_details() { let ctx = test_context().await; @@ -232,6 +243,7 @@ async fn fetch_block_and_decode_extrinsic_details() { assert!(tx.is_signed()); } +#[cfg(fullclient)] #[tokio::test] async fn decode_signed_extensions_from_blocks() { let ctx = test_context().await; diff --git a/testing/integration-tests/src/full_client/client/mod.rs b/testing/integration-tests/src/full_client/client/mod.rs index 49c89a28a0..74365166f8 100644 --- a/testing/integration-tests/src/full_client/client/mod.rs +++ b/testing/integration-tests/src/full_client/client/mod.rs @@ -7,7 +7,13 @@ use crate::{ utils::{node_runtime, wait_for_blocks}, }; use codec::{Decode, Encode}; + +#[cfg(fullclient)] use futures::StreamExt; + +#[cfg(lightclient)] +use subxt::client::OnlineClientT; + use subxt::{ backend::BackendExt, error::{DispatchError, Error}, @@ -18,6 +24,7 @@ use subxt_signer::sr25519::dev; mod legacy_rpcs; mod unstable_rpcs; +#[cfg(fullclient)] #[tokio::test] async fn storage_fetch_raw_keys() { let ctx = test_context().await; @@ -39,6 +46,7 @@ async fn storage_fetch_raw_keys() { assert_eq!(len, 13) } +#[cfg(fullclient)] #[tokio::test] async fn storage_iter() { let ctx = test_context().await; @@ -63,6 +71,7 @@ async fn storage_iter() { assert_eq!(len, 13); } +#[cfg(fullclient)] #[tokio::test] async fn storage_child_values_same_across_backends() { let ctx = test_context().await; @@ -204,6 +213,7 @@ async fn external_signing() { .unwrap(); } +#[cfg(fullclient)] // TODO: Investigate and fix this test failure when using the UnstableBackend. // (https://github.com/paritytech/subxt/issues/1308) #[cfg(not(feature = "unstable-backend-client"))] diff --git a/testing/integration-tests/src/full_client/client/unstable_rpcs.rs b/testing/integration-tests/src/full_client/client/unstable_rpcs.rs index 7704e0d002..22462a03f7 100644 --- a/testing/integration-tests/src/full_client/client/unstable_rpcs.rs +++ b/testing/integration-tests/src/full_client/client/unstable_rpcs.rs @@ -16,6 +16,10 @@ use subxt::{ }, utils::AccountId32, }; + +#[cfg(lightclient)] +use subxt::client::OfflineClientT; + use subxt_signer::sr25519::dev; #[tokio::test] @@ -215,6 +219,7 @@ async fn chainhead_unstable_unpin() { assert!(rpc.chainhead_unstable_unpin(sub_id, hash).await.is_err()); } +#[cfg(fullclient)] #[tokio::test] async fn chainspec_v1_genesishash() { let ctx = test_context().await; @@ -227,6 +232,7 @@ async fn chainspec_v1_genesishash() { assert_eq!(a, b); } +#[cfg(fullclient)] #[tokio::test] async fn chainspec_v1_chainname() { let ctx = test_context().await; @@ -239,6 +245,7 @@ async fn chainspec_v1_chainname() { assert_eq!(a, b); } +#[cfg(fullclient)] #[tokio::test] async fn chainspec_v1_properties() { let ctx = test_context().await; @@ -251,6 +258,7 @@ async fn chainspec_v1_properties() { assert_eq!(a, b); } +#[cfg(fullclient)] #[tokio::test] async fn transaction_unstable_submit_and_watch() { let ctx = test_context().await; diff --git a/testing/integration-tests/src/full_client/frame/balances.rs b/testing/integration-tests/src/full_client/frame/balances.rs index d4ef0392de..0fb1b02cac 100644 --- a/testing/integration-tests/src/full_client/frame/balances.rs +++ b/testing/integration-tests/src/full_client/frame/balances.rs @@ -13,6 +13,9 @@ use subxt::{ }; use subxt_signer::sr25519::dev; +#[cfg(lightclient)] +use subxt::client::OfflineClientT; + #[tokio::test] async fn tx_basic_transfer() -> Result<(), subxt::Error> { let alice = dev::alice(); diff --git a/testing/integration-tests/src/full_client/frame/contracts.rs b/testing/integration-tests/src/full_client/frame/contracts.rs index 080c456ebb..60039be1d7 100644 --- a/testing/integration-tests/src/full_client/frame/contracts.rs +++ b/testing/integration-tests/src/full_client/frame/contracts.rs @@ -9,10 +9,10 @@ use crate::{ runtime_types::{pallet_contracts::wasm::Determinism, sp_weights::weight_v2::Weight}, system, }, - test_context, TestContext, + test_context, TestClient, TestConfig, TestContext, }; use subxt::ext::futures::StreamExt; -use subxt::{tx::TxProgress, utils::MultiAddress, Config, Error, OnlineClient, SubstrateConfig}; +use subxt::{tx::TxProgress, utils::MultiAddress, Config, Error}; use subxt_signer::sr25519::{self, dev}; struct ContractsTestContext { @@ -20,8 +20,8 @@ struct ContractsTestContext { signer: sr25519::Keypair, } -type Hash = ::Hash; -type AccountId = ::AccountId; +type Hash = ::Hash; +type AccountId = ::AccountId; /// A dummy contract which does nothing at all. const CONTRACT: &str = r#" @@ -42,7 +42,7 @@ impl ContractsTestContext { Self { cxt, signer } } - fn client(&self) -> OnlineClient { + fn client(&self) -> TestClient { self.cxt.client() } @@ -147,7 +147,7 @@ impl ContractsTestContext { &self, contract: AccountId, input_data: Vec, - ) -> Result>, Error> { + ) -> Result, Error> { tracing::info!("call: {:?}", contract); let call_tx = node_runtime::tx().contracts().call( MultiAddress::Id(contract), diff --git a/testing/integration-tests/src/full_client/metadata/validation.rs b/testing/integration-tests/src/full_client/metadata/validation.rs index e10e953d76..733117b001 100644 --- a/testing/integration-tests/src/full_client/metadata/validation.rs +++ b/testing/integration-tests/src/full_client/metadata/validation.rs @@ -14,6 +14,9 @@ use scale_info::{ }; use subxt::{Metadata, OfflineClient, SubstrateConfig}; +#[cfg(lightclient)] +use subxt::client::OfflineClientT; + async fn metadata_to_api(metadata: Metadata, ctx: &TestContext) -> OfflineClient { OfflineClient::new( ctx.client().genesis_hash(), diff --git a/testing/integration-tests/src/full_client/storage/mod.rs b/testing/integration-tests/src/full_client/storage/mod.rs index e1cec5f939..af5b85f3a3 100644 --- a/testing/integration-tests/src/full_client/storage/mod.rs +++ b/testing/integration-tests/src/full_client/storage/mod.rs @@ -90,6 +90,7 @@ async fn storage_n_mapish_key_is_properly_created() -> Result<(), subxt::Error> Ok(()) } +#[cfg(fullclient)] #[tokio::test] async fn storage_n_map_storage_lookup() -> Result<(), subxt::Error> { let ctx = test_context().await; @@ -126,6 +127,7 @@ async fn storage_n_map_storage_lookup() -> Result<(), subxt::Error> { Ok(()) } +#[cfg(fullclient)] #[tokio::test] async fn storage_partial_lookup() -> Result<(), subxt::Error> { let ctx = test_context().await; diff --git a/testing/integration-tests/src/lib.rs b/testing/integration-tests/src/lib.rs index 0eeb3e607f..a57790d452 100644 --- a/testing/integration-tests/src/lib.rs +++ b/testing/integration-tests/src/lib.rs @@ -14,7 +14,10 @@ pub mod utils; #[cfg_attr(test, allow(unused_imports))] use utils::*; -#[cfg(all(test, not(feature = "unstable-light-client")))] +#[cfg(any( + all(test, not(feature = "unstable-light-client")), + all(test, feature = "unstable-light-client-long-running") +))] mod full_client; #[cfg(all(test, feature = "unstable-light-client"))] From 8fe7e86e995ef1a450dc90782a8c50cbf9ac2fae Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 29 Feb 2024 15:53:19 +0200 Subject: [PATCH 05/42] ci: Add long runnnig step Signed-off-by: Alexandru Vasile --- .github/workflows/rust.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 327a77bd31..dda0013f7c 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -364,6 +364,37 @@ jobs: - if: "failure()" uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + light_client_long_running_tests: + name: "Test (Light Client Long Running)" + runs-on: ubuntu-latest + needs: [clippy, wasm_clippy, check, wasm_check, docs] + timeout-minutes: 30 + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Use substrate and polkadot node binaries + uses: ./.github/workflows/actions/use-nodes + + - name: Install Rust stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Rust Cache + uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + - name: Run tests + uses: actions-rs/cargo@v1.0.3 + with: + command: test + args: --release --package integration-tests --features unstable-light-client-long-running + + - if: "failure()" + uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + wasm_tests: name: Test (WASM) runs-on: ubuntu-latest From 593fbeb957ddcc7fa82749baed6f2b4812fd3b86 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 29 Feb 2024 16:58:13 +0200 Subject: [PATCH 06/42] Revert "subxt: Use unstable backend for light client" This reverts commit ea6f3cc58b43cbd568c981aa131e0e119684a7df. --- subxt/Cargo.toml | 3 +-- subxt/src/client/light_client/mod.rs | 24 +----------------------- 2 files changed, 2 insertions(+), 25 deletions(-) diff --git a/subxt/Cargo.toml b/subxt/Cargo.toml index f06bd9dd63..4a18bb2b41 100644 --- a/subxt/Cargo.toml +++ b/subxt/Cargo.toml @@ -61,7 +61,7 @@ unstable-metadata = [] # Activate this to expose the Light Client functionality. # Note that this feature is experimental and things may break or not work as expected. -unstable-light-client = ["subxt-lightclient", "tokio-stream", "tokio"] +unstable-light-client = ["subxt-lightclient", "tokio-stream"] [dependencies] async-trait = { workspace = true } @@ -117,7 +117,6 @@ getrandom = { workspace = true, optional = true } # Included if "native" feature is enabled tokio-util = { workspace = true, features = ["compat"], optional = true } -tokio = { workspace = true, features = ["macros", "time", "rt-multi-thread"], optional = true } [dev-dependencies] bitvec = { workspace = true } diff --git a/subxt/src/client/light_client/mod.rs b/subxt/src/client/light_client/mod.rs index 6881e6ac76..a4b116652e 100644 --- a/subxt/src/client/light_client/mod.rs +++ b/subxt/src/client/light_client/mod.rs @@ -93,29 +93,7 @@ impl RawLightClient { ) -> Result, crate::Error> { let raw_rpc = self.raw_rpc.for_chain(chain_id); let rpc_client = RpcClient::new(raw_rpc.clone()); - - use crate::backend::unstable::UnstableBackend; - use std::sync::Arc; - let (backend, mut driver) = UnstableBackend::builder().build(rpc_client); - let future = async move { - use futures::StreamExt; - while let Some(val) = driver.next().await { - if let Err(e) = val { - // This is a test; bail if something does wrong and try to - // ensure that the message makes it to some logs. - eprintln!("Error driving unstable backend in tests (will panic): {e}"); - panic!("Error driving unstable backend in tests: {e}"); - } - } - }; - // The unstable backend needs driving: - #[cfg(feature = "native")] - tokio::spawn(future); - #[cfg(feature = "web")] - wasm_bindgen_futures::spawn_local(future); - let client = OnlineClient::from_backend(Arc::new(backend)) - .await - .map_err(|e| format!("Cannot construct OnlineClient from backend: {e}"))?; + let client = OnlineClient::::from_rpc_client(rpc_client).await?; Ok(LightClient { client, chain_id }) } From 1fc1bb41529676e018aa5789fe7d92676ae89277 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 29 Feb 2024 18:21:18 +0200 Subject: [PATCH 07/42] ci: Long running tests for 60 mins Signed-off-by: Alexandru Vasile --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index dda0013f7c..8d30c54a88 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -368,7 +368,7 @@ jobs: name: "Test (Light Client Long Running)" runs-on: ubuntu-latest needs: [clippy, wasm_clippy, check, wasm_check, docs] - timeout-minutes: 30 + timeout-minutes: 60 steps: - name: Checkout sources uses: actions/checkout@v4 From ca60c318d112e16766b7a873980432528a483de7 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 29 Feb 2024 18:54:36 +0200 Subject: [PATCH 08/42] ci: Use 16 cores for light-client testing Signed-off-by: Alexandru Vasile --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 8d30c54a88..787d7ae656 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -366,7 +366,7 @@ jobs: light_client_long_running_tests: name: "Test (Light Client Long Running)" - runs-on: ubuntu-latest + runs-on: ubuntu-latest-16-cores needs: [clippy, wasm_clippy, check, wasm_check, docs] timeout-minutes: 60 steps: From 3c58c5ec8858f9db5dea995baaeea576a1a1ccf8 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 29 Feb 2024 18:55:05 +0200 Subject: [PATCH 09/42] ci: Isolate light-client testing to save CI minutes Signed-off-by: Alexandru Vasile --- .github/workflows/rust.yml | 862 ++++++++++++++++++------------------- 1 file changed, 431 insertions(+), 431 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 787d7ae656..1dcdcfb880 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -22,352 +22,352 @@ env: WASM_BINDGEN_TEST_TIMEOUT: 60 jobs: - fmt: - name: Cargo fmt - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Install Rust nightly toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - components: rustfmt - - - name: Rust Cache - uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - - name: Cargo fmt - uses: actions-rs/cargo@v1.0.3 - with: - command: fmt - args: --all -- --check - - - if: "failure()" - uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 - - machete: - name: "Check unused dependencies" - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Use substrate and polkadot node binaries - uses: ./.github/workflows/actions/use-nodes - - - name: Install Rust stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - name: Rust Cache - uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - - name: Install cargo-machete - run: cargo install cargo-machete - - - name: Check unused dependencies - uses: actions-rs/cargo@v1.0.3 - with: - command: machete - - - if: "failure()" - uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 - - clippy: - name: Cargo clippy - runs-on: ubuntu-latest - needs: [fmt, machete] - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Use substrate and polkadot node binaries - uses: ./.github/workflows/actions/use-nodes - - - name: Install Rust stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - components: clippy - override: true - - - name: Rust Cache - uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - - name: Run clippy - run: | - cargo clippy --all-targets --features unstable-light-client -- -D warnings - cargo clippy -p subxt-lightclient --no-default-features --features web -- -D warnings - cargo clippy -p subxt --no-default-features --features web -- -D warnings - cargo clippy -p subxt --no-default-features --features web,unstable-light-client -- -D warnings - - - if: "failure()" - uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 - - wasm_clippy: - name: Cargo clippy (WASM) - runs-on: ubuntu-latest - needs: [fmt, machete] - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Use substrate and polkadot node binaries - uses: ./.github/workflows/actions/use-nodes - - - name: Install Rust stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - target: wasm32-unknown-unknown - override: true - - - name: Rust Cache - uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - - name: Run clippy - uses: actions-rs/cargo@v1 - with: - command: clippy - args: -p subxt --no-default-features --features web,unstable-light-client,jsonrpsee --target wasm32-unknown-unknown -- -D warnings - - - if: "failure()" - uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 - - check: - name: Cargo check - runs-on: ubuntu-latest - needs: [fmt, machete] - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Use substrate and polkadot node binaries - uses: ./.github/workflows/actions/use-nodes - - - name: Install Rust stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - name: Rust Cache - uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - - name: Install cargo-hack - uses: baptiste0928/cargo-install@v3 - with: - crate: cargo-hack - version: 0.5 - - # A basic check over all targets together. This may lead to features being combined etc, - # and doesn't test combinations of different features. - - name: Cargo check all targets. - run: cargo check --all-targets - - # Next, check subxt features. - # - `native` feature must always be enabled - # - `web` feature is always ignored. - # - This means, don't check --no-default-features and don't try enabling --all-features; both will fail - - name: Cargo hack; check each subxt feature - run: cargo hack -p subxt --each-feature check --exclude-no-default-features --exclude-all-features --exclude-features web --features native - - # Subxt-signer has the "subxt" features enabled in the "check all targets" test. Run it on its own to - # check it without. We can't enable subxt or web features here, so no cargo hack. - - name: Cargo check subxt-signer - run: | - cargo check -p subxt-signer - cargo check -p subxt-signer --no-default-features --features sr25519,native - cargo check -p subxt-signer --no-default-features --features ecdsa,native - - # We can't enable web features here, so no cargo hack. - - name: Cargo check subxt-lightclient - run: cargo check -p subxt-lightclient - - # Next, check each other package in isolation. - - name: Cargo hack; check each feature/crate on its own - run: cargo hack --exclude subxt --exclude subxt-signer --exclude subxt-lightclient --exclude-all-features --each-feature check --workspace - - # Check the parachain-example code, which isn't a part of the workspace so is otherwise ignored. - - name: Cargo check parachain-example - run: cargo check --manifest-path examples/parachain-example/Cargo.toml - - - if: "failure()" - uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 - - wasm_check: - name: Cargo check (WASM) - runs-on: ubuntu-latest - needs: [fmt, machete] - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Install Rust stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - target: wasm32-unknown-unknown - override: true - - - name: Rust Cache - uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - # Check WASM examples, which aren't a part of the workspace and so are otherwise missed: - - name: Cargo check WASM examples - run: | - cargo check --manifest-path examples/wasm-example/Cargo.toml --target wasm32-unknown-unknown - - - if: "failure()" - uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 - - docs: - name: Check documentation and run doc tests - runs-on: ubuntu-latest - needs: [fmt, machete] - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Use substrate and polkadot node binaries - uses: ./.github/workflows/actions/use-nodes - - - name: Install Rust stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - name: Rust Cache - uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - - name: Check internal documentation links - run: RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc -vv --workspace --no-deps --document-private-items - - - name: Run cargo test on documentation - uses: actions-rs/cargo@v1.0.3 - with: - command: test - args: --doc - - - if: "failure()" - uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 - - tests: - name: "Test (Native)" - runs-on: ubuntu-latest-16-cores - needs: [clippy, wasm_clippy, check, wasm_check, docs] - timeout-minutes: 30 - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Use substrate and polkadot node binaries - uses: ./.github/workflows/actions/use-nodes - - - name: Install Rust stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - name: Rust Cache - uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - - name: Install cargo-nextest - run: cargo install cargo-nextest - - - name: Run tests - uses: actions-rs/cargo@v1.0.3 - with: - command: nextest - args: run --workspace - - - if: "failure()" - uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 - - unstable_backend_tests: - name: "Test (Unstable Backend)" - runs-on: ubuntu-latest-16-cores - needs: [clippy, wasm_clippy, check, wasm_check, docs] - timeout-minutes: 30 - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Use substrate and polkadot node binaries - uses: ./.github/workflows/actions/use-nodes - - - name: Install Rust stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - name: Rust Cache - uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - - name: Install cargo-nextest - run: cargo install cargo-nextest - - - name: Run tests - uses: actions-rs/cargo@v1.0.3 - with: - command: nextest - args: run --workspace --features unstable-backend-client - - - if: "failure()" - uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 - - light_client_tests: - name: "Test (Light Client)" - runs-on: ubuntu-latest - needs: [clippy, wasm_clippy, check, wasm_check, docs] - timeout-minutes: 15 - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Use substrate and polkadot node binaries - uses: ./.github/workflows/actions/use-nodes - - - name: Install Rust stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - name: Rust Cache - uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - - name: Run tests - uses: actions-rs/cargo@v1.0.3 - with: - command: test - args: --release --package integration-tests --features unstable-light-client - - - if: "failure()" - uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + # fmt: + # name: Cargo fmt + # runs-on: ubuntu-latest + # steps: + # - name: Checkout sources + # uses: actions/checkout@v4 + + # - name: Install Rust nightly toolchain + # uses: actions-rs/toolchain@v1 + # with: + # profile: minimal + # toolchain: stable + # override: true + # components: rustfmt + + # - name: Rust Cache + # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + # - name: Cargo fmt + # uses: actions-rs/cargo@v1.0.3 + # with: + # command: fmt + # args: --all -- --check + + # - if: "failure()" + # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + + # machete: + # name: "Check unused dependencies" + # runs-on: ubuntu-latest + # steps: + # - name: Checkout sources + # uses: actions/checkout@v4 + + # - name: Use substrate and polkadot node binaries + # uses: ./.github/workflows/actions/use-nodes + + # - name: Install Rust stable toolchain + # uses: actions-rs/toolchain@v1 + # with: + # profile: minimal + # toolchain: stable + # override: true + + # - name: Rust Cache + # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + # - name: Install cargo-machete + # run: cargo install cargo-machete + + # - name: Check unused dependencies + # uses: actions-rs/cargo@v1.0.3 + # with: + # command: machete + + # - if: "failure()" + # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + + # clippy: + # name: Cargo clippy + # runs-on: ubuntu-latest + # needs: [fmt, machete] + # steps: + # - name: Checkout sources + # uses: actions/checkout@v4 + + # - name: Use substrate and polkadot node binaries + # uses: ./.github/workflows/actions/use-nodes + + # - name: Install Rust stable toolchain + # uses: actions-rs/toolchain@v1 + # with: + # profile: minimal + # toolchain: stable + # components: clippy + # override: true + + # - name: Rust Cache + # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + # - name: Run clippy + # run: | + # cargo clippy --all-targets --features unstable-light-client -- -D warnings + # cargo clippy -p subxt-lightclient --no-default-features --features web -- -D warnings + # cargo clippy -p subxt --no-default-features --features web -- -D warnings + # cargo clippy -p subxt --no-default-features --features web,unstable-light-client -- -D warnings + + # - if: "failure()" + # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + + # wasm_clippy: + # name: Cargo clippy (WASM) + # runs-on: ubuntu-latest + # needs: [fmt, machete] + # steps: + # - name: Checkout sources + # uses: actions/checkout@v4 + + # - name: Use substrate and polkadot node binaries + # uses: ./.github/workflows/actions/use-nodes + + # - name: Install Rust stable toolchain + # uses: actions-rs/toolchain@v1 + # with: + # profile: minimal + # toolchain: stable + # target: wasm32-unknown-unknown + # override: true + + # - name: Rust Cache + # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + # - name: Run clippy + # uses: actions-rs/cargo@v1 + # with: + # command: clippy + # args: -p subxt --no-default-features --features web,unstable-light-client,jsonrpsee --target wasm32-unknown-unknown -- -D warnings + + # - if: "failure()" + # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + + # check: + # name: Cargo check + # runs-on: ubuntu-latest + # needs: [fmt, machete] + # steps: + # - name: Checkout sources + # uses: actions/checkout@v4 + + # - name: Use substrate and polkadot node binaries + # uses: ./.github/workflows/actions/use-nodes + + # - name: Install Rust stable toolchain + # uses: actions-rs/toolchain@v1 + # with: + # profile: minimal + # toolchain: stable + # override: true + + # - name: Rust Cache + # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + # - name: Install cargo-hack + # uses: baptiste0928/cargo-install@v3 + # with: + # crate: cargo-hack + # version: 0.5 + + # # A basic check over all targets together. This may lead to features being combined etc, + # # and doesn't test combinations of different features. + # - name: Cargo check all targets. + # run: cargo check --all-targets + + # # Next, check subxt features. + # # - `native` feature must always be enabled + # # - `web` feature is always ignored. + # # - This means, don't check --no-default-features and don't try enabling --all-features; both will fail + # - name: Cargo hack; check each subxt feature + # run: cargo hack -p subxt --each-feature check --exclude-no-default-features --exclude-all-features --exclude-features web --features native + + # # Subxt-signer has the "subxt" features enabled in the "check all targets" test. Run it on its own to + # # check it without. We can't enable subxt or web features here, so no cargo hack. + # - name: Cargo check subxt-signer + # run: | + # cargo check -p subxt-signer + # cargo check -p subxt-signer --no-default-features --features sr25519,native + # cargo check -p subxt-signer --no-default-features --features ecdsa,native + + # # We can't enable web features here, so no cargo hack. + # - name: Cargo check subxt-lightclient + # run: cargo check -p subxt-lightclient + + # # Next, check each other package in isolation. + # - name: Cargo hack; check each feature/crate on its own + # run: cargo hack --exclude subxt --exclude subxt-signer --exclude subxt-lightclient --exclude-all-features --each-feature check --workspace + + # # Check the parachain-example code, which isn't a part of the workspace so is otherwise ignored. + # - name: Cargo check parachain-example + # run: cargo check --manifest-path examples/parachain-example/Cargo.toml + + # - if: "failure()" + # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + + # wasm_check: + # name: Cargo check (WASM) + # runs-on: ubuntu-latest + # needs: [fmt, machete] + # steps: + # - name: Checkout sources + # uses: actions/checkout@v4 + + # - name: Install Rust stable toolchain + # uses: actions-rs/toolchain@v1 + # with: + # profile: minimal + # toolchain: stable + # target: wasm32-unknown-unknown + # override: true + + # - name: Rust Cache + # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + # # Check WASM examples, which aren't a part of the workspace and so are otherwise missed: + # - name: Cargo check WASM examples + # run: | + # cargo check --manifest-path examples/wasm-example/Cargo.toml --target wasm32-unknown-unknown + + # - if: "failure()" + # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + + # docs: + # name: Check documentation and run doc tests + # runs-on: ubuntu-latest + # needs: [fmt, machete] + # steps: + # - name: Checkout sources + # uses: actions/checkout@v4 + + # - name: Use substrate and polkadot node binaries + # uses: ./.github/workflows/actions/use-nodes + + # - name: Install Rust stable toolchain + # uses: actions-rs/toolchain@v1 + # with: + # profile: minimal + # toolchain: stable + # override: true + + # - name: Rust Cache + # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + # - name: Check internal documentation links + # run: RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc -vv --workspace --no-deps --document-private-items + + # - name: Run cargo test on documentation + # uses: actions-rs/cargo@v1.0.3 + # with: + # command: test + # args: --doc + + # - if: "failure()" + # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + + # tests: + # name: "Test (Native)" + # runs-on: ubuntu-latest-16-cores + # needs: [clippy, wasm_clippy, check, wasm_check, docs] + # timeout-minutes: 30 + # steps: + # - name: Checkout sources + # uses: actions/checkout@v4 + + # - name: Use substrate and polkadot node binaries + # uses: ./.github/workflows/actions/use-nodes + + # - name: Install Rust stable toolchain + # uses: actions-rs/toolchain@v1 + # with: + # profile: minimal + # toolchain: stable + # override: true + + # - name: Rust Cache + # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + # - name: Install cargo-nextest + # run: cargo install cargo-nextest + + # - name: Run tests + # uses: actions-rs/cargo@v1.0.3 + # with: + # command: nextest + # args: run --workspace + + # - if: "failure()" + # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + + # unstable_backend_tests: + # name: "Test (Unstable Backend)" + # runs-on: ubuntu-latest-16-cores + # needs: [clippy, wasm_clippy, check, wasm_check, docs] + # timeout-minutes: 30 + # steps: + # - name: Checkout sources + # uses: actions/checkout@v4 + + # - name: Use substrate and polkadot node binaries + # uses: ./.github/workflows/actions/use-nodes + + # - name: Install Rust stable toolchain + # uses: actions-rs/toolchain@v1 + # with: + # profile: minimal + # toolchain: stable + # override: true + + # - name: Rust Cache + # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + # - name: Install cargo-nextest + # run: cargo install cargo-nextest + + # - name: Run tests + # uses: actions-rs/cargo@v1.0.3 + # with: + # command: nextest + # args: run --workspace --features unstable-backend-client + + # - if: "failure()" + # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + + # light_client_tests: + # name: "Test (Light Client)" + # runs-on: ubuntu-latest + # needs: [clippy, wasm_clippy, check, wasm_check, docs] + # timeout-minutes: 15 + # steps: + # - name: Checkout sources + # uses: actions/checkout@v4 + + # - name: Use substrate and polkadot node binaries + # uses: ./.github/workflows/actions/use-nodes + + # - name: Install Rust stable toolchain + # uses: actions-rs/toolchain@v1 + # with: + # profile: minimal + # toolchain: stable + # override: true + + # - name: Rust Cache + # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + # - name: Run tests + # uses: actions-rs/cargo@v1.0.3 + # with: + # command: test + # args: --release --package integration-tests --features unstable-light-client + + # - if: "failure()" + # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 light_client_long_running_tests: name: "Test (Light Client Long Running)" runs-on: ubuntu-latest-16-cores - needs: [clippy, wasm_clippy, check, wasm_check, docs] + # needs: [clippy, wasm_clippy, check, wasm_check, docs] timeout-minutes: 60 steps: - name: Checkout sources @@ -395,92 +395,92 @@ jobs: - if: "failure()" uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 - wasm_tests: - name: Test (WASM) - runs-on: ubuntu-latest - needs: [clippy, wasm_clippy, check, wasm_check, docs] - timeout-minutes: 30 - env: - # Set timeout for wasm tests to be much bigger than the default 20 secs. - WASM_BINDGEN_TEST_TIMEOUT: 300 - - steps: - - uses: actions/checkout@v4 - - - name: Install wasm-pack - run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh - - - name: Install firefox - uses: browser-actions/setup-firefox@latest - - - name: Install chrome - uses: browser-actions/setup-chrome@latest - - - name: Rust Cache - uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - - name: Use substrate and polkadot node binaries - uses: ./.github/workflows/actions/use-nodes - - - name: Run subxt WASM tests - run: | - # `listen-addr` is used to configure p2p to accept websocket connections instead of TCP. - # `node-key` provides a deterministic p2p address. - substrate-node --dev --node-key 0000000000000000000000000000000000000000000000000000000000000001 --listen-addr /ip4/0.0.0.0/tcp/30333/ws > /dev/null 2>&1 & - wasm-pack test --headless --firefox - wasm-pack test --headless --chrome - pkill substrate-node - working-directory: testing/wasm-rpc-tests - - - name: Run subxt-lightclient WASM tests - run: | - # `listen-addr` is used to configure p2p to accept websocket connections instead of TCP. - # `node-key` provides a deterministic p2p address. - substrate-node --dev --node-key 0000000000000000000000000000000000000000000000000000000000000001 --listen-addr /ip4/0.0.0.0/tcp/30333/ws > /dev/null 2>&1 & - wasm-pack test --headless --firefox - wasm-pack test --headless --chrome - pkill substrate-node - working-directory: testing/wasm-lightclient-tests - - - name: Run subxt-signer WASM tests - run: | - wasm-pack test --headless --firefox - wasm-pack test --headless --chrome - working-directory: signer/wasm-tests - - - if: "failure()" - uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 - - no-std-tests: - name: "Test (no_std)" - runs-on: ubuntu-latest - needs: [machete, docs] - timeout-minutes: 30 - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - # Note: needs nighly toolchain because otherwise we cannot define custom lang-items. - - name: Install Rust nightly toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true - target: thumbv7em-none-eabi - - - name: Install the gcc-arm-none-eabi linker - run: sudo apt install gcc-arm-none-eabi - - - name: Rust Cache - uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - # Note: We currently do not have a way to run real tests in a `no_std` environment. - # We can only make sure that they compile to ARM thumb ISA. - # Running the binary and inspecting the output would require an actual machine with matching ISA or some sort of emulator. - - name: Compile `no-std-tests` crate to `thumbv7em-none-eabi` target. - run: cargo build --target thumbv7em-none-eabi - working-directory: testing/no-std-tests - - - if: "failure()" - uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + # wasm_tests: + # name: Test (WASM) + # runs-on: ubuntu-latest + # needs: [clippy, wasm_clippy, check, wasm_check, docs] + # timeout-minutes: 30 + # env: + # # Set timeout for wasm tests to be much bigger than the default 20 secs. + # WASM_BINDGEN_TEST_TIMEOUT: 300 + + # steps: + # - uses: actions/checkout@v4 + + # - name: Install wasm-pack + # run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + + # - name: Install firefox + # uses: browser-actions/setup-firefox@latest + + # - name: Install chrome + # uses: browser-actions/setup-chrome@latest + + # - name: Rust Cache + # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + # - name: Use substrate and polkadot node binaries + # uses: ./.github/workflows/actions/use-nodes + + # - name: Run subxt WASM tests + # run: | + # # `listen-addr` is used to configure p2p to accept websocket connections instead of TCP. + # # `node-key` provides a deterministic p2p address. + # substrate-node --dev --node-key 0000000000000000000000000000000000000000000000000000000000000001 --listen-addr /ip4/0.0.0.0/tcp/30333/ws > /dev/null 2>&1 & + # wasm-pack test --headless --firefox + # wasm-pack test --headless --chrome + # pkill substrate-node + # working-directory: testing/wasm-rpc-tests + + # - name: Run subxt-lightclient WASM tests + # run: | + # # `listen-addr` is used to configure p2p to accept websocket connections instead of TCP. + # # `node-key` provides a deterministic p2p address. + # substrate-node --dev --node-key 0000000000000000000000000000000000000000000000000000000000000001 --listen-addr /ip4/0.0.0.0/tcp/30333/ws > /dev/null 2>&1 & + # wasm-pack test --headless --firefox + # wasm-pack test --headless --chrome + # pkill substrate-node + # working-directory: testing/wasm-lightclient-tests + + # - name: Run subxt-signer WASM tests + # run: | + # wasm-pack test --headless --firefox + # wasm-pack test --headless --chrome + # working-directory: signer/wasm-tests + + # - if: "failure()" + # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + + # no-std-tests: + # name: "Test (no_std)" + # runs-on: ubuntu-latest + # needs: [machete, docs] + # timeout-minutes: 30 + # steps: + # - name: Checkout sources + # uses: actions/checkout@v4 + + # # Note: needs nighly toolchain because otherwise we cannot define custom lang-items. + # - name: Install Rust nightly toolchain + # uses: actions-rs/toolchain@v1 + # with: + # profile: minimal + # toolchain: nightly + # override: true + # target: thumbv7em-none-eabi + + # - name: Install the gcc-arm-none-eabi linker + # run: sudo apt install gcc-arm-none-eabi + + # - name: Rust Cache + # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + # # Note: We currently do not have a way to run real tests in a `no_std` environment. + # # We can only make sure that they compile to ARM thumb ISA. + # # Running the binary and inspecting the output would require an actual machine with matching ISA or some sort of emulator. + # - name: Compile `no-std-tests` crate to `thumbv7em-none-eabi` target. + # run: cargo build --target thumbv7em-none-eabi + # working-directory: testing/no-std-tests + + # - if: "failure()" + # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 From 0248343a2b745c007b5e4782fdb92e3f65a8f52f Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 1 Mar 2024 11:25:02 +0200 Subject: [PATCH 10/42] testing: Retry on Tx::Dropped for lightclinet only Signed-off-by: Alexandru Vasile --- .../src/full_client/blocks/mod.rs | 7 +- .../src/full_client/client/mod.rs | 23 ++--- .../src/full_client/frame/balances.rs | 56 +++++++------ .../src/full_client/frame/contracts.rs | 23 +++-- .../src/full_client/frame/staking.rs | 84 +++++++++---------- .../src/full_client/frame/sudo.rs | 20 +++-- .../src/full_client/frame/system.rs | 11 +-- .../src/full_client/runtime_api/mod.rs | 10 +-- .../src/full_client/storage/mod.rs | 5 ++ testing/integration-tests/src/utils/mod.rs | 2 + .../integration-tests/src/utils/tx_retries.rs | 40 +++++++++ 11 files changed, 164 insertions(+), 117 deletions(-) create mode 100644 testing/integration-tests/src/utils/tx_retries.rs diff --git a/testing/integration-tests/src/full_client/blocks/mod.rs b/testing/integration-tests/src/full_client/blocks/mod.rs index f513d9a738..7df2cabfdd 100644 --- a/testing/integration-tests/src/full_client/blocks/mod.rs +++ b/testing/integration-tests/src/full_client/blocks/mod.rs @@ -2,13 +2,15 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::{test_context, utils::node_runtime}; +use crate::test_context; use codec::{Compact, Encode}; use futures::StreamExt; #[cfg(lightclient)] use subxt::client::OnlineClientT; +#[cfg(fullclient)] +use crate::utils::node_runtime; #[cfg(fullclient)] use subxt::config::signed_extensions::{ChargeAssetTxPayment, CheckMortality, CheckNonce}; #[cfg(fullclient)] @@ -17,9 +19,10 @@ use subxt::config::DefaultExtrinsicParamsBuilder; use subxt::config::SubstrateConfig; #[cfg(fullclient)] use subxt::utils::Era; +#[cfg(fullclient)] +use subxt_signer::sr25519::dev; use subxt_metadata::Metadata; -use subxt_signer::sr25519::dev; #[cfg(fullclient)] #[tokio::test] diff --git a/testing/integration-tests/src/full_client/client/mod.rs b/testing/integration-tests/src/full_client/client/mod.rs index 74365166f8..49c049bf48 100644 --- a/testing/integration-tests/src/full_client/client/mod.rs +++ b/testing/integration-tests/src/full_client/client/mod.rs @@ -3,7 +3,7 @@ // see LICENSE for license details. use crate::{ - test_context, + submit_tx_wait_for_finalized_success, test_context, utils::{node_runtime, wait_for_blocks}, }; use codec::{Decode, Encode}; @@ -137,11 +137,7 @@ async fn transaction_validation() { .await .expect("validation failed"); - signed_extrinsic - .submit_and_watch() - .await - .unwrap() - .wait_for_finalized_success() + submit_tx_wait_for_finalized_success(&signed_extrinsic) .await .unwrap(); } @@ -204,11 +200,7 @@ async fn external_signing() { .sign_with_address_and_signature(&alice.public_key().into(), &signature.into()); // And now submit it. - extrinsic - .submit_and_watch() - .await - .unwrap() - .wait_for_finalized_success() + submit_tx_wait_for_finalized_success(&extrinsic) .await .unwrap(); } @@ -258,12 +250,13 @@ async fn decode_a_module_error() { // "unknown" module error from the assets pallet. let freeze_unknown_asset = node_runtime::tx().assets().freeze(1, alice_addr); - let err = api + let signed_extrinsic = api .tx() - .sign_and_submit_then_watch_default(&freeze_unknown_asset, &alice) + .create_signed(&freeze_unknown_asset, &alice, Default::default()) .await - .unwrap() - .wait_for_finalized_success() + .unwrap(); + + let err = submit_tx_wait_for_finalized_success(&signed_extrinsic) .await .expect_err("an 'unknown asset' error"); diff --git a/testing/integration-tests/src/full_client/frame/balances.rs b/testing/integration-tests/src/full_client/frame/balances.rs index 0fb1b02cac..73ea7b8261 100644 --- a/testing/integration-tests/src/full_client/frame/balances.rs +++ b/testing/integration-tests/src/full_client/frame/balances.rs @@ -4,7 +4,7 @@ use crate::{ node_runtime::{self, balances, runtime_types, system}, - test_context, + submit_tx_wait_for_finalized_success, test_context, }; use codec::Decode; use subxt::{ @@ -48,12 +48,12 @@ async fn tx_basic_transfer() -> Result<(), subxt::Error> { .balances() .transfer_allow_death(bob_address, 10_000); - let events = api + let signed_extrinsic = api .tx() - .sign_and_submit_then_watch_default(&tx, &alice) - .await? - .wait_for_finalized_success() + .create_signed(&tx, &alice, Default::default()) .await?; + let events = submit_tx_wait_for_finalized_success(&signed_extrinsic).await?; + let event = events .find_first::() .expect("Failed to decode balances::events::Transfer") @@ -235,11 +235,12 @@ async fn multiple_sequential_transfers_work() -> Result<(), subxt::Error> { .balances() .transfer_allow_death(bob_address.clone(), 10_000); for _ in 0..3 { - api.tx() - .sign_and_submit_then_watch_default(&tx, &alice) - .await? - .wait_for_finalized_success() + let signed_extrinsic = api + .tx() + .create_signed(&tx, &alice, Default::default()) .await?; + + submit_tx_wait_for_finalized_success(&signed_extrinsic).await?; } let bob_post = api @@ -282,10 +283,11 @@ async fn storage_balance_lock() -> Result<(), subxt::Error> { runtime_types::pallet_staking::RewardDestination::Stash, ); - api.tx() - .sign_and_submit_then_watch_default(&tx, &bob_signer) - .await? - .wait_for_finalized_success() + let signed_extrinsic = api + .tx() + .create_signed(&tx, &bob_signer, Default::default()) + .await?; + submit_tx_wait_for_finalized_success(&signed_extrinsic) .await? .find_first::()? .expect("No ExtrinsicSuccess Event found"); @@ -327,23 +329,24 @@ async fn transfer_error() { .balances() .transfer_allow_death(alice_addr, 100_000_000_000_000_000); - api.tx() - .sign_and_submit_then_watch_default(&to_bob_tx, &alice) + let signed_extrinsic = api + .tx() + .create_signed(&to_bob_tx, &alice, Default::default()) .await - .unwrap() - .wait_for_finalized_success() + .unwrap(); + submit_tx_wait_for_finalized_success(&signed_extrinsic) .await .unwrap(); // When we try giving all of the funds back, Bob doesn't have // anything left to pay transfer fees, so we hit an error. - let res = api + let signed_extrinsic = api .tx() - .sign_and_submit_then_watch_default(&to_alice_tx, &bob) + .create_signed(&to_alice_tx, &bob, Default::default()) .await - .unwrap() - .wait_for_finalized_success() - .await; + .unwrap(); + + let res = submit_tx_wait_for_finalized_success(&signed_extrinsic).await; assert!( matches!( @@ -367,12 +370,13 @@ async fn transfer_implicit_subscription() { .balances() .transfer_allow_death(bob.clone().into(), 10_000); - let event = api + let signed_extrinsic = api .tx() - .sign_and_submit_then_watch_default(&to_bob_tx, &alice) + .create_signed(&to_bob_tx, &alice, Default::default()) .await - .unwrap() - .wait_for_finalized_success() + .unwrap(); + + let event = submit_tx_wait_for_finalized_success(&signed_extrinsic) .await .unwrap() .find_first::() diff --git a/testing/integration-tests/src/full_client/frame/contracts.rs b/testing/integration-tests/src/full_client/frame/contracts.rs index 60039be1d7..c6ee58374e 100644 --- a/testing/integration-tests/src/full_client/frame/contracts.rs +++ b/testing/integration-tests/src/full_client/frame/contracts.rs @@ -9,7 +9,7 @@ use crate::{ runtime_types::{pallet_contracts::wasm::Determinism, sp_weights::weight_v2::Weight}, system, }, - test_context, TestClient, TestConfig, TestContext, + submit_tx_wait_for_finalized_success, test_context, TestClient, TestConfig, TestContext, }; use subxt::ext::futures::StreamExt; use subxt::{tx::TxProgress, utils::MultiAddress, Config, Error}; @@ -54,13 +54,12 @@ impl ContractsTestContext { .contracts() .upload_code(code, None, Determinism::Enforced); - let events = self + let signed_extrinsic = self .client() .tx() - .sign_and_submit_then_watch_default(&upload_tx, &self.signer) - .await? - .wait_for_finalized_success() + .create_signed(&upload_tx, &self.signer, Default::default()) .await?; + let events = submit_tx_wait_for_finalized_success(&signed_extrinsic).await?; let code_stored = events .find_first::()? @@ -84,13 +83,12 @@ impl ContractsTestContext { vec![], // salt ); - let events = self + let signed_extrinsic = self .client() .tx() - .sign_and_submit_then_watch_default(&instantiate_tx, &self.signer) - .await? - .wait_for_finalized_success() + .create_signed(&instantiate_tx, &self.signer, Default::default()) .await?; + let events = submit_tx_wait_for_finalized_success(&signed_extrinsic).await?; let code_stored = events .find_first::()? @@ -127,13 +125,12 @@ impl ContractsTestContext { salt, ); - let result = self + let signed_extrinsic = self .client() .tx() - .sign_and_submit_then_watch_default(&instantiate_tx, &self.signer) - .await? - .wait_for_finalized_success() + .create_signed(&instantiate_tx, &self.signer, Default::default()) .await?; + let result = submit_tx_wait_for_finalized_success(&signed_extrinsic).await?; tracing::info!("Instantiate result: {:?}", result); let instantiated = result diff --git a/testing/integration-tests/src/full_client/frame/staking.rs b/testing/integration-tests/src/full_client/frame/staking.rs index 7d285faa8a..91eba84f43 100644 --- a/testing/integration-tests/src/full_client/frame/staking.rs +++ b/testing/integration-tests/src/full_client/frame/staking.rs @@ -11,7 +11,7 @@ use crate::{ }, staking, }, - test_context, + submit_tx_wait_for_finalized_success, test_context, }; use assert_matches::assert_matches; use subxt::error::{DispatchError, Error}; @@ -45,11 +45,12 @@ async fn validate_with_stash_account() { .staking() .validate(default_validator_prefs()); - api.tx() - .sign_and_submit_then_watch_default(&tx, &alice_stash) + let signed_extrinsic = api + .tx() + .create_signed(&tx, &alice_stash, Default::default()) .await - .unwrap() - .wait_for_finalized_success() + .unwrap(); + submit_tx_wait_for_finalized_success(&signed_extrinsic) .await .expect("should be successful"); } @@ -65,12 +66,12 @@ async fn validate_not_possible_for_controller_account() -> Result<(), Error> { .staking() .validate(default_validator_prefs()); - let announce_validator = api + let signed_extrinsic = api .tx() - .sign_and_submit_then_watch_default(&tx, &alice) - .await? - .wait_for_finalized_success() - .await; + .create_signed(&tx, &alice, Default::default()) + .await?; + let announce_validator = submit_tx_wait_for_finalized_success(&signed_extrinsic).await; + assert_matches!(announce_validator, Err(Error::Runtime(DispatchError::Module(err))) => { let details = err.details().unwrap(); assert_eq!(details.pallet.name(), "Staking"); @@ -91,11 +92,12 @@ async fn nominate_with_stash_account() { .staking() .nominate(vec![bob.public_key().to_address()]); - api.tx() - .sign_and_submit_then_watch_default(&tx, &alice_stash) + let signed_extrinsic = api + .tx() + .create_signed(&tx, &alice_stash, Default::default()) .await - .unwrap() - .wait_for_finalized_success() + .unwrap(); + submit_tx_wait_for_finalized_success(&signed_extrinsic) .await .expect("should be successful"); } @@ -112,13 +114,12 @@ async fn nominate_not_possible_for_controller_account() -> Result<(), Error> { .staking() .nominate(vec![bob.public_key().to_address()]); - let nomination = api + let signed_extrinsic = api .tx() - .sign_and_submit_then_watch_default(&tx, &alice) + .create_signed(&tx, &alice, Default::default()) .await - .unwrap() - .wait_for_finalized_success() - .await; + .unwrap(); + let nomination = submit_tx_wait_for_finalized_success(&signed_extrinsic).await; assert_matches!(nomination, Err(Error::Runtime(DispatchError::Module(err))) => { let details = err.details().unwrap(); @@ -141,11 +142,12 @@ async fn chill_works_for_stash_only() -> Result<(), Error> { let nominate_tx = node_runtime::tx() .staking() .nominate(vec![bob_stash.public_key().to_address()]); - api.tx() - .sign_and_submit_then_watch_default(&nominate_tx, &alice_stash) - .await? - .wait_for_finalized_success() + + let signed_extrinsic = api + .tx() + .create_signed(&nominate_tx, &alice_stash, Default::default()) .await?; + submit_tx_wait_for_finalized_success(&signed_extrinsic).await?; let ledger_addr = node_runtime::storage() .staking() @@ -161,12 +163,11 @@ async fn chill_works_for_stash_only() -> Result<(), Error> { let chill_tx = node_runtime::tx().staking().chill(); - let chill = api + let signed_extrinsic = api .tx() - .sign_and_submit_then_watch_default(&chill_tx, &alice) - .await? - .wait_for_finalized_success() - .await; + .create_signed(&chill_tx, &alice, Default::default()) + .await?; + let chill = submit_tx_wait_for_finalized_success(&signed_extrinsic).await; assert_matches!(chill, Err(Error::Runtime(DispatchError::Module(err))) => { let details = err.details().unwrap(); @@ -174,13 +175,14 @@ async fn chill_works_for_stash_only() -> Result<(), Error> { assert_eq!(&details.variant.name, "NotController"); }); - let is_chilled = api + let signed_extrinsic = api .tx() - .sign_and_submit_then_watch_default(&chill_tx, &alice_stash) - .await? - .wait_for_finalized_success() + .create_signed(&chill_tx, &alice_stash, Default::default()) + .await?; + let is_chilled = submit_tx_wait_for_finalized_success(&signed_extrinsic) .await? .has::()?; + assert!(is_chilled); Ok(()) @@ -197,21 +199,19 @@ async fn tx_bond() -> Result<(), Error> { .staking() .bond(100_000_000_000_000, RewardDestination::Stash); - let bond = api + let signed_extrinsic = api .tx() - .sign_and_submit_then_watch_default(&bond_tx, &alice) - .await? - .wait_for_finalized_success() - .await; + .create_signed(&bond_tx, &alice, Default::default()) + .await?; + let bond = submit_tx_wait_for_finalized_success(&signed_extrinsic).await; assert!(bond.is_ok()); - let bond_again = api + let signed_extrinsic = api .tx() - .sign_and_submit_then_watch_default(&bond_tx, &alice) - .await? - .wait_for_finalized_success() - .await; + .create_signed(&bond_tx, &alice, Default::default()) + .await?; + let bond_again = submit_tx_wait_for_finalized_success(&signed_extrinsic).await; assert_matches!(bond_again, Err(Error::Runtime(DispatchError::Module(err))) => { let details = err.details().unwrap(); diff --git a/testing/integration-tests/src/full_client/frame/sudo.rs b/testing/integration-tests/src/full_client/frame/sudo.rs index fad808d563..4d34ee862d 100644 --- a/testing/integration-tests/src/full_client/frame/sudo.rs +++ b/testing/integration-tests/src/full_client/frame/sudo.rs @@ -8,7 +8,7 @@ use crate::{ runtime_types::{self, sp_weights::weight_v2::Weight}, sudo, }, - test_context, + submit_tx_wait_for_finalized_success, test_context, }; use subxt_signer::sr25519::dev; @@ -29,11 +29,12 @@ async fn test_sudo() -> Result<(), subxt::Error> { }); let tx = node_runtime::tx().sudo().sudo(call); - let found_event = api + let signed_extrinsic = api .tx() - .sign_and_submit_then_watch_default(&tx, &alice) - .await? - .wait_for_finalized_success() + .create_signed(&tx, &alice, Default::default()) + .await?; + + let found_event = submit_tx_wait_for_finalized_success(&signed_extrinsic) .await? .has::()?; @@ -61,11 +62,12 @@ async fn test_sudo_unchecked_weight() -> Result<(), subxt::Error> { }, ); - let found_event = api + let signed_extrinsic = api .tx() - .sign_and_submit_then_watch_default(&tx, &alice) - .await? - .wait_for_finalized_success() + .create_signed(&tx, &alice, Default::default()) + .await?; + + let found_event = submit_tx_wait_for_finalized_success(&signed_extrinsic) .await? .has::()?; diff --git a/testing/integration-tests/src/full_client/frame/system.rs b/testing/integration-tests/src/full_client/frame/system.rs index 1b3823cead..bb966b1293 100644 --- a/testing/integration-tests/src/full_client/frame/system.rs +++ b/testing/integration-tests/src/full_client/frame/system.rs @@ -4,7 +4,7 @@ use crate::{ node_runtime::{self, system}, - test_context, + submit_tx_wait_for_finalized_success, test_context, }; use assert_matches::assert_matches; use subxt_signer::sr25519::dev; @@ -42,11 +42,12 @@ async fn tx_remark_with_event() -> Result<(), subxt::Error> { .system() .remark_with_event(b"remarkable".to_vec()); - let found_event = api + let signed_extrinsic = api .tx() - .sign_and_submit_then_watch_default(&tx, &alice) - .await? - .wait_for_finalized_success() + .create_signed(&tx, &alice, Default::default()) + .await?; + + let found_event = submit_tx_wait_for_finalized_success(&signed_extrinsic) .await? .has::()?; diff --git a/testing/integration-tests/src/full_client/runtime_api/mod.rs b/testing/integration-tests/src/full_client/runtime_api/mod.rs index 2a637f9aff..290c3b1534 100644 --- a/testing/integration-tests/src/full_client/runtime_api/mod.rs +++ b/testing/integration-tests/src/full_client/runtime_api/mod.rs @@ -2,7 +2,7 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::{node_runtime, test_context}; +use crate::{node_runtime, submit_tx_wait_for_finalized_success, test_context}; use codec::Encode; use subxt::utils::AccountId32; use subxt_signer::sr25519::dev; @@ -29,11 +29,11 @@ async fn account_nonce() -> Result<(), subxt::Error> { // Do some transaction to bump the Alice nonce to 1: let remark_tx = node_runtime::tx().system().remark(vec![1, 2, 3, 4, 5]); - api.tx() - .sign_and_submit_then_watch_default(&remark_tx, &alice) - .await? - .wait_for_finalized_success() + let signed_extrinsic = api + .tx() + .create_signed(&remark_tx, &alice, Default::default()) .await?; + submit_tx_wait_for_finalized_success(&signed_extrinsic).await?; let runtime_api_call = node_runtime::apis() .account_nonce_api() diff --git a/testing/integration-tests/src/full_client/storage/mod.rs b/testing/integration-tests/src/full_client/storage/mod.rs index af5b85f3a3..7ad44b8175 100644 --- a/testing/integration-tests/src/full_client/storage/mod.rs +++ b/testing/integration-tests/src/full_client/storage/mod.rs @@ -3,7 +3,10 @@ // see LICENSE for license details. use crate::{node_runtime, test_context, utils::wait_for_blocks}; + +#[cfg(fullclient)] use subxt::utils::AccountId32; +#[cfg(fullclient)] use subxt_signer::sr25519::dev; #[tokio::test] @@ -27,6 +30,7 @@ async fn storage_plain_lookup() -> Result<(), subxt::Error> { Ok(()) } +#[cfg(fullclient)] #[tokio::test] async fn storage_map_lookup() -> Result<(), subxt::Error> { let ctx = test_context().await; @@ -60,6 +64,7 @@ async fn storage_map_lookup() -> Result<(), subxt::Error> { // Here we create a key that looks a bit like a StorageNMap key, but should in fact be // treated as a StorageKey (ie we should hash both values together with one hasher, rather // than hash both values separately, or ignore the second value). +#[cfg(fullclient)] #[tokio::test] async fn storage_n_mapish_key_is_properly_created() -> Result<(), subxt::Error> { use codec::Encode; diff --git a/testing/integration-tests/src/utils/mod.rs b/testing/integration-tests/src/utils/mod.rs index 08a3111da8..ee668886c0 100644 --- a/testing/integration-tests/src/utils/mod.rs +++ b/testing/integration-tests/src/utils/mod.rs @@ -4,8 +4,10 @@ mod context; mod node_proc; +mod tx_retries; mod wait_for_blocks; pub use context::*; pub use node_proc::TestNodeProcess; +pub use tx_retries::*; pub use wait_for_blocks::wait_for_blocks; diff --git a/testing/integration-tests/src/utils/tx_retries.rs b/testing/integration-tests/src/utils/tx_retries.rs new file mode 100644 index 0000000000..800222a455 --- /dev/null +++ b/testing/integration-tests/src/utils/tx_retries.rs @@ -0,0 +1,40 @@ +// Copyright 2019-2024 Parity Technologies (UK) Ltd. +// This file is dual-licensed as Apache-2.0 or GPL-3.0. +// see LICENSE for license details. + +use subxt::client::OnlineClientT; +use subxt::tx::SubmittableExtrinsic; +use subxt::Config; + +pub async fn submit_tx_wait_for_finalized_success( + signed_extrinsic: &SubmittableExtrinsic, +) -> Result, subxt::Error> +where + T: Config, + C: OnlineClientT, +{ + let submit = || async { + signed_extrinsic + .submit_and_watch() + .await + .unwrap() + .wait_for_finalized_success() + .await + }; + + #[cfg(lightclient)] + for _ in 0..2 { + let result = submit().await; + + match result { + Ok(tx_in_block) => return Ok(tx_in_block), + Err(subxt::Error::Transaction(subxt::error::TransactionError::Dropped(_))) => { + // Retry if the transaction was dropped. + tokio::time::sleep(std::time::Duration::from_secs(5)).await; + } + Err(other) => return Err(other), + } + } + + submit().await +} From 8400a0e81ba32234389033153907c7e545b94ab0 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 1 Mar 2024 11:44:58 +0200 Subject: [PATCH 11/42] testing: Wait for more blocks for the lightclient init Signed-off-by: Alexandru Vasile --- testing/integration-tests/src/utils/mod.rs | 2 +- .../integration-tests/src/utils/node_proc.rs | 5 ++++- .../src/utils/wait_for_blocks.rs | 17 +++++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/testing/integration-tests/src/utils/mod.rs b/testing/integration-tests/src/utils/mod.rs index ee668886c0..dc5215feba 100644 --- a/testing/integration-tests/src/utils/mod.rs +++ b/testing/integration-tests/src/utils/mod.rs @@ -10,4 +10,4 @@ mod wait_for_blocks; pub use context::*; pub use node_proc::TestNodeProcess; pub use tx_retries::*; -pub use wait_for_blocks::wait_for_blocks; +pub use wait_for_blocks::*; diff --git a/testing/integration-tests/src/utils/node_proc.rs b/testing/integration-tests/src/utils/node_proc.rs index 419ce50b57..0531b89102 100644 --- a/testing/integration-tests/src/utils/node_proc.rs +++ b/testing/integration-tests/src/utils/node_proc.rs @@ -241,7 +241,10 @@ async fn build_light_client(proc: &SubstrateNode) -> Result(api: &impl OnlineClientT) { + // 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( + api: &impl OnlineClientT, + number_of_blocks: usize, +) { let mut sub = api.blocks().subscribe_finalized().await.unwrap(); - // The current finalized block: - sub.next().await; - // The next one: - sub.next().await; + + for _ in 0..number_of_blocks { + sub.next().await; + } } From d6716646e267b430a970705a1a95cba7cbfdc3b0 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 29 Feb 2024 15:51:04 +0200 Subject: [PATCH 12/42] subxt: Use unstable backend for light client Signed-off-by: Alexandru Vasile --- subxt/Cargo.toml | 3 ++- subxt/src/client/light_client/mod.rs | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/subxt/Cargo.toml b/subxt/Cargo.toml index 4a18bb2b41..f06bd9dd63 100644 --- a/subxt/Cargo.toml +++ b/subxt/Cargo.toml @@ -61,7 +61,7 @@ unstable-metadata = [] # Activate this to expose the Light Client functionality. # Note that this feature is experimental and things may break or not work as expected. -unstable-light-client = ["subxt-lightclient", "tokio-stream"] +unstable-light-client = ["subxt-lightclient", "tokio-stream", "tokio"] [dependencies] async-trait = { workspace = true } @@ -117,6 +117,7 @@ getrandom = { workspace = true, optional = true } # Included if "native" feature is enabled tokio-util = { workspace = true, features = ["compat"], optional = true } +tokio = { workspace = true, features = ["macros", "time", "rt-multi-thread"], optional = true } [dev-dependencies] bitvec = { workspace = true } diff --git a/subxt/src/client/light_client/mod.rs b/subxt/src/client/light_client/mod.rs index a4b116652e..6881e6ac76 100644 --- a/subxt/src/client/light_client/mod.rs +++ b/subxt/src/client/light_client/mod.rs @@ -93,7 +93,29 @@ impl RawLightClient { ) -> Result, crate::Error> { let raw_rpc = self.raw_rpc.for_chain(chain_id); let rpc_client = RpcClient::new(raw_rpc.clone()); - let client = OnlineClient::::from_rpc_client(rpc_client).await?; + + use crate::backend::unstable::UnstableBackend; + use std::sync::Arc; + let (backend, mut driver) = UnstableBackend::builder().build(rpc_client); + let future = async move { + use futures::StreamExt; + while let Some(val) = driver.next().await { + if let Err(e) = val { + // This is a test; bail if something does wrong and try to + // ensure that the message makes it to some logs. + eprintln!("Error driving unstable backend in tests (will panic): {e}"); + panic!("Error driving unstable backend in tests: {e}"); + } + } + }; + // The unstable backend needs driving: + #[cfg(feature = "native")] + tokio::spawn(future); + #[cfg(feature = "web")] + wasm_bindgen_futures::spawn_local(future); + let client = OnlineClient::from_backend(Arc::new(backend)) + .await + .map_err(|e| format!("Cannot construct OnlineClient from backend: {e}"))?; Ok(LightClient { client, chain_id }) } From 318ba5cae28430204cdfb765fa5ca0fe31eb325f Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 1 Mar 2024 13:23:33 +0200 Subject: [PATCH 13/42] testing: Disable legacy RPC tests Signed-off-by: Alexandru Vasile --- testing/integration-tests/src/full_client/client/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testing/integration-tests/src/full_client/client/mod.rs b/testing/integration-tests/src/full_client/client/mod.rs index 49c049bf48..7abdee3d7f 100644 --- a/testing/integration-tests/src/full_client/client/mod.rs +++ b/testing/integration-tests/src/full_client/client/mod.rs @@ -21,7 +21,9 @@ use subxt::{ }; use subxt_signer::sr25519::dev; +#[cfg(fullclient)] mod legacy_rpcs; + mod unstable_rpcs; #[cfg(fullclient)] From 1a6f1af8cbc5be35ca479da1d4c90b01f0afc813 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 1 Mar 2024 13:39:18 +0200 Subject: [PATCH 14/42] testing: Disable sudo and contracts tests Signed-off-by: Alexandru Vasile --- testing/integration-tests/src/full_client/frame/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/testing/integration-tests/src/full_client/frame/mod.rs b/testing/integration-tests/src/full_client/frame/mod.rs index 083c92f4dd..2822d0d8e0 100644 --- a/testing/integration-tests/src/full_client/frame/mod.rs +++ b/testing/integration-tests/src/full_client/frame/mod.rs @@ -5,8 +5,11 @@ //! Test interactions with some built-in FRAME pallets. mod balances; -mod contracts; mod staking; -mod sudo; mod system; mod timestamp; + +#[cfg(fullclient)] +mod contracts; +#[cfg(fullclient)] +mod sudo; From 332fa729cb88c79e7dc29df5f3e00d5ccac71a07 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 1 Mar 2024 13:39:53 +0200 Subject: [PATCH 15/42] testing: Retry constructing lightclient on read-proof errors Signed-off-by: Alexandru Vasile --- .../integration-tests/src/utils/node_proc.rs | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/testing/integration-tests/src/utils/node_proc.rs b/testing/integration-tests/src/utils/node_proc.rs index 0531b89102..ae64ba8ce0 100644 --- a/testing/integration-tests/src/utils/node_proc.rs +++ b/testing/integration-tests/src/utils/node_proc.rs @@ -244,7 +244,7 @@ async fn build_light_client(proc: &SubstrateNode) -> Result(proc: &SubstrateNode) -> Result Date: Fri, 1 Mar 2024 13:40:30 +0200 Subject: [PATCH 16/42] testing: Disable tx dynamic test Signed-off-by: Alexandru Vasile --- testing/integration-tests/src/full_client/frame/balances.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/testing/integration-tests/src/full_client/frame/balances.rs b/testing/integration-tests/src/full_client/frame/balances.rs index 73ea7b8261..ea0713b1e3 100644 --- a/testing/integration-tests/src/full_client/frame/balances.rs +++ b/testing/integration-tests/src/full_client/frame/balances.rs @@ -88,6 +88,7 @@ async fn tx_basic_transfer() -> Result<(), subxt::Error> { Ok(()) } +#[cfg(fullclient)] #[tokio::test] async fn tx_dynamic_transfer() -> Result<(), subxt::Error> { use subxt::ext::scale_value::{At, Composite, Value}; From b6c98c7fa0e2c6c1f01344cb5b95c2a413903f82 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 1 Mar 2024 20:20:14 +0200 Subject: [PATCH 17/42] proc-macro: Timeout for tests Signed-off-by: Alexandru Vasile --- Cargo.lock | 10 +++ Cargo.toml | 1 + testing/integration-tests/Cargo.toml | 1 + .../integration-tests/proc-macro/Cargo.toml | 21 +++++ .../integration-tests/proc-macro/src/lib.rs | 80 +++++++++++++++++++ testing/integration-tests/src/utils/mod.rs | 11 +++ 6 files changed, 124 insertions(+) create mode 100644 testing/integration-tests/proc-macro/Cargo.toml create mode 100644 testing/integration-tests/proc-macro/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index f34d4ae4b6..8e7988813b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2266,6 +2266,7 @@ dependencies = [ "frame-metadata 16.0.0", "futures", "hex", + "integration-tests-proc-macro", "parity-scale-codec", "regex", "scale-info", @@ -2284,6 +2285,15 @@ dependencies = [ "wabt", ] +[[package]] +name = "integration-tests-proc-macro" +version = "0.34.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "io-lifetimes" version = "1.0.11" diff --git a/Cargo.toml b/Cargo.toml index d7165f0dfc..16bb64831f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ members = [ "testing/substrate-runner", "testing/test-runtime", "testing/integration-tests", + "testing/integration-tests/proc-macro", "testing/ui-tests", "testing/generate-custom-metadata", "macro", diff --git a/testing/integration-tests/Cargo.toml b/testing/integration-tests/Cargo.toml index d52ceaa17a..4af5e927e2 100644 --- a/testing/integration-tests/Cargo.toml +++ b/testing/integration-tests/Cargo.toml @@ -46,6 +46,7 @@ tracing = { workspace = true } tracing-subscriber = { workspace = true } wabt = { workspace = true } substrate-runner = { workspace = true } +integration-tests-proc-macro = { path = "proc-macro" } [build-dependencies] cfg_aliases = "0.2.0" diff --git a/testing/integration-tests/proc-macro/Cargo.toml b/testing/integration-tests/proc-macro/Cargo.toml new file mode 100644 index 0000000000..b46bf20bd7 --- /dev/null +++ b/testing/integration-tests/proc-macro/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "integration-tests-proc-macro" +version.workspace = true +authors.workspace = true +edition.workspace = true +rust-version.workspace = true +publish = false + +license.workspace = true +repository.workspace = true +documentation.workspace = true +homepage.workspace = true +description = "Subxt integration tests proc-macros" + +[lib] +proc-macro = true + +[dependencies] +syn = { workspace = true } +proc-macro2 = { workspace = true } +quote = { workspace = true } diff --git a/testing/integration-tests/proc-macro/src/lib.rs b/testing/integration-tests/proc-macro/src/lib.rs new file mode 100644 index 0000000000..fef3b95066 --- /dev/null +++ b/testing/integration-tests/proc-macro/src/lib.rs @@ -0,0 +1,80 @@ +// Copyright 2019-2023 Parity Technologies (UK) Ltd. +// This file is dual-licensed as Apache-2.0 or GPL-3.0. +// see LICENSE for license details. + +extern crate proc_macro; +use proc_macro::TokenStream; + +use quote::{format_ident, quote}; +use syn::{ + parse::{Parse, ParseStream}, + Error, +}; + +#[proc_macro_attribute] +pub fn subxt_test(attr: TokenStream, item: TokenStream) -> TokenStream { + let subxt_attr = match syn::parse::(attr) { + Ok(subxt_attr) => subxt_attr, + Err(err) => return err.into_compile_error().into(), + }; + let timeout_duration = subxt_attr.timeout.unwrap_or(60 * 5); + + let func: syn::ItemFn = match syn::parse(item) { + Ok(func) => func, + Err(err) => return err.into_compile_error().into(), + }; + + let func_attrs = &func.attrs; + let func_vis = &func.vis; + let func_sig = &func.sig; + let func_block = &func.block; + let func_output = &func.sig.output; + + let func_name = &func.sig.ident; + let inner_func_name = format_ident!("{}_inner", func_name); + + let result = quote! { + #[tokio::test] + #( #func_attrs )* + #func_vis #func_sig #func_output { + async fn #inner_func_name() #func_output + #func_block + + tokio::time::timeout(std::time::Duration::from_secs(#timeout_duration), #inner_func_name()) + .await + .expect("Test timedout"); + } + }; + result.into() +} + +mod keywords { + syn::custom_keyword!(timeout); +} + +struct SubxtTestAttr { + timeout: Option, +} + +impl Parse for SubxtTestAttr { + fn parse(input: ParseStream) -> Result { + if input.is_empty() { + return Ok(Self { timeout: None }); + } + + let _keyword = input.parse::()?; + input.parse::()?; + let timeout = input.parse::()?.base10_parse::()?; + + if !input.is_empty() { + return Err(Error::new( + input.span(), + "Expected tokens: `timeout = value`", + )); + } + + Ok(Self { + timeout: Some(timeout), + }) + } +} diff --git a/testing/integration-tests/src/utils/mod.rs b/testing/integration-tests/src/utils/mod.rs index dc5215feba..c92d156d62 100644 --- a/testing/integration-tests/src/utils/mod.rs +++ b/testing/integration-tests/src/utils/mod.rs @@ -11,3 +11,14 @@ pub use context::*; pub use node_proc::TestNodeProcess; pub use tx_retries::*; pub use wait_for_blocks::*; + +pub use integration_tests_proc_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; +} From 20e75bca44853ca3e707649ddce1b23e678eb3d6 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 1 Mar 2024 20:23:14 +0200 Subject: [PATCH 18/42] testing: Add timeout 800 seconds Signed-off-by: Alexandru Vasile --- .../src/full_client/blocks/mod.rs | 12 ++++---- .../src/full_client/client/legacy_rpcs.rs | 28 +++++++++---------- .../src/full_client/client/mod.rs | 22 +++++++-------- .../src/full_client/client/unstable_rpcs.rs | 20 ++++++------- .../src/full_client/frame/balances.rs | 16 +++++------ .../src/full_client/frame/contracts.rs | 6 ++-- .../src/full_client/frame/staking.rs | 18 ++++++------ .../src/full_client/frame/sudo.rs | 4 +-- .../src/full_client/frame/system.rs | 4 +-- .../src/full_client/frame/timestamp.rs | 2 +- .../src/full_client/metadata/validation.rs | 8 +++--- .../src/full_client/runtime_api/mod.rs | 4 +-- .../src/full_client/storage/mod.rs | 14 +++++----- 13 files changed, 79 insertions(+), 79 deletions(-) diff --git a/testing/integration-tests/src/full_client/blocks/mod.rs b/testing/integration-tests/src/full_client/blocks/mod.rs index 7df2cabfdd..0aa4c4dcc9 100644 --- a/testing/integration-tests/src/full_client/blocks/mod.rs +++ b/testing/integration-tests/src/full_client/blocks/mod.rs @@ -25,7 +25,7 @@ use subxt_signer::sr25519::dev; use subxt_metadata::Metadata; #[cfg(fullclient)] -#[tokio::test] +#[subxt_test(timeout = 800)] async fn block_subscriptions_are_consistent_with_eachother() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); @@ -89,7 +89,7 @@ async fn block_subscriptions_are_consistent_with_eachother() -> Result<(), subxt Ok(()) } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn finalized_headers_subscription() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); @@ -106,7 +106,7 @@ async fn finalized_headers_subscription() -> Result<(), subxt::Error> { Ok(()) } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn missing_block_headers_will_be_filled_in() -> Result<(), subxt::Error> { use subxt::backend::legacy; @@ -151,7 +151,7 @@ async fn missing_block_headers_will_be_filled_in() -> Result<(), subxt::Error> { } // Check that we can subscribe to non-finalized blocks. -#[tokio::test] +#[subxt_test(timeout = 800)] async fn runtime_api_call() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); @@ -177,7 +177,7 @@ async fn runtime_api_call() -> Result<(), subxt::Error> { } #[cfg(fullclient)] -#[tokio::test] +#[subxt_test(timeout = 800)] async fn fetch_block_and_decode_extrinsic_details() { let ctx = test_context().await; let api = ctx.client(); @@ -247,7 +247,7 @@ async fn fetch_block_and_decode_extrinsic_details() { } #[cfg(fullclient)] -#[tokio::test] +#[subxt_test(timeout = 800)] async fn decode_signed_extensions_from_blocks() { let ctx = test_context().await; let api = ctx.client(); diff --git a/testing/integration-tests/src/full_client/client/legacy_rpcs.rs b/testing/integration-tests/src/full_client/client/legacy_rpcs.rs index 343079d14b..ba9f66f1ab 100644 --- a/testing/integration-tests/src/full_client/client/legacy_rpcs.rs +++ b/testing/integration-tests/src/full_client/client/legacy_rpcs.rs @@ -7,7 +7,7 @@ use crate::test_context; -#[tokio::test] +#[subxt_test(timeout = 800)] async fn chain_get_block_hash() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -15,7 +15,7 @@ async fn chain_get_block_hash() { rpc.chain_get_block_hash(None).await.unwrap(); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn chain_get_block() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -24,7 +24,7 @@ async fn chain_get_block() { rpc.chain_get_block(hash).await.unwrap(); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn chain_get_finalized_head() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -32,7 +32,7 @@ async fn chain_get_finalized_head() { rpc.chain_get_finalized_head().await.unwrap(); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn chain_subscribe_all_heads() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -41,7 +41,7 @@ async fn chain_subscribe_all_heads() { let _block_header = sub.next().await.unwrap().unwrap(); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn chain_subscribe_finalized_heads() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -50,7 +50,7 @@ async fn chain_subscribe_finalized_heads() { let _block_header = sub.next().await.unwrap().unwrap(); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn chain_subscribe_new_heads() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -59,7 +59,7 @@ async fn chain_subscribe_new_heads() { let _block_header = sub.next().await.unwrap().unwrap(); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn genesis_hash() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -67,7 +67,7 @@ async fn genesis_hash() { let _genesis_hash = rpc.genesis_hash().await.unwrap(); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn state_get_metadata() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -75,7 +75,7 @@ async fn state_get_metadata() { let _metadata = rpc.state_get_metadata(None).await.unwrap(); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn state_call() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -86,7 +86,7 @@ async fn state_call() { .unwrap(); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn system_health() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -94,7 +94,7 @@ async fn system_health() { let _ = rpc.system_health().await.unwrap(); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn system_chain() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -102,7 +102,7 @@ async fn system_chain() { let _ = rpc.system_chain().await.unwrap(); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn system_name() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -110,7 +110,7 @@ async fn system_name() { let _ = rpc.system_name().await.unwrap(); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn system_version() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -118,7 +118,7 @@ async fn system_version() { let _ = rpc.system_version().await.unwrap(); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn system_properties() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; diff --git a/testing/integration-tests/src/full_client/client/mod.rs b/testing/integration-tests/src/full_client/client/mod.rs index 7abdee3d7f..bb5d81dc3a 100644 --- a/testing/integration-tests/src/full_client/client/mod.rs +++ b/testing/integration-tests/src/full_client/client/mod.rs @@ -27,7 +27,7 @@ mod legacy_rpcs; mod unstable_rpcs; #[cfg(fullclient)] -#[tokio::test] +#[subxt_test(timeout = 800)] async fn storage_fetch_raw_keys() { let ctx = test_context().await; let api = ctx.client(); @@ -49,7 +49,7 @@ async fn storage_fetch_raw_keys() { } #[cfg(fullclient)] -#[tokio::test] +#[subxt_test(timeout = 800)] async fn storage_iter() { let ctx = test_context().await; let api = ctx.client(); @@ -74,7 +74,7 @@ async fn storage_iter() { } #[cfg(fullclient)] -#[tokio::test] +#[subxt_test(timeout = 800)] async fn storage_child_values_same_across_backends() { let ctx = test_context().await; @@ -114,7 +114,7 @@ async fn storage_child_values_same_across_backends() { } } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn transaction_validation() { let ctx = test_context().await; let api = ctx.client(); @@ -144,7 +144,7 @@ async fn transaction_validation() { .unwrap(); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn validation_fails() { use std::str::FromStr; use subxt_signer::{sr25519::Keypair, SecretUri}; @@ -178,7 +178,7 @@ async fn validation_fails() { ); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn external_signing() { let ctx = test_context().await; let api = ctx.client(); @@ -211,7 +211,7 @@ async fn external_signing() { // TODO: Investigate and fix this test failure when using the UnstableBackend. // (https://github.com/paritytech/subxt/issues/1308) #[cfg(not(feature = "unstable-backend-client"))] -#[tokio::test] +#[subxt_test(timeout = 800)] async fn submit_large_extrinsic() { let ctx = test_context().await; let api = ctx.client(); @@ -238,7 +238,7 @@ async fn submit_large_extrinsic() { .unwrap(); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn decode_a_module_error() { use node_runtime::runtime_types::pallet_assets::pallet as assets; @@ -276,7 +276,7 @@ async fn decode_a_module_error() { ); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn unsigned_extrinsic_is_same_shape_as_polkadotjs() { let ctx = test_context().await; let api = ctx.client(); @@ -304,7 +304,7 @@ async fn unsigned_extrinsic_is_same_shape_as_polkadotjs() { assert_eq!(actual_tx_bytes, expected_tx_bytes); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn extrinsic_hash_is_same_as_returned() { let ctx = test_context().await; let api = ctx.client(); @@ -356,7 +356,7 @@ pub struct InclusionFee { pub adjusted_weight_fee: u128, } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn partial_fee_estimate_correct() { let ctx = test_context().await; let api = ctx.client(); diff --git a/testing/integration-tests/src/full_client/client/unstable_rpcs.rs b/testing/integration-tests/src/full_client/client/unstable_rpcs.rs index 22462a03f7..9b1a7ae906 100644 --- a/testing/integration-tests/src/full_client/client/unstable_rpcs.rs +++ b/testing/integration-tests/src/full_client/client/unstable_rpcs.rs @@ -22,7 +22,7 @@ use subxt::client::OfflineClientT; use subxt_signer::sr25519::dev; -#[tokio::test] +#[subxt_test(timeout = 800)] async fn chainhead_unstable_follow() { let ctx = test_context().await; let rpc = ctx.unstable_rpc_methods().await; @@ -62,7 +62,7 @@ async fn chainhead_unstable_follow() { ); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn chainhead_unstable_body() { let ctx = test_context().await; let rpc = ctx.unstable_rpc_methods().await; @@ -90,7 +90,7 @@ async fn chainhead_unstable_body() { ); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn chainhead_unstable_header() { let ctx = test_context().await; let rpc = ctx.unstable_rpc_methods().await; @@ -118,7 +118,7 @@ async fn chainhead_unstable_header() { assert_eq!(new_header, old_header); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn chainhead_unstable_storage() { let ctx = test_context().await; let api = ctx.client(); @@ -164,7 +164,7 @@ async fn chainhead_unstable_storage() { assert_matches!(event, FollowEvent::OperationStorageDone(res) if res.operation_id == operation_id); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn chainhead_unstable_call() { let ctx = test_context().await; let rpc = ctx.unstable_rpc_methods().await; @@ -201,7 +201,7 @@ async fn chainhead_unstable_call() { ); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn chainhead_unstable_unpin() { let ctx = test_context().await; let rpc = ctx.unstable_rpc_methods().await; @@ -220,7 +220,7 @@ async fn chainhead_unstable_unpin() { } #[cfg(fullclient)] -#[tokio::test] +#[subxt_test(timeout = 800)] async fn chainspec_v1_genesishash() { let ctx = test_context().await; let old_rpc = ctx.legacy_rpc_methods().await; @@ -233,7 +233,7 @@ async fn chainspec_v1_genesishash() { } #[cfg(fullclient)] -#[tokio::test] +#[subxt_test(timeout = 800)] async fn chainspec_v1_chainname() { let ctx = test_context().await; let old_rpc = ctx.legacy_rpc_methods().await; @@ -246,7 +246,7 @@ async fn chainspec_v1_chainname() { } #[cfg(fullclient)] -#[tokio::test] +#[subxt_test(timeout = 800)] async fn chainspec_v1_properties() { let ctx = test_context().await; let old_rpc = ctx.legacy_rpc_methods().await; @@ -259,7 +259,7 @@ async fn chainspec_v1_properties() { } #[cfg(fullclient)] -#[tokio::test] +#[subxt_test(timeout = 800)] async fn transaction_unstable_submit_and_watch() { let ctx = test_context().await; let rpc = ctx.unstable_rpc_methods().await; diff --git a/testing/integration-tests/src/full_client/frame/balances.rs b/testing/integration-tests/src/full_client/frame/balances.rs index ea0713b1e3..509cb48ffa 100644 --- a/testing/integration-tests/src/full_client/frame/balances.rs +++ b/testing/integration-tests/src/full_client/frame/balances.rs @@ -16,7 +16,7 @@ use subxt_signer::sr25519::dev; #[cfg(lightclient)] use subxt::client::OfflineClientT; -#[tokio::test] +#[subxt_test(timeout = 800)] async fn tx_basic_transfer() -> Result<(), subxt::Error> { let alice = dev::alice(); let bob = dev::bob(); @@ -89,7 +89,7 @@ async fn tx_basic_transfer() -> Result<(), subxt::Error> { } #[cfg(fullclient)] -#[tokio::test] +#[subxt_test(timeout = 800)] async fn tx_dynamic_transfer() -> Result<(), subxt::Error> { use subxt::ext::scale_value::{At, Composite, Value}; @@ -211,7 +211,7 @@ async fn tx_dynamic_transfer() -> Result<(), subxt::Error> { Ok(()) } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn multiple_sequential_transfers_work() -> Result<(), subxt::Error> { let alice = dev::alice(); let bob = dev::bob(); @@ -255,7 +255,7 @@ async fn multiple_sequential_transfers_work() -> Result<(), subxt::Error> { Ok(()) } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn storage_total_issuance() { let ctx = test_context().await; let api = ctx.client(); @@ -272,7 +272,7 @@ async fn storage_total_issuance() { assert_ne!(total_issuance, 0); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn storage_balance_lock() -> Result<(), subxt::Error> { let bob_signer = dev::bob(); let bob: AccountId32 = dev::bob().public_key().into(); @@ -314,7 +314,7 @@ async fn storage_balance_lock() -> Result<(), subxt::Error> { Ok(()) } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn transfer_error() { let alice = dev::alice(); let alice_addr = alice.public_key().into(); @@ -360,7 +360,7 @@ async fn transfer_error() { ); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn transfer_implicit_subscription() { let alice = dev::alice(); let bob: AccountId32 = dev::bob().public_key().into(); @@ -394,7 +394,7 @@ async fn transfer_implicit_subscription() { ); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn constant_existential_deposit() { let ctx = test_context().await; let api = ctx.client(); diff --git a/testing/integration-tests/src/full_client/frame/contracts.rs b/testing/integration-tests/src/full_client/frame/contracts.rs index c6ee58374e..68821360ae 100644 --- a/testing/integration-tests/src/full_client/frame/contracts.rs +++ b/testing/integration-tests/src/full_client/frame/contracts.rs @@ -168,7 +168,7 @@ impl ContractsTestContext { } } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn tx_instantiate_with_code() { let ctx = ContractsTestContext::init().await; let result = ctx.instantiate_with_code().await; @@ -179,7 +179,7 @@ async fn tx_instantiate_with_code() { ); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn tx_instantiate() { let ctx = ContractsTestContext::init().await; let code_hash = ctx.upload_code().await.unwrap(); @@ -192,7 +192,7 @@ async fn tx_instantiate() { ); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn tx_call() { let cxt = ContractsTestContext::init().await; let (_, contract) = cxt.instantiate_with_code().await.unwrap(); diff --git a/testing/integration-tests/src/full_client/frame/staking.rs b/testing/integration-tests/src/full_client/frame/staking.rs index 91eba84f43..fd2ea0008f 100644 --- a/testing/integration-tests/src/full_client/frame/staking.rs +++ b/testing/integration-tests/src/full_client/frame/staking.rs @@ -34,7 +34,7 @@ fn default_validator_prefs() -> ValidatorPrefs { } } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn validate_with_stash_account() { let ctx = test_context().await; let api = ctx.client(); @@ -55,7 +55,7 @@ async fn validate_with_stash_account() { .expect("should be successful"); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn validate_not_possible_for_controller_account() -> Result<(), Error> { let ctx = test_context().await; let api = ctx.client(); @@ -80,7 +80,7 @@ async fn validate_not_possible_for_controller_account() -> Result<(), Error> { Ok(()) } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn nominate_with_stash_account() { let ctx = test_context().await; let api = ctx.client(); @@ -102,7 +102,7 @@ async fn nominate_with_stash_account() { .expect("should be successful"); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn nominate_not_possible_for_controller_account() -> Result<(), Error> { let ctx = test_context().await; let api = ctx.client(); @@ -129,7 +129,7 @@ async fn nominate_not_possible_for_controller_account() -> Result<(), Error> { Ok(()) } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn chill_works_for_stash_only() -> Result<(), Error> { let ctx = test_context().await; let api = ctx.client(); @@ -188,7 +188,7 @@ async fn chill_works_for_stash_only() -> Result<(), Error> { Ok(()) } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn tx_bond() -> Result<(), Error> { let ctx = test_context().await; let api = ctx.client(); @@ -221,7 +221,7 @@ async fn tx_bond() -> Result<(), Error> { Ok(()) } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn storage_history_depth() -> Result<(), Error> { let ctx = test_context().await; let api = ctx.client(); @@ -231,7 +231,7 @@ async fn storage_history_depth() -> Result<(), Error> { Ok(()) } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn storage_current_era() -> Result<(), Error> { let ctx = test_context().await; let api = ctx.client(); @@ -246,7 +246,7 @@ async fn storage_current_era() -> Result<(), Error> { Ok(()) } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn storage_era_reward_points() -> Result<(), Error> { let ctx = test_context().await; let api = ctx.client(); diff --git a/testing/integration-tests/src/full_client/frame/sudo.rs b/testing/integration-tests/src/full_client/frame/sudo.rs index 4d34ee862d..11f332e262 100644 --- a/testing/integration-tests/src/full_client/frame/sudo.rs +++ b/testing/integration-tests/src/full_client/frame/sudo.rs @@ -15,7 +15,7 @@ use subxt_signer::sr25519::dev; type Call = runtime_types::kitchensink_runtime::RuntimeCall; type BalancesCall = runtime_types::pallet_balances::pallet::Call; -#[tokio::test] +#[subxt_test(timeout = 800)] async fn test_sudo() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); @@ -42,7 +42,7 @@ async fn test_sudo() -> Result<(), subxt::Error> { Ok(()) } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn test_sudo_unchecked_weight() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); diff --git a/testing/integration-tests/src/full_client/frame/system.rs b/testing/integration-tests/src/full_client/frame/system.rs index bb966b1293..b110d782b7 100644 --- a/testing/integration-tests/src/full_client/frame/system.rs +++ b/testing/integration-tests/src/full_client/frame/system.rs @@ -9,7 +9,7 @@ use crate::{ use assert_matches::assert_matches; use subxt_signer::sr25519::dev; -#[tokio::test] +#[subxt_test(timeout = 800)] async fn storage_account() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); @@ -31,7 +31,7 @@ async fn storage_account() -> Result<(), subxt::Error> { Ok(()) } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn tx_remark_with_event() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); diff --git a/testing/integration-tests/src/full_client/frame/timestamp.rs b/testing/integration-tests/src/full_client/frame/timestamp.rs index d291042ae5..44cd06b184 100644 --- a/testing/integration-tests/src/full_client/frame/timestamp.rs +++ b/testing/integration-tests/src/full_client/frame/timestamp.rs @@ -4,7 +4,7 @@ use crate::{node_runtime, test_context}; -#[tokio::test] +#[subxt_test(timeout = 800)] async fn storage_get_current_timestamp() { let ctx = test_context().await; let api = ctx.client(); diff --git a/testing/integration-tests/src/full_client/metadata/validation.rs b/testing/integration-tests/src/full_client/metadata/validation.rs index 733117b001..215bbaafec 100644 --- a/testing/integration-tests/src/full_client/metadata/validation.rs +++ b/testing/integration-tests/src/full_client/metadata/validation.rs @@ -100,7 +100,7 @@ fn pallets_to_metadata(pallets: Vec) -> Metadata { )) } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn full_metadata_check() { let ctx = test_context().await; let api = ctx.client(); @@ -117,7 +117,7 @@ async fn full_metadata_check() { assert!(!node_runtime::is_codegen_valid_for(&metadata)); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn constant_values_are_not_validated() { let ctx = test_context().await; let api = ctx.client(); @@ -149,7 +149,7 @@ async fn constant_values_are_not_validated() { assert!(api.constants().at(&deposit_addr).is_ok()); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn calls_check() { let ctx = test_context().await; let api = ctx.client(); @@ -235,7 +235,7 @@ async fn calls_check() { assert!(api.tx().validate(&withdraw_unbonded_addr).is_ok()); } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn storage_check() { let ctx = test_context().await; let api = ctx.client(); diff --git a/testing/integration-tests/src/full_client/runtime_api/mod.rs b/testing/integration-tests/src/full_client/runtime_api/mod.rs index 290c3b1534..e18df2bcda 100644 --- a/testing/integration-tests/src/full_client/runtime_api/mod.rs +++ b/testing/integration-tests/src/full_client/runtime_api/mod.rs @@ -7,7 +7,7 @@ use codec::Encode; use subxt::utils::AccountId32; use subxt_signer::sr25519::dev; -#[tokio::test] +#[subxt_test(timeout = 800)] async fn account_nonce() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); @@ -49,7 +49,7 @@ async fn account_nonce() -> Result<(), subxt::Error> { Ok(()) } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn unchecked_extrinsic_encoding() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); diff --git a/testing/integration-tests/src/full_client/storage/mod.rs b/testing/integration-tests/src/full_client/storage/mod.rs index 7ad44b8175..783687a2a1 100644 --- a/testing/integration-tests/src/full_client/storage/mod.rs +++ b/testing/integration-tests/src/full_client/storage/mod.rs @@ -9,7 +9,7 @@ use subxt::utils::AccountId32; #[cfg(fullclient)] use subxt_signer::sr25519::dev; -#[tokio::test] +#[subxt_test(timeout = 800)] async fn storage_plain_lookup() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); @@ -31,7 +31,7 @@ async fn storage_plain_lookup() -> Result<(), subxt::Error> { } #[cfg(fullclient)] -#[tokio::test] +#[subxt_test(timeout = 800)] async fn storage_map_lookup() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); @@ -65,7 +65,7 @@ async fn storage_map_lookup() -> Result<(), subxt::Error> { // treated as a StorageKey (ie we should hash both values together with one hasher, rather // than hash both values separately, or ignore the second value). #[cfg(fullclient)] -#[tokio::test] +#[subxt_test(timeout = 800)] async fn storage_n_mapish_key_is_properly_created() -> Result<(), subxt::Error> { use codec::Encode; use node_runtime::runtime_types::sp_core::crypto::KeyTypeId; @@ -96,7 +96,7 @@ async fn storage_n_mapish_key_is_properly_created() -> Result<(), subxt::Error> } #[cfg(fullclient)] -#[tokio::test] +#[subxt_test(timeout = 800)] async fn storage_n_map_storage_lookup() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); @@ -133,7 +133,7 @@ async fn storage_n_map_storage_lookup() -> Result<(), subxt::Error> { } #[cfg(fullclient)] -#[tokio::test] +#[subxt_test(timeout = 800)] async fn storage_partial_lookup() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); @@ -206,7 +206,7 @@ async fn storage_partial_lookup() -> Result<(), subxt::Error> { Ok(()) } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn storage_runtime_wasm_code() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); @@ -215,7 +215,7 @@ async fn storage_runtime_wasm_code() -> Result<(), subxt::Error> { Ok(()) } -#[tokio::test] +#[subxt_test(timeout = 800)] async fn storage_pallet_storage_version() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); From c5c797232ded0b1a2867c80b3c178d9a61c2db7e Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Mon, 4 Mar 2024 17:45:04 +0200 Subject: [PATCH 19/42] proc-macro/tests: Adjust subxt-test proc-macro Signed-off-by: Alexandru Vasile --- testing/integration-tests/proc-macro/src/lib.rs | 12 ++++++------ .../integration-tests/src/full_client/blocks/mod.rs | 2 +- .../src/full_client/client/legacy_rpcs.rs | 2 +- .../integration-tests/src/full_client/client/mod.rs | 2 +- .../src/full_client/client/unstable_rpcs.rs | 2 +- .../src/full_client/frame/balances.rs | 2 +- .../src/full_client/frame/contracts.rs | 3 ++- .../src/full_client/frame/staking.rs | 2 +- .../integration-tests/src/full_client/frame/sudo.rs | 2 +- .../src/full_client/frame/system.rs | 2 +- .../src/full_client/frame/timestamp.rs | 2 +- .../src/full_client/metadata/validation.rs | 2 +- .../src/full_client/runtime_api/mod.rs | 2 +- .../integration-tests/src/full_client/storage/mod.rs | 2 +- 14 files changed, 20 insertions(+), 19 deletions(-) diff --git a/testing/integration-tests/proc-macro/src/lib.rs b/testing/integration-tests/proc-macro/src/lib.rs index fef3b95066..edc9a6b7e3 100644 --- a/testing/integration-tests/proc-macro/src/lib.rs +++ b/testing/integration-tests/proc-macro/src/lib.rs @@ -28,21 +28,21 @@ pub fn subxt_test(attr: TokenStream, item: TokenStream) -> TokenStream { let func_vis = &func.vis; let func_sig = &func.sig; let func_block = &func.block; - let func_output = &func.sig.output; - let func_name = &func.sig.ident; - let inner_func_name = format_ident!("{}_inner", func_name); + let mut inner_func_sig = func.sig.clone(); + inner_func_sig.ident = format_ident!("{}_inner", inner_func_sig.ident); + let inner_func_name = &inner_func_sig.ident; let result = quote! { #[tokio::test] #( #func_attrs )* - #func_vis #func_sig #func_output { - async fn #inner_func_name() #func_output + #func_vis #func_sig { + #func_vis #inner_func_sig #func_block tokio::time::timeout(std::time::Duration::from_secs(#timeout_duration), #inner_func_name()) .await - .expect("Test timedout"); + .expect("Test timedout") } }; result.into() diff --git a/testing/integration-tests/src/full_client/blocks/mod.rs b/testing/integration-tests/src/full_client/blocks/mod.rs index 0aa4c4dcc9..b4090a2e00 100644 --- a/testing/integration-tests/src/full_client/blocks/mod.rs +++ b/testing/integration-tests/src/full_client/blocks/mod.rs @@ -2,7 +2,7 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::test_context; +use crate::{subxt_test, test_context}; use codec::{Compact, Encode}; use futures::StreamExt; diff --git a/testing/integration-tests/src/full_client/client/legacy_rpcs.rs b/testing/integration-tests/src/full_client/client/legacy_rpcs.rs index ba9f66f1ab..7a33d9feb2 100644 --- a/testing/integration-tests/src/full_client/client/legacy_rpcs.rs +++ b/testing/integration-tests/src/full_client/client/legacy_rpcs.rs @@ -5,7 +5,7 @@ //! Just sanity checking some of the legacy RPC methods to make //! sure they don't error out and can decode their results OK. -use crate::test_context; +use crate::{subxt_test, test_context}; #[subxt_test(timeout = 800)] async fn chain_get_block_hash() { diff --git a/testing/integration-tests/src/full_client/client/mod.rs b/testing/integration-tests/src/full_client/client/mod.rs index bb5d81dc3a..8a4d66aafc 100644 --- a/testing/integration-tests/src/full_client/client/mod.rs +++ b/testing/integration-tests/src/full_client/client/mod.rs @@ -3,7 +3,7 @@ // see LICENSE for license details. use crate::{ - submit_tx_wait_for_finalized_success, test_context, + submit_tx_wait_for_finalized_success, subxt_test, test_context, utils::{node_runtime, wait_for_blocks}, }; use codec::{Decode, Encode}; diff --git a/testing/integration-tests/src/full_client/client/unstable_rpcs.rs b/testing/integration-tests/src/full_client/client/unstable_rpcs.rs index 9b1a7ae906..5267ce50f0 100644 --- a/testing/integration-tests/src/full_client/client/unstable_rpcs.rs +++ b/testing/integration-tests/src/full_client/client/unstable_rpcs.rs @@ -5,7 +5,7 @@ //! Just sanity checking some of the new RPC methods to try and //! catch differences as the implementations evolve. -use crate::{test_context, utils::node_runtime}; +use crate::{subxt_test, test_context, utils::node_runtime}; use assert_matches::assert_matches; use codec::Encode; use futures::Stream; diff --git a/testing/integration-tests/src/full_client/frame/balances.rs b/testing/integration-tests/src/full_client/frame/balances.rs index 509cb48ffa..d5df7805fb 100644 --- a/testing/integration-tests/src/full_client/frame/balances.rs +++ b/testing/integration-tests/src/full_client/frame/balances.rs @@ -4,7 +4,7 @@ use crate::{ node_runtime::{self, balances, runtime_types, system}, - submit_tx_wait_for_finalized_success, test_context, + submit_tx_wait_for_finalized_success, subxt_test, test_context, }; use codec::Decode; use subxt::{ diff --git a/testing/integration-tests/src/full_client/frame/contracts.rs b/testing/integration-tests/src/full_client/frame/contracts.rs index 68821360ae..8642eaa267 100644 --- a/testing/integration-tests/src/full_client/frame/contracts.rs +++ b/testing/integration-tests/src/full_client/frame/contracts.rs @@ -9,7 +9,8 @@ use crate::{ runtime_types::{pallet_contracts::wasm::Determinism, sp_weights::weight_v2::Weight}, system, }, - submit_tx_wait_for_finalized_success, test_context, TestClient, TestConfig, TestContext, + submit_tx_wait_for_finalized_success, subxt_test, test_context, TestClient, TestConfig, + TestContext, }; use subxt::ext::futures::StreamExt; use subxt::{tx::TxProgress, utils::MultiAddress, Config, Error}; diff --git a/testing/integration-tests/src/full_client/frame/staking.rs b/testing/integration-tests/src/full_client/frame/staking.rs index fd2ea0008f..95a8ddee35 100644 --- a/testing/integration-tests/src/full_client/frame/staking.rs +++ b/testing/integration-tests/src/full_client/frame/staking.rs @@ -11,7 +11,7 @@ use crate::{ }, staking, }, - submit_tx_wait_for_finalized_success, test_context, + submit_tx_wait_for_finalized_success, subxt_test, test_context, }; use assert_matches::assert_matches; use subxt::error::{DispatchError, Error}; diff --git a/testing/integration-tests/src/full_client/frame/sudo.rs b/testing/integration-tests/src/full_client/frame/sudo.rs index 11f332e262..27a9b4e639 100644 --- a/testing/integration-tests/src/full_client/frame/sudo.rs +++ b/testing/integration-tests/src/full_client/frame/sudo.rs @@ -8,7 +8,7 @@ use crate::{ runtime_types::{self, sp_weights::weight_v2::Weight}, sudo, }, - submit_tx_wait_for_finalized_success, test_context, + submit_tx_wait_for_finalized_success, subxt_test, test_context, }; use subxt_signer::sr25519::dev; diff --git a/testing/integration-tests/src/full_client/frame/system.rs b/testing/integration-tests/src/full_client/frame/system.rs index b110d782b7..0876feeb96 100644 --- a/testing/integration-tests/src/full_client/frame/system.rs +++ b/testing/integration-tests/src/full_client/frame/system.rs @@ -4,7 +4,7 @@ use crate::{ node_runtime::{self, system}, - submit_tx_wait_for_finalized_success, test_context, + submit_tx_wait_for_finalized_success, subxt_test, test_context, }; use assert_matches::assert_matches; use subxt_signer::sr25519::dev; diff --git a/testing/integration-tests/src/full_client/frame/timestamp.rs b/testing/integration-tests/src/full_client/frame/timestamp.rs index 44cd06b184..7df9345fab 100644 --- a/testing/integration-tests/src/full_client/frame/timestamp.rs +++ b/testing/integration-tests/src/full_client/frame/timestamp.rs @@ -2,7 +2,7 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::{node_runtime, test_context}; +use crate::{node_runtime, subxt_test, test_context}; #[subxt_test(timeout = 800)] async fn storage_get_current_timestamp() { diff --git a/testing/integration-tests/src/full_client/metadata/validation.rs b/testing/integration-tests/src/full_client/metadata/validation.rs index 215bbaafec..253720a652 100644 --- a/testing/integration-tests/src/full_client/metadata/validation.rs +++ b/testing/integration-tests/src/full_client/metadata/validation.rs @@ -2,7 +2,7 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::{node_runtime, test_context, TestContext}; +use crate::{node_runtime, subxt_test, test_context, TestContext}; use frame_metadata::v15::{ CustomMetadata, ExtrinsicMetadata, OuterEnums, PalletCallMetadata, PalletMetadata, PalletStorageMetadata, RuntimeMetadataV15, StorageEntryMetadata, StorageEntryModifier, diff --git a/testing/integration-tests/src/full_client/runtime_api/mod.rs b/testing/integration-tests/src/full_client/runtime_api/mod.rs index e18df2bcda..9c766aaeda 100644 --- a/testing/integration-tests/src/full_client/runtime_api/mod.rs +++ b/testing/integration-tests/src/full_client/runtime_api/mod.rs @@ -2,7 +2,7 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::{node_runtime, submit_tx_wait_for_finalized_success, test_context}; +use crate::{node_runtime, submit_tx_wait_for_finalized_success, subxt_test, test_context}; use codec::Encode; use subxt::utils::AccountId32; use subxt_signer::sr25519::dev; diff --git a/testing/integration-tests/src/full_client/storage/mod.rs b/testing/integration-tests/src/full_client/storage/mod.rs index 783687a2a1..d52bdd5f2a 100644 --- a/testing/integration-tests/src/full_client/storage/mod.rs +++ b/testing/integration-tests/src/full_client/storage/mod.rs @@ -2,7 +2,7 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::{node_runtime, test_context, utils::wait_for_blocks}; +use crate::{node_runtime, subxt_test, test_context, utils::wait_for_blocks}; #[cfg(fullclient)] use subxt::utils::AccountId32; From d3923c871511faccbee90bedb7f605ba2203c55f Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 5 Mar 2024 15:28:32 +0200 Subject: [PATCH 20/42] proc-macro: Rename crate to subxt-test-proc-macro Signed-off-by: Alexandru Vasile --- Cargo.lock | 20 +++++++++---------- testing/integration-tests/Cargo.toml | 2 +- .../integration-tests/proc-macro/Cargo.toml | 2 +- testing/integration-tests/src/utils/mod.rs | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8e7988813b..d830a09f7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2266,7 +2266,6 @@ dependencies = [ "frame-metadata 16.0.0", "futures", "hex", - "integration-tests-proc-macro", "parity-scale-codec", "regex", "scale-info", @@ -2277,6 +2276,7 @@ dependencies = [ "subxt-codegen", "subxt-metadata", "subxt-signer", + "subxt-test-proc-macro", "syn 2.0.48", "test-runtime", "tokio", @@ -2285,15 +2285,6 @@ dependencies = [ "wabt", ] -[[package]] -name = "integration-tests-proc-macro" -version = "0.34.0" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] - [[package]] name = "io-lifetimes" version = "1.0.11" @@ -4684,6 +4675,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "subxt-test-proc-macro" +version = "0.34.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "syn" version = "1.0.109" diff --git a/testing/integration-tests/Cargo.toml b/testing/integration-tests/Cargo.toml index 4af5e927e2..fb55fb857d 100644 --- a/testing/integration-tests/Cargo.toml +++ b/testing/integration-tests/Cargo.toml @@ -46,7 +46,7 @@ tracing = { workspace = true } tracing-subscriber = { workspace = true } wabt = { workspace = true } substrate-runner = { workspace = true } -integration-tests-proc-macro = { path = "proc-macro" } +subxt-test-proc-macro = { path = "proc-macro" } [build-dependencies] cfg_aliases = "0.2.0" diff --git a/testing/integration-tests/proc-macro/Cargo.toml b/testing/integration-tests/proc-macro/Cargo.toml index b46bf20bd7..49e1467a41 100644 --- a/testing/integration-tests/proc-macro/Cargo.toml +++ b/testing/integration-tests/proc-macro/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "integration-tests-proc-macro" +name = "subxt-test-proc-macro" version.workspace = true authors.workspace = true edition.workspace = true diff --git a/testing/integration-tests/src/utils/mod.rs b/testing/integration-tests/src/utils/mod.rs index c92d156d62..5c6c11e0a0 100644 --- a/testing/integration-tests/src/utils/mod.rs +++ b/testing/integration-tests/src/utils/mod.rs @@ -12,7 +12,7 @@ pub use node_proc::TestNodeProcess; pub use tx_retries::*; pub use wait_for_blocks::*; -pub use integration_tests_proc_macro::subxt_test; +pub use subxt_test_proc_macro::subxt_test; /// The test timeout is set to 1 second. /// However, the test is sleeping for 5 seconds. From 1a647500a7d87fa48296b41dd1a708f8f72d15db Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 5 Mar 2024 15:29:38 +0200 Subject: [PATCH 21/42] Use default subxt-proc-macro timeout Signed-off-by: Alexandru Vasile --- .../src/full_client/blocks/mod.rs | 12 ++++---- .../src/full_client/client/legacy_rpcs.rs | 28 +++++++++---------- .../src/full_client/client/mod.rs | 22 +++++++-------- .../src/full_client/client/unstable_rpcs.rs | 20 ++++++------- .../src/full_client/frame/balances.rs | 16 +++++------ .../src/full_client/frame/contracts.rs | 6 ++-- .../src/full_client/frame/staking.rs | 18 ++++++------ .../src/full_client/frame/sudo.rs | 4 +-- .../src/full_client/frame/system.rs | 4 +-- .../src/full_client/frame/timestamp.rs | 2 +- .../src/full_client/metadata/validation.rs | 8 +++--- .../src/full_client/runtime_api/mod.rs | 4 +-- .../src/full_client/storage/mod.rs | 14 +++++----- 13 files changed, 79 insertions(+), 79 deletions(-) diff --git a/testing/integration-tests/src/full_client/blocks/mod.rs b/testing/integration-tests/src/full_client/blocks/mod.rs index b4090a2e00..d0ef601a38 100644 --- a/testing/integration-tests/src/full_client/blocks/mod.rs +++ b/testing/integration-tests/src/full_client/blocks/mod.rs @@ -25,7 +25,7 @@ use subxt_signer::sr25519::dev; use subxt_metadata::Metadata; #[cfg(fullclient)] -#[subxt_test(timeout = 800)] +#[subxt_test] async fn block_subscriptions_are_consistent_with_eachother() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); @@ -89,7 +89,7 @@ async fn block_subscriptions_are_consistent_with_eachother() -> Result<(), subxt Ok(()) } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn finalized_headers_subscription() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); @@ -106,7 +106,7 @@ async fn finalized_headers_subscription() -> Result<(), subxt::Error> { Ok(()) } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn missing_block_headers_will_be_filled_in() -> Result<(), subxt::Error> { use subxt::backend::legacy; @@ -151,7 +151,7 @@ async fn missing_block_headers_will_be_filled_in() -> Result<(), subxt::Error> { } // Check that we can subscribe to non-finalized blocks. -#[subxt_test(timeout = 800)] +#[subxt_test] async fn runtime_api_call() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); @@ -177,7 +177,7 @@ async fn runtime_api_call() -> Result<(), subxt::Error> { } #[cfg(fullclient)] -#[subxt_test(timeout = 800)] +#[subxt_test] async fn fetch_block_and_decode_extrinsic_details() { let ctx = test_context().await; let api = ctx.client(); @@ -247,7 +247,7 @@ async fn fetch_block_and_decode_extrinsic_details() { } #[cfg(fullclient)] -#[subxt_test(timeout = 800)] +#[subxt_test] async fn decode_signed_extensions_from_blocks() { let ctx = test_context().await; let api = ctx.client(); diff --git a/testing/integration-tests/src/full_client/client/legacy_rpcs.rs b/testing/integration-tests/src/full_client/client/legacy_rpcs.rs index 7a33d9feb2..cd932146fc 100644 --- a/testing/integration-tests/src/full_client/client/legacy_rpcs.rs +++ b/testing/integration-tests/src/full_client/client/legacy_rpcs.rs @@ -7,7 +7,7 @@ use crate::{subxt_test, test_context}; -#[subxt_test(timeout = 800)] +#[subxt_test] async fn chain_get_block_hash() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -15,7 +15,7 @@ async fn chain_get_block_hash() { rpc.chain_get_block_hash(None).await.unwrap(); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn chain_get_block() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -24,7 +24,7 @@ async fn chain_get_block() { rpc.chain_get_block(hash).await.unwrap(); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn chain_get_finalized_head() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -32,7 +32,7 @@ async fn chain_get_finalized_head() { rpc.chain_get_finalized_head().await.unwrap(); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn chain_subscribe_all_heads() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -41,7 +41,7 @@ async fn chain_subscribe_all_heads() { let _block_header = sub.next().await.unwrap().unwrap(); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn chain_subscribe_finalized_heads() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -50,7 +50,7 @@ async fn chain_subscribe_finalized_heads() { let _block_header = sub.next().await.unwrap().unwrap(); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn chain_subscribe_new_heads() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -59,7 +59,7 @@ async fn chain_subscribe_new_heads() { let _block_header = sub.next().await.unwrap().unwrap(); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn genesis_hash() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -67,7 +67,7 @@ async fn genesis_hash() { let _genesis_hash = rpc.genesis_hash().await.unwrap(); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn state_get_metadata() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -75,7 +75,7 @@ async fn state_get_metadata() { let _metadata = rpc.state_get_metadata(None).await.unwrap(); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn state_call() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -86,7 +86,7 @@ async fn state_call() { .unwrap(); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn system_health() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -94,7 +94,7 @@ async fn system_health() { let _ = rpc.system_health().await.unwrap(); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn system_chain() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -102,7 +102,7 @@ async fn system_chain() { let _ = rpc.system_chain().await.unwrap(); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn system_name() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -110,7 +110,7 @@ async fn system_name() { let _ = rpc.system_name().await.unwrap(); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn system_version() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; @@ -118,7 +118,7 @@ async fn system_version() { let _ = rpc.system_version().await.unwrap(); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn system_properties() { let ctx = test_context().await; let rpc = ctx.legacy_rpc_methods().await; diff --git a/testing/integration-tests/src/full_client/client/mod.rs b/testing/integration-tests/src/full_client/client/mod.rs index 8a4d66aafc..246191a280 100644 --- a/testing/integration-tests/src/full_client/client/mod.rs +++ b/testing/integration-tests/src/full_client/client/mod.rs @@ -27,7 +27,7 @@ mod legacy_rpcs; mod unstable_rpcs; #[cfg(fullclient)] -#[subxt_test(timeout = 800)] +#[subxt_test] async fn storage_fetch_raw_keys() { let ctx = test_context().await; let api = ctx.client(); @@ -49,7 +49,7 @@ async fn storage_fetch_raw_keys() { } #[cfg(fullclient)] -#[subxt_test(timeout = 800)] +#[subxt_test] async fn storage_iter() { let ctx = test_context().await; let api = ctx.client(); @@ -74,7 +74,7 @@ async fn storage_iter() { } #[cfg(fullclient)] -#[subxt_test(timeout = 800)] +#[subxt_test] async fn storage_child_values_same_across_backends() { let ctx = test_context().await; @@ -114,7 +114,7 @@ async fn storage_child_values_same_across_backends() { } } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn transaction_validation() { let ctx = test_context().await; let api = ctx.client(); @@ -144,7 +144,7 @@ async fn transaction_validation() { .unwrap(); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn validation_fails() { use std::str::FromStr; use subxt_signer::{sr25519::Keypair, SecretUri}; @@ -178,7 +178,7 @@ async fn validation_fails() { ); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn external_signing() { let ctx = test_context().await; let api = ctx.client(); @@ -211,7 +211,7 @@ async fn external_signing() { // TODO: Investigate and fix this test failure when using the UnstableBackend. // (https://github.com/paritytech/subxt/issues/1308) #[cfg(not(feature = "unstable-backend-client"))] -#[subxt_test(timeout = 800)] +#[subxt_test] async fn submit_large_extrinsic() { let ctx = test_context().await; let api = ctx.client(); @@ -238,7 +238,7 @@ async fn submit_large_extrinsic() { .unwrap(); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn decode_a_module_error() { use node_runtime::runtime_types::pallet_assets::pallet as assets; @@ -276,7 +276,7 @@ async fn decode_a_module_error() { ); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn unsigned_extrinsic_is_same_shape_as_polkadotjs() { let ctx = test_context().await; let api = ctx.client(); @@ -304,7 +304,7 @@ async fn unsigned_extrinsic_is_same_shape_as_polkadotjs() { assert_eq!(actual_tx_bytes, expected_tx_bytes); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn extrinsic_hash_is_same_as_returned() { let ctx = test_context().await; let api = ctx.client(); @@ -356,7 +356,7 @@ pub struct InclusionFee { pub adjusted_weight_fee: u128, } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn partial_fee_estimate_correct() { let ctx = test_context().await; let api = ctx.client(); diff --git a/testing/integration-tests/src/full_client/client/unstable_rpcs.rs b/testing/integration-tests/src/full_client/client/unstable_rpcs.rs index 5267ce50f0..1cf65473f2 100644 --- a/testing/integration-tests/src/full_client/client/unstable_rpcs.rs +++ b/testing/integration-tests/src/full_client/client/unstable_rpcs.rs @@ -22,7 +22,7 @@ use subxt::client::OfflineClientT; use subxt_signer::sr25519::dev; -#[subxt_test(timeout = 800)] +#[subxt_test] async fn chainhead_unstable_follow() { let ctx = test_context().await; let rpc = ctx.unstable_rpc_methods().await; @@ -62,7 +62,7 @@ async fn chainhead_unstable_follow() { ); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn chainhead_unstable_body() { let ctx = test_context().await; let rpc = ctx.unstable_rpc_methods().await; @@ -90,7 +90,7 @@ async fn chainhead_unstable_body() { ); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn chainhead_unstable_header() { let ctx = test_context().await; let rpc = ctx.unstable_rpc_methods().await; @@ -118,7 +118,7 @@ async fn chainhead_unstable_header() { assert_eq!(new_header, old_header); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn chainhead_unstable_storage() { let ctx = test_context().await; let api = ctx.client(); @@ -164,7 +164,7 @@ async fn chainhead_unstable_storage() { assert_matches!(event, FollowEvent::OperationStorageDone(res) if res.operation_id == operation_id); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn chainhead_unstable_call() { let ctx = test_context().await; let rpc = ctx.unstable_rpc_methods().await; @@ -201,7 +201,7 @@ async fn chainhead_unstable_call() { ); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn chainhead_unstable_unpin() { let ctx = test_context().await; let rpc = ctx.unstable_rpc_methods().await; @@ -220,7 +220,7 @@ async fn chainhead_unstable_unpin() { } #[cfg(fullclient)] -#[subxt_test(timeout = 800)] +#[subxt_test] async fn chainspec_v1_genesishash() { let ctx = test_context().await; let old_rpc = ctx.legacy_rpc_methods().await; @@ -233,7 +233,7 @@ async fn chainspec_v1_genesishash() { } #[cfg(fullclient)] -#[subxt_test(timeout = 800)] +#[subxt_test] async fn chainspec_v1_chainname() { let ctx = test_context().await; let old_rpc = ctx.legacy_rpc_methods().await; @@ -246,7 +246,7 @@ async fn chainspec_v1_chainname() { } #[cfg(fullclient)] -#[subxt_test(timeout = 800)] +#[subxt_test] async fn chainspec_v1_properties() { let ctx = test_context().await; let old_rpc = ctx.legacy_rpc_methods().await; @@ -259,7 +259,7 @@ async fn chainspec_v1_properties() { } #[cfg(fullclient)] -#[subxt_test(timeout = 800)] +#[subxt_test] async fn transaction_unstable_submit_and_watch() { let ctx = test_context().await; let rpc = ctx.unstable_rpc_methods().await; diff --git a/testing/integration-tests/src/full_client/frame/balances.rs b/testing/integration-tests/src/full_client/frame/balances.rs index d5df7805fb..52d9fab7b3 100644 --- a/testing/integration-tests/src/full_client/frame/balances.rs +++ b/testing/integration-tests/src/full_client/frame/balances.rs @@ -16,7 +16,7 @@ use subxt_signer::sr25519::dev; #[cfg(lightclient)] use subxt::client::OfflineClientT; -#[subxt_test(timeout = 800)] +#[subxt_test] async fn tx_basic_transfer() -> Result<(), subxt::Error> { let alice = dev::alice(); let bob = dev::bob(); @@ -89,7 +89,7 @@ async fn tx_basic_transfer() -> Result<(), subxt::Error> { } #[cfg(fullclient)] -#[subxt_test(timeout = 800)] +#[subxt_test] async fn tx_dynamic_transfer() -> Result<(), subxt::Error> { use subxt::ext::scale_value::{At, Composite, Value}; @@ -211,7 +211,7 @@ async fn tx_dynamic_transfer() -> Result<(), subxt::Error> { Ok(()) } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn multiple_sequential_transfers_work() -> Result<(), subxt::Error> { let alice = dev::alice(); let bob = dev::bob(); @@ -255,7 +255,7 @@ async fn multiple_sequential_transfers_work() -> Result<(), subxt::Error> { Ok(()) } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn storage_total_issuance() { let ctx = test_context().await; let api = ctx.client(); @@ -272,7 +272,7 @@ async fn storage_total_issuance() { assert_ne!(total_issuance, 0); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn storage_balance_lock() -> Result<(), subxt::Error> { let bob_signer = dev::bob(); let bob: AccountId32 = dev::bob().public_key().into(); @@ -314,7 +314,7 @@ async fn storage_balance_lock() -> Result<(), subxt::Error> { Ok(()) } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn transfer_error() { let alice = dev::alice(); let alice_addr = alice.public_key().into(); @@ -360,7 +360,7 @@ async fn transfer_error() { ); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn transfer_implicit_subscription() { let alice = dev::alice(); let bob: AccountId32 = dev::bob().public_key().into(); @@ -394,7 +394,7 @@ async fn transfer_implicit_subscription() { ); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn constant_existential_deposit() { let ctx = test_context().await; let api = ctx.client(); diff --git a/testing/integration-tests/src/full_client/frame/contracts.rs b/testing/integration-tests/src/full_client/frame/contracts.rs index 8642eaa267..3bad5a29b8 100644 --- a/testing/integration-tests/src/full_client/frame/contracts.rs +++ b/testing/integration-tests/src/full_client/frame/contracts.rs @@ -169,7 +169,7 @@ impl ContractsTestContext { } } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn tx_instantiate_with_code() { let ctx = ContractsTestContext::init().await; let result = ctx.instantiate_with_code().await; @@ -180,7 +180,7 @@ async fn tx_instantiate_with_code() { ); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn tx_instantiate() { let ctx = ContractsTestContext::init().await; let code_hash = ctx.upload_code().await.unwrap(); @@ -193,7 +193,7 @@ async fn tx_instantiate() { ); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn tx_call() { let cxt = ContractsTestContext::init().await; let (_, contract) = cxt.instantiate_with_code().await.unwrap(); diff --git a/testing/integration-tests/src/full_client/frame/staking.rs b/testing/integration-tests/src/full_client/frame/staking.rs index 95a8ddee35..40a36bc271 100644 --- a/testing/integration-tests/src/full_client/frame/staking.rs +++ b/testing/integration-tests/src/full_client/frame/staking.rs @@ -34,7 +34,7 @@ fn default_validator_prefs() -> ValidatorPrefs { } } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn validate_with_stash_account() { let ctx = test_context().await; let api = ctx.client(); @@ -55,7 +55,7 @@ async fn validate_with_stash_account() { .expect("should be successful"); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn validate_not_possible_for_controller_account() -> Result<(), Error> { let ctx = test_context().await; let api = ctx.client(); @@ -80,7 +80,7 @@ async fn validate_not_possible_for_controller_account() -> Result<(), Error> { Ok(()) } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn nominate_with_stash_account() { let ctx = test_context().await; let api = ctx.client(); @@ -102,7 +102,7 @@ async fn nominate_with_stash_account() { .expect("should be successful"); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn nominate_not_possible_for_controller_account() -> Result<(), Error> { let ctx = test_context().await; let api = ctx.client(); @@ -129,7 +129,7 @@ async fn nominate_not_possible_for_controller_account() -> Result<(), Error> { Ok(()) } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn chill_works_for_stash_only() -> Result<(), Error> { let ctx = test_context().await; let api = ctx.client(); @@ -188,7 +188,7 @@ async fn chill_works_for_stash_only() -> Result<(), Error> { Ok(()) } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn tx_bond() -> Result<(), Error> { let ctx = test_context().await; let api = ctx.client(); @@ -221,7 +221,7 @@ async fn tx_bond() -> Result<(), Error> { Ok(()) } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn storage_history_depth() -> Result<(), Error> { let ctx = test_context().await; let api = ctx.client(); @@ -231,7 +231,7 @@ async fn storage_history_depth() -> Result<(), Error> { Ok(()) } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn storage_current_era() -> Result<(), Error> { let ctx = test_context().await; let api = ctx.client(); @@ -246,7 +246,7 @@ async fn storage_current_era() -> Result<(), Error> { Ok(()) } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn storage_era_reward_points() -> Result<(), Error> { let ctx = test_context().await; let api = ctx.client(); diff --git a/testing/integration-tests/src/full_client/frame/sudo.rs b/testing/integration-tests/src/full_client/frame/sudo.rs index 27a9b4e639..5118b3013b 100644 --- a/testing/integration-tests/src/full_client/frame/sudo.rs +++ b/testing/integration-tests/src/full_client/frame/sudo.rs @@ -15,7 +15,7 @@ use subxt_signer::sr25519::dev; type Call = runtime_types::kitchensink_runtime::RuntimeCall; type BalancesCall = runtime_types::pallet_balances::pallet::Call; -#[subxt_test(timeout = 800)] +#[subxt_test] async fn test_sudo() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); @@ -42,7 +42,7 @@ async fn test_sudo() -> Result<(), subxt::Error> { Ok(()) } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn test_sudo_unchecked_weight() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); diff --git a/testing/integration-tests/src/full_client/frame/system.rs b/testing/integration-tests/src/full_client/frame/system.rs index 0876feeb96..3ec5432b6b 100644 --- a/testing/integration-tests/src/full_client/frame/system.rs +++ b/testing/integration-tests/src/full_client/frame/system.rs @@ -9,7 +9,7 @@ use crate::{ use assert_matches::assert_matches; use subxt_signer::sr25519::dev; -#[subxt_test(timeout = 800)] +#[subxt_test] async fn storage_account() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); @@ -31,7 +31,7 @@ async fn storage_account() -> Result<(), subxt::Error> { Ok(()) } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn tx_remark_with_event() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); diff --git a/testing/integration-tests/src/full_client/frame/timestamp.rs b/testing/integration-tests/src/full_client/frame/timestamp.rs index 7df9345fab..5d74801434 100644 --- a/testing/integration-tests/src/full_client/frame/timestamp.rs +++ b/testing/integration-tests/src/full_client/frame/timestamp.rs @@ -4,7 +4,7 @@ use crate::{node_runtime, subxt_test, test_context}; -#[subxt_test(timeout = 800)] +#[subxt_test] async fn storage_get_current_timestamp() { let ctx = test_context().await; let api = ctx.client(); diff --git a/testing/integration-tests/src/full_client/metadata/validation.rs b/testing/integration-tests/src/full_client/metadata/validation.rs index 253720a652..4b3e531efd 100644 --- a/testing/integration-tests/src/full_client/metadata/validation.rs +++ b/testing/integration-tests/src/full_client/metadata/validation.rs @@ -100,7 +100,7 @@ fn pallets_to_metadata(pallets: Vec) -> Metadata { )) } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn full_metadata_check() { let ctx = test_context().await; let api = ctx.client(); @@ -117,7 +117,7 @@ async fn full_metadata_check() { assert!(!node_runtime::is_codegen_valid_for(&metadata)); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn constant_values_are_not_validated() { let ctx = test_context().await; let api = ctx.client(); @@ -149,7 +149,7 @@ async fn constant_values_are_not_validated() { assert!(api.constants().at(&deposit_addr).is_ok()); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn calls_check() { let ctx = test_context().await; let api = ctx.client(); @@ -235,7 +235,7 @@ async fn calls_check() { assert!(api.tx().validate(&withdraw_unbonded_addr).is_ok()); } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn storage_check() { let ctx = test_context().await; let api = ctx.client(); diff --git a/testing/integration-tests/src/full_client/runtime_api/mod.rs b/testing/integration-tests/src/full_client/runtime_api/mod.rs index 9c766aaeda..fbd4370a4b 100644 --- a/testing/integration-tests/src/full_client/runtime_api/mod.rs +++ b/testing/integration-tests/src/full_client/runtime_api/mod.rs @@ -7,7 +7,7 @@ use codec::Encode; use subxt::utils::AccountId32; use subxt_signer::sr25519::dev; -#[subxt_test(timeout = 800)] +#[subxt_test] async fn account_nonce() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); @@ -49,7 +49,7 @@ async fn account_nonce() -> Result<(), subxt::Error> { Ok(()) } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn unchecked_extrinsic_encoding() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); diff --git a/testing/integration-tests/src/full_client/storage/mod.rs b/testing/integration-tests/src/full_client/storage/mod.rs index d52bdd5f2a..cf05042683 100644 --- a/testing/integration-tests/src/full_client/storage/mod.rs +++ b/testing/integration-tests/src/full_client/storage/mod.rs @@ -9,7 +9,7 @@ use subxt::utils::AccountId32; #[cfg(fullclient)] use subxt_signer::sr25519::dev; -#[subxt_test(timeout = 800)] +#[subxt_test] async fn storage_plain_lookup() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); @@ -31,7 +31,7 @@ async fn storage_plain_lookup() -> Result<(), subxt::Error> { } #[cfg(fullclient)] -#[subxt_test(timeout = 800)] +#[subxt_test] async fn storage_map_lookup() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); @@ -65,7 +65,7 @@ async fn storage_map_lookup() -> Result<(), subxt::Error> { // treated as a StorageKey (ie we should hash both values together with one hasher, rather // than hash both values separately, or ignore the second value). #[cfg(fullclient)] -#[subxt_test(timeout = 800)] +#[subxt_test] async fn storage_n_mapish_key_is_properly_created() -> Result<(), subxt::Error> { use codec::Encode; use node_runtime::runtime_types::sp_core::crypto::KeyTypeId; @@ -96,7 +96,7 @@ async fn storage_n_mapish_key_is_properly_created() -> Result<(), subxt::Error> } #[cfg(fullclient)] -#[subxt_test(timeout = 800)] +#[subxt_test] async fn storage_n_map_storage_lookup() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); @@ -133,7 +133,7 @@ async fn storage_n_map_storage_lookup() -> Result<(), subxt::Error> { } #[cfg(fullclient)] -#[subxt_test(timeout = 800)] +#[subxt_test] async fn storage_partial_lookup() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); @@ -206,7 +206,7 @@ async fn storage_partial_lookup() -> Result<(), subxt::Error> { Ok(()) } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn storage_runtime_wasm_code() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); @@ -215,7 +215,7 @@ async fn storage_runtime_wasm_code() -> Result<(), subxt::Error> { Ok(()) } -#[subxt_test(timeout = 800)] +#[subxt_test] async fn storage_pallet_storage_version() -> Result<(), subxt::Error> { let ctx = test_context().await; let api = ctx.client(); From 4c3226e70a5da3a961ec5a76d87d9941181a1710 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 5 Mar 2024 15:30:51 +0200 Subject: [PATCH 22/42] light-client: Remove println Signed-off-by: Alexandru Vasile --- subxt/src/client/light_client/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/subxt/src/client/light_client/mod.rs b/subxt/src/client/light_client/mod.rs index 6881e6ac76..121fadcdab 100644 --- a/subxt/src/client/light_client/mod.rs +++ b/subxt/src/client/light_client/mod.rs @@ -103,7 +103,6 @@ impl RawLightClient { if let Err(e) = val { // This is a test; bail if something does wrong and try to // ensure that the message makes it to some logs. - eprintln!("Error driving unstable backend in tests (will panic): {e}"); panic!("Error driving unstable backend in tests: {e}"); } } From fbe2a7498be9834dfec131b63b81359713fe37ca Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 5 Mar 2024 18:00:21 +0200 Subject: [PATCH 23/42] subxt: Remove tokio as dependency, use it only for testing Signed-off-by: Alexandru Vasile --- Cargo.lock | 1 + subxt/Cargo.toml | 4 +- subxt/src/client/light_client/mod.rs | 56 ++++++++++++++++++---------- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d830a09f7c..3b7cefb4ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4547,6 +4547,7 @@ dependencies = [ "tracing", "tracing-subscriber 0.3.18", "url", + "wasm-bindgen-futures", ] [[package]] diff --git a/subxt/Cargo.toml b/subxt/Cargo.toml index f06bd9dd63..9b927ed1db 100644 --- a/subxt/Cargo.toml +++ b/subxt/Cargo.toml @@ -61,7 +61,7 @@ unstable-metadata = [] # Activate this to expose the Light Client functionality. # Note that this feature is experimental and things may break or not work as expected. -unstable-light-client = ["subxt-lightclient", "tokio-stream", "tokio"] +unstable-light-client = ["subxt-lightclient", "tokio-stream"] [dependencies] async-trait = { workspace = true } @@ -117,7 +117,6 @@ getrandom = { workspace = true, optional = true } # Included if "native" feature is enabled tokio-util = { workspace = true, features = ["compat"], optional = true } -tokio = { workspace = true, features = ["macros", "time", "rt-multi-thread"], optional = true } [dev-dependencies] bitvec = { workspace = true } @@ -129,6 +128,7 @@ sp-keyring = { workspace = true } sp-runtime = { workspace = true } assert_matches = { workspace = true } subxt-signer = { path = "../signer" } +wasm-bindgen-futures = { workspace = true } # Tracing subscriber is useful for light-client examples to ensure that # the `bootNodes` and chain spec are configured correctly. If all is fine, then # the light-client wlll emit INFO logs with diff --git a/subxt/src/client/light_client/mod.rs b/subxt/src/client/light_client/mod.rs index 121fadcdab..4eeb58da18 100644 --- a/subxt/src/client/light_client/mod.rs +++ b/subxt/src/client/light_client/mod.rs @@ -94,27 +94,43 @@ impl RawLightClient { let raw_rpc = self.raw_rpc.for_chain(chain_id); let rpc_client = RpcClient::new(raw_rpc.clone()); - use crate::backend::unstable::UnstableBackend; - use std::sync::Arc; - let (backend, mut driver) = UnstableBackend::builder().build(rpc_client); - let future = async move { - use futures::StreamExt; - while let Some(val) = driver.next().await { - if let Err(e) = val { - // This is a test; bail if something does wrong and try to - // ensure that the message makes it to some logs. - panic!("Error driving unstable backend in tests: {e}"); + // Production code should use the legacy backend. + #[cfg(not(test))] + async fn build_online_client( + rpc_client: RpcClient, + ) -> Result, crate::Error> { + OnlineClient::::from_rpc_client(rpc_client).await + } + + // For testing we are only interested in using the unstable-backend with + // the lightclient. + #[cfg(test)] + async fn build_online_client( + rpc_client: RpcClient, + ) -> Result, crate::Error> { + use crate::backend::unstable::UnstableBackend; + use std::sync::Arc; + let (backend, mut driver) = UnstableBackend::builder().build(rpc_client); + let future = async move { + use futures::StreamExt; + while let Some(val) = driver.next().await { + if let Err(e) = val { + // This is a test; bail if something does wrong and try to + // ensure that the message makes it to some logs. + panic!("Error driving unstable backend in tests: {e}"); + } } - } - }; - // The unstable backend needs driving: - #[cfg(feature = "native")] - tokio::spawn(future); - #[cfg(feature = "web")] - wasm_bindgen_futures::spawn_local(future); - let client = OnlineClient::from_backend(Arc::new(backend)) - .await - .map_err(|e| format!("Cannot construct OnlineClient from backend: {e}"))?; + }; + // The unstable backend needs driving: + #[cfg(feature = "native")] + tokio::spawn(future); + #[cfg(feature = "web")] + wasm_bindgen_futures::spawn_local(future); + + OnlineClient::from_backend(Arc::new(backend)).await + } + + let client = build_online_client(rpc_client).await?; Ok(LightClient { client, chain_id }) } From 30073d3c6b386b959c351597d71b22a687a80a2f Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 5 Mar 2024 18:03:57 +0200 Subject: [PATCH 24/42] testing: Chagne default timeout to 6 seconds Signed-off-by: Alexandru Vasile --- testing/integration-tests/proc-macro/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/integration-tests/proc-macro/src/lib.rs b/testing/integration-tests/proc-macro/src/lib.rs index edc9a6b7e3..2ca2ce4aa6 100644 --- a/testing/integration-tests/proc-macro/src/lib.rs +++ b/testing/integration-tests/proc-macro/src/lib.rs @@ -17,7 +17,7 @@ pub fn subxt_test(attr: TokenStream, item: TokenStream) -> TokenStream { Ok(subxt_attr) => subxt_attr, Err(err) => return err.into_compile_error().into(), }; - let timeout_duration = subxt_attr.timeout.unwrap_or(60 * 5); + let timeout_duration = subxt_attr.timeout.unwrap_or(60 * 6); let func: syn::ItemFn = match syn::parse(item) { Ok(func) => func, From aa55ceaa549fd2bfce36a14153e11dba8d0326e6 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 6 Mar 2024 15:43:04 +0200 Subject: [PATCH 25/42] proc-macro: Add env timeout variable Signed-off-by: Alexandru Vasile --- testing/integration-tests/proc-macro/src/lib.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/testing/integration-tests/proc-macro/src/lib.rs b/testing/integration-tests/proc-macro/src/lib.rs index 2ca2ce4aa6..d102643ddc 100644 --- a/testing/integration-tests/proc-macro/src/lib.rs +++ b/testing/integration-tests/proc-macro/src/lib.rs @@ -11,13 +11,28 @@ use syn::{ Error, }; +/// Environment variable for setting the timeout for the test. +const SUBXT_TEST_TIMEOUT: &str = "SUBXT_TEST_TIMEOUT"; + +/// Default timeout for the test. +const DEFAULT_TIMEOUT: u64 = 60 * 6; + #[proc_macro_attribute] pub fn subxt_test(attr: TokenStream, item: TokenStream) -> TokenStream { let subxt_attr = match syn::parse::(attr) { Ok(subxt_attr) => subxt_attr, Err(err) => return err.into_compile_error().into(), }; - let timeout_duration = subxt_attr.timeout.unwrap_or(60 * 6); + + // Timeout is determined by: + // - The timeout attribute if it is set. + // - The SUBXT_TEST_TIMEOUT environment variable if it is set. + // - A default of 6 minutes. + let timeout_duration = subxt_attr.timeout.unwrap_or_else(|| { + std::env::var(SUBXT_TEST_TIMEOUT) + .map(|str| str.parse().unwrap_or(DEFAULT_TIMEOUT)) + .unwrap_or(DEFAULT_TIMEOUT) + }); let func: syn::ItemFn = match syn::parse(item) { Ok(func) => func, From 09277fe51a3e055b1189d4103dc94d23cee9659f Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 6 Mar 2024 15:44:50 +0200 Subject: [PATCH 26/42] ci: Add subxt env var for controling test timeouts Signed-off-by: Alexandru Vasile --- .github/workflows/rust.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1dcdcfb880..ea8fd2cb13 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -369,6 +369,10 @@ jobs: runs-on: ubuntu-latest-16-cores # needs: [clippy, wasm_clippy, check, wasm_check, docs] timeout-minutes: 60 + env: + # Set timeout for subxt tests. Light client needs to syncup properly. + # Per test we timeout after 15mins, more than enough for a single test. + SUBXT_TEST_TIMEOUT: 900 steps: - name: Checkout sources uses: actions/checkout@v4 From 5039f1cccb2bc141392c29591fab1cc23694fae3 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 6 Mar 2024 16:25:20 +0200 Subject: [PATCH 27/42] tests/tx-retries: Retry on `Non node available` error Signed-off-by: Alexandru Vasile --- testing/integration-tests/src/utils/tx_retries.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/testing/integration-tests/src/utils/tx_retries.rs b/testing/integration-tests/src/utils/tx_retries.rs index 800222a455..074db64a5e 100644 --- a/testing/integration-tests/src/utils/tx_retries.rs +++ b/testing/integration-tests/src/utils/tx_retries.rs @@ -22,6 +22,8 @@ where .await }; + const RETRY_TIME: u64 = 5; + #[cfg(lightclient)] for _ in 0..2 { let result = submit().await; @@ -29,8 +31,17 @@ where match result { Ok(tx_in_block) => return Ok(tx_in_block), Err(subxt::Error::Transaction(subxt::error::TransactionError::Dropped(_))) => { + tracing::info!("Transaction was dropped, retrying..."); // Retry if the transaction was dropped. - tokio::time::sleep(std::time::Duration::from_secs(5)).await; + tokio::time::sleep(std::time::Duration::from_secs(RETRY_TIME)).await; + } + Err(subxt::Error::Rpc(subxt::error::RpcError::ClientError(err))) + if err.to_string().contains("No node available") => + { + tracing::info!("Transaction error: {}, retrying...", err.to_string()); + + // Retry if the client is not connected. + tokio::time::sleep(std::time::Duration::from_secs(RETRY_TIME)).await; } Err(other) => return Err(other), } From d81c70cd1fb7ba9ce540413181da9eaa3c1aa705 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 26 Mar 2024 18:06:57 +0200 Subject: [PATCH 28/42] testing: Use unstable backend for testing lightclient Signed-off-by: Alexandru Vasile --- testing/integration-tests/src/utils/node_proc.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/testing/integration-tests/src/utils/node_proc.rs b/testing/integration-tests/src/utils/node_proc.rs index c49d5edb6a..76588427c6 100644 --- a/testing/integration-tests/src/utils/node_proc.rs +++ b/testing/integration-tests/src/utils/node_proc.rs @@ -254,9 +254,5 @@ async fn build_light_client(proc: &SubstrateNode) -> Result Date: Tue, 26 Mar 2024 18:08:13 +0200 Subject: [PATCH 29/42] testing: Remove old lightclient object Signed-off-by: Alexandru Vasile --- Cargo.lock | 20 ++++++++++++++++++- .../integration-tests/src/utils/context.rs | 11 +--------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f374c7f25a..bb5e10fc68 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -758,6 +758,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e53693616d3075149f4ead59bdeecd204ac6b8192d8969757601b74bddf00f" + [[package]] name = "chacha20" version = "0.9.1" @@ -2259,6 +2265,7 @@ name = "integration-tests" version = "0.35.0" dependencies = [ "assert_matches", + "cfg_aliases", "frame-metadata 16.0.0", "futures", "hex", @@ -2272,6 +2279,7 @@ dependencies = [ "subxt-codegen", "subxt-metadata", "subxt-signer", + "subxt-test-proc-macro", "syn 2.0.53", "test-runtime", "tokio", @@ -2816,7 +2824,7 @@ checksum = "4e69bf016dc406eff7d53a7d3f7cf1c2e72c82b9088aac1118591e36dd2cd3e9" dependencies = [ "bitcoin_hashes 0.13.0", "rand", - "rand_core 0.5.1", + "rand_core 0.6.4", "serde", "unicode-normalization", ] @@ -4649,6 +4657,7 @@ dependencies = [ "tracing", "tracing-subscriber 0.3.18", "url", + "wasm-bindgen-futures", ] [[package]] @@ -4777,6 +4786,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "subxt-test-proc-macro" +version = "0.35.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.53", +] + [[package]] name = "syn" version = "1.0.109" diff --git a/testing/integration-tests/src/utils/context.rs b/testing/integration-tests/src/utils/context.rs index 2ad0d8edfb..e987763eb3 100644 --- a/testing/integration-tests/src/utils/context.rs +++ b/testing/integration-tests/src/utils/context.rs @@ -4,13 +4,8 @@ pub(crate) use crate::{node_runtime, utils::TestNodeProcess}; -use subxt::SubstrateConfig; - -#[cfg(lightclient)] -use subxt::client::LightClient; - -#[cfg(fullclient)] use subxt::client::OnlineClient; +use subxt::SubstrateConfig; /// `substrate-node` should be installed on the $PATH. We fall back /// to also checking for an older `substrate` binary. @@ -30,12 +25,8 @@ pub type TestConfig = SubstrateConfig; pub type TestContext = TestNodeProcess; -#[cfg(fullclient)] pub type TestClient = OnlineClient; -#[cfg(lightclient)] -pub type TestClient = LightClient; - pub async fn test_context() -> TestContext { test_context_with("alice".to_string()).await } From 03da9046c90e9c4cd0ffe30ade7e6f71dff93c7a Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 26 Mar 2024 18:18:55 +0200 Subject: [PATCH 30/42] testing: Adjust for the new interface Signed-off-by: Alexandru Vasile --- testing/integration-tests/src/full_client/blocks/mod.rs | 3 --- testing/integration-tests/src/full_client/client/mod.rs | 3 --- .../src/full_client/client/unstable_rpcs.rs | 3 --- testing/integration-tests/src/full_client/frame/balances.rs | 3 --- .../integration-tests/src/full_client/metadata/validation.rs | 3 --- testing/integration-tests/src/utils/node_proc.rs | 5 ++--- 6 files changed, 2 insertions(+), 18 deletions(-) diff --git a/testing/integration-tests/src/full_client/blocks/mod.rs b/testing/integration-tests/src/full_client/blocks/mod.rs index d0ef601a38..0adb87395c 100644 --- a/testing/integration-tests/src/full_client/blocks/mod.rs +++ b/testing/integration-tests/src/full_client/blocks/mod.rs @@ -6,9 +6,6 @@ use crate::{subxt_test, test_context}; use codec::{Compact, Encode}; use futures::StreamExt; -#[cfg(lightclient)] -use subxt::client::OnlineClientT; - #[cfg(fullclient)] use crate::utils::node_runtime; #[cfg(fullclient)] diff --git a/testing/integration-tests/src/full_client/client/mod.rs b/testing/integration-tests/src/full_client/client/mod.rs index 246191a280..954546d028 100644 --- a/testing/integration-tests/src/full_client/client/mod.rs +++ b/testing/integration-tests/src/full_client/client/mod.rs @@ -11,9 +11,6 @@ use codec::{Decode, Encode}; #[cfg(fullclient)] use futures::StreamExt; -#[cfg(lightclient)] -use subxt::client::OnlineClientT; - use subxt::{ backend::BackendExt, error::{DispatchError, Error}, diff --git a/testing/integration-tests/src/full_client/client/unstable_rpcs.rs b/testing/integration-tests/src/full_client/client/unstable_rpcs.rs index f87aff9ff5..71cff65f0a 100644 --- a/testing/integration-tests/src/full_client/client/unstable_rpcs.rs +++ b/testing/integration-tests/src/full_client/client/unstable_rpcs.rs @@ -19,9 +19,6 @@ use subxt::{ SubstrateConfig, }; -#[cfg(lightclient)] -use subxt::client::OfflineClientT; - use subxt_signer::sr25519::dev; #[subxt_test] diff --git a/testing/integration-tests/src/full_client/frame/balances.rs b/testing/integration-tests/src/full_client/frame/balances.rs index 52d9fab7b3..5ed4f6423e 100644 --- a/testing/integration-tests/src/full_client/frame/balances.rs +++ b/testing/integration-tests/src/full_client/frame/balances.rs @@ -13,9 +13,6 @@ use subxt::{ }; use subxt_signer::sr25519::dev; -#[cfg(lightclient)] -use subxt::client::OfflineClientT; - #[subxt_test] async fn tx_basic_transfer() -> Result<(), subxt::Error> { let alice = dev::alice(); diff --git a/testing/integration-tests/src/full_client/metadata/validation.rs b/testing/integration-tests/src/full_client/metadata/validation.rs index 4b3e531efd..6fbda7bbe8 100644 --- a/testing/integration-tests/src/full_client/metadata/validation.rs +++ b/testing/integration-tests/src/full_client/metadata/validation.rs @@ -14,9 +14,6 @@ use scale_info::{ }; use subxt::{Metadata, OfflineClient, SubstrateConfig}; -#[cfg(lightclient)] -use subxt::client::OfflineClientT; - async fn metadata_to_api(metadata: Metadata, ctx: &TestContext) -> OfflineClient { OfflineClient::new( ctx.client().genesis_hash(), diff --git a/testing/integration-tests/src/utils/node_proc.rs b/testing/integration-tests/src/utils/node_proc.rs index 76588427c6..08b35e60fd 100644 --- a/testing/integration-tests/src/utils/node_proc.rs +++ b/testing/integration-tests/src/utils/node_proc.rs @@ -228,12 +228,11 @@ async fn build_light_client(proc: &SubstrateNode) -> Result(proc: &SubstrateNode) -> Result Date: Wed, 27 Mar 2024 18:10:02 +0200 Subject: [PATCH 31/42] backend/rpc: Allow older version of the initialized event Signed-off-by: Alexandru Vasile --- subxt/src/backend/unstable/rpc_methods.rs | 29 ++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/subxt/src/backend/unstable/rpc_methods.rs b/subxt/src/backend/unstable/rpc_methods.rs index fd2a1dcf9c..3da380c35c 100644 --- a/subxt/src/backend/unstable/rpc_methods.rs +++ b/subxt/src/backend/unstable/rpc_methods.rs @@ -11,7 +11,7 @@ use crate::config::BlockHash; use crate::{Config, Error}; use derivative::Derivative; use futures::{Stream, StreamExt}; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Deserializer, Serialize}; use std::collections::{HashMap, VecDeque}; use std::task::Poll; @@ -378,8 +378,7 @@ pub enum FollowEvent { /// /// This is the first event generated by the `follow` subscription /// and is submitted only once. -#[derive(Debug, Clone, PartialEq, Eq, Deserialize)] -#[serde(rename_all = "camelCase")] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct Initialized { /// The hashes of the last finalized blocks. pub finalized_block_hashes: Vec, @@ -392,6 +391,30 @@ pub struct Initialized { pub finalized_block_runtime: Option, } +impl<'de, Hash: Deserialize<'de>> Deserialize<'de> for Initialized { + fn deserialize>(deserializer: D) -> Result { + // Custom struct that can deserialize both `finalizedBlockHash` and `finalizedBlockHashes`. + #[derive(Debug, Clone, PartialEq, Eq, Deserialize)] + #[serde(rename_all = "camelCase")] + struct InitializedIR { + finalized_block_hashes: Option>, + finalized_block_hash: Option, + finalized_block_runtime: Option, + } + + let ir = InitializedIR::deserialize(deserializer)?; + let finalized_block_hashes = ir + .finalized_block_hashes + .or_else(|| ir.finalized_block_hash.map(|hash| vec![hash])) + .ok_or_else(|| serde::de::Error::custom("Missing finalized block hashes"))?; + + Ok(Initialized { + finalized_block_hashes, + finalized_block_runtime: ir.finalized_block_runtime, + }) + } +} + /// The runtime event generated if the `follow` subscription /// has set the `with_runtime` flag. #[derive(Debug, Clone, PartialEq, Eq, Deserialize)] From 2bc8947617bfc2f1b6aa4ee30c10cf32a43fc82e Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 28 Mar 2024 13:42:19 +0200 Subject: [PATCH 32/42] rpc/tests: Check initialized decodes correctly Signed-off-by: Alexandru Vasile --- subxt/src/backend/unstable/rpc_methods.rs | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/subxt/src/backend/unstable/rpc_methods.rs b/subxt/src/backend/unstable/rpc_methods.rs index 3da380c35c..da7bc015c0 100644 --- a/subxt/src/backend/unstable/rpc_methods.rs +++ b/subxt/src/backend/unstable/rpc_methods.rs @@ -997,4 +997,30 @@ mod test { let _ = serde_json::from_value::(from_err) .expect_err("can't deser invalid num into u32"); } + + #[test] + fn chain_head_initialized() { + // Latest format version. + let event = serde_json::json!({ + "finalizedBlockHashes": ["0x1", "0x2"], + }); + let decoded: Initialized = serde_json::from_value(event).unwrap(); + assert_eq!( + decoded.finalized_block_hashes, + vec!["0x1".to_string(), "0x2".to_string()] + ); + + // Old format. + let event = serde_json::json!({ + "finalizedBlockHash": "0x1", + }); + let decoded: Initialized = serde_json::from_value(event).unwrap(); + assert_eq!(decoded.finalized_block_hashes, vec!["0x1".to_string()]); + + // Wrong format. + let event = serde_json::json!({ + "finalizedBlockHash": ["0x1"], + }); + let _ = serde_json::from_value::>(event).unwrap_err(); + } } From 811f70c70e1a49750f8e7e2342b87f60e4f635c8 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 28 Mar 2024 13:47:10 +0200 Subject: [PATCH 33/42] ci: Reset workflow Signed-off-by: Alexandru Vasile --- .github/workflows/rust.yml | 845 ++++++++++++++++++------------------- 1 file changed, 405 insertions(+), 440 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index ea8fd2cb13..0f1843ca69 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -22,357 +22,322 @@ env: WASM_BINDGEN_TEST_TIMEOUT: 60 jobs: - # fmt: - # name: Cargo fmt - # runs-on: ubuntu-latest - # steps: - # - name: Checkout sources - # uses: actions/checkout@v4 - - # - name: Install Rust nightly toolchain - # uses: actions-rs/toolchain@v1 - # with: - # profile: minimal - # toolchain: stable - # override: true - # components: rustfmt - - # - name: Rust Cache - # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - # - name: Cargo fmt - # uses: actions-rs/cargo@v1.0.3 - # with: - # command: fmt - # args: --all -- --check - - # - if: "failure()" - # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 - - # machete: - # name: "Check unused dependencies" - # runs-on: ubuntu-latest - # steps: - # - name: Checkout sources - # uses: actions/checkout@v4 - - # - name: Use substrate and polkadot node binaries - # uses: ./.github/workflows/actions/use-nodes - - # - name: Install Rust stable toolchain - # uses: actions-rs/toolchain@v1 - # with: - # profile: minimal - # toolchain: stable - # override: true - - # - name: Rust Cache - # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - # - name: Install cargo-machete - # run: cargo install cargo-machete - - # - name: Check unused dependencies - # uses: actions-rs/cargo@v1.0.3 - # with: - # command: machete - - # - if: "failure()" - # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 - - # clippy: - # name: Cargo clippy - # runs-on: ubuntu-latest - # needs: [fmt, machete] - # steps: - # - name: Checkout sources - # uses: actions/checkout@v4 - - # - name: Use substrate and polkadot node binaries - # uses: ./.github/workflows/actions/use-nodes - - # - name: Install Rust stable toolchain - # uses: actions-rs/toolchain@v1 - # with: - # profile: minimal - # toolchain: stable - # components: clippy - # override: true - - # - name: Rust Cache - # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - # - name: Run clippy - # run: | - # cargo clippy --all-targets --features unstable-light-client -- -D warnings - # cargo clippy -p subxt-lightclient --no-default-features --features web -- -D warnings - # cargo clippy -p subxt --no-default-features --features web -- -D warnings - # cargo clippy -p subxt --no-default-features --features web,unstable-light-client -- -D warnings - - # - if: "failure()" - # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 - - # wasm_clippy: - # name: Cargo clippy (WASM) - # runs-on: ubuntu-latest - # needs: [fmt, machete] - # steps: - # - name: Checkout sources - # uses: actions/checkout@v4 - - # - name: Use substrate and polkadot node binaries - # uses: ./.github/workflows/actions/use-nodes - - # - name: Install Rust stable toolchain - # uses: actions-rs/toolchain@v1 - # with: - # profile: minimal - # toolchain: stable - # target: wasm32-unknown-unknown - # override: true - - # - name: Rust Cache - # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - # - name: Run clippy - # uses: actions-rs/cargo@v1 - # with: - # command: clippy - # args: -p subxt --no-default-features --features web,unstable-light-client,jsonrpsee --target wasm32-unknown-unknown -- -D warnings - - # - if: "failure()" - # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 - - # check: - # name: Cargo check - # runs-on: ubuntu-latest - # needs: [fmt, machete] - # steps: - # - name: Checkout sources - # uses: actions/checkout@v4 - - # - name: Use substrate and polkadot node binaries - # uses: ./.github/workflows/actions/use-nodes - - # - name: Install Rust stable toolchain - # uses: actions-rs/toolchain@v1 - # with: - # profile: minimal - # toolchain: stable - # override: true - - # - name: Rust Cache - # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - # - name: Install cargo-hack - # uses: baptiste0928/cargo-install@v3 - # with: - # crate: cargo-hack - # version: 0.5 - - # # A basic check over all targets together. This may lead to features being combined etc, - # # and doesn't test combinations of different features. - # - name: Cargo check all targets. - # run: cargo check --all-targets - - # # Next, check subxt features. - # # - `native` feature must always be enabled - # # - `web` feature is always ignored. - # # - This means, don't check --no-default-features and don't try enabling --all-features; both will fail - # - name: Cargo hack; check each subxt feature - # run: cargo hack -p subxt --each-feature check --exclude-no-default-features --exclude-all-features --exclude-features web --features native - - # # Subxt-signer has the "subxt" features enabled in the "check all targets" test. Run it on its own to - # # check it without. We can't enable subxt or web features here, so no cargo hack. - # - name: Cargo check subxt-signer - # run: | - # cargo check -p subxt-signer - # cargo check -p subxt-signer --no-default-features --features sr25519,native - # cargo check -p subxt-signer --no-default-features --features ecdsa,native - - # # We can't enable web features here, so no cargo hack. - # - name: Cargo check subxt-lightclient - # run: cargo check -p subxt-lightclient - - # # Next, check each other package in isolation. - # - name: Cargo hack; check each feature/crate on its own - # run: cargo hack --exclude subxt --exclude subxt-signer --exclude subxt-lightclient --exclude-all-features --each-feature check --workspace - - # # Check the parachain-example code, which isn't a part of the workspace so is otherwise ignored. - # - name: Cargo check parachain-example - # run: cargo check --manifest-path examples/parachain-example/Cargo.toml - - # - if: "failure()" - # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 - - # wasm_check: - # name: Cargo check (WASM) - # runs-on: ubuntu-latest - # needs: [fmt, machete] - # steps: - # - name: Checkout sources - # uses: actions/checkout@v4 - - # - name: Install Rust stable toolchain - # uses: actions-rs/toolchain@v1 - # with: - # profile: minimal - # toolchain: stable - # target: wasm32-unknown-unknown - # override: true - - # - name: Rust Cache - # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - # # Check WASM examples, which aren't a part of the workspace and so are otherwise missed: - # - name: Cargo check WASM examples - # run: | - # cargo check --manifest-path examples/wasm-example/Cargo.toml --target wasm32-unknown-unknown - - # - if: "failure()" - # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 - - # docs: - # name: Check documentation and run doc tests - # runs-on: ubuntu-latest - # needs: [fmt, machete] - # steps: - # - name: Checkout sources - # uses: actions/checkout@v4 - - # - name: Use substrate and polkadot node binaries - # uses: ./.github/workflows/actions/use-nodes - - # - name: Install Rust stable toolchain - # uses: actions-rs/toolchain@v1 - # with: - # profile: minimal - # toolchain: stable - # override: true - - # - name: Rust Cache - # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - # - name: Check internal documentation links - # run: RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc -vv --workspace --no-deps --document-private-items - - # - name: Run cargo test on documentation - # uses: actions-rs/cargo@v1.0.3 - # with: - # command: test - # args: --doc - - # - if: "failure()" - # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 - - # tests: - # name: "Test (Native)" - # runs-on: ubuntu-latest-16-cores - # needs: [clippy, wasm_clippy, check, wasm_check, docs] - # timeout-minutes: 30 - # steps: - # - name: Checkout sources - # uses: actions/checkout@v4 - - # - name: Use substrate and polkadot node binaries - # uses: ./.github/workflows/actions/use-nodes - - # - name: Install Rust stable toolchain - # uses: actions-rs/toolchain@v1 - # with: - # profile: minimal - # toolchain: stable - # override: true - - # - name: Rust Cache - # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - # - name: Install cargo-nextest - # run: cargo install cargo-nextest - - # - name: Run tests - # uses: actions-rs/cargo@v1.0.3 - # with: - # command: nextest - # args: run --workspace - - # - if: "failure()" - # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 - - # unstable_backend_tests: - # name: "Test (Unstable Backend)" - # runs-on: ubuntu-latest-16-cores - # needs: [clippy, wasm_clippy, check, wasm_check, docs] - # timeout-minutes: 30 - # steps: - # - name: Checkout sources - # uses: actions/checkout@v4 - - # - name: Use substrate and polkadot node binaries - # uses: ./.github/workflows/actions/use-nodes - - # - name: Install Rust stable toolchain - # uses: actions-rs/toolchain@v1 - # with: - # profile: minimal - # toolchain: stable - # override: true - - # - name: Rust Cache - # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - # - name: Install cargo-nextest - # run: cargo install cargo-nextest - - # - name: Run tests - # uses: actions-rs/cargo@v1.0.3 - # with: - # command: nextest - # args: run --workspace --features unstable-backend-client - - # - if: "failure()" - # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 - - # light_client_tests: - # name: "Test (Light Client)" - # runs-on: ubuntu-latest - # needs: [clippy, wasm_clippy, check, wasm_check, docs] - # timeout-minutes: 15 - # steps: - # - name: Checkout sources - # uses: actions/checkout@v4 - - # - name: Use substrate and polkadot node binaries - # uses: ./.github/workflows/actions/use-nodes - - # - name: Install Rust stable toolchain - # uses: actions-rs/toolchain@v1 - # with: - # profile: minimal - # toolchain: stable - # override: true - - # - name: Rust Cache - # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - # - name: Run tests - # uses: actions-rs/cargo@v1.0.3 - # with: - # command: test - # args: --release --package integration-tests --features unstable-light-client - - # - if: "failure()" - # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 - - light_client_long_running_tests: - name: "Test (Light Client Long Running)" + fmt: + name: Cargo fmt + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install Rust nightly toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + components: rustfmt + + - name: Rust Cache + uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + - name: Cargo fmt + uses: actions-rs/cargo@v1.0.3 + with: + command: fmt + args: --all -- --check + + - if: "failure()" + uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + + machete: + name: "Check unused dependencies" + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Use substrate and polkadot node binaries + uses: ./.github/workflows/actions/use-nodes + + - name: Install Rust stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Rust Cache + uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + - name: Install cargo-machete + run: cargo install cargo-machete + + - name: Check unused dependencies + uses: actions-rs/cargo@v1.0.3 + with: + command: machete + + - if: "failure()" + uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + + clippy: + name: Cargo clippy + runs-on: ubuntu-latest + needs: [fmt, machete] + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Use substrate and polkadot node binaries + uses: ./.github/workflows/actions/use-nodes + + - name: Install Rust stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + components: clippy + override: true + + - name: Rust Cache + uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + - name: Run clippy + run: | + cargo clippy --all-targets --features unstable-light-client -- -D warnings + cargo clippy -p subxt-lightclient --no-default-features --features web -- -D warnings + cargo clippy -p subxt --no-default-features --features web -- -D warnings + cargo clippy -p subxt --no-default-features --features web,unstable-light-client -- -D warnings + + - if: "failure()" + uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + + wasm_clippy: + name: Cargo clippy (WASM) + runs-on: ubuntu-latest + needs: [fmt, machete] + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Use substrate and polkadot node binaries + uses: ./.github/workflows/actions/use-nodes + + - name: Install Rust stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + target: wasm32-unknown-unknown + override: true + + - name: Rust Cache + uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + - name: Run clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + args: -p subxt --no-default-features --features web,unstable-light-client,jsonrpsee --target wasm32-unknown-unknown -- -D warnings + + - if: "failure()" + uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + + check: + name: Cargo check + runs-on: ubuntu-latest + needs: [fmt, machete] + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Use substrate and polkadot node binaries + uses: ./.github/workflows/actions/use-nodes + + - name: Install Rust stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Rust Cache + uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + - name: Install cargo-hack + uses: baptiste0928/cargo-install@v3 + with: + crate: cargo-hack + version: 0.5 + + # A basic check over all targets together. This may lead to features being combined etc, + # and doesn't test combinations of different features. + - name: Cargo check all targets. + run: cargo check --all-targets + + # Next, check subxt features. + # - `native` feature must always be enabled + # - `web` feature is always ignored. + # - This means, don't check --no-default-features and don't try enabling --all-features; both will fail + - name: Cargo hack; check each subxt feature + run: cargo hack -p subxt --each-feature check --exclude-no-default-features --exclude-all-features --exclude-features web --features native + + # Subxt-signer has the "subxt" features enabled in the "check all targets" test. Run it on its own to + # check it without. We can't enable subxt or web features here, so no cargo hack. + - name: Cargo check subxt-signer + run: | + cargo check -p subxt-signer + cargo check -p subxt-signer --no-default-features --features sr25519 + cargo check -p subxt-signer --no-default-features --features ecdsa + + # We can't enable web features here, so no cargo hack. + - name: Cargo check subxt-lightclient + run: cargo check -p subxt-lightclient + + # Next, check each other package in isolation. + - name: Cargo hack; check each feature/crate on its own + run: cargo hack --exclude subxt --exclude subxt-signer --exclude subxt-lightclient --exclude-all-features --each-feature check --workspace + + # Check the parachain-example code, which isn't a part of the workspace so is otherwise ignored. + - name: Cargo check parachain-example + run: cargo check --manifest-path examples/parachain-example/Cargo.toml + + - if: "failure()" + uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + + wasm_check: + name: Cargo check (WASM) + runs-on: ubuntu-latest + needs: [fmt, machete] + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install Rust stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + target: wasm32-unknown-unknown + override: true + + - name: Rust Cache + uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + # Check WASM examples, which aren't a part of the workspace and so are otherwise missed: + - name: Cargo check WASM examples + run: | + cargo check --manifest-path examples/wasm-example/Cargo.toml --target wasm32-unknown-unknown + + - if: "failure()" + uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + + docs: + name: Check documentation and run doc tests + runs-on: ubuntu-latest + needs: [fmt, machete] + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Use substrate and polkadot node binaries + uses: ./.github/workflows/actions/use-nodes + + - name: Install Rust stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Rust Cache + uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + - name: Check internal documentation links + run: RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc -vv --workspace --no-deps --document-private-items + + - name: Run cargo test on documentation + uses: actions-rs/cargo@v1.0.3 + with: + command: test + args: --doc + + - if: "failure()" + uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + + tests: + name: "Test (Native)" runs-on: ubuntu-latest-16-cores - # needs: [clippy, wasm_clippy, check, wasm_check, docs] - timeout-minutes: 60 - env: - # Set timeout for subxt tests. Light client needs to syncup properly. - # Per test we timeout after 15mins, more than enough for a single test. - SUBXT_TEST_TIMEOUT: 900 + needs: [clippy, wasm_clippy, check, wasm_check, docs] + timeout-minutes: 30 + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Use substrate and polkadot node binaries + uses: ./.github/workflows/actions/use-nodes + + - name: Install Rust stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Rust Cache + uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + - name: Install cargo-nextest + run: cargo install cargo-nextest + + - name: Run tests + uses: actions-rs/cargo@v1.0.3 + with: + command: nextest + args: run --workspace + + - if: "failure()" + uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + + unstable_backend_tests: + name: "Test (Unstable Backend)" + runs-on: ubuntu-latest-16-cores + needs: [clippy, wasm_clippy, check, wasm_check, docs] + timeout-minutes: 30 + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Use substrate and polkadot node binaries + uses: ./.github/workflows/actions/use-nodes + + - name: Install Rust stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Rust Cache + uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + - name: Install cargo-nextest + run: cargo install cargo-nextest + + - name: Run tests + uses: actions-rs/cargo@v1.0.3 + with: + command: nextest + args: run --workspace --features unstable-backend-client + + - if: "failure()" + uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + + light_client_tests: + name: "Test (Light Client)" + runs-on: ubuntu-latest + needs: [clippy, wasm_clippy, check, wasm_check, docs] + timeout-minutes: 15 steps: - name: Checkout sources uses: actions/checkout@v4 @@ -394,97 +359,97 @@ jobs: uses: actions-rs/cargo@v1.0.3 with: command: test - args: --release --package integration-tests --features unstable-light-client-long-running + args: --release --package integration-tests --features unstable-light-client - if: "failure()" uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 - # wasm_tests: - # name: Test (WASM) - # runs-on: ubuntu-latest - # needs: [clippy, wasm_clippy, check, wasm_check, docs] - # timeout-minutes: 30 - # env: - # # Set timeout for wasm tests to be much bigger than the default 20 secs. - # WASM_BINDGEN_TEST_TIMEOUT: 300 - - # steps: - # - uses: actions/checkout@v4 - - # - name: Install wasm-pack - # run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh - - # - name: Install firefox - # uses: browser-actions/setup-firefox@latest - - # - name: Install chrome - # uses: browser-actions/setup-chrome@latest - - # - name: Rust Cache - # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - # - name: Use substrate and polkadot node binaries - # uses: ./.github/workflows/actions/use-nodes - - # - name: Run subxt WASM tests - # run: | - # # `listen-addr` is used to configure p2p to accept websocket connections instead of TCP. - # # `node-key` provides a deterministic p2p address. - # substrate-node --dev --node-key 0000000000000000000000000000000000000000000000000000000000000001 --listen-addr /ip4/0.0.0.0/tcp/30333/ws > /dev/null 2>&1 & - # wasm-pack test --headless --firefox - # wasm-pack test --headless --chrome - # pkill substrate-node - # working-directory: testing/wasm-rpc-tests - - # - name: Run subxt-lightclient WASM tests - # run: | - # # `listen-addr` is used to configure p2p to accept websocket connections instead of TCP. - # # `node-key` provides a deterministic p2p address. - # substrate-node --dev --node-key 0000000000000000000000000000000000000000000000000000000000000001 --listen-addr /ip4/0.0.0.0/tcp/30333/ws > /dev/null 2>&1 & - # wasm-pack test --headless --firefox - # wasm-pack test --headless --chrome - # pkill substrate-node - # working-directory: testing/wasm-lightclient-tests - - # - name: Run subxt-signer WASM tests - # run: | - # wasm-pack test --headless --firefox - # wasm-pack test --headless --chrome - # working-directory: signer/wasm-tests - - # - if: "failure()" - # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 - - # no-std-tests: - # name: "Test (no_std)" - # runs-on: ubuntu-latest - # needs: [machete, docs] - # timeout-minutes: 30 - # steps: - # - name: Checkout sources - # uses: actions/checkout@v4 - - # # Note: needs nighly toolchain because otherwise we cannot define custom lang-items. - # - name: Install Rust nightly toolchain - # uses: actions-rs/toolchain@v1 - # with: - # profile: minimal - # toolchain: nightly - # override: true - # target: thumbv7em-none-eabi - - # - name: Install the gcc-arm-none-eabi linker - # run: sudo apt install gcc-arm-none-eabi - - # - name: Rust Cache - # uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - # # Note: We currently do not have a way to run real tests in a `no_std` environment. - # # We can only make sure that they compile to ARM thumb ISA. - # # Running the binary and inspecting the output would require an actual machine with matching ISA or some sort of emulator. - # - name: Compile `no-std-tests` crate to `thumbv7em-none-eabi` target. - # run: cargo build --target thumbv7em-none-eabi - # working-directory: testing/no-std-tests - - # - if: "failure()" - # uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + wasm_tests: + name: Test (WASM) + runs-on: ubuntu-latest + needs: [clippy, wasm_clippy, check, wasm_check, docs] + timeout-minutes: 30 + env: + # Set timeout for wasm tests to be much bigger than the default 20 secs. + WASM_BINDGEN_TEST_TIMEOUT: 300 + + steps: + - uses: actions/checkout@v4 + + - name: Install wasm-pack + run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + + - name: Install firefox + uses: browser-actions/setup-firefox@latest + + - name: Install chrome + uses: browser-actions/setup-chrome@latest + + - name: Rust Cache + uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + - name: Use substrate and polkadot node binaries + uses: ./.github/workflows/actions/use-nodes + + - name: Run subxt WASM tests + run: | + # `listen-addr` is used to configure p2p to accept websocket connections instead of TCP. + # `node-key` provides a deterministic p2p address. + substrate-node --dev --node-key 0000000000000000000000000000000000000000000000000000000000000001 --listen-addr /ip4/0.0.0.0/tcp/30333/ws > /dev/null 2>&1 & + wasm-pack test --headless --firefox + wasm-pack test --headless --chrome + pkill substrate-node + working-directory: testing/wasm-rpc-tests + + - name: Run subxt-lightclient WASM tests + run: | + # `listen-addr` is used to configure p2p to accept websocket connections instead of TCP. + # `node-key` provides a deterministic p2p address. + substrate-node --dev --node-key 0000000000000000000000000000000000000000000000000000000000000001 --listen-addr /ip4/0.0.0.0/tcp/30333/ws > /dev/null 2>&1 & + wasm-pack test --headless --firefox + wasm-pack test --headless --chrome + pkill substrate-node + working-directory: testing/wasm-lightclient-tests + + - name: Run subxt-signer WASM tests + run: | + wasm-pack test --headless --firefox + wasm-pack test --headless --chrome + working-directory: signer/wasm-tests + + - if: "failure()" + uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 + + no-std-tests: + name: "Test (no_std)" + runs-on: ubuntu-latest + needs: [machete, docs] + timeout-minutes: 30 + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + # Note: needs nighly toolchain because otherwise we cannot define custom lang-items. + - name: Install Rust nightly toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + target: thumbv7em-none-eabi + + - name: Install the gcc-arm-none-eabi linker + run: sudo apt install gcc-arm-none-eabi + + - name: Rust Cache + uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + + # Note: We currently do not have a way to run real tests in a `no_std` environment. + # We can only make sure that they compile to ARM thumb ISA. + # Running the binary and inspecting the output would require an actual machine with matching ISA or some sort of emulator. + - name: Compile `no-std-tests` crate to `thumbv7em-none-eabi` target. + run: cargo build --target thumbv7em-none-eabi + working-directory: testing/no-std-tests + + - if: "failure()" + uses: "andymckay/cancel-action@271cfbfa11ca9222f7be99a47e8f929574549e0a" # v0.4 From 2bb8acb07fbe133615118430fb9f8dc15ee525a7 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 28 Mar 2024 13:48:21 +0200 Subject: [PATCH 34/42] Apply cargo fmt Signed-off-by: Alexandru Vasile --- testing/integration-tests/src/full_client/storage/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/testing/integration-tests/src/full_client/storage/mod.rs b/testing/integration-tests/src/full_client/storage/mod.rs index 64c66723b2..300260016c 100644 --- a/testing/integration-tests/src/full_client/storage/mod.rs +++ b/testing/integration-tests/src/full_client/storage/mod.rs @@ -60,7 +60,6 @@ async fn storage_map_lookup() -> Result<(), subxt::Error> { Ok(()) } - #[cfg(fullclient)] #[subxt_test] async fn storage_n_mapish_key_is_properly_created() -> Result<(), subxt::Error> { From 1fdd73447a956220ceb86cfd685db2fdb7433135 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 28 Mar 2024 13:53:38 +0200 Subject: [PATCH 35/42] Remove unused dep Signed-off-by: Alexandru Vasile --- Cargo.lock | 1 - testing/integration-tests/proc-macro/Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bb5e10fc68..166c8f69ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4790,7 +4790,6 @@ dependencies = [ name = "subxt-test-proc-macro" version = "0.35.0" dependencies = [ - "proc-macro2", "quote", "syn 2.0.53", ] diff --git a/testing/integration-tests/proc-macro/Cargo.toml b/testing/integration-tests/proc-macro/Cargo.toml index 49e1467a41..0d55ee83e2 100644 --- a/testing/integration-tests/proc-macro/Cargo.toml +++ b/testing/integration-tests/proc-macro/Cargo.toml @@ -17,5 +17,4 @@ proc-macro = true [dependencies] syn = { workspace = true } -proc-macro2 = { workspace = true } quote = { workspace = true } From 56927032dc257a3a9c017ab47b27cf8afe6ea651 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 28 Mar 2024 14:10:51 +0200 Subject: [PATCH 36/42] Remove gitmerge old file Signed-off-by: Alexandru Vasile --- subxt/src/client/light_client/mod.rs | 231 --------------------------- 1 file changed, 231 deletions(-) delete mode 100644 subxt/src/client/light_client/mod.rs diff --git a/subxt/src/client/light_client/mod.rs b/subxt/src/client/light_client/mod.rs deleted file mode 100644 index 4eeb58da18..0000000000 --- a/subxt/src/client/light_client/mod.rs +++ /dev/null @@ -1,231 +0,0 @@ -// Copyright 2019-2023 Parity Technologies (UK) Ltd. -// This file is dual-licensed as Apache-2.0 or GPL-3.0. -// see LICENSE for license details. - -//! This module provides support for light clients. - -mod builder; -mod rpc; - -use crate::{ - backend::rpc::RpcClient, - blocks::BlocksClient, - client::{OfflineClientT, OnlineClientT}, - config::Config, - constants::ConstantsClient, - custom_values::CustomValuesClient, - events::EventsClient, - runtime_api::RuntimeApiClient, - storage::StorageClient, - tx::TxClient, - OnlineClient, -}; -pub use builder::{LightClientBuilder, RawLightClientBuilder}; -use derivative::Derivative; -use subxt_lightclient::LightClientRpcError; - -// Re-export smoldot related objects. -pub use subxt_lightclient::smoldot; - -/// Light client error. -#[derive(Debug, thiserror::Error)] -pub enum LightClientError { - /// Error originated from the low-level RPC layer. - #[error("Rpc error: {0}")] - Rpc(LightClientRpcError), - /// The background task is closed. - #[error("Failed to communicate with the background task.")] - BackgroundClosed, - /// Invalid RPC parameters cannot be serialized as JSON string. - #[error("RPC parameters cannot be serialized as JSON string.")] - InvalidParams, - /// The provided URL scheme is invalid. - /// - /// Supported versions: WS, WSS. - #[error("The provided URL scheme is invalid.")] - InvalidScheme, - /// The provided URL is invalid. - #[error("The provided URL scheme is invalid.")] - InvalidUrl, - /// The provided chain spec is invalid. - #[error("The provided chain spec is not a valid JSON object.")] - InvalidChainSpec, - /// Handshake error while connecting to a node. - #[error("WS handshake failed.")] - Handshake, -} - -/// The raw light-client RPC implementation that is used to connect with the chain. -#[derive(Clone)] -pub struct RawLightClient { - raw_rpc: rpc::RawLightClientRpc, -} - -impl RawLightClient { - /// Construct a [`RawLightClient`] using its builder interface. - /// - /// The raw builder is utilized for constructing light-clients from a low - /// level smoldot client. - /// - /// This is especially useful when you want to gain access to the smoldot client. - /// For example, you may want to connect to multiple chains and/or parachains while reusing the - /// same smoldot client under the hood. Or you may want to configure different values for - /// smoldot internal buffers, number of subscriptions and relay chains. - /// - /// # Note - /// - /// If you are unsure, please use [`LightClient::builder`] instead. - pub fn builder() -> RawLightClientBuilder { - RawLightClientBuilder::default() - } - - /// Target a different chain identified by the provided chain ID for requests. - /// - /// The provided chain ID is provided by the `smoldot_light::Client::add_chain` and it must - /// match one of the `smoldot_light::JsonRpcResponses` provided in [`RawLightClientBuilder::add_chain`]. - /// - /// # Note - /// - /// This uses the same underlying instance spawned by the builder. - pub async fn for_chain( - &self, - chain_id: smoldot::ChainId, - ) -> Result, crate::Error> { - let raw_rpc = self.raw_rpc.for_chain(chain_id); - let rpc_client = RpcClient::new(raw_rpc.clone()); - - // Production code should use the legacy backend. - #[cfg(not(test))] - async fn build_online_client( - rpc_client: RpcClient, - ) -> Result, crate::Error> { - OnlineClient::::from_rpc_client(rpc_client).await - } - - // For testing we are only interested in using the unstable-backend with - // the lightclient. - #[cfg(test)] - async fn build_online_client( - rpc_client: RpcClient, - ) -> Result, crate::Error> { - use crate::backend::unstable::UnstableBackend; - use std::sync::Arc; - let (backend, mut driver) = UnstableBackend::builder().build(rpc_client); - let future = async move { - use futures::StreamExt; - while let Some(val) = driver.next().await { - if let Err(e) = val { - // This is a test; bail if something does wrong and try to - // ensure that the message makes it to some logs. - panic!("Error driving unstable backend in tests: {e}"); - } - } - }; - // The unstable backend needs driving: - #[cfg(feature = "native")] - tokio::spawn(future); - #[cfg(feature = "web")] - wasm_bindgen_futures::spawn_local(future); - - OnlineClient::from_backend(Arc::new(backend)).await - } - - let client = build_online_client(rpc_client).await?; - - Ok(LightClient { client, chain_id }) - } -} - -/// The light-client RPC implementation that is used to connect with the chain. -#[derive(Derivative)] -#[derivative(Clone(bound = ""))] -pub struct LightClient { - client: OnlineClient, - chain_id: smoldot::ChainId, -} - -impl LightClient { - /// Construct a [`LightClient`] using its builder interface. - pub fn builder() -> LightClientBuilder { - LightClientBuilder::new() - } - - // We add the below impls so that we don't need to - // think about importing the OnlineClientT/OfflineClientT - // traits to use these things: - - /// Return the [`crate::Metadata`] used in this client. - fn metadata(&self) -> crate::Metadata { - self.client.metadata() - } - - /// Return the genesis hash. - fn genesis_hash(&self) -> ::Hash { - self.client.genesis_hash() - } - - /// Return the runtime version. - fn runtime_version(&self) -> crate::backend::RuntimeVersion { - self.client.runtime_version() - } - - /// Work with transactions. - pub fn tx(&self) -> TxClient { - >::tx(self) - } - - /// Work with events. - pub fn events(&self) -> EventsClient { - >::events(self) - } - - /// Work with storage. - pub fn storage(&self) -> StorageClient { - >::storage(self) - } - - /// Access constants. - pub fn constants(&self) -> ConstantsClient { - >::constants(self) - } - - /// Access custom types. - pub fn custom_values(&self) -> CustomValuesClient { - >::custom_values(self) - } - - /// Work with blocks. - pub fn blocks(&self) -> BlocksClient { - >::blocks(self) - } - - /// Work with runtime API. - pub fn runtime_api(&self) -> RuntimeApiClient { - >::runtime_api(self) - } - - /// Returns the chain ID of the current light-client. - pub fn chain_id(&self) -> smoldot::ChainId { - self.chain_id - } -} - -impl OnlineClientT for LightClient { - fn backend(&self) -> &dyn crate::backend::Backend { - self.client.backend() - } -} - -impl OfflineClientT for LightClient { - fn metadata(&self) -> crate::Metadata { - self.metadata() - } - - fn genesis_hash(&self) -> ::Hash { - self.genesis_hash() - } - - fn runtime_version(&self) -> crate::backend::RuntimeVersion { - self.runtime_version() - } -} From fd47be1b2e500d7938f4dca4242cb109364e4a4c Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 28 Mar 2024 14:11:51 +0200 Subject: [PATCH 37/42] Remove unused dep Signed-off-by: Alexandru Vasile --- Cargo.lock | 1 - subxt/Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aa5876a1b1..8d7cc2f67b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4668,7 +4668,6 @@ dependencies = [ "tracing", "tracing-subscriber 0.3.18", "url", - "wasm-bindgen-futures", ] [[package]] diff --git a/subxt/Cargo.toml b/subxt/Cargo.toml index 65fdd846b5..8f8cc847de 100644 --- a/subxt/Cargo.toml +++ b/subxt/Cargo.toml @@ -120,7 +120,6 @@ sp-keyring = { workspace = true } sp-runtime = { workspace = true } assert_matches = { workspace = true } subxt-signer = { path = "../signer" } -wasm-bindgen-futures = { workspace = true } # Tracing subscriber is useful for light-client examples to ensure that # the `bootNodes` and chain spec are configured correctly. If all is fine, then # the light-client wlll emit INFO logs with From be4b34cfc09901449840a0665f31fd41b8c18bce Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 2 Apr 2024 16:09:53 +0300 Subject: [PATCH 38/42] rename proc-macro to subxt-test-macro Signed-off-by: Alexandru Vasile --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- testing/integration-tests/Cargo.toml | 2 +- testing/integration-tests/src/utils/mod.rs | 2 +- .../{proc-macro => subxt-test-macro}/Cargo.toml | 2 +- .../{proc-macro => subxt-test-macro}/src/lib.rs | 0 6 files changed, 6 insertions(+), 6 deletions(-) rename testing/integration-tests/{proc-macro => subxt-test-macro}/Cargo.toml (92%) rename testing/integration-tests/{proc-macro => subxt-test-macro}/src/lib.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 8d7cc2f67b..d50344bc13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2290,7 +2290,7 @@ dependencies = [ "subxt-codegen", "subxt-metadata", "subxt-signer", - "subxt-test-proc-macro", + "subxt-test-macro", "syn 2.0.53", "test-runtime", "tokio", @@ -4827,7 +4827,7 @@ dependencies = [ ] [[package]] -name = "subxt-test-proc-macro" +name = "subxt-test-macro" version = "0.35.0" dependencies = [ "quote", diff --git a/Cargo.toml b/Cargo.toml index 8c538043c6..549c713a02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ members = [ "testing/substrate-runner", "testing/test-runtime", "testing/integration-tests", - "testing/integration-tests/proc-macro", + "testing/integration-tests/subxt-test-macro", "testing/ui-tests", "testing/generate-custom-metadata", "macro", diff --git a/testing/integration-tests/Cargo.toml b/testing/integration-tests/Cargo.toml index 670b0a80ac..47293cd1ea 100644 --- a/testing/integration-tests/Cargo.toml +++ b/testing/integration-tests/Cargo.toml @@ -46,7 +46,7 @@ tracing = { workspace = true } tracing-subscriber = { workspace = true } wabt = { workspace = true } substrate-runner = { workspace = true } -subxt-test-proc-macro = { path = "proc-macro" } +subxt-test-macro = { path = "subxt-test-macro" } [build-dependencies] cfg_aliases = "0.2.0" diff --git a/testing/integration-tests/src/utils/mod.rs b/testing/integration-tests/src/utils/mod.rs index 5c6c11e0a0..93cb618117 100644 --- a/testing/integration-tests/src/utils/mod.rs +++ b/testing/integration-tests/src/utils/mod.rs @@ -12,7 +12,7 @@ pub use node_proc::TestNodeProcess; pub use tx_retries::*; pub use wait_for_blocks::*; -pub use subxt_test_proc_macro::subxt_test; +pub use subxt_test_macro::subxt_test; /// The test timeout is set to 1 second. /// However, the test is sleeping for 5 seconds. diff --git a/testing/integration-tests/proc-macro/Cargo.toml b/testing/integration-tests/subxt-test-macro/Cargo.toml similarity index 92% rename from testing/integration-tests/proc-macro/Cargo.toml rename to testing/integration-tests/subxt-test-macro/Cargo.toml index 0d55ee83e2..513afd7e7b 100644 --- a/testing/integration-tests/proc-macro/Cargo.toml +++ b/testing/integration-tests/subxt-test-macro/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "subxt-test-proc-macro" +name = "subxt-test-macro" version.workspace = true authors.workspace = true edition.workspace = true diff --git a/testing/integration-tests/proc-macro/src/lib.rs b/testing/integration-tests/subxt-test-macro/src/lib.rs similarity index 100% rename from testing/integration-tests/proc-macro/src/lib.rs rename to testing/integration-tests/subxt-test-macro/src/lib.rs From 7270da825c442c9d4fca831cd18f8f3d3d914bdc Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 3 Apr 2024 18:53:01 +0300 Subject: [PATCH 39/42] tests: Remove txretries for lightclient Signed-off-by: Alexandru Vasile --- .../src/full_client/client/mod.rs | 20 ++++-- .../src/full_client/frame/balances.rs | 43 ++++++++++-- .../src/full_client/frame/contracts.rs | 26 ++++++-- .../src/full_client/frame/staking.rs | 65 +++++++++++++++---- .../src/full_client/frame/sudo.rs | 12 +++- .../src/full_client/frame/system.rs | 7 +- .../src/full_client/runtime_api/mod.rs | 9 ++- testing/integration-tests/src/utils/mod.rs | 2 - .../integration-tests/src/utils/tx_retries.rs | 51 --------------- 9 files changed, 148 insertions(+), 87 deletions(-) delete mode 100644 testing/integration-tests/src/utils/tx_retries.rs diff --git a/testing/integration-tests/src/full_client/client/mod.rs b/testing/integration-tests/src/full_client/client/mod.rs index 954546d028..5cdedab679 100644 --- a/testing/integration-tests/src/full_client/client/mod.rs +++ b/testing/integration-tests/src/full_client/client/mod.rs @@ -3,7 +3,7 @@ // see LICENSE for license details. use crate::{ - submit_tx_wait_for_finalized_success, subxt_test, test_context, + subxt_test, test_context, utils::{node_runtime, wait_for_blocks}, }; use codec::{Decode, Encode}; @@ -136,7 +136,11 @@ async fn transaction_validation() { .await .expect("validation failed"); - submit_tx_wait_for_finalized_success(&signed_extrinsic) + signed_extrinsic + .submit_and_watch() + .await + .unwrap() + .wait_for_finalized_success() .await .unwrap(); } @@ -199,7 +203,11 @@ async fn external_signing() { .sign_with_address_and_signature(&alice.public_key().into(), &signature.into()); // And now submit it. - submit_tx_wait_for_finalized_success(&extrinsic) + extrinsic + .submit_and_watch() + .await + .unwrap() + .wait_for_finalized_success() .await .unwrap(); } @@ -255,7 +263,11 @@ async fn decode_a_module_error() { .await .unwrap(); - let err = submit_tx_wait_for_finalized_success(&signed_extrinsic) + let err = signed_extrinsic + .submit_and_watch() + .await + .unwrap() + .wait_for_finalized_success() .await .expect_err("an 'unknown asset' error"); diff --git a/testing/integration-tests/src/full_client/frame/balances.rs b/testing/integration-tests/src/full_client/frame/balances.rs index 5ed4f6423e..d721d8e58c 100644 --- a/testing/integration-tests/src/full_client/frame/balances.rs +++ b/testing/integration-tests/src/full_client/frame/balances.rs @@ -4,7 +4,7 @@ use crate::{ node_runtime::{self, balances, runtime_types, system}, - submit_tx_wait_for_finalized_success, subxt_test, test_context, + subxt_test, test_context, }; use codec::Decode; use subxt::{ @@ -49,7 +49,13 @@ async fn tx_basic_transfer() -> Result<(), subxt::Error> { .tx() .create_signed(&tx, &alice, Default::default()) .await?; - let events = submit_tx_wait_for_finalized_success(&signed_extrinsic).await?; + + let events = signed_extrinsic + .submit_and_watch() + .await + .unwrap() + .wait_for_finalized_success() + .await?; let event = events .find_first::() @@ -238,7 +244,12 @@ async fn multiple_sequential_transfers_work() -> Result<(), subxt::Error> { .create_signed(&tx, &alice, Default::default()) .await?; - submit_tx_wait_for_finalized_success(&signed_extrinsic).await?; + signed_extrinsic + .submit_and_watch() + .await + .unwrap() + .wait_for_finalized_success() + .await?; } let bob_post = api @@ -285,7 +296,12 @@ async fn storage_balance_lock() -> Result<(), subxt::Error> { .tx() .create_signed(&tx, &bob_signer, Default::default()) .await?; - submit_tx_wait_for_finalized_success(&signed_extrinsic) + + signed_extrinsic + .submit_and_watch() + .await + .unwrap() + .wait_for_finalized_success() .await? .find_first::()? .expect("No ExtrinsicSuccess Event found"); @@ -332,7 +348,11 @@ async fn transfer_error() { .create_signed(&to_bob_tx, &alice, Default::default()) .await .unwrap(); - submit_tx_wait_for_finalized_success(&signed_extrinsic) + signed_extrinsic + .submit_and_watch() + .await + .unwrap() + .wait_for_finalized_success() .await .unwrap(); @@ -344,7 +364,12 @@ async fn transfer_error() { .await .unwrap(); - let res = submit_tx_wait_for_finalized_success(&signed_extrinsic).await; + let res = signed_extrinsic + .submit_and_watch() + .await + .unwrap() + .wait_for_finalized_success() + .await; assert!( matches!( @@ -374,7 +399,11 @@ async fn transfer_implicit_subscription() { .await .unwrap(); - let event = submit_tx_wait_for_finalized_success(&signed_extrinsic) + let event = signed_extrinsic + .submit_and_watch() + .await + .unwrap() + .wait_for_finalized_success() .await .unwrap() .find_first::() diff --git a/testing/integration-tests/src/full_client/frame/contracts.rs b/testing/integration-tests/src/full_client/frame/contracts.rs index 675e33626b..65428eeb37 100644 --- a/testing/integration-tests/src/full_client/frame/contracts.rs +++ b/testing/integration-tests/src/full_client/frame/contracts.rs @@ -9,8 +9,7 @@ use crate::{ runtime_types::{pallet_contracts::wasm::Determinism, sp_weights::weight_v2::Weight}, system, }, - submit_tx_wait_for_finalized_success, subxt_test, test_context, TestClient, TestConfig, - TestContext, + subxt_test, test_context, TestClient, TestConfig, TestContext, }; use subxt::ext::futures::StreamExt; use subxt::{tx::TxProgress, utils::MultiAddress, Config, Error}; @@ -60,7 +59,13 @@ impl ContractsTestContext { .tx() .create_signed(&upload_tx, &self.signer, Default::default()) .await?; - let events = submit_tx_wait_for_finalized_success(&signed_extrinsic).await?; + + let events = signed_extrinsic + .submit_and_watch() + .await + .unwrap() + .wait_for_finalized_success() + .await?; let code_stored = events .find_first::()? @@ -89,7 +94,13 @@ impl ContractsTestContext { .tx() .create_signed(&instantiate_tx, &self.signer, Default::default()) .await?; - let events = submit_tx_wait_for_finalized_success(&signed_extrinsic).await?; + + let events = signed_extrinsic + .submit_and_watch() + .await + .unwrap() + .wait_for_finalized_success() + .await?; let code_stored = events .find_first::()? @@ -130,7 +141,12 @@ impl ContractsTestContext { .tx() .create_signed(&instantiate_tx, &self.signer, Default::default()) .await?; - let result = submit_tx_wait_for_finalized_success(&signed_extrinsic).await?; + let result = signed_extrinsic + .submit_and_watch() + .await + .unwrap() + .wait_for_finalized_success() + .await?; tracing::info!("Instantiate result: {:?}", result); let instantiated = result diff --git a/testing/integration-tests/src/full_client/frame/staking.rs b/testing/integration-tests/src/full_client/frame/staking.rs index 40a36bc271..db3742185d 100644 --- a/testing/integration-tests/src/full_client/frame/staking.rs +++ b/testing/integration-tests/src/full_client/frame/staking.rs @@ -11,7 +11,7 @@ use crate::{ }, staking, }, - submit_tx_wait_for_finalized_success, subxt_test, test_context, + subxt_test, test_context, }; use assert_matches::assert_matches; use subxt::error::{DispatchError, Error}; @@ -50,7 +50,12 @@ async fn validate_with_stash_account() { .create_signed(&tx, &alice_stash, Default::default()) .await .unwrap(); - submit_tx_wait_for_finalized_success(&signed_extrinsic) + + signed_extrinsic + .submit_and_watch() + .await + .unwrap() + .wait_for_finalized_success() .await .expect("should be successful"); } @@ -70,7 +75,13 @@ async fn validate_not_possible_for_controller_account() -> Result<(), Error> { .tx() .create_signed(&tx, &alice, Default::default()) .await?; - let announce_validator = submit_tx_wait_for_finalized_success(&signed_extrinsic).await; + + let announce_validator = signed_extrinsic + .submit_and_watch() + .await + .unwrap() + .wait_for_finalized_success() + .await; assert_matches!(announce_validator, Err(Error::Runtime(DispatchError::Module(err))) => { let details = err.details().unwrap(); @@ -97,7 +108,12 @@ async fn nominate_with_stash_account() { .create_signed(&tx, &alice_stash, Default::default()) .await .unwrap(); - submit_tx_wait_for_finalized_success(&signed_extrinsic) + + signed_extrinsic + .submit_and_watch() + .await + .unwrap() + .wait_for_finalized_success() .await .expect("should be successful"); } @@ -119,7 +135,12 @@ async fn nominate_not_possible_for_controller_account() -> Result<(), Error> { .create_signed(&tx, &alice, Default::default()) .await .unwrap(); - let nomination = submit_tx_wait_for_finalized_success(&signed_extrinsic).await; + let nomination = signed_extrinsic + .submit_and_watch() + .await + .unwrap() + .wait_for_finalized_success() + .await; assert_matches!(nomination, Err(Error::Runtime(DispatchError::Module(err))) => { let details = err.details().unwrap(); @@ -147,7 +168,12 @@ async fn chill_works_for_stash_only() -> Result<(), Error> { .tx() .create_signed(&nominate_tx, &alice_stash, Default::default()) .await?; - submit_tx_wait_for_finalized_success(&signed_extrinsic).await?; + signed_extrinsic + .submit_and_watch() + .await + .unwrap() + .wait_for_finalized_success() + .await?; let ledger_addr = node_runtime::storage() .staking() @@ -167,7 +193,13 @@ async fn chill_works_for_stash_only() -> Result<(), Error> { .tx() .create_signed(&chill_tx, &alice, Default::default()) .await?; - let chill = submit_tx_wait_for_finalized_success(&signed_extrinsic).await; + + let chill = signed_extrinsic + .submit_and_watch() + .await + .unwrap() + .wait_for_finalized_success() + .await; assert_matches!(chill, Err(Error::Runtime(DispatchError::Module(err))) => { let details = err.details().unwrap(); @@ -179,7 +211,10 @@ async fn chill_works_for_stash_only() -> Result<(), Error> { .tx() .create_signed(&chill_tx, &alice_stash, Default::default()) .await?; - let is_chilled = submit_tx_wait_for_finalized_success(&signed_extrinsic) + let is_chilled = signed_extrinsic + .submit_and_watch() + .await? + .wait_for_finalized_success() .await? .has::()?; @@ -203,15 +238,23 @@ async fn tx_bond() -> Result<(), Error> { .tx() .create_signed(&bond_tx, &alice, Default::default()) .await?; - let bond = submit_tx_wait_for_finalized_success(&signed_extrinsic).await; - + let bond = signed_extrinsic + .submit_and_watch() + .await? + .wait_for_finalized_success() + .await; assert!(bond.is_ok()); let signed_extrinsic = api .tx() .create_signed(&bond_tx, &alice, Default::default()) .await?; - let bond_again = submit_tx_wait_for_finalized_success(&signed_extrinsic).await; + + let bond_again = signed_extrinsic + .submit_and_watch() + .await? + .wait_for_finalized_success() + .await; assert_matches!(bond_again, Err(Error::Runtime(DispatchError::Module(err))) => { let details = err.details().unwrap(); diff --git a/testing/integration-tests/src/full_client/frame/sudo.rs b/testing/integration-tests/src/full_client/frame/sudo.rs index 5118b3013b..489030e497 100644 --- a/testing/integration-tests/src/full_client/frame/sudo.rs +++ b/testing/integration-tests/src/full_client/frame/sudo.rs @@ -8,7 +8,7 @@ use crate::{ runtime_types::{self, sp_weights::weight_v2::Weight}, sudo, }, - submit_tx_wait_for_finalized_success, subxt_test, test_context, + subxt_test, test_context, }; use subxt_signer::sr25519::dev; @@ -34,7 +34,10 @@ async fn test_sudo() -> Result<(), subxt::Error> { .create_signed(&tx, &alice, Default::default()) .await?; - let found_event = submit_tx_wait_for_finalized_success(&signed_extrinsic) + let found_event = signed_extrinsic + .submit_and_watch() + .await? + .wait_for_finalized_success() .await? .has::()?; @@ -67,7 +70,10 @@ async fn test_sudo_unchecked_weight() -> Result<(), subxt::Error> { .create_signed(&tx, &alice, Default::default()) .await?; - let found_event = submit_tx_wait_for_finalized_success(&signed_extrinsic) + let found_event = signed_extrinsic + .submit_and_watch() + .await? + .wait_for_finalized_success() .await? .has::()?; diff --git a/testing/integration-tests/src/full_client/frame/system.rs b/testing/integration-tests/src/full_client/frame/system.rs index 3ec5432b6b..260ea24c61 100644 --- a/testing/integration-tests/src/full_client/frame/system.rs +++ b/testing/integration-tests/src/full_client/frame/system.rs @@ -4,7 +4,7 @@ use crate::{ node_runtime::{self, system}, - submit_tx_wait_for_finalized_success, subxt_test, test_context, + subxt_test, test_context, }; use assert_matches::assert_matches; use subxt_signer::sr25519::dev; @@ -47,7 +47,10 @@ async fn tx_remark_with_event() -> Result<(), subxt::Error> { .create_signed(&tx, &alice, Default::default()) .await?; - let found_event = submit_tx_wait_for_finalized_success(&signed_extrinsic) + let found_event = signed_extrinsic + .submit_and_watch() + .await? + .wait_for_finalized_success() .await? .has::()?; diff --git a/testing/integration-tests/src/full_client/runtime_api/mod.rs b/testing/integration-tests/src/full_client/runtime_api/mod.rs index fbd4370a4b..a24dc73603 100644 --- a/testing/integration-tests/src/full_client/runtime_api/mod.rs +++ b/testing/integration-tests/src/full_client/runtime_api/mod.rs @@ -2,7 +2,7 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::{node_runtime, submit_tx_wait_for_finalized_success, subxt_test, test_context}; +use crate::{node_runtime, subxt_test, test_context}; use codec::Encode; use subxt::utils::AccountId32; use subxt_signer::sr25519::dev; @@ -33,7 +33,12 @@ async fn account_nonce() -> Result<(), subxt::Error> { .tx() .create_signed(&remark_tx, &alice, Default::default()) .await?; - submit_tx_wait_for_finalized_success(&signed_extrinsic).await?; + + signed_extrinsic + .submit_and_watch() + .await? + .wait_for_finalized_success() + .await?; let runtime_api_call = node_runtime::apis() .account_nonce_api() diff --git a/testing/integration-tests/src/utils/mod.rs b/testing/integration-tests/src/utils/mod.rs index 93cb618117..741e152913 100644 --- a/testing/integration-tests/src/utils/mod.rs +++ b/testing/integration-tests/src/utils/mod.rs @@ -4,12 +4,10 @@ mod context; mod node_proc; -mod tx_retries; mod wait_for_blocks; pub use context::*; pub use node_proc::TestNodeProcess; -pub use tx_retries::*; pub use wait_for_blocks::*; pub use subxt_test_macro::subxt_test; diff --git a/testing/integration-tests/src/utils/tx_retries.rs b/testing/integration-tests/src/utils/tx_retries.rs deleted file mode 100644 index 074db64a5e..0000000000 --- a/testing/integration-tests/src/utils/tx_retries.rs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2019-2024 Parity Technologies (UK) Ltd. -// This file is dual-licensed as Apache-2.0 or GPL-3.0. -// see LICENSE for license details. - -use subxt::client::OnlineClientT; -use subxt::tx::SubmittableExtrinsic; -use subxt::Config; - -pub async fn submit_tx_wait_for_finalized_success( - signed_extrinsic: &SubmittableExtrinsic, -) -> Result, subxt::Error> -where - T: Config, - C: OnlineClientT, -{ - let submit = || async { - signed_extrinsic - .submit_and_watch() - .await - .unwrap() - .wait_for_finalized_success() - .await - }; - - const RETRY_TIME: u64 = 5; - - #[cfg(lightclient)] - for _ in 0..2 { - let result = submit().await; - - match result { - Ok(tx_in_block) => return Ok(tx_in_block), - Err(subxt::Error::Transaction(subxt::error::TransactionError::Dropped(_))) => { - tracing::info!("Transaction was dropped, retrying..."); - // Retry if the transaction was dropped. - tokio::time::sleep(std::time::Duration::from_secs(RETRY_TIME)).await; - } - Err(subxt::Error::Rpc(subxt::error::RpcError::ClientError(err))) - if err.to_string().contains("No node available") => - { - tracing::info!("Transaction error: {}, retrying...", err.to_string()); - - // Retry if the client is not connected. - tokio::time::sleep(std::time::Duration::from_secs(RETRY_TIME)).await; - } - Err(other) => return Err(other), - } - } - - submit().await -} From a62ceb7d7268433942beb247a7c87dc231a5d6ff Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 3 Apr 2024 18:56:42 +0300 Subject: [PATCH 40/42] tests: Wait for 5 blocks for the lightclient full testing suite Signed-off-by: Alexandru Vasile --- testing/integration-tests/src/utils/node_proc.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/integration-tests/src/utils/node_proc.rs b/testing/integration-tests/src/utils/node_proc.rs index 08b35e60fd..65ce790b3f 100644 --- a/testing/integration-tests/src/utils/node_proc.rs +++ b/testing/integration-tests/src/utils/node_proc.rs @@ -228,10 +228,10 @@ async fn build_light_client(proc: &SubstrateNode) -> Result Date: Mon, 8 Apr 2024 10:58:20 +0300 Subject: [PATCH 41/42] tests: Group imports Signed-off-by: Alexandru Vasile --- .../src/full_client/blocks/mod.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/testing/integration-tests/src/full_client/blocks/mod.rs b/testing/integration-tests/src/full_client/blocks/mod.rs index 0adb87395c..2686b954ae 100644 --- a/testing/integration-tests/src/full_client/blocks/mod.rs +++ b/testing/integration-tests/src/full_client/blocks/mod.rs @@ -8,14 +8,16 @@ use futures::StreamExt; #[cfg(fullclient)] use crate::utils::node_runtime; + #[cfg(fullclient)] -use subxt::config::signed_extensions::{ChargeAssetTxPayment, CheckMortality, CheckNonce}; -#[cfg(fullclient)] -use subxt::config::DefaultExtrinsicParamsBuilder; -#[cfg(fullclient)] -use subxt::config::SubstrateConfig; -#[cfg(fullclient)] -use subxt::utils::Era; +use subxt::{ + config::{ + signed_extensions::{ChargeAssetTxPayment, CheckMortality, CheckNonce}, + DefaultExtrinsicParamsBuilder, SubstrateConfig, + }, + utils::Era, +}; + #[cfg(fullclient)] use subxt_signer::sr25519::dev; From 510578f59286dfd4749912fd156b42bb22dae8d6 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Mon, 8 Apr 2024 11:05:34 +0300 Subject: [PATCH 42/42] macro: Rename const value Signed-off-by: Alexandru Vasile --- testing/integration-tests/subxt-test-macro/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/testing/integration-tests/subxt-test-macro/src/lib.rs b/testing/integration-tests/subxt-test-macro/src/lib.rs index d102643ddc..0a0e81843c 100644 --- a/testing/integration-tests/subxt-test-macro/src/lib.rs +++ b/testing/integration-tests/subxt-test-macro/src/lib.rs @@ -15,7 +15,7 @@ use syn::{ const SUBXT_TEST_TIMEOUT: &str = "SUBXT_TEST_TIMEOUT"; /// Default timeout for the test. -const DEFAULT_TIMEOUT: u64 = 60 * 6; +const DEFAULT_TIMEOUT_SECS: u64 = 60 * 6; #[proc_macro_attribute] pub fn subxt_test(attr: TokenStream, item: TokenStream) -> TokenStream { @@ -30,8 +30,8 @@ pub fn subxt_test(attr: TokenStream, item: TokenStream) -> TokenStream { // - A default of 6 minutes. let timeout_duration = subxt_attr.timeout.unwrap_or_else(|| { std::env::var(SUBXT_TEST_TIMEOUT) - .map(|str| str.parse().unwrap_or(DEFAULT_TIMEOUT)) - .unwrap_or(DEFAULT_TIMEOUT) + .map(|str| str.parse().unwrap_or(DEFAULT_TIMEOUT_SECS)) + .unwrap_or(DEFAULT_TIMEOUT_SECS) }); let func: syn::ItemFn = match syn::parse(item) {