Skip to content

Commit

Permalink
migrate pallet-sudo-and-statement to umbrella crate
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathy-bajo committed Jan 12, 2025
1 parent 49335d8 commit 5f99526
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 110 deletions.
22 changes: 2 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 2 additions & 16 deletions substrate/frame/statement/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { features = ["derive"], workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"]}
log = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
sp-api = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-statement-store = { workspace = true }

[dev-dependencies]
Expand All @@ -33,22 +28,13 @@ pallet-balances = { workspace = true, default-features = true }
default = ["std"]
std = [
"codec/std",
"frame-support/std",
"frame-system/std",
"frame/std",
"log/std",
"pallet-balances/std",
"scale-info/std",
"sp-api/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-statement-store/std",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-balances/try-runtime",
"frame/try-runtime",
"sp-runtime/try-runtime",
"sp-runtime/try-runtime",
]
8 changes: 4 additions & 4 deletions substrate/frame/statement/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
#![cfg_attr(not(feature = "std"), no_std)]

use frame::prelude::*;
use frame::deps::{sp_io, sp_statement_store::{
use frame::{prelude::*, traits::fungible::Inspect, deps::sp_io};
use sp_statement_store::{
runtime_api::{InvalidStatement, StatementSource, ValidStatement},
Proof, SignatureVerificationResult, Statement,
}};
use frame::traits::fungible::Inspect;
};


#[cfg(test)]
mod mock;
Expand Down
14 changes: 1 addition & 13 deletions substrate/frame/statement/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ use super::*;

use crate as pallet_statement;
use frame::testing_prelude::*;
use frame::deps::{sp_runtime::{traits::IdentityLookup, AccountId32, BuildStorage}, sp_core::Pair};
use frame_support::{
derive_impl, ord_parameter_types,
traits::{ConstU32, ConstU64},
};
use sp_core::Pair;
use sp_runtime::{traits::IdentityLookup, AccountId32, BuildStorage};

type Block = frame_system::mocking::MockBlock<Test>;

Expand All @@ -36,7 +29,7 @@ pub const MAX_ALLOWED_STATEMENTS: u32 = 10;
pub const MIN_ALLOWED_BYTES: u32 = 1024;
pub const MAX_ALLOWED_BYTES: u32 = 4096;

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test
{
System: frame_system,
Expand Down Expand Up @@ -74,12 +67,7 @@ impl Config for Test {
type MaxAllowedBytes = ConstU32<MAX_ALLOWED_BYTES>;
}

<<<<<<< HEAD
pub fn new_test_ext() -> TestState {
pub fn new_test_ext() -> sp_io::TestExternalities {
=======
>>>>>>> parent of fed7211911 (migrate pallet-statement to use umbrella crate)
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
let balances = pallet_balances::GenesisConfig::<Test> {
balances: vec![
Expand Down
8 changes: 2 additions & 6 deletions substrate/frame/statement/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,12 @@

use super::*;
use crate::mock::*;
use frame::deps::{sp_runtime::AccountId32, sp_core::{Pair, H256}, sp_statement_store::{
runtime_api::{InvalidStatement, StatementSource, ValidStatement},
Proof, Statement,
}};
use sp_core::Pair;
use sp_runtime::AccountId32;
use frame::testing_prelude::*;
use sp_statement_store::{
runtime_api::{InvalidStatement, StatementSource, ValidStatement},
Proof, Statement,
};

#[test]
fn sign_and_validate_no_balance() {
new_test_ext().execute_with(|| {
Expand Down
21 changes: 3 additions & 18 deletions substrate/frame/sudo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,23 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { features = ["derive"], workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"]}
frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }

docify = { workspace = true }

[dev-dependencies]
sp-core = { workspace = true, default-features = true }

[features]
default = ["std"]
std = [
"codec/std",
"frame/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
"frame/try-runtime"
]
7 changes: 3 additions & 4 deletions substrate/frame/sudo/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
use super::*;
use crate::Pallet;
use alloc::{boxed::Box, vec};
use frame_benchmarking::v2::*;
use frame_support::dispatch::{DispatchInfo, GetDispatchInfo};
use frame_system::RawOrigin;
use sp_runtime::traits::{
use frame::prelude::*;
use frame::benchmarking::prelude::*
use frame::deps::sp_runtime::traits::{
AsSystemOriginSigner, AsTransactionAuthorizedOrigin, DispatchTransaction, Dispatchable,
};

Expand Down
10 changes: 1 addition & 9 deletions substrate/frame/sudo/src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,8 @@
use crate::{Config, Key};
use codec::{Decode, Encode};
use core::{fmt, marker::PhantomData};
use frame_support::{dispatch::DispatchInfo, ensure, pallet_prelude::TransactionSource};
use scale_info::TypeInfo;
use sp_runtime::{
impl_tx_ext_default,
traits::{AsSystemOriginSigner, DispatchInfoOf, Dispatchable, TransactionExtension},
transaction_validity::{
InvalidTransaction, TransactionPriority, TransactionValidityError, UnknownTransaction,
ValidTransaction,
},
};
use frame::prelude::*;

/// Ensure that signed transactions are only valid if they are signed by sudo account.
///
Expand Down
17 changes: 7 additions & 10 deletions substrate/frame/sudo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@
//! Here's an example of a privileged function in another pallet:
//!
//! ```
//! #[frame_support::pallet]
//! #[frame::pallet]
//! pub mod pallet {
//! use super::*;
//! use frame_support::pallet_prelude::*;
//! use frame_system::pallet_prelude::*;
//! use frame::prelude::*;
//!
//! #[pallet::pallet]
//! pub struct Pallet<T>(_);
Expand Down Expand Up @@ -125,9 +124,8 @@ extern crate alloc;

use alloc::boxed::Box;

use sp_runtime::{traits::StaticLookup, DispatchResult};
// use sp_runtime::{traits::StaticLookup, DispatchResult};

use frame_support::{dispatch::GetDispatchInfo, traits::UnfilteredDispatchable};

mod extension;
#[cfg(test)]
Expand All @@ -145,11 +143,10 @@ pub use pallet::*;

type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;

#[frame_support::pallet]
#[frame::pallet]
pub mod pallet {
use super::{DispatchResult, *};
use frame_support::pallet_prelude::*;
use frame_system::{pallet_prelude::*, RawOrigin};
use frame::prelude::*;

/// Default preludes for [`Config`].
pub mod config_preludes {
Expand All @@ -162,7 +159,7 @@ pub mod pallet {
#[derive_impl(frame_system::config_preludes::TestDefaultConfig, no_aggregated_types)]
impl frame_system::DefaultConfig for TestDefaultConfig {}

#[frame_support::register_default_impl(TestDefaultConfig)]
#[frame::register_default_impl(TestDefaultConfig)]
impl DefaultConfig for TestDefaultConfig {
type WeightInfo = ();
#[inject_runtime_type]
Expand Down Expand Up @@ -335,7 +332,7 @@ pub mod pallet {
pub(super) type Key<T: Config> = StorageValue<_, T::AccountId, OptionQuery>;

#[pallet::genesis_config]
#[derive(frame_support::DefaultNoBound)]
#[derive(DefaultNoBound)]
pub struct GenesisConfig<T: Config> {
/// The `AccountId` of the sudo key.
pub key: Option<T::AccountId>,
Expand Down
11 changes: 4 additions & 7 deletions substrate/frame/sudo/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@
use super::*;
use crate as sudo;
use frame_support::{derive_impl, traits::Contains};
use sp_io;
use sp_runtime::BuildStorage;
use frame::testing_prelude::*;

// Logger module to track execution.
#[frame_support::pallet]
#[frame::pallet]
pub mod logger {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use frame::preliude::*

#[pallet::config]
pub trait Config: frame_system::Config {
Expand Down Expand Up @@ -127,7 +124,7 @@ pub type SudoCall = sudo::Call<Test>;
pub type LoggerCall = logger::Call<Test>;

// Build test environment by setting the root `key` for the Genesis.
pub fn new_test_ext(root_key: u64) -> sp_io::TestExternalities {
pub fn new_test_ext(root_key: u64) -> TestState {
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
sudo::GenesisConfig::<Test> { key: Some(root_key) }
.assimilate_storage(&mut t)
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/sudo/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! Tests for the module.
use super::*;
use frame_support::{assert_noop, assert_ok, weights::Weight};
use frame::testing_prelude::*;
use mock::{
new_test_ext, Logger, LoggerCall, RuntimeCall, RuntimeEvent as TestEvent, RuntimeOrigin, Sudo,
SudoCall, System, Test,
Expand Down
3 changes: 1 addition & 2 deletions substrate/frame/sudo/src/weights.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5f99526

Please sign in to comment.