From 0e3c6b52a31f4d3f69499825ec2b4a4e23e06d9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Mon, 1 May 2023 09:47:43 +0200 Subject: [PATCH] Fix bags-list tests execution (#14047) The `test` feature isn't propagated to dependencies in Rust, so we should just enable the method as well for `std`. --- frame/bags-list/src/lib.rs | 2 +- frame/bags-list/src/mock.rs | 7 ++++--- frame/election-provider-support/src/lib.rs | 15 ++++++++++++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/frame/bags-list/src/lib.rs b/frame/bags-list/src/lib.rs index 87eb2d1b341aa..d4d54b9a134bb 100644 --- a/frame/bags-list/src/lib.rs +++ b/frame/bags-list/src/lib.rs @@ -397,7 +397,7 @@ impl, I: 'static> ScoreProvider for Pallet { Node::::get(id).map(|node| node.score()).unwrap_or_default() } - frame_election_provider_support::runtime_benchmarks_or_fuzz_enabled! { + frame_election_provider_support::runtime_benchmarks_fuzz_or_std_enabled! { fn set_score_of(id: &T::AccountId, new_score: T::Score) { ListNodes::::mutate(id, |maybe_node| { if let Some(node) = maybe_node.as_mut() { diff --git a/frame/bags-list/src/mock.rs b/frame/bags-list/src/mock.rs index a48b66b200e8e..efbb2ed94c49f 100644 --- a/frame/bags-list/src/mock.rs +++ b/frame/bags-list/src/mock.rs @@ -40,9 +40,10 @@ impl frame_election_provider_support::ScoreProvider for StakingMock { *NextVoteWeightMap::get().get(id).unwrap_or(&NextVoteWeight::get()) } - #[cfg(any(feature = "runtime-benchmarks", feature = "fuzz", test))] - fn set_score_of(id: &AccountId, weight: Self::Score) { - NEXT_VOTE_WEIGHT_MAP.with(|m| m.borrow_mut().insert(*id, weight)); + frame_election_provider_support::runtime_benchmarks_fuzz_or_std_enabled! { + fn set_score_of(id: &AccountId, weight: Self::Score) { + NEXT_VOTE_WEIGHT_MAP.with(|m| m.borrow_mut().insert(*id, weight)); + } } } diff --git a/frame/election-provider-support/src/lib.rs b/frame/election-provider-support/src/lib.rs index 750ccca46213f..ee0e41a90cd60 100644 --- a/frame/election-provider-support/src/lib.rs +++ b/frame/election-provider-support/src/lib.rs @@ -582,7 +582,7 @@ pub trait ScoreProvider { fn score(who: &AccountId) -> Self::Score; /// For tests, benchmarks and fuzzing, set the `score`. - #[cfg(any(feature = "runtime-benchmarks", feature = "fuzz", test))] + #[cfg(any(feature = "runtime-benchmarks", feature = "fuzz", feature = "std"))] fn set_score_of(_: &AccountId, _: Self::Score) {} } @@ -673,5 +673,14 @@ pub type BoundedSupportsOf = BoundedSupports< ::MaxWinners, >; -sp_core::generate_feature_enabled_macro!(runtime_benchmarks_enabled, feature = "runtime-benchmarks", $); -sp_core::generate_feature_enabled_macro!(runtime_benchmarks_or_fuzz_enabled, any(feature = "runtime-benchmarks", feature = "fuzzing"), $); +sp_core::generate_feature_enabled_macro!( + runtime_benchmarks_enabled, + feature = "runtime-benchmarks", + $ +); + +sp_core::generate_feature_enabled_macro!( + runtime_benchmarks_fuzz_or_std_enabled, + any(feature = "runtime-benchmarks", feature = "fuzzing", feature = "std"), + $ +);