Skip to content

Commit

Permalink
frame import
Browse files Browse the repository at this point in the history
  • Loading branch information
runcomet committed Nov 21, 2024
1 parent 09757a4 commit 5ff5cb7
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 41 deletions.
7 changes: 1 addition & 6 deletions Cargo.lock

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

23 changes: 4 additions & 19 deletions substrate/frame/assets-freezer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,29 @@ targets = ["x86_64-unknown-linux-gnu"]
codec = { workspace = true }
log = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"] }
pallet-assets = { workspace = true }
sp-runtime = { workspace = true }

[dev-dependencies]
sp-io = { workspace = true }
sp-core = { workspace = true }
pallet-balances = { workspace = true }

[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"frame/std",
"log/std",
"pallet-assets/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-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"frame/try-runtime",
"pallet-assets/try-runtime",
"pallet-balances/try-runtime",
"sp-runtime/try-runtime",
]
6 changes: 5 additions & 1 deletion substrate/frame/assets-freezer/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@

use super::*;

/*
use frame_support::traits::{
fungibles::{Inspect, InspectFreeze, MutateFreeze},
tokens::{DepositConsequence, Fortitude, Preservation, Provenance, WithdrawConsequence},
};
*/
use pallet_assets::FrozenBalance;
use sp_runtime::traits::Zero;
// use sp_runtime::traits::Zero;

use frame::{deps::sp_runtime, traits::{fungibles::{Inspect, InspectFreeze, MutateFreeze}, tokens::{DepositConsequence, Fortitude, Preservation, Provenance, WithdrawConsequence}, Zero}};

// Implements [`FrozenBalance`] from [`pallet-assets`], so it can understand how much of an
// account balance is frozen, and is able to signal to this pallet when to clear the state of an
Expand Down
13 changes: 8 additions & 5 deletions substrate/frame/assets-freezer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

#![cfg_attr(not(feature = "std"), no_std)]

/*
use frame_support::{
pallet_prelude::*,
traits::{tokens::IdAmount, VariantCount, VariantCountOf},
Expand All @@ -52,7 +53,8 @@ use sp_runtime::{
traits::{Saturating, Zero},
BoundedSlice,
};

*/
use frame::{prelude::*, traits::{tokens::IdAmount, VariantCount, VariantCountOf, Saturating, Zero}};
pub use pallet::*;

#[cfg(test)]
Expand All @@ -62,7 +64,8 @@ mod tests;

mod impls;

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

Expand Down Expand Up @@ -125,7 +128,7 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {
#[cfg(feature = "try-runtime")]
fn try_state(_: BlockNumberFor<T>) -> Result<(), sp_runtime::TryRuntimeError> {
fn try_state(_: BlockNumberFor<T>) -> Result<(), frame::deps::sp_runtime::TryRuntimeError> {
Self::do_try_state()
}
}
Expand Down Expand Up @@ -160,12 +163,12 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
}

#[cfg(any(test, feature = "try-runtime"))]
fn do_try_state() -> Result<(), sp_runtime::TryRuntimeError> {
fn do_try_state() -> Result<(), frame::deps::sp_runtime::TryRuntimeError> {
for (asset, who, _) in FrozenBalances::<T, I>::iter() {
let max_frozen_amount =
Freezes::<T, I>::get(asset.clone(), who.clone()).iter().map(|l| l.amount).max();

frame_support::ensure!(
ensure!(
FrozenBalances::<T, I>::get(asset, who) == max_frozen_amount,
"The `FrozenAmount` is not equal to the maximum amount in `Freezes` for (`asset`, `who`)"
);
Expand Down
17 changes: 11 additions & 6 deletions substrate/frame/assets-freezer/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,28 @@
use crate as pallet_assets_freezer;
pub use crate::*;
use codec::{Compact, Decode, Encode, MaxEncodedLen};
use frame::{pallet_macros::derive_impl, runtime::testing_prelude::BuildStorage, testing_prelude::{TestExternalities, assert_ok}, traits::{AsEnsureOriginWithArg, BlakeTwo256, IdentityLookup, Everything}, hashing::H256, runtime::prelude::{ConstU32, ConstU64, construct_runtime}};
/*
use frame_support::{
derive_impl,
traits::{AsEnsureOriginWithArg, ConstU64},
};
*/
use scale_info::TypeInfo;
/*
use sp_core::{ConstU32, H256};
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
*/

pub type AccountId = u64;
pub type Balance = u64;
pub type AssetId = u32;
type Block = frame_system::mocking::MockBlock<Test>;

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test
{
System: frame_system,
Expand All @@ -48,7 +53,7 @@ frame_support::construct_runtime!(

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
type BaseCallFilter = Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
Expand All @@ -70,7 +75,7 @@ impl frame_system::Config for Test {
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
type MaxConsumers = ConstU32<16>;
}

impl pallet_balances::Config for Test {
Expand Down Expand Up @@ -132,7 +137,7 @@ impl Config for Test {
type RuntimeEvent = RuntimeEvent;
}

pub fn new_test_ext(execute: impl FnOnce()) -> sp_io::TestExternalities {
pub fn new_test_ext(execute: impl FnOnce()) -> TestExternalities {
let t = RuntimeGenesisConfig {
assets: pallet_assets::GenesisConfig {
assets: vec![(1, 0, true, 1)],
Expand All @@ -145,11 +150,11 @@ pub fn new_test_ext(execute: impl FnOnce()) -> sp_io::TestExternalities {
}
.build_storage()
.unwrap();
let mut ext: sp_io::TestExternalities = t.into();
let mut ext: TestExternalities = t.into();
ext.execute_with(|| {
System::set_block_number(1);
execute();
frame_support::assert_ok!(AssetsFreezer::do_try_state());
assert_ok!(AssetsFreezer::do_try_state());
});

ext
Expand Down
5 changes: 4 additions & 1 deletion substrate/frame/assets-freezer/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
use crate::mock::*;

use codec::Compact;
/*
use frame_support::{
assert_ok, assert_storage_noop,
traits::{
fungibles::{Inspect, InspectFreeze, MutateFreeze},
tokens::{Fortitude, Preservation},
},
};
*/
use frame::{testing_prelude::*, traits::{fungibles::{Inspect, InspectFreeze, MutateFreeze}, tokens::{Fortitude, Preservation}}};
use pallet_assets::FrozenBalance;

const WHO: AccountId = 1;
Expand Down Expand Up @@ -281,7 +284,7 @@ mod impl_mutate_freeze {
}

mod with_pallet_assets {
use frame_support::assert_noop;
// use frame_support::assert_noop;

use super::*;

Expand Down
6 changes: 3 additions & 3 deletions substrate/frame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ pub mod prelude {

/// Runtime traits
#[doc(no_inline)]
pub use sp_runtime::traits::{
pub use sp_runtime::{traits::{
Bounded, DispatchInfoOf, Dispatchable, SaturatedConversion, Saturating, StaticLookup,
TrailingZeroInput,
};
}, BoundedSlice};

/// Other error/result types for runtime
#[doc(no_inline)]
Expand Down Expand Up @@ -307,7 +307,7 @@ 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_err, assert_err_ignore_postinfo, assert_error_encoded_size, assert_noop, assert_ok, ensure,
assert_storage_noop, storage_alias,
};

Expand Down

0 comments on commit 5ff5cb7

Please sign in to comment.