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

Fix try-runtime follow-chain, try-runtime upgrade tuple tests, cli test utils #13794

Merged
merged 31 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
cf0874d
new test for try-runtime tuple stuff
kianenigma Mar 31, 2023
b62c68c
fix
kianenigma Mar 31, 2023
7ccae6c
Merge branch 'master' of github.com:paritytech/substrate into liam-fi…
liamaharon Mar 31, 2023
d1ac703
remove development comment
liamaharon Mar 31, 2023
e826168
formatting
liamaharon Mar 31, 2023
cfd0dd7
remove todo comment
liamaharon Apr 1, 2023
d5d58bc
follow-chain working test
liamaharon Apr 4, 2023
8094ba8
refactor common cli testing utils
liamaharon Apr 4, 2023
b2ad590
fix comment
liamaharon Apr 4, 2023
f644dfa
revert Cargo.lock changes
liamaharon Apr 4, 2023
b9a6eba
update Cargo.lock
liamaharon Apr 4, 2023
90f135e
improve doc comment
liamaharon Apr 4, 2023
00aa83b
fix error typo
liamaharon Apr 4, 2023
cd56330
Merge branch 'master' of github.com:paritytech/substrate into liam-fi…
liamaharon Apr 4, 2023
0f79142
update Cargo.lock
liamaharon Apr 4, 2023
44b456b
feature gate try-runtime test
liamaharon Apr 5, 2023
38dee61
build_substrate cli test util
liamaharon Apr 5, 2023
5532ee6
feature gate follow_chain tests
liamaharon Apr 5, 2023
3ca75d3
move fn start_node to test-utils
liamaharon Apr 5, 2023
2a6d812
improve test pkg name
liamaharon Apr 5, 2023
7b3ca6f
use tokio Child and Command
liamaharon Apr 5, 2023
a1907b3
Merge branch 'master' of github.com:paritytech/substrate into liam-fi…
liamaharon Apr 5, 2023
391b741
remove redundant import
liamaharon Apr 5, 2023
99e23ae
fix ci
liamaharon Apr 5, 2023
b122fe6
Merge branch 'master' of github.com:paritytech/substrate into liam-fi…
liamaharon Apr 5, 2023
28dab86
fix ci
liamaharon Apr 5, 2023
ffeb781
don't leave hanging processes
liamaharon Apr 5, 2023
99c62a7
improved child process cleanup
liamaharon Apr 5, 2023
8c351c2
use existing KillChildOnDrop
liamaharon Apr 5, 2023
10a7b9e
remove redundant comment
liamaharon Apr 5, 2023
a01da35
Update test-utils/cli/src/lib.rs
liamaharon Apr 6, 2023
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
6 changes: 2 additions & 4 deletions frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
58 changes: 56 additions & 2 deletions frame/support/src/traits/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?); )* );
Expand Down Expand Up @@ -359,10 +359,64 @@ pub trait OnTimestampSet<Moment> {
#[cfg(test)]
mod tests {
use super::*;
use sp_io::TestExternalities;

#[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();
// todo unify the API for storage parameter_types! output.
liamaharon marked this conversation as resolved.
Show resolved Hide resolved
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 {
Expand Down
12 changes: 8 additions & 4 deletions utils/frame/try-runtime/cli/src/commands/follow_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ where
.or_else(|e| {
if matches!(e, substrate_rpc_client::Error::ParseError(_)) {
log::error!(
target: LOG_TARGET,
"failed to parse the block format of remote against the local \
codebase. The block format has changed, and follow-chain cannot run in \
this case. Try running this command in a branch of your codebase that has \
the same block format as the remote chain. For now, we replace the block with an empty one"
codebase. The block format has changed, and follow-chain cannot run in \
this case. Try running this command in a branch of your codebase that
has the same block format as the remote chain. For now, we replace the \
block with an empty one."
);
}
Err(rpc_err_handler(e))
Expand Down Expand Up @@ -148,7 +150,9 @@ where
state_ext,
&executor,
"TryRuntime_execute_block",
(block, command.state_root_check, command.try_state.clone()).encode().as_ref(),
(block, command.state_root_check, true, command.try_state.clone())
.encode()
.as_ref(),
full_extensions(),
shared
.export_proof
Expand Down