mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 08:47:57 +00:00
Add Authorize Upgrade Pattern to Frame System (#2682)
Adds the `authorize_upgrade` -> `enact_authorized_upgrade` pattern to `frame-system`. This will be useful for upgrading bridged chains that are under the governance of Polkadot without passing entire runtime Wasm blobs over a bridge. Notes: - Changed `enact_authorized_upgrade` to `apply_authorized_upgrade`. Personal opinion, "apply" more accurately expresses what it's doing. Can change back if outvoted. - Remove `check_version` in favor of two extrinsics, so as to make _checked_ the default. - Left calls in `parachain-system` and marked as deprecated to prevent breaking the API. They just call into the `frame-system` functions. - Updated `frame-system` benchmarks to v2 syntax. --------- Co-authored-by: command-bot <>
This commit is contained in:
@@ -675,6 +675,46 @@ fn set_code_with_real_wasm_blob() {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_code_via_authorization_works() {
|
||||
let executor = substrate_test_runtime_client::new_native_or_wasm_executor();
|
||||
let mut ext = new_test_ext();
|
||||
ext.register_extension(sp_core::traits::ReadRuntimeVersionExt::new(executor));
|
||||
ext.execute_with(|| {
|
||||
System::set_block_number(1);
|
||||
assert!(System::authorized_upgrade().is_none());
|
||||
|
||||
let runtime = substrate_test_runtime_client::runtime::wasm_binary_unwrap().to_vec();
|
||||
let hash = <mock::Test as pallet::Config>::Hashing::hash(&runtime);
|
||||
|
||||
// Can't apply before authorization
|
||||
assert_noop!(
|
||||
System::apply_authorized_upgrade(RawOrigin::None.into(), runtime.clone()),
|
||||
Error::<Test>::NothingAuthorized,
|
||||
);
|
||||
|
||||
// Can authorize
|
||||
assert_ok!(System::authorize_upgrade(RawOrigin::Root.into(), hash));
|
||||
System::assert_has_event(
|
||||
SysEvent::UpgradeAuthorized { code_hash: hash, check_version: true }.into(),
|
||||
);
|
||||
assert!(System::authorized_upgrade().is_some());
|
||||
|
||||
// Can't be sneaky
|
||||
let mut bad_runtime = substrate_test_runtime_client::runtime::wasm_binary_unwrap().to_vec();
|
||||
bad_runtime.extend(b"sneaky");
|
||||
assert_noop!(
|
||||
System::apply_authorized_upgrade(RawOrigin::None.into(), bad_runtime),
|
||||
Error::<Test>::Unauthorized,
|
||||
);
|
||||
|
||||
// Can apply correct runtime
|
||||
assert_ok!(System::apply_authorized_upgrade(RawOrigin::None.into(), runtime));
|
||||
System::assert_has_event(SysEvent::CodeUpdated.into());
|
||||
assert!(System::authorized_upgrade().is_none());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runtime_upgraded_with_set_storage() {
|
||||
let executor = substrate_test_runtime_client::new_native_or_wasm_executor();
|
||||
|
||||
Reference in New Issue
Block a user