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

Concrete fungible ledger integration tests #519

Merged
merged 4 commits into from
May 4, 2022
Merged
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
6 changes: 3 additions & 3 deletions pallets/manta-pay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ pub mod pallet {
pub enum Event<T: Config> {
/// Public Transfer Event
Transfer {
/// Asset Transfered
/// Asset Transferred
asset: Asset,

/// Source Account
Expand Down Expand Up @@ -302,7 +302,7 @@ pub mod pallet {

/// Balance Low
///
/// Attempted to withdraw from balance which was smaller than the withdrawl amount.
/// Attempted to withdraw from balance which was smaller than the withdrawal amount.
BalanceLow,

/// Invalid Serialized Form
Expand Down Expand Up @@ -450,7 +450,7 @@ pub mod pallet {
FungibleLedgerError::ReducedToZero(_) => Self::PublicUpdateReducedToZero,
FungibleLedgerError::NoFunds => Self::PublicUpdateNoFunds,
FungibleLedgerError::WouldDie => Self::PublicUpdateWouldDie,
FungibleLedgerError::InvalidTransfer => Self::PublicUpdateInvalidTransfer,
FungibleLedgerError::InvalidTransfer(_e) => Self::PublicUpdateInvalidTransfer,
_ => Self::InternalLedgerError,
}
}
Expand Down
14 changes: 7 additions & 7 deletions primitives/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use frame_support::{
};
use scale_info::TypeInfo;
use sp_core::H160;
use sp_runtime::{traits::Member, DispatchResult};
use sp_runtime::{traits::Member, DispatchError, DispatchResult};
use sp_std::{borrow::Borrow, marker::PhantomData, prelude::Vec};
use xcm::{
v1::{Junctions, MultiLocation},
Expand Down Expand Up @@ -250,14 +250,14 @@ where
}

/// Fungible Ledger Error
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum FungibleLedgerError {
/// Invalid Asset Id
InvalidAssetId,

/// Deposit couldn't happen due to the amount being too low. This is usually because the
/// account doesn't yet exist and the deposit wouldn't bring it to at least the minimum needed
/// for existance.
/// for existence.
BelowMinimum,

/// Deposit cannot happen since the account cannot be created (usually because it's a consumer
Expand Down Expand Up @@ -294,10 +294,10 @@ pub enum FungibleLedgerError {
WouldDie,

/// Unable to Mint an Asset
InvalidMint,
InvalidMint(DispatchError),

/// Unable to Transfer an Asset
InvalidTransfer,
InvalidTransfer(DispatchError),
}

impl FungibleLedgerError {
Expand Down Expand Up @@ -439,7 +439,7 @@ where
<Native as Currency<C::AccountId>>::deposit_creating(beneficiary, amount);
} else {
<NonNative as Mutate<C::AccountId>>::mint_into(asset_id, beneficiary, amount)
.map_err(|_| FungibleLedgerError::InvalidMint)?;
.map_err(|e| FungibleLedgerError::InvalidMint(e))?;
}
Ok(())
}
Expand Down Expand Up @@ -469,6 +469,6 @@ where
)
.map(|_| ())
}
.map_err(|_| FungibleLedgerError::InvalidTransfer)
.map_err(|e| FungibleLedgerError::InvalidTransfer(e))
}
}
5 changes: 4 additions & 1 deletion runtime/calamari/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,9 @@ parameter_types! {
pub const AssetManagerPalletId: PalletId = ASSET_MANAGER_PALLET_ID;
}

pub type CalamariConcreteFungibleLedger =
ConcreteFungibleLedger<Runtime, CalamariAssetConfig, Balances, Assets>;

#[derive(Clone, Eq, PartialEq)]
pub struct CalamariAssetConfig;

Expand All @@ -697,7 +700,7 @@ impl AssetConfig<Runtime> for CalamariAssetConfig {
type StorageMetadata = AssetStorageMetadata;
type AssetLocation = AssetLocation;
type AssetRegistrar = CalamariAssetRegistrar;
type FungibleLedger = ConcreteFungibleLedger<Runtime, CalamariAssetConfig, Balances, Assets>;
type FungibleLedger = CalamariConcreteFungibleLedger;
}

impl pallet_asset_manager::Config for Runtime {
Expand Down
13 changes: 11 additions & 2 deletions runtime/calamari/tests/common/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
use crate::common::*;

pub use calamari_runtime::{
currency::KMA, Call, CollatorSelection, Democracy, Runtime, Scheduler, Session, System,
TransactionPayment,
currency::KMA, CalamariAssetConfig, Call, CollatorSelection, Democracy, Runtime, Scheduler,
Session, System, TransactionPayment,
};
use frame_support::traits::{GenesisBuild, OnFinalize, OnInitialize};
use manta_primitives::{
assets::AssetConfig,
helpers::{get_account_id_from_seed, get_collator_keys_from_seed},
types::{AccountId, AuraId, Balance},
};
Expand All @@ -33,6 +34,7 @@ pub struct ExtBuilder {
desired_candidates: u32,
safe_xcm_version: Option<u32>,
}
use sp_std::marker::PhantomData;

impl Default for ExtBuilder {
fn default() -> ExtBuilder {
Expand Down Expand Up @@ -113,6 +115,13 @@ impl ExtBuilder {
.assimilate_storage(&mut t)
.unwrap();

pallet_asset_manager::GenesisConfig::<Runtime> {
start_id: <CalamariAssetConfig as AssetConfig<Runtime>>::StartNonNativeAssetId::get(),
_marker: PhantomData::<Runtime>::default(),
}
.assimilate_storage(&mut t)
.unwrap();

<pallet_xcm::GenesisConfig as GenesisBuild<Runtime>>::assimilate_storage(
&pallet_xcm::GenesisConfig {
safe_xcm_version: self.safe_xcm_version,
Expand Down
Loading