Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AurevoirXavier committed Jun 24, 2024
1 parent 655eaae commit 1d3956f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 35 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions pallet/account-migration/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub const VERSION: sp_version::RuntimeVersion = sp_version::RuntimeVersion {
frame_support::parameter_types! {
pub const Version: sp_version::RuntimeVersion = VERSION;
}
#[frame_support::derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Runtime {
type AccountData = pallet_balances::AccountData<Balance>;
type AccountId = AccountId;
Expand Down
1 change: 0 additions & 1 deletion pallet/deposit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ sp-std = { workspace = true, optional = true }
# substrate
pallet-assets = { workspace = true, features = ["std"] }
pallet-balances = { workspace = true, features = ["std"] }
sp-core = { workspace = true, features = ["std"] }
sp-io = { workspace = true, features = ["std"] }

[features]
Expand Down
39 changes: 8 additions & 31 deletions pallet/deposit/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,55 +20,32 @@ pub use crate as darwinia_deposit;
pub use dc_types::{AssetId, Balance, Moment, UNIT};

// substrate
use frame_support::derive_impl;
use sp_io::TestExternalities;
use sp_runtime::BuildStorage;

#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Runtime {
type AccountData = pallet_balances::AccountData<Balance>;
type AccountId = u32;
type BaseCallFilter = frame_support::traits::Everything;
type Block = frame_system::mocking::MockBlock<Self>;
type BlockHashCount = ();
type BlockLength = ();
type BlockWeights = ();
type DbWeight = ();
type Hash = sp_core::H256;
type Hashing = sp_runtime::traits::BlakeTwo256;
type Lookup = sp_runtime::traits::IdentityLookup<Self::AccountId>;
type MaxConsumers = frame_support::traits::ConstU32<16>;
type Nonce = u64;
type OnKilledAccount = ();
type OnNewAccount = ();
type OnSetCode = ();
type PalletInfo = PalletInfo;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type SS58Prefix = ();
type SystemWeightInfo = ();
type Version = ();
}

#[derive_impl(pallet_timestamp::config_preludes::TestDefaultConfig as pallet_timestamp::DefaultConfig)]
impl pallet_timestamp::Config for Runtime {
type MinimumPeriod = ();
type Moment = Moment;
type OnTimestampSet = ();
type WeightInfo = ();
}

#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)]
impl pallet_balances::Config for Runtime {
type AccountStore = System;
type Balance = Balance;
type DustRemoval = ();
type ExistentialDeposit = frame_support::traits::ConstU128<0>;
type FreezeIdentifier = ();
type MaxFreezes = ();
type MaxLocks = ();
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type ExistentialDeposit = ();
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = ();
type WeightInfo = ();
}

#[cfg(feature = "runtime-benchmarks")]
Expand All @@ -90,11 +67,11 @@ impl pallet_assets::Config for Runtime {
type BenchmarkHelper = BenchmarkHelper;
type CallbackHandle = ();
type CreateOrigin = frame_support::traits::AsEnsureOriginWithArg<
frame_system::EnsureSignedBy<frame_support::traits::IsInVec<()>, u32>,
frame_system::EnsureSignedBy<frame_support::traits::IsInVec<()>, Self::AccountId>,
>;
type Currency = Balances;
type Extra = ();
type ForceOrigin = frame_system::EnsureRoot<u32>;
type ForceOrigin = frame_system::EnsureRoot<Self::AccountId>;
type Freezer = ();
type MetadataDepositBase = ();
type MetadataDepositPerByte = ();
Expand All @@ -106,7 +83,7 @@ impl pallet_assets::Config for Runtime {

pub enum KtonMinting {}
impl darwinia_deposit::SimpleAsset for KtonMinting {
type AccountId = u32;
type AccountId = <Runtime as frame_system::Config>::AccountId;

fn mint(beneficiary: &Self::AccountId, amount: Balance) -> sp_runtime::DispatchResult {
Assets::mint(RuntimeOrigin::signed(0), 0.into(), *beneficiary, amount)
Expand Down
14 changes: 12 additions & 2 deletions pallet/deposit/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,21 @@ use sp_runtime::TokenError;
fn lock_should_work() {
new_test_ext().execute_with(|| {
assert_eq!(System::account(1).consumers, 0);
assert_eq!(Balances::free_balance(darwinia_deposit::account_id::<u32>()), 0);
assert_eq!(
Balances::free_balance(darwinia_deposit::account_id::<
<Runtime as frame_system::Config>::AccountId,
>()),
0
);
assert_eq!(Balances::free_balance(1), 1_000 * UNIT);
assert_ok!(Deposit::lock(RuntimeOrigin::signed(1), 10 * UNIT, 1));
assert_eq!(System::account(1).consumers, 1);
assert_eq!(Balances::free_balance(darwinia_deposit::account_id::<u32>()), 10 * UNIT);
assert_eq!(
Balances::free_balance(darwinia_deposit::account_id::<
<Runtime as frame_system::Config>::AccountId,
>()),
10 * UNIT
);
assert_eq!(Balances::free_balance(1), 990 * UNIT);
});
}
Expand Down

0 comments on commit 1d3956f

Please sign in to comment.