Skip to content
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

IT: Simplify liquidity_pool test module #1869

Merged
merged 25 commits into from
Jun 24, 2024
Merged

Conversation

lemunozm
Copy link
Contributor

@lemunozm lemunozm commented Jun 11, 2024

Description

There are a lot of overlapping and boilerplate in the current liquidity-pool tests.

  • Minor IT utilities improvements & simplifications.
  • Added an approx() to check approximation amounts.
  • Give more "multi-runtime" support in several tests
  • Extracted and refactored some modules from liquidity_pools.rs into their own files, trying to avoid as much testing overlapping as possible:
    • Module transfer into xcm_transfer.rs file:
      • para -> para
      • relay -> para -> relay
    • Module asset_registry into assets.rs file.
    • Module currency_id_convert into currency_conversion.rs file.
    • Module restricted_tokens into the already existent restricted_tokens.rs file.
  • Remove fudge from proxy tests.
  • PARA_ID and SIBLING_ID no longer tied to FudgeHandle. They are gloval values that can be read in any place without using T::FudgeHandle

I do not touch any tests related to liquidity pools itself. I want to give them support for altair and centrifuge and remove the Fudge requirement in another PR. Also, I think there is a lot of overlap with the new lp module, so maybe some of them can just be removed.

Next in line (future PRs):

  • Move gateway tests to its own module tested for all runtimes: Liquidity-pools: Add unitary tests #1879
  • Move routers tests to its own module tested for all runtimes.
  • liquidity pool tests without fudge, and tested for all runtimes.

@lemunozm lemunozm added I4-tests Test needs fixing or improving. crcl-protocol Circle protocol related. labels Jun 11, 2024
@lemunozm lemunozm self-assigned this Jun 11, 2024
@lemunozm lemunozm force-pushed the it/simplify-xtransfer-tests branch 3 times, most recently from 8ccf242 to 650e96e Compare June 11, 2024 15:41
@lemunozm lemunozm force-pushed the it/simplify-xtransfer-tests branch from 650e96e to 0bc96f6 Compare June 11, 2024 15:43
@lemunozm lemunozm requested a review from cdamian June 12, 2024 15:54

assert_eq!(
orml_tokens::Pallet::<T>::free_balance(curr.id(), &Keyring::Alice.id()),
curr.val(INITIAL) - curr.val(TRANSFER)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: the val() method will create the balance with the correct decimals based on the currency it is. We no longer need usd6()/usd12()/usd18() methods which leads to errors mixing different amounts.


assert_ne!(1000u128, 996.approx(0.01));
assert_ne!(1000u128, 1004.approx(-0.01));
assert_ne!(1000u128, 1500.approx(0.1));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value 0.01 means that both values are equal if the right-hand side is as much as 1% higher than the other one. -0.01 means lower than.

@lemunozm lemunozm force-pushed the it/simplify-xtransfer-tests branch from 02ca1ad to 5b41f5e Compare June 13, 2024 09:16
@lemunozm
Copy link
Contributor Author

lemunozm commented Jun 13, 2024

There are a lot of git diffs in liquidity_pools.rs file. But 99% of the changes is just removing the modules transfer, asset_registry, currency_id_convert, and restricted_transfer

Comment on lines +81 to +86
assert_eq!(
CurrencyIdConvert::<T>::convert(Location::new(0, Here)),
Some(curr.id()),
);

assert_eq!(CurrencyIdConvert::<T>::convert(curr.id()), None);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, here I would expect a symmetric behavior, but it isn't.

The implementation only checks the transferability when converting from location -> currency ref. Should we add the same filter for currency -> location ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly not sure if we want this to be symmetric. AFAICT, we could switch to that based on my below observations.

If we decide on that, it blocks converting any local currency locations into their corresponding currency id. One implication is that those currencies cannot be used for paying XCM transaction fees. On mainnet, CFG is configured as XCM transferable.

It would be interesting to see the failing tests when switching to symmetric behaviour. Depending on the failing tests, this could be a good indicator on whether we require location-to-currency location for local currencies as part of XCM for instance.

AFAICS, the CurrencyIdConvert is used to determine and withdraw cross-chain fee amounts in the configured fee currency in three different pallets:

  1. As orml_xtokens::CurrencyIdConvert to derive the asset origination location
  2. As pallet_xcm_transactor::CurrencyIdLocation to withdraw the fee amount of the configured fee currency
  3. In staging_xcm_executor::Config::AssetTransactor = FungiblesTransactor as Matcher AT of our FungiblesAdaptor impl to withdraw the XCM fee in the configured fee currencies

Curious about your thoughts @mustermeiszer

@lemunozm lemunozm marked this pull request as ready for review June 13, 2024 14:25
Copy link

codecov bot commented Jun 13, 2024

Codecov Report

Attention: Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.

Project coverage is 46.84%. Comparing base (737278c) to head (3991dea).

Files Patch % Lines
libs/types/src/tokens.rs 0.00% 6 Missing ⚠️
runtime/common/src/xcm.rs 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1869      +/-   ##
==========================================
- Coverage   46.87%   46.84%   -0.03%     
==========================================
  Files         170      170              
  Lines       13223    13221       -2     
==========================================
- Hits         6198     6194       -4     
- Misses       7025     7027       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lemunozm lemunozm changed the title IT: Simplify cross transfer tests IT: Simplify liquidity_pool test module Jun 14, 2024
@lemunozm lemunozm force-pushed the it/simplify-xtransfer-tests branch from f285d2e to 5a832ad Compare June 17, 2024 06:49
Comment on lines +368 to +383
/// Fees will be charged using `FixedRateOfFungible`.
#[cfg(feature = "std")]
pub fn xcm_default() -> Self {
Self::Xcm(XcmMetadata {
fee_per_second: None,
})
}

/// Fees will be charged using `AssetRegistryTrader`.
/// If value is 0, no fees will be charged.
#[cfg(feature = "std")]
pub fn xcm_with_fees(value: Balance) -> Self {
Self::Xcm(XcmMetadata {
fee_per_second: Some(value),
})
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tech-debt to create some tests to be able to compute the exact fee charged in the above two cases. Using FixedRateOfFungible and using AssetRegistryTrader

@lemunozm lemunozm force-pushed the it/simplify-xtransfer-tests branch from ec2c1e5 to de3760a Compare June 17, 2024 07:53
cdamian
cdamian previously approved these changes Jun 21, 2024
wischli
wischli previously approved these changes Jun 24, 2024
Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super organized and clean, love it! Two minor nits, which can be ignored and one comment from my side.

libs/primitives/src/lib.rs Show resolved Hide resolved
Comment on lines +81 to +86
assert_eq!(
CurrencyIdConvert::<T>::convert(Location::new(0, Here)),
Some(curr.id()),
);

assert_eq!(CurrencyIdConvert::<T>::convert(curr.id()), None);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly not sure if we want this to be symmetric. AFAICT, we could switch to that based on my below observations.

If we decide on that, it blocks converting any local currency locations into their corresponding currency id. One implication is that those currencies cannot be used for paying XCM transaction fees. On mainnet, CFG is configured as XCM transferable.

It would be interesting to see the failing tests when switching to symmetric behaviour. Depending on the failing tests, this could be a good indicator on whether we require location-to-currency location for local currencies as part of XCM for instance.

AFAICS, the CurrencyIdConvert is used to determine and withdraw cross-chain fee amounts in the configured fee currency in three different pallets:

  1. As orml_xtokens::CurrencyIdConvert to derive the asset origination location
  2. As pallet_xcm_transactor::CurrencyIdLocation to withdraw the fee amount of the configured fee currency
  3. In staging_xcm_executor::Config::AssetTransactor = FungiblesTransactor as Matcher AT of our FungiblesAdaptor impl to withdraw the XCM fee in the configured fee currencies

Curious about your thoughts @mustermeiszer

@lemunozm lemunozm enabled auto-merge (squash) June 24, 2024 13:53
@lemunozm lemunozm requested review from cdamian and wischli June 24, 2024 16:37
@lemunozm
Copy link
Contributor Author

@wischli @cdamian can you re-approve this? 🙏🏻

@lemunozm lemunozm merged commit ee8fc69 into main Jun 24, 2024
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crcl-protocol Circle protocol related. I4-tests Test needs fixing or improving.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants