From 1421c8e9d0ee079d06b17ebdbabd413ddf9addaf Mon Sep 17 00:00:00 2001 From: Sebastian Miasojed Date: Wed, 18 Oct 2023 12:05:26 +0200 Subject: [PATCH] Remove check for compatible scale and scale-info versions (#1370) * Remove check for compatible scale and scale-info versions * fmt * fix clippy * Add Option arg to check_contract_ink_compatibility --- CHANGELOG.md | 3 +- crates/build/src/lib.rs | 81 +------------------------ crates/metadata/compatibility_list.json | 5 +- crates/metadata/src/compatibility.rs | 41 ++++++++----- crates/metadata/src/lib.rs | 1 + 5 files changed, 35 insertions(+), 96 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27cd54f60..d9f35a222 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,8 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `--binary` flag for `info` command - [#1311](https://github.com/paritytech/cargo-contract/pull/1311/) - Add `--all` flag for `info` command - [#1319](https://github.com/paritytech/cargo-contract/pull/1319) - Fix for a Url to String conversion in `info` command - [#1330](https://github.com/paritytech/cargo-contract/pull/1330) -- Add warning message when using incompatible contract's ink! version [#1334](https://github.com/paritytech/cargo-contract/pull/1334) +- Add warning message when using incompatible contract's ink! version - [#1334](https://github.com/paritytech/cargo-contract/pull/1334) - Bump `subxt` to `0.32.0` - [#1352](https://github.com/paritytech/cargo-contract/pull/1352) +- Remove check for compatible `scale` and `scale-info` versions - [#1370](https://github.com/paritytech/cargo-contract/pull/1370) ## [4.0.0-alpha] diff --git a/crates/build/src/lib.rs b/crates/build/src/lib.rs index 823d727ef..add3b2103 100644 --- a/crates/build/src/lib.rs +++ b/crates/build/src/lib.rs @@ -764,38 +764,6 @@ fn post_process_wasm( Ok(()) } -/// Asserts that the contract's dependencies are compatible to the ones used in ink!. -/// -/// This function utilizes `cargo tree`, which takes semver into consideration. -/// -/// Hence this function only returns an `Err` if it is a proper mismatch according -/// to semantic versioning. This means that either: -/// - the major version mismatches, differences in the minor/patch version are not -/// considered incompatible. -/// - or if the version starts with zero (i.e. `0.y.z`) a mismatch in the minor -/// version is already considered incompatible. -fn assert_compatible_ink_dependencies( - manifest_path: &ManifestPath, - verbosity: Verbosity, -) -> Result<()> { - for dependency in ["parity-scale-codec", "scale-info"].iter() { - let args = ["-i", dependency, "--duplicates"]; - let cargo = - util::cargo_cmd("tree", args, manifest_path.directory(), verbosity, vec![]); - cargo - .stdout_null() - .run() - .with_context(|| { - format!( - "Mismatching versions of `{dependency}` were found!\n\ - Please ensure that your contract and your ink! dependencies use a compatible \ - version of this package." - ) - })?; - } - Ok(()) -} - /// Checks whether the supplied `ink_version` already contains the debug feature. /// /// This feature was introduced in `3.0.0-rc4` with `ink_env/ink-debug`. @@ -853,12 +821,11 @@ pub fn execute(args: ExecuteArgs) -> Result { let crate_metadata = CrateMetadata::collect(manifest_path, *target)?; - assert_compatible_ink_dependencies(manifest_path, *verbosity)?; if build_mode == &BuildMode::Debug { assert_debug_mode_supported(&crate_metadata.ink_version)?; } - if let Err(e) = check_contract_ink_compatibility(&crate_metadata.ink_version) { + if let Err(e) = check_contract_ink_compatibility(&crate_metadata.ink_version, None) { eprintln!("{} {}", "warning:".yellow().bold(), e.to_string().bold()); } @@ -1126,13 +1093,7 @@ fn blake2_hash(code: &[u8]) -> [u8; 32] { #[cfg(test)] mod unit_tests { use super::*; - use crate::{ - util::tests::{ - with_new_contract_project, - TestContractManifest, - }, - Verbosity, - }; + use crate::Verbosity; use semver::Version; #[test] @@ -1161,44 +1122,6 @@ mod unit_tests { ); } - #[test] - fn project_template_dependencies_must_be_ink_compatible() { - with_new_contract_project(|manifest_path| { - // given - // the manifest path - - // when - let res = - assert_compatible_ink_dependencies(&manifest_path, Verbosity::Default); - - // then - assert!(res.is_ok()); - Ok(()) - }) - } - - #[test] - fn detect_mismatching_parity_scale_codec_dependencies() { - with_new_contract_project(|manifest_path| { - // given - // the manifest path - - // at the time of writing this test ink! already uses `parity-scale-codec` - // in a version > 2, hence 1 is an incompatible version. - let mut manifest = TestContractManifest::new(manifest_path.clone())?; - manifest.set_dependency_version("scale", "1.0.0")?; - manifest.write()?; - - // when - let res = - assert_compatible_ink_dependencies(&manifest_path, Verbosity::Default); - - // then - assert!(res.is_err()); - Ok(()) - }) - } - #[test] fn build_result_seralization_sanity_check() { // given diff --git a/crates/metadata/compatibility_list.json b/crates/metadata/compatibility_list.json index 58aa7fed4..3318b8d7a 100644 --- a/crates/metadata/compatibility_list.json +++ b/crates/metadata/compatibility_list.json @@ -3,8 +3,11 @@ "1.5.0": { "ink": [">=3.0.0,<4.0.0", ">=3.0.0-alpha, <4.0.0-alpha.3"] }, + "3.2.0": { + "ink": ["4.0.0-alpha.3", "4.0.0"] + }, "4.0.0-alpha": { - "ink": ["4.0.0-alpha.3", "4.0.0", "5.0.0-alpha"] + "ink": ["5.0.0-alpha", "5.0.0"] } } } diff --git a/crates/metadata/src/compatibility.rs b/crates/metadata/src/compatibility.rs index a55162c33..ba981d1b2 100644 --- a/crates/metadata/src/compatibility.rs +++ b/crates/metadata/src/compatibility.rs @@ -43,11 +43,17 @@ struct Requirements { /// Checks whether the contract's ink! version is compatible with the cargo-contract /// binary. -pub fn check_contract_ink_compatibility(ink_version: &Version) -> Result<()> { +pub fn check_contract_ink_compatibility( + ink_version: &Version, + cargo_contract_version: Option, +) -> Result<()> { let compatibility_list = include_str!("../compatibility_list.json"); let compatibility: Compatibility = serde_json::from_str(compatibility_list)?; - let cargo_contract_version = - semver::Version::parse(VERSION).expect("Parsing version failed"); + let cargo_contract_version = if let Some(version) = cargo_contract_version { + version + } else { + semver::Version::parse(VERSION).expect("Parsing version failed") + }; let ink_req = &compatibility .cargo_contract_compatibility .get(&cargo_contract_version) @@ -127,38 +133,43 @@ mod tests { #[test] fn ink_check_failes_when_incompatible_version() { let ink_version = Version::new(3, 2, 0); - let res = check_contract_ink_compatibility(&ink_version) - .expect_err("Ink version check should fail"); + let cargo_contract_version = Some(Version::new(3, 2, 0)); + let res = check_contract_ink_compatibility( + &ink_version, + cargo_contract_version.clone(), + ) + .expect_err("Ink version check should fail"); assert_eq!( res.to_string(), "The cargo-contract is not compatible with the contract's ink! version. \ Please update the cargo-contract to version '1.5.0' or update \ - the contract ink! to a version of '^4.0.0-alpha.3', '^4.0.0', '^5.0.0-alpha'" + the contract ink! to a version of '^4.0.0-alpha.3', '^4.0.0'" ); let ink_version = Version::parse("4.0.0-alpha.1").expect("Parsing version must work"); - let res = check_contract_ink_compatibility(&ink_version) + let res = check_contract_ink_compatibility(&ink_version, cargo_contract_version) .expect_err("Ink version check should fail"); assert_eq!( - res.to_string(), - "The cargo-contract is not compatible with the contract's ink! version. \ - Please update the cargo-contract to version '1.5.0' or update \ - the contract ink! to a version of '^4.0.0-alpha.3', '^4.0.0', '^5.0.0-alpha'" + res.to_string(), + "The cargo-contract is not compatible with the contract's ink! version. \ + Please update the cargo-contract to version '1.5.0' or update \ + the contract ink! to a version of '^4.0.0-alpha.3', '^4.0.0'" ); } #[test] fn ink_check_succeeds_when_compatible_version() { - let ink_version = Version::new(4, 2, 3); - let res = check_contract_ink_compatibility(&ink_version); + let ink_version = Version::new(4, 2, 0); + let cargo_contract_version = Some(Version::new(3, 2, 0)); + let res = check_contract_ink_compatibility(&ink_version, cargo_contract_version); assert!(res.is_ok()); let ink_version = - Version::parse("4.0.0-alpha.4").expect("Parsing version must work"); - let res = check_contract_ink_compatibility(&ink_version); + Version::parse("5.0.0-alpha.4").expect("Parsing version must work"); + let res = check_contract_ink_compatibility(&ink_version, None); assert!(res.is_ok()); } } diff --git a/crates/metadata/src/lib.rs b/crates/metadata/src/lib.rs index dc95c7046..e0eba5f59 100644 --- a/crates/metadata/src/lib.rs +++ b/crates/metadata/src/lib.rs @@ -156,6 +156,7 @@ impl ContractMetadata { if let Language::Ink = self.source.language.language { compatibility::check_contract_ink_compatibility( &self.source.language.version, + None, )?; } Ok(())