Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate pallet-lottery to umbrella crate #6740

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 2 additions & 7 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions substrate/frame/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ sp-runtime = { workspace = true }

# frame deps, for developing FRAME pallets.
frame-support = { workspace = true }
frame-support-test = { optional = true, workspace = true }
frame-system = { workspace = true }

# primitive types used for developing FRAME runtimes.
Expand Down Expand Up @@ -89,6 +90,7 @@ std = [
"frame-benchmarking?/std",
"frame-executive?/std",
"frame-support/std",
"frame-support-test/std",
"frame-system-benchmarking?/std",
"frame-system-rpc-runtime-api?/std",
"frame-system/std",
Expand Down
26 changes: 4 additions & 22 deletions substrate/frame/lottery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,25 @@ targets = ["x86_64-unknown-linux-gnu"]
codec = { features = [
"derive",
], workspace = true }
frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
sp-runtime = { workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"] }

[dev-dependencies]
frame-support-test = { workspace = true }
pallet-balances = { workspace = true, default-features = true }
sp-core = { workspace = true, default-features = true }
sp-io = { workspace = true, default-features = true }

[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support-test/std",
"frame-support/std",
"frame-system/std",
"frame/std",
"pallet-balances/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",
"frame/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support-test/try-runtime",
"frame-support/try-runtime",
"frame-system/try-runtime",
"frame/try-runtime",
"pallet-balances/try-runtime",
"sp-runtime/try-runtime",
]
12 changes: 1 addition & 11 deletions substrate/frame/lottery/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,7 @@ use super::*;

use crate::Pallet as Lottery;
use alloc::{boxed::Box, vec};
use frame_benchmarking::{
v1::{account, whitelisted_caller, BenchmarkError},
v2::*,
};
use frame_support::{
storage::bounded_vec::BoundedVec,
traits::{EnsureOrigin, OnInitialize},
};
use frame_system::RawOrigin;
use sp_runtime::traits::{Bounded, Zero};

use frame::benchmarking::prelude::*;
// Set up and start a lottery
fn setup_lottery<T: Config>(repeat: bool) -> Result<(), &'static str> {
let price = T::Currency::minimum_balance();
Expand Down
21 changes: 7 additions & 14 deletions substrate/frame/lottery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,14 @@ extern crate alloc;

use alloc::{boxed::Box, vec::Vec};
use codec::{Decode, Encode};
use frame_support::{
dispatch::{DispatchResult, GetDispatchInfo},
ensure,
pallet_prelude::MaxEncodedLen,
storage::bounded_vec::BoundedVec,
traits::{Currency, ExistenceRequirement::KeepAlive, Get, Randomness, ReservableCurrency},
PalletId,
use frame::{
runtime::prelude::*,
traits::{
AccountIdConversion, Currency, ExistenceRequirement::KeepAlive, Randomness,
ReservableCurrency,
},
};
pub use pallet::*;
use sp_runtime::{
traits::{AccountIdConversion, Dispatchable, Saturating, Zero},
ArithmeticError, DispatchError, RuntimeDebug,
};
pub use weights::WeightInfo;

type BalanceOf<T> =
Expand Down Expand Up @@ -118,11 +113,9 @@ impl<T: Config> ValidateCall<T> for Pallet<T> {
}
}

#[frame_support::pallet]
#[frame::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

#[pallet::pallet]
pub struct Pallet<T>(_);
Expand Down
14 changes: 4 additions & 10 deletions substrate/frame/lottery/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,11 @@
use super::*;
use crate as pallet_lottery;

use frame_support::{
derive_impl, parameter_types,
traits::{ConstU32, OnFinalize, OnInitialize},
};
use frame_support_test::TestRandomness;
use frame_system::EnsureRoot;
use sp_runtime::{BuildStorage, Perbill};
use frame::testing_prelude::*;

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

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test
{
System: frame_system,
Expand Down Expand Up @@ -74,7 +68,7 @@ impl Config for Test {
pub type SystemCall = frame_system::Call<Test>;
pub type BalancesCall = pallet_balances::Call<Test>;

pub fn new_test_ext() -> sp_io::TestExternalities {
pub fn new_test_ext() -> TestExternalities {
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
pallet_balances::GenesisConfig::<Test> {
balances: vec![(1, 100), (2, 100), (3, 100), (4, 100), (5, 100)],
Expand Down
3 changes: 1 addition & 2 deletions substrate/frame/lottery/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
//! Tests for the module.

use super::*;
use frame_support::{assert_noop, assert_ok, assert_storage_noop};
use frame::testing_prelude::*;
use mock::{
new_test_ext, run_to_block, Balances, BalancesCall, Lottery, RuntimeCall, RuntimeOrigin,
SystemCall, Test,
};
use sp_runtime::{traits::BadOrigin, TokenError};

#[test]
fn initial_state() {
Expand Down
3 changes: 1 addition & 2 deletions substrate/frame/lottery/src/weights.rs

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

17 changes: 14 additions & 3 deletions substrate/frame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub mod prelude {

/// Dispatch types from `frame-support`, other fundamental traits
#[doc(no_inline)]
pub use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo};
pub use frame_support::dispatch::{DispatchResult, GetDispatchInfo, PostDispatchInfo};
pub use frame_support::traits::{
Contains, EstimateNextSessionRotation, IsSubType, OnRuntimeUpgrade, OneSessionHandler,
};
Expand Down Expand Up @@ -232,10 +232,15 @@ pub mod prelude {
Saturating, StaticLookup, TrailingZeroInput,
};

/// Bounded storage related types.
pub use sp_runtime::{BoundedSlice, BoundedVec};

/// Other runtime types and traits
#[doc(no_inline)]
pub use sp_runtime::{
BoundToRuntimeAppPublic, DispatchErrorWithPostInfo, DispatchResultWithInfo, TokenError,
BoundToRuntimeAppPublic,
DispatchError::{self, BadOrigin},
DispatchErrorWithPostInfo, DispatchResultWithInfo, TokenError,
};
}

Expand Down Expand Up @@ -319,9 +324,11 @@ pub mod testing_prelude {
/// Other helper macros from `frame_support` that help with asserting in tests.
pub use frame_support::{
assert_err, assert_err_ignore_postinfo, assert_error_encoded_size, assert_noop, assert_ok,
assert_storage_noop, storage_alias,
assert_storage_noop, ensure, storage_alias,
};

pub use frame_support_test::TestRandomness;

pub use frame_system::{self, mocking::*};

#[deprecated(note = "Use `frame::testing_prelude::TestExternalities` instead.")]
Expand Down Expand Up @@ -361,6 +368,9 @@ pub mod runtime {
/// Macro to easily derive the `Config` trait of various pallet for `Runtime`.
pub use frame_support::derive_impl;

/// Sovereign account ID for a pallet.
pub use frame_support::PalletId;

/// Macros to easily impl traits such as `Get` for types.
// TODO: using linking in the Get in the line above triggers an ICE :/
pub use frame_support::{ord_parameter_types, parameter_types};
Expand Down Expand Up @@ -524,6 +534,7 @@ pub mod traits {
/// This is already part of the [`prelude`].
pub mod arithmetic {
pub use sp_arithmetic::{traits::*, *};
pub use sp_runtime::ArithmeticError;
}

/// All derive macros used in frame.
Expand Down
Loading