-
Notifications
You must be signed in to change notification settings - Fork 86
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
Liquidity-pools: Add unitary tests #1879
Conversation
impl Convert<(Domain, [u8; 32]), AccountId32> for AccountConverter { | ||
fn convert((domain, account): (Domain, [u8; 32])) -> AccountId32 { | ||
match domain { | ||
Domain::Centrifuge => AccountId32::new(account), | ||
// EVM AccountId20 addresses are right-padded to 32 bytes | ||
Domain::EVM(chain_id) => { | ||
let mut bytes20 = [0; 20]; | ||
bytes20.copy_from_slice(&account[..20]); | ||
Self::convert_evm_address(chain_id, bytes20) | ||
} | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can implement this converter as a composition of the above two converters. This is also valid for liquidity pools
, and we do not need to pass the extra Convert
as a trait to the Config
.
pub fn domain_account_to_account(domain: Domain, account_id: AccountId) -> AccountId { | ||
let domain_address = Self::convert((domain, account_id.into())); | ||
Self::convert(domain_address) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A utility is still here for testing or other stuff
@@ -61,10 +61,15 @@ impl AccountConverter { | |||
} | |||
} | |||
|
|||
pub fn into_account_id<R: pallet_evm_chain_id::Config>(address: H160) -> AccountId { | |||
pub fn evm_to_account<R: pallet_evm_chain_id::Config>(address: H160) -> AccountId { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified the name (open to other names that match better) for two reasons:
- The
into_*
names are usually used when the own type is converted into something, not when the thing to convert is used as a parameter. The nameinto_account_id()
was inherited from the name used by the traitAddressMapping
, not chosen by us. Anyways, theinto_account_id()
is still accessible through the trait. - The new name follows the format:
FROM_to_TO
, as other methods:location_to_account()
domain_account_to_account()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit - evm_address_to_account_id
^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like it more!
@@ -1,276 +0,0 @@ | |||
use std::ops::Add; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed this file because:
- No longer used in our gateway tests, which were correctly covered by its UTs.
- It tests just democracy stuff which is not under our umbrella. We do not want to maintain this.
- No longer used after OpenGov (?): feat: Open Gov for Development and Altair Runtimes #1828
Anyways, I am open to discussing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you!
pallets/liquidity-pools/src/mock.rs
Outdated
ForeignInvestment: cfg_mocks::foreign_investment::pallet, | ||
Gateway: cfg_mocks::outbound_queue::pallet, | ||
DomainAddressToAccountId: cfg_mocks::converter::pallet::<Instance1>, | ||
DomainAccountToDomainAddress: cfg_mocks::converter::pallet::<Instance3>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have to use Instance3
here? IIRC we used maximum 2 instances in tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right! I had an Instance2
before. I will change it! Good eye 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ultra-clean, as always :D Thank you @lemunozm!
ensure!( | ||
T::PoolInspect::tranche_exists(pool_id, tranche_id), | ||
Error::<T>::TrancheNotFound | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already checked under derive_invest_id()
to create the investment_id
@@ -1097,25 +1068,3 @@ pub mod pallet { | |||
} | |||
} | |||
} | |||
|
|||
#[cfg(test)] | |||
mod tests { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to domain_address.rs
tests
a95397c
to
91b79bb
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1879 +/- ##
==========================================
+ Coverage 46.81% 47.65% +0.83%
==========================================
Files 170 171 +1
Lines 13221 13233 +12
==========================================
+ Hits 6190 6306 +116
+ Misses 7031 6927 -104 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great improvement! Loving the clean distinction between all test scenarios instead of the previous huge blocks. I have two minor nits which can be ignored.
assert_ok!(LiquidityPools::transfer( | ||
RuntimeOrigin::signed(ALICE), | ||
CurrencyId::ForeignAsset(1), | ||
EVM_ADDRESS, | ||
AMOUNT | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Please add the previously existing check that the balance of the sender and total issuance of the assed was reduced by AMOUNT
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially I removed that check because it's checking that orml_tokens is correctly working (which is out of scope from this UT test), but thinking again, it makes sense to check that actually this method calls correctly to orml_tokens, with the correct amount. So, will do 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good point BTW
pallets/liquidity-pools/src/tests.rs
Outdated
assert_ok!(LiquidityPools::transfer_tranche_tokens( | ||
RuntimeOrigin::signed(ALICE), | ||
POOL_ID, | ||
TRANCHE_ID, | ||
EVM_ADDRESS, | ||
AMOUNT | ||
),); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Same as above: Can we add a check which ensures the balance was altered correctly on the sender and the domain account?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! I've also simplified in the process some minor thing regarding this: ebdebbd
Generally, the Convert
trait is quite obscure when you have different conversions, and in that case, we didn't need it.
83e175f
to
d2e04cc
Compare
The base branch was changed.
d2e04cc
to
f870660
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adhering to my nits!
Description
We didn't have UTs for the liquidity pool. Although the Integration Tests cover more or less the basics of
liquidity-pools
, having those checks there makes Integration Tests more boilerplate. We can simplify some tests if the basics are moved to the unitary tests.Changes:
liquidity::gateway
tests, which are correctly checked in UTs.utils::democracy
which are no longer needed (see comment below)liquidity_pools::transfer
covered in UTs.BLOCKED BY #1869