Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
Signed-off-by: Shumo Chu <shumo.chu@protonmail.com>
  • Loading branch information
stechu committed Apr 9, 2022
1 parent f77a196 commit 37ff30b
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 63 deletions.
6 changes: 1 addition & 5 deletions pallets/asset-manager/src/mock.rs
Expand Up @@ -20,11 +20,7 @@
//! Mock runtime for asset-manager

use crate as pallet_asset_manager;
use frame_support::{
construct_runtime, parameter_types,
traits::ConstU32,
PalletId,
};
use frame_support::{construct_runtime, parameter_types, traits::ConstU32, PalletId};
use frame_system as system;
use frame_system::EnsureRoot;
use manta_primitives::{
Expand Down
2 changes: 1 addition & 1 deletion pallets/manta-pay/src/mock.rs
Expand Up @@ -16,7 +16,7 @@

use frame_support::{
parameter_types,
traits::{ConstU32, Everything,},
traits::{ConstU32, Everything},
PalletId,
};
use frame_system::EnsureRoot;
Expand Down
39 changes: 25 additions & 14 deletions pallets/manta-pay/src/test/payment.rs
Expand Up @@ -52,7 +52,8 @@ lazy_static::lazy_static! {
}

pub const ALICE: sp_runtime::AccountId32 = sp_runtime::AccountId32::new([0u8; 32]);
pub const NATIVE_ASSET_ID: AssetId = AssetId(<MantaAssetConfig as AssetConfig<Test>>::NativeAssetId::get());
pub const NATIVE_ASSET_ID: AssetId =
AssetId(<MantaAssetConfig as AssetConfig<Test>>::NativeAssetId::get());

/// Loads the [`MultiProvingContext`] from the SDK.
#[inline]
Expand Down Expand Up @@ -148,13 +149,17 @@ where

/// Builds `count`-many [`PrivateTransfer`] tests.
#[inline]
fn private_transfer_test<R>(count: usize, asset_id_option: Option<AssetId>, rng: &mut R) -> Vec<TransferPost>
fn private_transfer_test<R>(
count: usize,
asset_id_option: Option<AssetId>,
rng: &mut R,
) -> Vec<TransferPost>
where
R: CryptoRng + RngCore + ?Sized,
{
let asset_id = match asset_id_option {
Some(id) => id,
None => rng.gen()
None => rng.gen(),
};
// FIXME: get rid of the division after parity fixes the pallet-asset bug
let double_balance: u128 = rng.gen();
Expand Down Expand Up @@ -226,7 +231,7 @@ where
{
let asset_id = match id_option {
Some(id) => id,
None => rng.gen()
None => rng.gen(),
};
// FIXME: This is a workaround due to the substrate asset bug
let double_balance: u128 = rng.gen();
Expand Down Expand Up @@ -296,12 +301,18 @@ fn initialize_test(id: AssetId, value: AssetValue) {
metadata.into(),
true
));
assert_ok!(<<MantaAssetConfig as AssetConfig<Test>>::FungibleLedger as FungibleLedger<Test>>::mint(id.0, &ALICE, value.0));
assert_ok!(<<MantaAssetConfig as AssetConfig<Test>>::FungibleLedger as FungibleLedger<Test>>::mint(
id.0,
&MantaPayPallet::account_id(),
DEFAULT_ASSET_ED
));
assert_ok!(
<<MantaAssetConfig as AssetConfig<Test>>::FungibleLedger as FungibleLedger<Test>>::mint(
id.0, &ALICE, value.0
)
);
assert_ok!(
<<MantaAssetConfig as AssetConfig<Test>>::FungibleLedger as FungibleLedger<Test>>::mint(
id.0,
&MantaPayPallet::account_id(),
DEFAULT_ASSET_ED
)
);
}

/// Tests multiple to_private from some total supply.
Expand All @@ -324,7 +335,7 @@ fn to_private_should_work() {
}

#[test]
fn native_asset_to_private_should_work(){
fn native_asset_to_private_should_work() {
let mut rng = thread_rng();
new_test_ext().execute_with(|| {
// FIXME: get rid of divide by two after parity fix pallet-asset
Expand Down Expand Up @@ -432,13 +443,13 @@ fn double_spend_in_private_transfer_should_not_work() {
/// Tests a [`Reclaim`] transaction.
#[test]
fn reclaim_should_work() {
new_test_ext().execute_with(|| reclaim_test(1, None,&mut thread_rng()));
new_test_ext().execute_with(|| reclaim_test(1, None, &mut thread_rng()));
}

/// Test a [`Reclaim`] of native currency
#[test]
fn reclaim_native_should_work(){
new_test_ext().execute_with(|| reclaim_test(1, Some(NATIVE_ASSET_ID),&mut thread_rng()));
fn reclaim_native_should_work() {
new_test_ext().execute_with(|| reclaim_test(1, Some(NATIVE_ASSET_ID), &mut thread_rng()));
}

/// Tests multiple [`Reclaim`] transactions.
Expand Down
69 changes: 29 additions & 40 deletions primitives/src/assets.rs
Expand Up @@ -22,12 +22,12 @@ use crate::{
use codec::{Codec, Decode, Encode};
use frame_support::{
pallet_prelude::Get,
traits::{tokens::{
fungible::Inspect as FungibleInspect,
traits::tokens::{
currency::Currency,
fungible::Inspect as FungibleInspect,
fungibles::{Inspect as FungiblesInspect, Mutate, Transfer},
currency::Currency,
ExistenceRequirement,
DepositConsequence, WithdrawConsequence}},
DepositConsequence, ExistenceRequirement, WithdrawConsequence,
},
Parameter,
};
use scale_info::TypeInfo;
Expand Down Expand Up @@ -355,26 +355,21 @@ where
) -> Result<(), FungibleLedgerConsequence>;
}

pub struct ConcreteFungibleLedger<
FrameConfig,
AssetConfig,
NativeAsset,
NonNativeAsset,>
(PhantomData<(FrameConfig, AssetConfig, NativeAsset, NonNativeAsset)>);
pub struct ConcreteFungibleLedger<FrameConfig, AssetConfig, NativeAsset, NonNativeAsset>(
PhantomData<(FrameConfig, AssetConfig, NativeAsset, NonNativeAsset)>,
);
impl<C, A, Native, NonNative> FungibleLedger<C> for ConcreteFungibleLedger<C, A, Native, NonNative>
where
where
C: frame_system::Config,
A: AssetConfig<C>,
Native: FungibleInspect<C::AccountId, Balance = Balance> + Currency<C::AccountId, Balance = Balance>,
NonNative:
FungiblesInspect<C::AccountId, AssetId = AssetId, Balance = Balance> +
Mutate<C::AccountId, AssetId = AssetId, Balance = Balance> +
Transfer<C::AccountId, AssetId = AssetId, Balance = Balance>,
Native: FungibleInspect<C::AccountId, Balance = Balance>
+ Currency<C::AccountId, Balance = Balance>,
NonNative: FungiblesInspect<C::AccountId, AssetId = AssetId, Balance = Balance>
+ Mutate<C::AccountId, AssetId = AssetId, Balance = Balance>
+ Transfer<C::AccountId, AssetId = AssetId, Balance = Balance>,
{
fn is_valid(asset_id: AssetId) -> Result<(), FungibleLedgerConsequence>{
if asset_id >= A::StartNonNativeAssetId::get()
|| asset_id == A::NativeAssetId::get()
{
fn is_valid(asset_id: AssetId) -> Result<(), FungibleLedgerConsequence> {
if asset_id >= A::StartNonNativeAssetId::get() || asset_id == A::NativeAssetId::get() {
Ok(())
} else {
Err(FungibleLedgerConsequence::InvalidAssetId)
Expand All @@ -393,7 +388,9 @@ where
other => Err(other.into()),
}
} else {
match <NonNative as FungiblesInspect<C::AccountId>>::can_deposit(asset_id, account, amount) {
match <NonNative as FungiblesInspect<C::AccountId>>::can_deposit(
asset_id, account, amount,
) {
DepositConsequence::Success => Ok(()),
other => Err(other.into()),
}
Expand All @@ -412,7 +409,9 @@ where
other => Err(other.into()),
}
} else {
match <NonNative as FungiblesInspect<C::AccountId>>::can_withdraw(asset_id, account, amount) {
match <NonNative as FungiblesInspect<C::AccountId>>::can_withdraw(
asset_id, account, amount,
) {
WithdrawConsequence::Success => Ok(()),
other => Err(other.into()),
}
Expand All @@ -435,11 +434,9 @@ where
)
.map_err(|_| FungibleLedgerConsequence::InternalError)
} else {
<NonNative as Transfer<C::AccountId>>::transfer(
asset_id, source, dest, amount, true,
)
.map(|_| ())
.map_err(|_| FungibleLedgerConsequence::InternalError)
<NonNative as Transfer<C::AccountId>>::transfer(asset_id, source, dest, amount, true)
.map(|_| ())
.map_err(|_| FungibleLedgerConsequence::InternalError)
}
}

Expand All @@ -451,20 +448,12 @@ where
Self::is_valid(asset_id)?;
Self::can_deposit(asset_id, beneficiary, amount)?;
if asset_id == A::NativeAssetId::get() {
let _ =
<Native as Currency<C::AccountId>>::deposit_creating(
&beneficiary,
amount,
);
let _ = <Native as Currency<C::AccountId>>::deposit_creating(&beneficiary, amount);
Ok(())
} else {
<NonNative as Mutate<C::AccountId>>::mint_into(
asset_id,
&beneficiary,
amount,
)
.map(|_| ())
.map_err(|_| FungibleLedgerConsequence::InternalError)
<NonNative as Mutate<C::AccountId>>::mint_into(asset_id, &beneficiary, amount)
.map(|_| ())
.map_err(|_| FungibleLedgerConsequence::InternalError)
}
}
}
5 changes: 3 additions & 2 deletions runtime/dolphin/src/lib.rs
Expand Up @@ -41,12 +41,13 @@ use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

use frame_support::{
construct_runtime, match_type, parameter_types,
construct_runtime, match_type,
pallet_prelude::DispatchResult,
parameter_types,
traits::{
ConstU16, ConstU32, ConstU8, Contains, Currency, EnsureOneOf, Everything, Nothing,
PrivilegeCmp,
},
pallet_prelude::DispatchResult,
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, WEIGHT_PER_SECOND},
DispatchClass, Weight,
Expand Down
2 changes: 1 addition & 1 deletion runtime/dolphin/src/tests/xcm_mock/parachain.rs
Expand Up @@ -43,7 +43,7 @@ use polkadot_core_primitives::BlockNumber as RelayBlockNumber;
use polkadot_parachain::primitives::{
DmpMessageHandler, Id as ParaId, Sibling, XcmpMessageFormat, XcmpMessageHandler,
};
use xcm::{VersionedMultiLocation, latest::prelude::*, Version as XcmVersion, VersionedXcm};
use xcm::{latest::prelude::*, Version as XcmVersion, VersionedMultiLocation, VersionedXcm};
use xcm_builder::{
AccountId32Aliases, AllowUnpaidExecutionFrom, ConvertedConcreteAssetId,
CurrencyAdapter as XcmCurrencyAdapter, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds,
Expand Down

0 comments on commit 37ff30b

Please sign in to comment.