-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Liquidity-pools: Add unitary tests (#1879)
* prepare mock for UTs and simplify some minor things * normal function instead of Convert trait * rename into_account_id() to evm_to_account() * add UTs for transfer * simplify account conversion * remove unused CurrencyIdOf * remove already covered tests * remove democracy utils * apply Cosmin suggestions * add transfer_tranche_tokens tests * minor clean * add add_pool tests * add add_tranche tests * check balance post transfers * fix lp tests * fix imports after rebasing
- Loading branch information
Showing
32 changed files
with
1,207 additions
and
1,155 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
#[frame_support::pallet(dev_mode)] | ||
pub mod pallet { | ||
use cfg_traits::investments::ForeignInvestment; | ||
use frame_support::pallet_prelude::*; | ||
use mock_builder::{execute_call, register_call}; | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config { | ||
type Amount; | ||
type TrancheAmount; | ||
type CurrencyId; | ||
type InvestmentId; | ||
} | ||
|
||
#[pallet::pallet] | ||
pub struct Pallet<T>(_); | ||
|
||
#[pallet::storage] | ||
type CallIds<T: Config> = StorageMap<_, _, String, mock_builder::CallId>; | ||
|
||
impl<T: Config> Pallet<T> { | ||
pub fn mock_increase_foreign_investment( | ||
f: impl Fn(&T::AccountId, T::InvestmentId, T::Amount, T::CurrencyId) -> DispatchResult | ||
+ 'static, | ||
) { | ||
register_call!(move |(a, b, c, d)| f(a, b, c, d)); | ||
} | ||
|
||
pub fn mock_decrease_foreign_investment( | ||
f: impl Fn(&T::AccountId, T::InvestmentId, T::Amount, T::CurrencyId) -> DispatchResult | ||
+ 'static, | ||
) { | ||
register_call!(move |(a, b, c, d)| f(a, b, c, d)); | ||
} | ||
|
||
pub fn mock_increase_foreign_redemption( | ||
f: impl Fn( | ||
&T::AccountId, | ||
T::InvestmentId, | ||
T::TrancheAmount, | ||
T::CurrencyId, | ||
) -> DispatchResult | ||
+ 'static, | ||
) { | ||
register_call!(move |(a, b, c, d)| f(a, b, c, d)); | ||
} | ||
|
||
pub fn mock_decrease_foreign_redemption( | ||
f: impl Fn( | ||
&T::AccountId, | ||
T::InvestmentId, | ||
T::TrancheAmount, | ||
T::CurrencyId, | ||
) -> DispatchResult | ||
+ 'static, | ||
) { | ||
register_call!(move |(a, b, c, d)| f(a, b, c, d)); | ||
} | ||
|
||
pub fn mock_collect_foreign_investment( | ||
f: impl Fn(&T::AccountId, T::InvestmentId, T::CurrencyId) -> DispatchResult + 'static, | ||
) { | ||
register_call!(move |(a, b, c)| f(a, b, c)); | ||
} | ||
|
||
pub fn mock_collect_foreign_redemption( | ||
f: impl Fn(&T::AccountId, T::InvestmentId, T::CurrencyId) -> DispatchResult + 'static, | ||
) { | ||
register_call!(move |(a, b, c)| f(a, b, c)); | ||
} | ||
|
||
pub fn mock_investment( | ||
f: impl Fn(&T::AccountId, T::InvestmentId) -> Result<T::Amount, DispatchError> + 'static, | ||
) { | ||
register_call!(move |(a, b)| f(a, b)); | ||
} | ||
|
||
pub fn mock_redemption( | ||
f: impl Fn(&T::AccountId, T::InvestmentId) -> Result<T::TrancheAmount, DispatchError> | ||
+ 'static, | ||
) { | ||
register_call!(move |(a, b)| f(a, b)); | ||
} | ||
} | ||
|
||
impl<T: Config> ForeignInvestment<T::AccountId> for Pallet<T> { | ||
type Amount = T::Amount; | ||
type CurrencyId = T::CurrencyId; | ||
type Error = DispatchError; | ||
type InvestmentId = T::InvestmentId; | ||
type TrancheAmount = T::TrancheAmount; | ||
|
||
fn increase_foreign_investment( | ||
a: &T::AccountId, | ||
b: Self::InvestmentId, | ||
c: Self::Amount, | ||
d: Self::CurrencyId, | ||
) -> DispatchResult { | ||
execute_call!((a, b, c, d)) | ||
} | ||
|
||
fn decrease_foreign_investment( | ||
a: &T::AccountId, | ||
b: Self::InvestmentId, | ||
c: Self::Amount, | ||
d: Self::CurrencyId, | ||
) -> DispatchResult { | ||
execute_call!((a, b, c, d)) | ||
} | ||
|
||
fn increase_foreign_redemption( | ||
a: &T::AccountId, | ||
b: Self::InvestmentId, | ||
c: Self::TrancheAmount, | ||
d: Self::CurrencyId, | ||
) -> DispatchResult { | ||
execute_call!((a, b, c, d)) | ||
} | ||
|
||
fn decrease_foreign_redemption( | ||
a: &T::AccountId, | ||
b: Self::InvestmentId, | ||
c: Self::TrancheAmount, | ||
d: Self::CurrencyId, | ||
) -> DispatchResult { | ||
execute_call!((a, b, c, d)) | ||
} | ||
|
||
fn collect_foreign_investment( | ||
a: &T::AccountId, | ||
b: Self::InvestmentId, | ||
c: Self::CurrencyId, | ||
) -> DispatchResult { | ||
execute_call!((a, b, c)) | ||
} | ||
|
||
fn collect_foreign_redemption( | ||
a: &T::AccountId, | ||
b: Self::InvestmentId, | ||
c: Self::CurrencyId, | ||
) -> DispatchResult { | ||
execute_call!((a, b, c)) | ||
} | ||
|
||
fn investment( | ||
a: &T::AccountId, | ||
b: Self::InvestmentId, | ||
) -> Result<Self::Amount, DispatchError> { | ||
execute_call!((a, b)) | ||
} | ||
|
||
fn redemption( | ||
a: &T::AccountId, | ||
b: Self::InvestmentId, | ||
) -> Result<Self::TrancheAmount, DispatchError> { | ||
execute_call!((a, b)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#[frame_support::pallet(dev_mode)] | ||
pub mod pallet { | ||
use cfg_traits::liquidity_pools::OutboundQueue; | ||
use frame_support::pallet_prelude::*; | ||
use mock_builder::{execute_call, register_call}; | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config { | ||
type Sender; | ||
type Destination; | ||
type Message; | ||
} | ||
|
||
#[pallet::pallet] | ||
pub struct Pallet<T>(_); | ||
|
||
#[pallet::storage] | ||
type CallIds<T: Config> = StorageMap<_, _, String, mock_builder::CallId>; | ||
|
||
impl<T: Config> Pallet<T> { | ||
pub fn mock_submit( | ||
f: impl Fn(T::Sender, T::Destination, T::Message) -> DispatchResult + 'static, | ||
) { | ||
register_call!(move |(a, b, c)| f(a, b, c)); | ||
} | ||
} | ||
|
||
impl<T: Config> OutboundQueue for Pallet<T> { | ||
type Destination = T::Destination; | ||
type Message = T::Message; | ||
type Sender = T::Sender; | ||
|
||
fn submit(a: Self::Sender, b: Self::Destination, c: Self::Message) -> DispatchResult { | ||
execute_call!((a, b, c)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.