Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Replicate e2e integration test as emulated #2958

Merged
merged 64 commits into from
Aug 10, 2023

Conversation

NachoPal
Copy link
Contributor

@NachoPal NachoPal commented Aug 1, 2023

Along with integration the tests for AssetHub, this PR includes improvements in xcm-emulator:

  • assert_expected_events!
    • Prevents from false negatives and looks for a perfect match in case there are two events with the same pattern
    • Prevents from matching with the same event as now they are removed from potential matches after a match
    • Event logs are moved outside the macro, so now they are always logged inside execute_with()
  • move_ext_in and move_ext_out methods added to TextExt to allow sharing externalities states between tests.
  • Refactor of Relay and Parachain traits
    • Common functionality has been moved to a common Chain trait.
    • Runtime, RuntimeEvent, RuntimeCall, RuntimeOrigin have been removed from decl_test_relay_chains! and decl_test_parachains!. The rationale behind this is that they are generated by construct_runtime! and we can consider it as a standard. To get a reference to them, a new runtime attribute has been added. This attribute is expecting the path to the runtime crate, and the former runtime attribute has been renamed to core. It expresses the mandatory building blocks xcm-emulator needs to work (for this reason we removed Balances from core).
    • Other items such as System have been removed, and kept/added only those ones that can be bounded by a trait.
  • Removal of the unnecessary RELAY_BLOCK_NUMBER thread variable, keeping relay block number accountability as part of the Relay Chain Externality
  • A Test struct and its impl that helps with re-usability avoiding repeating yourself.
  • And more refactor...

New helper parachains events methods have been added to each integration-tests crate + relay chain events in the common crate.

Finally, other helper methods such as xcm_paid_execution, xcm_unpaid_execution and force_create_and_mint_asset have been added too.

@bkontur
Copy link
Contributor

bkontur commented Aug 3, 2023

@NachoPal I did some small nits here #2971 please check, continue tomorrow

Copy link
Contributor

@gilescope gilescope left a comment

Choose a reason for hiding this comment

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

Loving it, lot's of good ideas in here.

…also for BridgeHubs) (#2971)

* Extracted some commonality for Kusama/Polkadot (which will be reused also for BridgeHubs)

* AssetHubRococo should better use AssetHubKusama runtime

* add fund_account

---------

Co-authored-by: NachoPal <ignacio.palacios.santos@gmail.com>
type RuntimeEvent = <Polkadot as Chain>::RuntimeEvent;

// Dispatchable is completely executed and XCM sent
pub fn xcm_pallet_attempted_complete(expected_weight: Option<Weight>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@NachoPal
I would not use two levels of modules here,
why not just move this functions to revelant runtime, e.g.:

impl Kusama {
   pub fn xcm_pallet_attempted_complete(expected_weight: Option<Weight>) {...
}

impl Polkadot {
   pub fn xcm_pallet_attempted_complete(expected_weight: Option<Weight>) {...
}

...

then usage will be much nicer:

// instead of:
events::polkadot::xcm_pallet_attempted_complete

// use just:
Polkadot::xcm_pallet_attempted_complete

later when we split this common per runtime, it will be easier to refactor,

Copy link
Contributor

@bkontur bkontur Aug 4, 2023

Choose a reason for hiding this comment

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

other thing is that I think those function looks the same,
and they could be write in generic way for trait Chain with some argument to specific Pallet if needed

Copy link
Contributor Author

@NachoPal NachoPal Aug 4, 2023

Choose a reason for hiding this comment

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

Now that we can have chains impl, yes, I can move it to the impls.

About moving to Chain... xcm-emulator will not compile for someone who is using a chain without one of the expected RuntimeEvents variants. I do not think it is a good idea or necessary. It would fail for those chains that use xTokens pallet instead of XcmPallet, for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't want to, but I ended up using macros. It was too much repetition.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, I got it that xcm-emulator is general, but there is also possiblity to create CumulusChain / PolkadotLikeTelayChain in emulated/common and so on

@NachoPal
Copy link
Contributor Author

NachoPal commented Aug 7, 2023

bot fmt

@command-bot
Copy link

command-bot bot commented Aug 7, 2023

@NachoPal https://gitlab.parity.io/parity/mirrors/cumulus/-/jobs/3338725 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". Check out https://gitlab.parity.io/parity/mirrors/cumulus/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 15-6a422efa-db7f-4236-83a9-bcf9ee469cfd to cancel this command or bot cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Aug 7, 2023

@NachoPal Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/cumulus/-/jobs/3338725 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/cumulus/-/jobs/3338725/artifacts/download.

@NachoPal
Copy link
Contributor Author

NachoPal commented Aug 7, 2023

All comments addressed

@muharem muharem self-requested a review August 7, 2023 15:39
@NachoPal
Copy link
Contributor Author

@bkontur @muharem I'll proceed to merge

Copy link
Contributor

@bkontur bkontur left a comment

Choose a reason for hiding this comment

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

ok, cool, lets go :),
we can still add imrpovements on the way :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes T7-system_parachains This PR/Issue is related to System Parachains.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants