Skip to content

Commit

Permalink
loan testing in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Oct 17, 2023
1 parent 5d056ab commit ef4d158
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 9 deletions.
23 changes: 23 additions & 0 deletions runtime/integration-tests/src/generic/cases/issue.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use crate::generic::{
environment::Env,
envs::{
fudge_env::{FudgeEnv, FudgeSupport},
runtime_env::RuntimeEnv,
},
runtime::Runtime,
utils::genesis::{self, Genesis, MUSD_CURRENCY_ID},
};

fn what<T: Runtime + FudgeSupport>() {
let env = RuntimeEnv::<T>::from_storage(
Genesis::<T>::default()
.add(genesis::assets(vec![MUSD_CURRENCY_ID]))
.storage(),
);

env.state(|| {
orml_asset_registry::Pallet::<T>::metadata(MUSD_CURRENCY_ID).unwrap();
});
}

crate::test_for_runtimes!(all, what);
18 changes: 16 additions & 2 deletions runtime/integration-tests/src/generic/cases/loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,30 @@ fn borrow<T: Runtime + FudgeSupport>() {
);

env.state_mut(|| {
utils::give_balance_to::<T>(POOL_ADMIN.id(), T::PoolDeposit::get());
utils::give_nft_to::<T>(BORROWER.id(), NFT_A);
// Creating a pool

/*
orml_asset_registry::Pallet::<T>::metadata(
&MUSD_CURRENCY_ID
);
*/

//utils::give_balance_to::<T>(POOL_ADMIN.id(), T::PoolDeposit::get());
//utils::create_empty_pool::<T>(POOL_ADMIN.id(), POOL_A,
// MUSD_CURRENCY_ID);

// Funding a pool
// utils::give_nft_to::<T>(BORROWER.id(), NFT_A);
});

/*
env.state(|| {
assert_eq!(
pallet_uniques::Pallet::<T>::owner(NFT_A.0, NFT_A.1).unwrap(),
BORROWER.id(),
)
});
*/
}

crate::test_for_runtimes!(all, borrow);
1 change: 1 addition & 0 deletions runtime/integration-tests/src/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub mod utils;
// Test cases
mod cases {
mod example;
mod issue;
mod loans;
}

Expand Down
8 changes: 4 additions & 4 deletions runtime/integration-tests/src/generic/utils/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn assets<T: Runtime>(currency_ids: Vec<CurrencyId>) -> impl GenesisBuild<T>
(
AUSD_CURRENCY_ID,
AssetMetadata {
decimals: 12,
decimals: AUSD_DECIMALS,
name: "Acala Dollar".as_bytes().to_vec(),
symbol: "AUSD".as_bytes().to_vec(),
existential_deposit: 0 as Balance,
Expand All @@ -102,10 +102,10 @@ pub fn assets<T: Runtime>(currency_ids: Vec<CurrencyId>) -> impl GenesisBuild<T>
]);

orml_asset_registry::GenesisConfig::<T> {
assets: currency_ids
assets: dbg!(currency_ids
.into_iter()
.map(|id| (id, assets.get(&id).unwrap().clone()))
.collect(),
last_asset_id: Default::default(), // It seems deprecated
.collect()),
last_asset_id: AUSD_CURRENCY_ID, // It seems deprecated
}
}
81 changes: 78 additions & 3 deletions runtime/integration-tests/src/generic/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
// Divide this utilties into files when it grows

use cfg_primitives::{AccountId, Balance, CollectionId, ItemId, PoolId};
use cfg_primitives::{AccountId, Balance, CollectionId, ItemId, PoolId, TrancheId};
use cfg_traits::investments::TrancheCurrency as _;
use cfg_types::{
permissions::{PermissionScope, PoolRole, Role},
tokens::CurrencyId,
tokens::{CurrencyId, TrancheCurrency},
};
use frame_system::RawOrigin;
use sp_runtime::traits::StaticLookup;
pub mod genesis;

use crate::generic::runtime::Runtime;
use cfg_types::pools::TrancheMetadata;
use frame_support::BoundedVec;
use pallet_pool_system::tranches::{TrancheInput, TrancheLoc, TrancheType};
use sp_runtime::{traits::One, AccountId32, Perquintill};

use crate::generic::runtime::{Runtime, RuntimeKind};

pub fn give_nft_to<T: Runtime>(dest: AccountId, (collection_id, item_id): (CollectionId, ItemId)) {
pallet_uniques::Pallet::<T>::force_create(
Expand Down Expand Up @@ -62,3 +68,72 @@ pub fn give_pool_role<T: Runtime>(dest: AccountId, pool_id: PoolId, role: PoolRo
)
.unwrap();
}

pub fn create_empty_pool<T: Runtime>(admin: AccountId32, pool_id: PoolId, currency_id: CurrencyId) {
pallet_pool_registry::Pallet::<T>::register(
match T::KIND {
RuntimeKind::Development => RawOrigin::Signed(admin.clone()).into(),
_ => RawOrigin::Root.into(),
},
admin,
pool_id,
vec![
TrancheInput {
tranche_type: TrancheType::Residual,
seniority: None,
metadata: TrancheMetadata {
token_name: BoundedVec::default(),
token_symbol: BoundedVec::default(),
},
},
TrancheInput {
tranche_type: TrancheType::NonResidual {
interest_rate_per_sec: One::one(),
min_risk_buffer: Perquintill::from_percent(0),
},
seniority: None,
metadata: TrancheMetadata {
token_name: BoundedVec::default(),
token_symbol: BoundedVec::default(),
},
},
],
currency_id,
Balance::MAX,
None,
BoundedVec::default(),
)
.unwrap();
}

pub fn close_pool_epoch<T: Runtime>(admin: AccountId32, pool_id: PoolId) {
pallet_pool_system::Pallet::<T>::close_epoch(RawOrigin::Signed(admin.clone()).into(), pool_id)
.unwrap();
}

pub fn invest<T: Runtime>(
investor: AccountId32,
pool_id: PoolId,
tranche_id: TrancheId,
amount: Balance,
) {
pallet_investments::Pallet::<T>::update_invest_order(
RawOrigin::Signed(investor).into(),
TrancheCurrency::generate(pool_id, tranche_id),
amount,
)
.unwrap();
}

// Utilities that does not modify the state
pub mod get {
use super::*;

pub fn default_tranche_id<T: Runtime>(pool_id: PoolId) -> TrancheId {
pallet_pool_system::Pool::<T>::get(pool_id)
.unwrap()
.tranches
.tranche_id(TrancheLoc::Index(0))
.unwrap()
}
}

0 comments on commit ef4d158

Please sign in to comment.