Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielMartinezRodriguez committed Jan 23, 2024
1 parent dc8ad7a commit 3bcd397
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 31 deletions.
6 changes: 2 additions & 4 deletions pallets/upgrade-runtime-proposal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ mod mock;
mod tests;

use frame_support::dispatch::UnfilteredDispatchable;
use frame_support::sp_runtime::traits::Hash;
use frame_support::traits::EnsureOrigin;
use frame_system::pallet_prelude::BlockNumberFor;
use frame_system::pallet_prelude::OriginFor;
use frame_support::sp_runtime::traits::Hash;

#[frame_support::pallet]
pub mod pallet {
Expand Down Expand Up @@ -185,9 +185,7 @@ pub mod pallet {
}

pub fn hash_of_proposed_code() -> Option<T::Hash> {
<ProposedCode<T>>::get().map(|code| {
T::Hashing::hash(&code)
})
<ProposedCode<T>>::get().map(|code| T::Hashing::hash(&code))
}

pub fn set_current_code_hash(hash: T::Hash) -> () {
Expand Down
2 changes: 1 addition & 1 deletion pallets/upgrade-runtime-proposal/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use frame_support::parameter_types;
use frame_support::traits::{ConstU32, ConstU64, Contains};
use frame_system::EnsureRoot;
use sp_core::H256;
use sp_runtime::generic;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};
use sp_version::RuntimeVersion;
use sp_runtime::generic;

type Block = frame_system::mocking::MockBlock<Test>;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
Expand Down
59 changes: 33 additions & 26 deletions pallets/upgrade-runtime-proposal/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use crate::mock::UpgradeRuntimeProposal;

use super::*;
use frame_support::traits::Hooks;
use frame_support::{assert_noop, assert_ok, dispatch::DispatchError};
use mock::{
new_test_ext, Test, assert_runtime_updated_digest
};
use mock::{assert_runtime_updated_digest, new_test_ext, Test};
use sp_core::keccak_256;
use frame_support::traits::Hooks;

#[test]
fn test_setup_works() {
Expand Down Expand Up @@ -103,7 +101,10 @@ fn test_set_block_application() {
frame_system::RawOrigin::Root.into(),
1
));
assert_eq!(UpgradeRuntimeProposal::get_application_block_number().unwrap(), 1);
assert_eq!(
UpgradeRuntimeProposal::get_application_block_number().unwrap(),
1
);
});
}

Expand Down Expand Up @@ -197,31 +198,37 @@ fn test_fails_reject_proposed_code_if_no_proposed_code() {

#[test]
fn test_scheduled_update_runtime() {
let executor = stability_test_runtime_client::new_native_or_wasm_executor();
let mut ext = new_test_ext();
ext.register_extension(sp_core::traits::ReadRuntimeVersionExt::new(executor));
let executor = stability_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(|| {
assert_ok!(UpgradeRuntimeProposal::propose_code(
frame_system::RawOrigin::Root.into(),
stability_test_runtime_client::runtime::wasm_binary_unwrap().to_vec()
));
ext.execute_with(|| {
assert_ok!(UpgradeRuntimeProposal::propose_code(
frame_system::RawOrigin::Root.into(),
stability_test_runtime_client::runtime::wasm_binary_unwrap().to_vec()
));

let proposed_code_hash = UpgradeRuntimeProposal::hash_of_proposed_code().unwrap();

assert_ok!(UpgradeRuntimeProposal::set_block_application(
frame_system::RawOrigin::Root.into(),
1
));
assert_eq!(UpgradeRuntimeProposal::get_application_block_number().unwrap(), 1);

UpgradeRuntimeProposal::on_initialize(1);
assert_ok!(UpgradeRuntimeProposal::set_block_application(
frame_system::RawOrigin::Root.into(),
1
));
assert_eq!(
UpgradeRuntimeProposal::get_application_block_number().unwrap(),
1
);

UpgradeRuntimeProposal::on_initialize(1);

assert_runtime_updated_digest(1);
assert_runtime_updated_digest(1);

assert!(UpgradeRuntimeProposal::hash_of_proposed_code().is_none());
assert_eq!(UpgradeRuntimeProposal::get_current_code_hash().unwrap(), proposed_code_hash);
assert!(UpgradeRuntimeProposal::get_proposed_code().is_none());
assert!(UpgradeRuntimeProposal::get_application_block_number().is_none());
});
}
assert_eq!(
UpgradeRuntimeProposal::get_current_code_hash().unwrap(),
proposed_code_hash
);
assert!(UpgradeRuntimeProposal::get_proposed_code().is_none());
assert!(UpgradeRuntimeProposal::get_application_block_number().is_none());
});
}

0 comments on commit 3bcd397

Please sign in to comment.