Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Prepare for rust stable 1.60 (#11138)
Browse files Browse the repository at this point in the history
* Prepare for rust stable 1.59

Besides preparing the UI tests this also adds a new script update-rust-stable.sh script for
simplifying the update of a rust stable version. This script will run all UI tests for the new
rust stable version and updating the expected output.

* Ensure we run the UI tests in CI

* use staging ci image

* More test updates

* Unignore test (#11097)

* empty commit for pipeline rerun

* empty commit for pipeline rerun

* Try to make clippy happy

* More clippy fixes

* FMT

* ci image production

Co-authored-by: alvicsam <alvicsam@gmail.com>
Co-authored-by: Alexander Samusev <41779041+alvicsam@users.noreply.github.com>
  • Loading branch information
3 people committed Apr 11, 2022
1 parent 4c82679 commit b647138
Show file tree
Hide file tree
Showing 36 changed files with 329 additions and 368 deletions.
2 changes: 2 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ test-linux-stable: &test-linux
RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings"
RUST_BACKTRACE: 1
WASM_BUILD_NO_COLOR: 1
# Ensure we run the UI tests.
RUN_UI_TESTS: 1
script:
# this job runs all tests in former runtime-benchmarks, frame-staking and wasmtime tests
- time cargo test --workspace --locked --release --verbose --features runtime-benchmarks --manifest-path ./bin/node/cli/Cargo.toml
Expand Down
42 changes: 42 additions & 0 deletions .maintain/update-rust-stable.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
#
# Script for updating the UI tests for a new rust stable version.
#
# It needs to be called like this:
#
# update-rust-stable.sh 1.61
#
# This will run all UI tests with the rust stable 1.61. The script
# requires that rustup is installed.
set -e

if [ "$#" -ne 1 ]; then
echo "Please specify the rust version to use. E.g. update-rust-stable.sh 1.61"
exit
fi

RUST_VERSION=$1

if ! command -v rustup &> /dev/null
then
echo "rustup needs to be installed"
exit
fi

rustup install $RUST_VERSION
rustup component add rust-src --toolchain $RUST_VERSION

# Ensure we run the ui tests
export RUN_UI_TESTS=1
# We don't need any wasm files for ui tests
export SKIP_WASM_BUILD=1
# Let trybuild overwrite the .stderr files
export TRYBUILD=overwrite

# Run all the relevant UI tests
#
# Any new UI tests in different crates need to be added here as well.
rustup run $RUST_VERSION cargo test -p sp-runtime-interface ui
rustup run $RUST_VERSION cargo test -p sp-api-test ui
rustup run $RUST_VERSION cargo test -p frame-election-provider-solution-type ui
rustup run $RUST_VERSION cargo test -p frame-support-test ui
6 changes: 2 additions & 4 deletions bin/node/cli/benches/transaction_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn create_account_extrinsics(
accounts
.iter()
.enumerate()
.map(|(i, a)| {
.flat_map(|(i, a)| {
vec![
// Reset the nonce by removing any funds
create_extrinsic(
Expand Down Expand Up @@ -162,7 +162,6 @@ fn create_account_extrinsics(
),
]
})
.flatten()
.map(OpaqueExtrinsic::from)
.collect()
}
Expand All @@ -174,7 +173,7 @@ fn create_benchmark_extrinsics(
) -> Vec<OpaqueExtrinsic> {
accounts
.iter()
.map(|account| {
.flat_map(|account| {
(0..extrinsics_per_account).map(move |nonce| {
create_extrinsic(
client,
Expand All @@ -187,7 +186,6 @@ fn create_benchmark_extrinsics(
)
})
})
.flatten()
.map(OpaqueExtrinsic::from)
.collect()
}
Expand Down
2 changes: 1 addition & 1 deletion client/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
.collect();

let endpoint = if let Some(e) =
swarm.behaviour_mut().node(peer_id).map(|i| i.endpoint()).flatten()
swarm.behaviour_mut().node(peer_id).and_then(|i| i.endpoint())
{
e.clone().into()
} else {
Expand Down
4 changes: 2 additions & 2 deletions client/offchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ where
H: ExHashT,
{
fn set_authorized_peers(&self, peers: HashSet<PeerId>) {
self.set_authorized_peers(peers)
NetworkService::set_authorized_peers(self, peers)
}

fn set_authorized_only(&self, reserved_only: bool) {
self.set_authorized_only(reserved_only)
NetworkService::set_authorized_only(self, reserved_only)
}
}

Expand Down
42 changes: 20 additions & 22 deletions client/service/src/client/call_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,28 +91,26 @@ where
B: backend::Backend<Block>,
{
let spec = CallExecutor::runtime_version(self, id)?;
let code = if let Some(d) = self
.wasm_override
.as_ref()
.as_ref()
.map(|o| o.get(&spec.spec_version, onchain_code.heap_pages, &spec.spec_name))
.flatten()
{
log::debug!(target: "wasm_overrides", "using WASM override for block {}", id);
d
} else if let Some(s) =
self.wasm_substitutes.get(spec.spec_version, onchain_code.heap_pages, id)
{
log::debug!(target: "wasm_substitutes", "Using WASM substitute for block {:?}", id);
s
} else {
log::debug!(
target: "wasm_overrides",
"No WASM override available for block {}, using onchain code",
id
);
onchain_code
};
let code =
if let Some(d) =
self.wasm_override.as_ref().as_ref().and_then(|o| {
o.get(&spec.spec_version, onchain_code.heap_pages, &spec.spec_name)
}) {
log::debug!(target: "wasm_overrides", "using WASM override for block {}", id);
d
} else if let Some(s) =
self.wasm_substitutes.get(spec.spec_version, onchain_code.heap_pages, id)
{
log::debug!(target: "wasm_substitutes", "Using WASM substitute for block {:?}", id);
s
} else {
log::debug!(
target: "wasm_overrides",
"No WASM override available for block {}, using onchain code",
id
);
onchain_code
};

Ok(code)
}
Expand Down
2 changes: 1 addition & 1 deletion client/service/src/client/wasm_override.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl WasmOverride {
for entry in fs::read_dir(dir).map_err(handle_err)? {
let entry = entry.map_err(handle_err)?;
let path = entry.path();
match path.extension().map(|e| e.to_str()).flatten() {
match path.extension().and_then(|e| e.to_str()) {
Some("wasm") => {
let code = fs::read(&path).map_err(handle_err)?;
let code_hash = make_hash(&code);
Expand Down
8 changes: 8 additions & 0 deletions docs/CONTRIBUTING.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ Please label issues with the following labels:

Declaring formal releases remains the prerogative of the project maintainer(s).

== UI tests

UI tests are used for macros to ensure that the output of a macro doesn't change and is in the expected format. These UI tests are sensible to any changes
in the macro generated code or to switching the rust stable version. The tests are only run when the `RUN_UI_TESTS` environment variable is set. So, when
the CI is for example complaining about failing UI tests and it is expected that they fail these tests need to be executed locally. To simplify the updating
of the UI test ouput there is the `.maintain/update-rust-stable.sh` script. This can be run with `.maintain/update-rust-stable.sh CURRENT_STABLE_VERSION`
and then it will run all UI tests to update the expected output.

== Changes to this arrangement

This is an experiment and feedback is welcome! This document may also be subject to pull-requests or changes by contributors where you believe you have something valuable to add or change.
Expand Down
5 changes: 5 additions & 0 deletions frame/election-provider-support/solution-type/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ fn imports() -> Result<TokenStream2> {
mod tests {
#[test]
fn ui_fail() {
// Only run the ui tests when `RUN_UI_TESTS` is set.
if std::env::var("RUN_UI_TESTS").is_err() {
return
}

let cases = trybuild::TestCases::new();
cases.compile_fail("tests/ui/fail/*.rs");
}
Expand Down
5 changes: 5 additions & 0 deletions frame/support/test/tests/construct_runtime_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ use std::env;
#[cfg(not(feature = "disable-ui-tests"))]
#[test]
fn ui() {
// Only run the ui tests when `RUN_UI_TESTS` is set.
if env::var("RUN_UI_TESTS").is_err() {
return
}

// As trybuild is using `cargo check`, we don't need the real WASM binaries.
env::set_var("SKIP_WASM_BUILD", "1");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,16 @@ help: consider importing this struct
|

error[E0283]: type annotations needed
--> tests/construct_runtime_ui/no_std_genesis_config.rs:40:1
|
40 | / construct_runtime! {
41 | | pub enum Runtime where
42 | | Block = Block,
43 | | NodeBlock = Block,
... |
48 | | }
49 | | }
| |_^ cannot infer type
|
= note: cannot satisfy `_: std::default::Default`
note: required by `std::default::Default::default`
--> $RUST/core/src/default.rs
|
| fn default() -> Self;
| ^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
--> tests/construct_runtime_ui/no_std_genesis_config.rs:40:1
|
40 | / construct_runtime! {
41 | | pub enum Runtime where
42 | | Block = Block,
43 | | NodeBlock = Block,
... |
48 | | }
49 | | }
| |_^ cannot infer type
|
= note: cannot satisfy `_: std::default::Default`
= note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,16 @@ help: consider importing this struct
|

error[E0283]: type annotations needed
--> tests/construct_runtime_ui/undefined_genesis_config_part.rs:49:1
|
49 | / construct_runtime! {
50 | | pub enum Runtime where
51 | | Block = Block,
52 | | NodeBlock = Block,
... |
57 | | }
58 | | }
| |_^ cannot infer type
|
= note: cannot satisfy `_: std::default::Default`
note: required by `std::default::Default::default`
--> $RUST/core/src/default.rs
|
| fn default() -> Self;
| ^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
--> tests/construct_runtime_ui/undefined_genesis_config_part.rs:49:1
|
49 | / construct_runtime! {
50 | | pub enum Runtime where
51 | | Block = Block,
52 | | NodeBlock = Block,
... |
57 | | }
58 | | }
| |_^ cannot infer type
|
= note: cannot satisfy `_: std::default::Default`
= note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
5 changes: 5 additions & 0 deletions frame/support/test/tests/decl_module_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
#[cfg(not(feature = "disable-ui-tests"))]
#[test]
fn decl_module_ui() {
// Only run the ui tests when `RUN_UI_TESTS` is set.
if std::env::var("RUN_UI_TESTS").is_err() {
return
}

// As trybuild is using `cargo check`, we don't need the real WASM binaries.
std::env::set_var("SKIP_WASM_BUILD", "1");

Expand Down
5 changes: 5 additions & 0 deletions frame/support/test/tests/decl_storage_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
#[cfg(not(feature = "disable-ui-tests"))]
#[test]
fn decl_storage_ui() {
// Only run the ui tests when `RUN_UI_TESTS` is set.
if std::env::var("RUN_UI_TESTS").is_err() {
return
}

// As trybuild is using `cargo check`, we don't need the real WASM binaries.
std::env::set_var("SKIP_WASM_BUILD", "1");

Expand Down
5 changes: 5 additions & 0 deletions frame/support/test/tests/derive_no_bound_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
#[cfg(not(feature = "disable-ui-tests"))]
#[test]
fn derive_no_bound_ui() {
// Only run the ui tests when `RUN_UI_TESTS` is set.
if std::env::var("RUN_UI_TESTS").is_err() {
return
}

// As trybuild is using `cargo check`, we don't need the real WASM binaries.
std::env::set_var("SKIP_WASM_BUILD", "1");

Expand Down
14 changes: 4 additions & 10 deletions frame/support/test/tests/derive_no_bound_ui/clone.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
error[E0277]: the trait bound `<T as Config>::C: Clone` is not satisfied
--> tests/derive_no_bound_ui/clone.rs:7:2
|
7 | c: T::C,
| ^ the trait `Clone` is not implemented for `<T as Config>::C`
|
note: required by `clone`
--> $RUST/core/src/clone.rs
|
| fn clone(&self) -> Self;
| ^^^^^^^^^^^^^^^^^^^^^^^^
--> tests/derive_no_bound_ui/clone.rs:7:2
|
7 | c: T::C,
| ^ the trait `Clone` is not implemented for `<T as Config>::C`
14 changes: 4 additions & 10 deletions frame/support/test/tests/derive_no_bound_ui/default.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
error[E0277]: the trait bound `<T as Config>::C: std::default::Default` is not satisfied
--> $DIR/default.rs:7:2
|
7 | c: T::C,
| ^ the trait `std::default::Default` is not implemented for `<T as Config>::C`
|
note: required by `std::default::Default::default`
--> $DIR/default.rs:116:5
|
116 | fn default() -> Self;
| ^^^^^^^^^^^^^^^^^^^^^
--> tests/derive_no_bound_ui/default.rs:7:2
|
7 | c: T::C,
| ^ the trait `std::default::Default` is not implemented for `<T as Config>::C`
5 changes: 5 additions & 0 deletions frame/support/test/tests/pallet_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
#[cfg(not(feature = "disable-ui-tests"))]
#[test]
fn pallet_ui() {
// Only run the ui tests when `RUN_UI_TESTS` is set.
if std::env::var("RUN_UI_TESTS").is_err() {
return
}

// As trybuild is using `cargo check`, we don't need the real WASM binaries.
std::env::set_var("SKIP_WASM_BUILD", "1");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@ error[E0277]: `<T as pallet::Config>::Bar` doesn't implement `std::fmt::Debug`
= note: required for the cast to the object type `dyn std::fmt::Debug`

error[E0277]: the trait bound `<T as pallet::Config>::Bar: Clone` is not satisfied
--> tests/pallet_ui/call_argument_invalid_bound.rs:20:36
|
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
| ^^^ the trait `Clone` is not implemented for `<T as pallet::Config>::Bar`
|
note: required by `clone`
--> $RUST/core/src/clone.rs
|
| fn clone(&self) -> Self;
| ^^^^^^^^^^^^^^^^^^^^^^^^
--> tests/pallet_ui/call_argument_invalid_bound.rs:20:36
|
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
| ^^^ the trait `Clone` is not implemented for `<T as pallet::Config>::Bar`

error[E0369]: binary operation `==` cannot be applied to type `&<T as pallet::Config>::Bar`
--> tests/pallet_ui/call_argument_invalid_bound.rs:20:36
Expand Down
Loading

0 comments on commit b647138

Please sign in to comment.