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

Remove check for compatible scale and scale-info versions #1370

Merged
merged 4 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
81 changes: 2 additions & 79 deletions crates/build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -853,12 +821,11 @@ pub fn execute(args: ExecuteArgs) -> Result<BuildResult> {

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());
}

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion crates/metadata/compatibility_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
}
}
41 changes: 26 additions & 15 deletions crates/metadata/src/compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Version>,
) -> 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)
Expand Down Expand Up @@ -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());
}
}
1 change: 1 addition & 0 deletions crates/metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
Loading