mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 15:47:58 +00:00
Fix try-runtime follow-chain, try-runtime upgrade tuple tests, cli test utils (#13794)
* new test for try-runtime tuple stuff * fix * remove development comment * formatting * remove todo comment * follow-chain working test * refactor common cli testing utils * fix comment * revert Cargo.lock changes * update Cargo.lock * improve doc comment * fix error typo * update Cargo.lock * feature gate try-runtime test * build_substrate cli test util * feature gate follow_chain tests * move fn start_node to test-utils * improve test pkg name * use tokio Child and Command * remove redundant import * fix ci * fix ci * don't leave hanging processes * improved child process cleanup * use existing KillChildOnDrop * remove redundant comment * Update test-utils/cli/src/lib.rs Co-authored-by: Koute <koute@users.noreply.github.com> --------- Co-authored-by: kianenigma <kian@parity.io> Co-authored-by: Koute <koute@users.noreply.github.com>
This commit is contained in:
@@ -371,16 +371,14 @@ macro_rules! parameter_types {
|
||||
|
||||
/// Set the value of this parameter type in the storage.
|
||||
///
|
||||
/// This needs to be executed in an externalities provided
|
||||
/// environment.
|
||||
/// This needs to be executed in an externalities provided environment.
|
||||
pub fn set(value: &$type) {
|
||||
$crate::storage::unhashed::put(&Self::key(), value);
|
||||
}
|
||||
|
||||
/// Returns the value of this parameter type.
|
||||
///
|
||||
/// This needs to be executed in an externalities provided
|
||||
/// environment.
|
||||
/// This needs to be executed in an externalities provided environment.
|
||||
#[allow(unused)]
|
||||
pub fn get() -> $type {
|
||||
$crate::storage::unhashed::get(&Self::key()).unwrap_or_else(|| $value)
|
||||
|
||||
@@ -197,10 +197,10 @@ impl OnRuntimeUpgrade for Tuple {
|
||||
weight
|
||||
}
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
/// We are executing pre- and post-checks sequentially in order to be able to test several
|
||||
/// consecutive migrations for the same pallet without errors. Therefore pre and post upgrade
|
||||
/// hooks for tuples are a noop.
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn try_on_runtime_upgrade(checks: bool) -> Result<Weight, &'static str> {
|
||||
let mut weight = Weight::zero();
|
||||
for_tuples!( #( weight = weight.saturating_add(Tuple::try_on_runtime_upgrade(checks)?); )* );
|
||||
@@ -364,10 +364,64 @@ pub trait OnTimestampSet<Moment> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use sp_io::TestExternalities;
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
#[test]
|
||||
fn on_runtime_upgrade_pre_post_executed_tuple() {
|
||||
crate::parameter_types! {
|
||||
pub static Pre: Vec<&'static str> = Default::default();
|
||||
pub static Post: Vec<&'static str> = Default::default();
|
||||
}
|
||||
|
||||
macro_rules! impl_test_type {
|
||||
($name:ident) => {
|
||||
struct $name;
|
||||
impl OnRuntimeUpgrade for $name {
|
||||
fn on_runtime_upgrade() -> Weight {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
|
||||
Pre::mutate(|s| s.push(stringify!($name)));
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn post_upgrade(_: Vec<u8>) -> Result<(), &'static str> {
|
||||
Post::mutate(|s| s.push(stringify!($name)));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl_test_type!(Foo);
|
||||
impl_test_type!(Bar);
|
||||
impl_test_type!(Baz);
|
||||
|
||||
TestExternalities::default().execute_with(|| {
|
||||
Foo::try_on_runtime_upgrade(true).unwrap();
|
||||
assert_eq!(Pre::take(), vec!["Foo"]);
|
||||
assert_eq!(Post::take(), vec!["Foo"]);
|
||||
|
||||
<(Foo, Bar, Baz)>::try_on_runtime_upgrade(true).unwrap();
|
||||
assert_eq!(Pre::take(), vec!["Foo", "Bar", "Baz"]);
|
||||
assert_eq!(Post::take(), vec!["Foo", "Bar", "Baz"]);
|
||||
|
||||
<((Foo, Bar), Baz)>::try_on_runtime_upgrade(true).unwrap();
|
||||
assert_eq!(Pre::take(), vec!["Foo", "Bar", "Baz"]);
|
||||
assert_eq!(Post::take(), vec!["Foo", "Bar", "Baz"]);
|
||||
|
||||
<(Foo, (Bar, Baz))>::try_on_runtime_upgrade(true).unwrap();
|
||||
assert_eq!(Pre::take(), vec!["Foo", "Bar", "Baz"]);
|
||||
assert_eq!(Post::take(), vec!["Foo", "Bar", "Baz"]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn on_initialize_and_on_runtime_upgrade_weight_merge_works() {
|
||||
use sp_io::TestExternalities;
|
||||
struct Test;
|
||||
|
||||
impl OnInitialize<u8> for Test {
|
||||
|
||||
Reference in New Issue
Block a user