Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9940e78
update interfaces of OnRuntimeUpgrade & Hooks
NingLin-P Sep 4, 2022
df6c7d3
remove try-runtime for PreStateDigest
NingLin-P Sep 4, 2022
958f645
remove the Default bound of PreStateDigest
NingLin-P Sep 4, 2022
4cbfda0
remove try-runtime for PreStateDigest & pre_upgrade
NingLin-P Sep 4, 2022
6367791
remove tmp storage between upgrade hooks
NingLin-P Sep 4, 2022
a0c953b
Merge branch 'master' of github.com:paritytech/substrate into upgrade…
NingLin-P Sep 4, 2022
ca1c9e3
ensure hooks are storage noop
NingLin-P Sep 4, 2022
46e47c0
remove OnRuntimeUpgradeHelpersExt
NingLin-P Sep 4, 2022
e80c7fb
cargo check & fmt
NingLin-P Sep 5, 2022
49f487c
rename PreStateDigest to PreUpgradeState
NingLin-P Sep 6, 2022
c95eed3
replace associate type with codec & vec
NingLin-P Sep 6, 2022
44226fc
add helper strcut to help encode/decode tuple
NingLin-P Sep 6, 2022
88e4da5
update comment
NingLin-P Sep 6, 2022
33a4227
fix
NingLin-P Sep 6, 2022
ffea862
add test
NingLin-P Sep 7, 2022
4e19a3f
address comment
NingLin-P Sep 8, 2022
313bc4e
fix doc
NingLin-P Sep 8, 2022
f71a5c2
Merge branch 'master' of github.com:paritytech/substrate into upgrade…
NingLin-P Sep 8, 2022
af17cbf
fix ci
NingLin-P Sep 9, 2022
90108ec
address comment
NingLin-P Sep 13, 2022
eb0cb8b
add more test cases
NingLin-P Sep 13, 2022
2beb905
merge master
NingLin-P Sep 13, 2022
96f3a21
make clippy happy
NingLin-P Sep 13, 2022
c623720
fmt
NingLin-P Sep 13, 2022
7df0f56
update comment
NingLin-P Sep 16, 2022
8714113
fmt
NingLin-P Sep 16, 2022
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
Prev Previous commit
Next Next commit
add test
Signed-off-by: linning <[email protected]>
  • Loading branch information
NingLin-P committed Sep 7, 2022
commit ffea86287252cf401859e15f9438d5ec1e11d9bd
61 changes: 61 additions & 0 deletions frame/support/src/traits/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,65 @@ mod tests {
ON_IDLE_INVOCATION_ORDER.clear();
}
}

#[cfg(feature = "try-runtime")]
#[test]
fn on_runtime_upgrade_tuple() {
struct Test1;
struct Test2;
struct Test3;

impl OnRuntimeUpgrade for Test1 {
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
Ok("Test1".encode())
}
fn post_upgrade(state: Vec<u8>) -> Result<(), &'static str> {
let s: String = Decode::decode(&mut state.as_slice()).unwrap();
assert_eq!(s, "Test1");
Ok(())
}
}
impl OnRuntimeUpgrade for Test2 {
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
Ok(100u32.encode())
}
fn post_upgrade(state: Vec<u8>) -> Result<(), &'static str> {
let s: u32 = Decode::decode(&mut state.as_slice()).unwrap();
assert_eq!(s, 100);
Ok(())
}
}
impl OnRuntimeUpgrade for Test3 {
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
Ok(true.encode())
}
fn post_upgrade(state: Vec<u8>) -> Result<(), &'static str> {
let s: bool = Decode::decode(&mut state.as_slice()).unwrap();
assert_eq!(s, true);
Ok(())
}
}

type Test123 = (Test1, Test2, Test3);
let state = <Test123 as OnRuntimeUpgrade>::pre_upgrade().unwrap();
let helper: TupleCodecHelper = Decode::decode(&mut state.as_slice()).unwrap();
assert_eq!(
<String as Decode>::decode(&mut helper.0[0].as_slice()).unwrap(),
"Test1".to_owned()
);
assert_eq!(<u32 as Decode>::decode(&mut helper.0[1].as_slice()).unwrap(), 100u32);
assert_eq!(<bool as Decode>::decode(&mut helper.0[2].as_slice()).unwrap(), true);
<Test123 as OnRuntimeUpgrade>::post_upgrade(state).unwrap();

type Test321 = (Test3, Test2, Test1);
let state = <Test321 as OnRuntimeUpgrade>::pre_upgrade().unwrap();
let helper: TupleCodecHelper = Decode::decode(&mut state.as_slice()).unwrap();
assert_eq!(<bool as Decode>::decode(&mut helper.0[0].as_slice()).unwrap(), true);
assert_eq!(<u32 as Decode>::decode(&mut helper.0[1].as_slice()).unwrap(), 100u32);
assert_eq!(
<String as Decode>::decode(&mut helper.0[2].as_slice()).unwrap(),
"Test1".to_owned()
);
<Test321 as OnRuntimeUpgrade>::post_upgrade(state).unwrap();
}
}