Skip to content

Commit b2c71b2

Browse files
authored
test: create pool (#785)
1 parent aa6555d commit b2c71b2

File tree

6 files changed

+331
-25
lines changed

6 files changed

+331
-25
lines changed

pallets/pallet-bonded-coins/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ pub mod pallet {
289289

290290
let pool_account = &pool_id.clone().into();
291291

292+
// Touch the pool account in order to be able to transfer the collateral
293+
// currency to it. This should also verify that the currency actually exists.
294+
T::CollateralCurrencies::touch(collateral_id.clone(), pool_account, &who)?;
295+
292296
currencies
293297
.into_iter()
294298
.zip(currency_ids.iter())
@@ -313,10 +317,6 @@ pub mod pallet {
313317
Ok(())
314318
})?;
315319

316-
// Touch the pool account in order to be able to transfer the collateral
317-
// currency to it. This should also verify that the currency actually exists.
318-
T::CollateralCurrencies::touch(collateral_id.clone(), pool_account, &who)?;
319-
320320
Pools::<T>::set(
321321
&pool_id,
322322
Some(PoolDetails::new(
@@ -961,13 +961,13 @@ pub mod pallet {
961961
Ok((currency_array, start_id))
962962
}
963963

964-
fn get_currencies_number(pool_details: &PoolDetailsOf<T>) -> u32 {
964+
pub(crate) fn get_currencies_number(pool_details: &PoolDetailsOf<T>) -> u32 {
965965
// bonded_currencies is a BoundedVec with maximum length MaxCurrencies, which is
966966
// a u32; conversion to u32 must thus be lossless.
967967
pool_details.bonded_currencies.len().saturated_into()
968968
}
969969

970-
fn calculate_pool_deposit<N: UniqueSaturatedInto<DepositCurrencyBalanceOf<T>>>(
970+
pub(crate) fn calculate_pool_deposit<N: UniqueSaturatedInto<DepositCurrencyBalanceOf<T>>>(
971971
n_currencies: N,
972972
) -> DepositCurrencyBalanceOf<T> {
973973
T::BaseDeposit::get()

pallets/pallet-bonded-coins/src/mock.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ pub(crate) const ACCOUNT_00: AccountId = AccountId::new([0u8; 32]);
3838
pub(crate) const ACCOUNT_01: AccountId = AccountId::new([1u8; 32]);
3939
const ACCOUNT_99: AccountId = AccountId::new([99u8; 32]);
4040
// assets
41-
pub(crate) const DEFAULT_BONDED_CURRENCY_ID: AssetId = 0;
42-
pub(crate) const DEFAULT_COLLATERAL_CURRENCY_ID: AssetId = AssetId::MAX;
41+
pub(crate) const DEFAULT_BONDED_CURRENCY_ID: AssetId = 1;
42+
pub(crate) const DEFAULT_COLLATERAL_CURRENCY_ID: AssetId = 0;
4343
pub(crate) const DEFAULT_COLLATERAL_DENOMINATION: u8 = 10;
4444
pub(crate) const DEFAULT_BONDED_DENOMINATION: u8 = 10;
45+
pub(crate) const ONE_HUNDRED_KILT: u128 = 100_000_000_000_000_000;
4546

4647
// helper functions
4748
pub fn assert_relative_eq(target: Float, expected: Float, epsilon: Float) {
@@ -98,7 +99,7 @@ pub mod runtime {
9899
bonded_currencies,
99100
state,
100101
collateral_id,
101-
denomination: 10,
102+
denomination: DEFAULT_BONDED_DENOMINATION,
102103
owner,
103104
}
104105
}
@@ -276,19 +277,24 @@ pub mod runtime {
276277

277278
let collateral_assets = self.collaterals.into_iter().map(|id| (id, ACCOUNT_99, false, 1));
278279

279-
pallet_assets::GenesisConfig::<Test> {
280-
assets: self
281-
.pools
282-
.iter()
283-
.flat_map(|(owner, pool)| {
284-
pool.bonded_currencies
285-
.iter()
286-
.map(|id| (*id, owner.to_owned(), false, 1u128))
287-
.collect::<Vec<(AssetId, AccountId, bool, Balance)>>()
288-
})
289-
.chain(collateral_assets)
290-
.collect(),
280+
let all_assets: Vec<_> = self
281+
.pools
282+
.iter()
283+
.flat_map(|(owner, pool)| {
284+
pool.bonded_currencies
285+
.iter()
286+
.map(|id| (*id, owner.to_owned(), false, 1u128))
287+
.collect::<Vec<(AssetId, AccountId, bool, Balance)>>()
288+
})
289+
.chain(collateral_assets)
290+
.collect();
291+
292+
// NextAssetId is set to the maximum value of all collateral/bonded currency ids, plus one.
293+
// If no currencies are created, it's set to 0.
294+
let next_asset_id = all_assets.iter().map(|(id, ..)| id).max().map_or(0, |id| id + 1);
291295

296+
pallet_assets::GenesisConfig::<Test> {
297+
assets: all_assets,
292298
accounts: self.bonded_balance,
293299
metadata: self
294300
.pools
@@ -313,6 +319,8 @@ pub mod runtime {
313319
self.pools.into_iter().for_each(|(pool_id, pool)| {
314320
crate::Pools::<Test>::insert(pool_id, pool);
315321
});
322+
323+
crate::NextAssetId::<Test>::set(next_asset_id);
316324
});
317325

318326
ext
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
mod curves;
2+
mod transactions;

0 commit comments

Comments
 (0)