Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Put integration tests behind feature flag #515

Merged
merged 27 commits into from
Apr 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
03f5f74
subxt: Add integration-tests feature flag
lexnv Apr 22, 2022
45b84eb
subxt: Guard integration tests under feature flag
lexnv Apr 22, 2022
fbdfdf6
test-runtime: Place build.rs under feature flag
lexnv Apr 22, 2022
c9ad19b
subxt: Pass `integration-tests` feature to `test-runtime`
lexnv Apr 22, 2022
8e5f38b
CI: Use `integration-tests` feature to run all tests
lexnv Apr 22, 2022
3087ada
Merge remote-tracking branch 'origin/master' into 351_test_feature
lexnv Apr 28, 2022
057f075
subxt: Rely on `#[cfg(feature = "integration-tests")]` for integration
lexnv Apr 28, 2022
e596c68
subxt/metadata: Manually construct test metadata
lexnv Apr 28, 2022
c192f17
artifacts: Move scale binary blob to dedicated folder
lexnv Apr 28, 2022
680bc05
examples: Update path to metadata blob
lexnv Apr 28, 2022
3a1a692
metadata: Rely on artifact metadata blob for benches
lexnv Apr 28, 2022
2461c3b
metadata: Remove `test-runtime` dependency
lexnv Apr 28, 2022
3d9b9ab
examples: Modify runtime path for `custom_type_derives`
lexnv Apr 28, 2022
06c587c
Merge remote-tracking branch 'origin/master' into 351_test_feature
lexnv Apr 28, 2022
1e0522d
subxt: Remove tests folder
lexnv Apr 28, 2022
e73c763
test-runtime: Remove `integration-tests` feature flag
lexnv Apr 28, 2022
e309328
integration-tests: Add an integration test crate for subxt
lexnv Apr 28, 2022
77818e0
subxt: Remove `test-runtime` dependency
lexnv Apr 28, 2022
8c1c681
subxt: Add comment for feature flags
lexnv Apr 28, 2022
cd91831
integration-tests: Trim dependencies
lexnv Apr 28, 2022
bc0f719
integration-tests: Move dependencies under dev
lexnv Apr 28, 2022
bce0562
Revert "CI: Use `integration-tests` feature to run all tests"
lexnv Apr 28, 2022
a989404
integration-tests: Remove integration folder
lexnv Apr 29, 2022
755a871
subxt: Fix feature flag and test comment
lexnv Apr 29, 2022
1890dc1
subxt: Extra feature flag comment
lexnv Apr 29, 2022
5e49b4e
Merge remote-tracking branch 'origin/master' into 351_test_feature
lexnv Apr 29, 2022
e857e7e
integration-tests: Move tests content under src
lexnv Apr 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"cli",
"codegen",
"examples",
"integration-tests",
"macro",
"metadata",
"subxt",
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/balance_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use subxt::{
PolkadotExtrinsicParams,
};

#[subxt::subxt(runtime_metadata_path = "examples/polkadot_metadata.scale")]
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
pub mod polkadot {}

#[tokio::main]
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/balance_transfer_with_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use subxt::{
PolkadotExtrinsicParamsBuilder as Params,
};

#[subxt::subxt(runtime_metadata_path = "examples/polkadot_metadata.scale")]
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
pub mod polkadot {}

#[tokio::main]
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/custom_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use subxt::{
PolkadotExtrinsicParams,
};

#[subxt::subxt(runtime_metadata_path = "examples/polkadot_metadata.scale")]
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
pub mod polkadot {}

/// Custom [`Config`] impl where the default types for the target chain differ from the
Expand Down
3 changes: 1 addition & 2 deletions examples/examples/custom_type_derives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
#![allow(clippy::redundant_clone)]

#[subxt::subxt(
runtime_metadata_path = "examples/polkadot_metadata.scale",

runtime_metadata_path = "../artifacts/polkadot_metadata.scale",
// We can add (certain) custom derives to the generated types by providing
// a comma separated list to the below attribute. Most useful for adding `Clone`.
// The derives that we can add ultimately is limited to the traits that the base
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/fetch_all_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use subxt::{
PolkadotExtrinsicParams,
};

#[subxt::subxt(runtime_metadata_path = "examples/polkadot_metadata.scale")]
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
pub mod polkadot {}

#[tokio::main]
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/fetch_staking_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use subxt::{
PolkadotExtrinsicParams,
};

#[subxt::subxt(runtime_metadata_path = "examples/polkadot_metadata.scale")]
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
pub mod polkadot {}

#[tokio::main]
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/metadata_compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use subxt::{
PolkadotExtrinsicParams,
};

#[subxt::subxt(runtime_metadata_path = "examples/polkadot_metadata.scale")]
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
pub mod polkadot {}

#[tokio::main]
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/rpc_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use subxt::{
PolkadotExtrinsicParams,
};

#[subxt::subxt(runtime_metadata_path = "examples/polkadot_metadata.scale")]
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
pub mod polkadot {}

#[tokio::main]
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/submit_and_watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use subxt::{
PolkadotExtrinsicParams,
};

#[subxt::subxt(runtime_metadata_path = "examples/polkadot_metadata.scale")]
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
pub mod polkadot {}

#[tokio::main]
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/subscribe_all_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use subxt::{
PolkadotExtrinsicParams,
};

#[subxt::subxt(runtime_metadata_path = "examples/polkadot_metadata.scale")]
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
pub mod polkadot {}

/// Subscribe to all events, and then manually look through them and
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/subscribe_one_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use subxt::{
PolkadotExtrinsicParams,
};

#[subxt::subxt(runtime_metadata_path = "examples/polkadot_metadata.scale")]
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
pub mod polkadot {}

/// Subscribe to all events, and then manually look through them and
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/subscribe_some_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use subxt::{
PolkadotExtrinsicParams,
};

#[subxt::subxt(runtime_metadata_path = "examples/polkadot_metadata.scale")]
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
pub mod polkadot {}

/// Subscribe to all events, and then manually look through them and
Expand Down
34 changes: 34 additions & 0 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "subxt-integration"
version = "0.20.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021"

license = "GPL-3.0"
readme = "../README.md"
repository = "https://github.com/paritytech/subxt"
documentation = "https://docs.rs/subxt"
homepage = "https://www.parity.io/"
description = "Subxt integration tests that rely on the Substrate binary"

[features]
default = ["subxt/integration-tests"]

[dev-dependencies]
assert_matches = "1.5.0"
async-trait = "0.1.49"
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "full", "bit-vec"] }
env_logger = "0.9.0"
frame-metadata = "15.0.0"
futures = "0.3.13"
hex = "0.4.3"
log = "0.4.14"
scale-info = { version = "2.0.0", features = ["bit-vec"] }
sp-core = { version = "6.0.0", default-features = false }
sp-keyring = "6.0.0"
sp-runtime = "6.0.0"
subxt = { version = "0.20.0", path = "../subxt" }
test-runtime = { path = "../test-runtime" }
tokio = { version = "1.8", features = ["macros", "time"] }
wabt = "0.10.0"
which = "4.0.2"
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with subxt. If not, see <http://www.gnu.org/licenses/>.

#[cfg(test)]
mod codegen;
#[cfg(test)]
mod utils;

#[cfg(test)]
Expand All @@ -24,10 +26,11 @@ mod events;
#[cfg(test)]
mod frame;
#[cfg(test)]
#[cfg(integration_tests)]
mod metadata;
#[cfg(test)]
mod storage;

#[cfg(test)]
use test_runtime::node_runtime;
#[cfg(test)]
use utils::*;
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ use subxt::{
pub struct TestNodeProcess<R: Config> {
proc: process::Child,
client: Client<R>,
#[cfg(integration_tests)]
ws_url: String,
}

Expand Down Expand Up @@ -79,7 +78,6 @@ where
}

/// Returns the address to which the client is connected.
#[cfg(integration_tests)]
pub fn ws_url(&self) -> &str {
&self.ws_url
}
Expand Down Expand Up @@ -149,7 +147,6 @@ impl TestNodeProcessBuilder {
Ok(TestNodeProcess {
proc,
client,
#[cfg(integration_tests)]
ws_url,
})
}
Expand Down
1 change: 0 additions & 1 deletion metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ sp-core = { version = "6.0.0" }
bitvec = { version = "1.0.0", default-features = false, features = ["alloc"] }
criterion = "0.3"
scale-info = { version = "2.0.0", features = ["bit-vec"] }
test-runtime = { path = "../test-runtime" }

[lib]
# Without this, libtest cli opts interfere with criteron benches:
Expand Down
7 changes: 6 additions & 1 deletion metadata/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ use scale_info::{
TypeDef,
TypeDefVariant,
};
use std::{
fs,
path::Path,
};
use subxt_metadata::{
get_call_hash,
get_constant_hash,
Expand All @@ -35,7 +39,8 @@ use subxt_metadata::{
};

fn load_metadata() -> RuntimeMetadataV14 {
let bytes = test_runtime::METADATA;
let bytes = fs::read(Path::new("../artifacts/polkadot_metadata.scale"))
.expect("Cannot read metadata blob");
let meta: RuntimeMetadataPrefixed =
Decode::decode(&mut &*bytes).expect("Cannot decode scale metadata");

Expand Down
7 changes: 6 additions & 1 deletion subxt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ homepage = "https://www.parity.io/"
description = "Submit extrinsics (transactions) to a substrate node via RPC"
keywords = ["parity", "substrate", "blockchain"]

[features]
# Activate this to expose functionality only used for integration testing.
# The exposed functionality is subject to breaking changes at any point,
# and should not be relied upon.
integration-tests = []

[dependencies]
bitvec = { version = "1.0.0", default-features = false, features = ["alloc"] }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "full", "bit-vec"] }
Expand Down Expand Up @@ -42,5 +48,4 @@ env_logger = "0.9.0"
tempdir = "0.3.7"
wabt = "0.10.0"
which = "4.0.2"
test-runtime = { path = "../test-runtime" }
sp-keyring = "6.0.0"
2 changes: 1 addition & 1 deletion subxt/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl ClientBuilder {
/// Set the metadata.
///
/// *Note:* Metadata will no longer be downloaded from the runtime node.
#[cfg(integration_tests)]
#[cfg(feature = "integration-tests")]
pub fn set_metadata(mut self, metadata: Metadata) -> Self {
self.metadata = Some(metadata);
self
Expand Down
67 changes: 59 additions & 8 deletions subxt/src/metadata/metadata_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,64 @@ impl TryFrom<RuntimeMetadataPrefixed> for Metadata {
mod tests {
use super::*;
use crate::StorageEntryKey;
use frame_metadata::{
ExtrinsicMetadata,
PalletStorageMetadata,
StorageEntryModifier,
StorageEntryType,
};
use scale_info::{
meta_type,
TypeInfo,
};

fn load_metadata() -> Metadata {
let bytes = test_runtime::METADATA;
let meta: RuntimeMetadataPrefixed =
codec::Decode::decode(&mut &*bytes).expect("Cannot decode scale metadata");
#[allow(dead_code)]
#[allow(non_camel_case_types)]
#[derive(TypeInfo)]
enum Call {
fill_block { param: u128 },
}
let storage = PalletStorageMetadata {
prefix: "System",
entries: vec![StorageEntryMetadata {
name: "Account",
modifier: StorageEntryModifier::Optional,
ty: StorageEntryType::Plain(meta_type::<u32>()),
default: vec![0],
docs: vec![],
}],
};
let constant = PalletConstantMetadata {
name: "BlockWeights",
ty: meta_type::<u32>(),
value: vec![1, 2, 3],
docs: vec![],
};
let pallet = frame_metadata::PalletMetadata {
index: 0,
name: "System",
calls: Some(frame_metadata::PalletCallMetadata {
ty: meta_type::<Call>(),
}),
storage: Some(storage),
constants: vec![constant],
event: None,
error: None,
};

let metadata = RuntimeMetadataV14::new(
vec![pallet],
ExtrinsicMetadata {
ty: meta_type::<()>(),
version: 0,
signed_extensions: vec![],
},
meta_type::<()>(),
);
let prefixed = RuntimeMetadataPrefixed::from(metadata);

Metadata::try_from(meta)
Metadata::try_from(prefixed)
.expect("Cannot translate runtime metadata to internal Metadata")
}

Copy link
Collaborator

@jsdw jsdw Apr 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Currently the caching does not take into account different pallets
// as the intended behavior is to use this method only once.
// Enforce this behavior into testing.
let hash_old = metadata.metadata_hash(&["Balances"]);
assert_eq!(hash_old, hash);

I don't really understand what this line does? (also doesn't look like there is a balances pallet in the fake metadata?)

(alas I couldn't comment on the line itself; sorry!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have updated the comment. If we call metadata_hash with an argument of pallets: ["System"] it would produce a hash that is cached internally. Therefore, if we call the same method again, but with different arguments (ie pallets: ["Balances"]), it would fetch the previously cached value 😄

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that is clearer! :)

Expand All @@ -501,10 +552,10 @@ mod tests {
hash
);

// Currently the caching does not take into account different pallets
// as the intended behavior is to use this method only once.
// Enforce this behavior into testing.
let hash_old = metadata.metadata_hash(&["Balances"]);
// The cache `metadata.inner.cached_metadata_hash` is already populated from
// the previous call. Therefore, changing the pallets argument must not
// change the methods behavior.
let hash_old = metadata.metadata_hash(&["no-pallet"]);
assert_eq!(hash_old, hash);
}

Expand Down