Newer
Older
//! Mocks for the currencies module.
#![cfg(test)]
use frame_support::{impl_outer_event, impl_outer_origin, parameter_types};
use orml_traits::parameter_type_with_key;
use sp_runtime::{
testing::Header,
traits::{AccountIdConversion, IdentityLookup},
mod currencies {
pub use crate::Event;
}
impl_outer_event! {
pub enum TestEvent for Runtime {
frame_system<T>,
currencies<T>,
}
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Runtime;
parameter_types! {
pub const BlockHashCount: u64 = 250;
}
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type BlockWeights = ();
type BlockLength = ();
type AccountData = pallet_balances::AccountData<u64>;
type OnNewAccount = ();
type CurrencyId = u32;
type Balance = u64;
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
pub type PalletBalances = pallet_balances::Module<Runtime>;
pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance {
Default::default()
};
}
parameter_types! {
pub DustAccount: AccountId = ModuleId(*b"orml/dst").into_account();
}
type Balance = Balance;
type Amount = i64;
type CurrencyId = CurrencyId;
type ExistentialDeposits = ExistentialDeposits;
type OnDust = orml_tokens::TransferDust<Runtime, DustAccount>;
pub type Tokens = orml_tokens::Module<Runtime>;
pub const NATIVE_CURRENCY_ID: CurrencyId = 1;
pub const X_TOKEN_ID: CurrencyId = 2;
parameter_types! {
pub const GetNativeCurrencyId: CurrencyId = NATIVE_CURRENCY_ID;
}
type NativeCurrency = AdaptedBasicCurrency;
}
pub type Currencies = Module<Runtime>;
pub type NativeCurrency = NativeCurrencyOf<Runtime>;
pub type AdaptedBasicCurrency = BasicCurrencyAdapter<Runtime, PalletBalances, i64, u64>;
pub const ALICE: AccountId = AccountId32::new([1u8; 32]);
pub const BOB: AccountId = AccountId32::new([2u8; 32]);
pub const EVA: AccountId = AccountId32::new([5u8; 32]);
pub const ID_1: LockIdentifier = *b"1 ";
endowed_accounts: Vec<(AccountId, CurrencyId, Balance)>,
}
impl Default for ExtBuilder {
fn default() -> Self {
Self {
endowed_accounts: vec![],
pub fn balances(mut self, endowed_accounts: Vec<(AccountId, CurrencyId, Balance)>) -> Self {
self.endowed_accounts = endowed_accounts;
self
}
pub fn one_hundred_for_alice_n_bob(self) -> Self {
self.balances(vec![
(ALICE, NATIVE_CURRENCY_ID, 100),
(BOB, NATIVE_CURRENCY_ID, 100),
(ALICE, X_TOKEN_ID, 100),
(BOB, X_TOKEN_ID, 100),
])
.build_storage::<Runtime>()
.unwrap();
pallet_balances::GenesisConfig::<Runtime> {
balances: self
.endowed_accounts
.clone()
.into_iter()
.filter(|(_, currency_id, _)| *currency_id == NATIVE_CURRENCY_ID)
.map(|(account_id, _, initial_balance)| (account_id, initial_balance))
.collect::<Vec<_>>(),
}
.assimilate_storage(&mut t)
.unwrap();
orml_tokens::GenesisConfig::<Runtime> {
endowed_accounts: self
.endowed_accounts
.into_iter()
.filter(|(_, currency_id, _)| *currency_id != NATIVE_CURRENCY_ID)
.collect::<Vec<_>>(),
.assimilate_storage(&mut t)
.unwrap();