Skip to content

Conversation

pLabarta
Copy link
Contributor

@pLabarta pLabarta commented Jul 22, 2025

What does it do?

  • Refactor and split Moonbase XCM tests which were sitting in a single 4k line file.
  • Added some helpers to extract some login from the test cases into setup and common functions.

What important points should reviewers know?

The test cases should remain the same, these are not meant to change in this PR.

Reviewers might need to compare current tests with the original ones at https://github.com/moonbeam-foundation/moonbeam/blob/fb5af73509cccc5ecef95de28896679b7cef11c5/runtime/moonbase/tests/xcm_tests.rs (current commit at master when writing this)

I've commented on the new tests with links to the original ones.

Is there something left for follow-up PRs?

To make this PR smaller, only Moonbase tests were changed. Once merged, a new PR is needed to update Moonriver and Moonbeam tests.

What alternative implementations were considered?

Are there relevant PRs or issues in other repositories (Substrate, Polkadot, Frontier, Cumulus)?

What value does it bring to the blockchain users?

Copy link

coderabbitai bot commented Jul 22, 2025

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one) (1)
  • agent-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pablo/refactor-moonbase-xcm-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

github-actions bot commented Jul 22, 2025

WASM runtime size check:

Compared to target branch

Moonbase runtime: 2348 KB (no changes) ✅

Moonbeam runtime: 2504 KB (no changes) 🚨

Moonriver runtime: 2496 KB (no changes) 🚨

Compared to latest release (runtime-3800)

Moonbase runtime: 2348 KB (+304 KB compared to latest release) ⚠️

Moonbeam runtime: 2504 KB (+340 KB compared to latest release) 🚨

Moonriver runtime: 2496 KB (+332 KB compared to latest release) 🚨

@pLabarta pLabarta added B0-silent Changes should not be mentioned in any release notes D2-notlive PR doesn't change runtime code (so can't be audited) labels Jul 22, 2025
Copy link
Contributor

github-actions bot commented Jul 22, 2025

Coverage Report

@@                          Coverage Diff                          @@
##           master   pablo/refactor-moonbase-xcm-tests      +/-   ##
=====================================================================
- Coverage   73.50%                              73.34%   -0.16%     
+ Files         409                                 425      +16     
- Lines       99362                               98773     -589     
=====================================================================
- Hits        73028                               72439     -589     
  Misses      26334                               26334              
Files Changed Coverage

Coverage generated Thu Aug 7 18:03:51 UTC 2025

use cumulus_primitives_core::relay_chain::HrmpChannelId;

#[test]
fn hrmp_init_accept_through_root() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original

fn hrmp_init_accept_through_root() {

}

#[test]
fn hrmp_close_works() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original

fn hrmp_close_works() {

use xcm_simulator::TestExt;

#[test]
fn test_automatic_versioning_on_runtime_upgrade_with_relay() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original

fn test_automatic_versioning_on_runtime_upgrade_with_relay() {

}

#[test]
fn test_automatic_versioning_on_runtime_upgrade_with_para_b() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original

fn test_automatic_versioning_on_runtime_upgrade_with_para_b() {

use crate::{xcm_mock::*, xcm_testing::helpers::*};

#[test]
fn evm_account_receiving_assets_should_handle_sufficients_ref_count() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original

fn evm_account_receiving_assets_should_handle_sufficients_ref_count() {

}

#[test]
fn empty_account_should_not_be_reset() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original

fn empty_account_should_not_be_reset() {

use xcm_simulator::TestExt;

#[test]
fn send_para_a_asset_to_para_b() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

#[test]
fn send_para_a_asset_from_para_b_to_para_c() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original

fn send_para_a_asset_from_para_b_to_para_c() {

}

#[test]
fn send_para_a_asset_to_para_b_and_back_to_para_a() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original

fn send_para_a_asset_to_para_b_and_back_to_para_a() {

}

#[test]
fn send_para_a_asset_to_para_b_and_back_to_para_a_with_new_reanchoring() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original

fn send_para_a_asset_to_para_b_and_back_to_para_a_with_new_reanchoring() {

}

#[test]
fn send_para_a_asset_to_para_b_with_trader() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original

fn send_para_a_asset_to_para_b_with_trader() {

}

#[test]
fn send_para_a_asset_to_para_b_with_trader_and_fee() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original

fn send_para_a_asset_to_para_b_with_trader_and_fee() {


// Send a relay asset (like DOT) to a parachain A
#[test]
fn receive_relay_asset_from_relay() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original

fn receive_relay_asset_from_relay() {


// Send relay asset (like DOT) back from Parachain A to relaychain
#[test]
fn send_relay_asset_to_relay() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original

fn send_relay_asset_to_relay() {

}

#[test]
fn send_relay_asset_to_para_b() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original

fn send_relay_asset_to_para_b() {

}

#[test]
fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_with_fee() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

#[test]
fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_multiasset() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original

fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_multiasset() {

}

#[test]
fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_multicurrencies() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

#[test]
fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_multiassets() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

use xcm_simulator::TestExt;

#[test]
fn transact_through_derivative_multilocation() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original

fn transact_through_derivative_multilocation() {

}

#[test]
fn transact_through_derivative_with_custom_fee_weight() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original

fn transact_through_derivative_with_custom_fee_weight() {

}

#[test]
fn transact_through_derivative_with_custom_fee_weight_refund() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

use xcm_simulator::TestExt;

#[test]
fn transact_through_signed_multilocation() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original

fn transact_through_signed_multilocation() {

}

#[test]
fn transact_through_signed_multilocation_custom_fee_and_weight() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original

fn transact_through_signed_multilocation_custom_fee_and_weight() {

}

#[test]
fn transact_through_signed_multilocation_custom_fee_and_weight_refund() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

#[test]
fn transact_through_signed_multilocation_para_to_para() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original

fn transact_through_signed_multilocation_para_to_para() {

}

#[test]
fn transact_through_signed_multilocation_para_to_para_refund() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

#[test]
fn transact_through_signed_multilocation_para_to_para_ethereum() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

#[test]
fn transact_through_signed_multilocation_para_to_para_ethereum_no_proxy_fails() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

#[test]
fn transact_through_signed_multilocation_para_to_para_ethereum_proxy_succeeds() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

use xcm_simulator::{Encode, TestExt};

#[test]
fn transact_through_sovereign() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original

fn transact_through_sovereign() {

}

#[test]
fn transact_through_sovereign_fee_payer_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.

Original

fn transact_through_sovereign_fee_payer_none() {

}

#[test]
fn transact_through_sovereign_with_custom_fee_weight() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original

fn transact_through_sovereign_with_custom_fee_weight() {

}

#[test]
fn transact_through_sovereign_with_custom_fee_weight_refund() {
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

@pLabarta pLabarta left a comment

Choose a reason for hiding this comment

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

Left comments with links to the original tests

@pLabarta pLabarta marked this pull request as ready for review July 22, 2025 17:21
librelois
librelois previously approved these changes Jul 29, 2025
Copy link
Contributor

@RomarQ RomarQ left a comment

Choose a reason for hiding this comment

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

Lets just refactor "test setup" things, like registration of assets, xcm version configuration, etc...

For functions that are only used once, and are not duplicated elsewhere, we should just move them to the specific test.

Over-refactoring testing code can lead to loss of clarity, harder debugging, and less maintainable tests. Unlike production code, tests should prioritize readability and explicitness over DRY (Don't Repeat Yourself). Over-abstraction in tests can make it difficult to understand what a test does at a glance or what it’s verifying when it fails.

Comment on lines 31 to 41
pub fn assert_asset_balance_para_b(
account: &[u8; 20],
asset_id: parachain::AssetId,
expected: u128,
) {
use crate::xcm_mock::ParaB;
ParaB::execute_with(|| {
let account_id = parachain::AccountId::from(*account);
assert_eq!(Assets::balance(asset_id, &account_id), expected);
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to only be used once and uses Assets, which is going to be removed. Every function that is only used once should either be moved to the specific test that uses it or we should update other tests to also use it.

@pLabarta pLabarta requested review from RomarQ and librelois August 14, 2025 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B0-silent Changes should not be mentioned in any release notes D2-notlive PR doesn't change runtime code (so can't be audited)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants