Skip to content

Zombienet-SDK test for the happy path of the new staking-async flow #8317

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

Open
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

tdimitrov
Copy link
Contributor

Adds a zombienet test for the happy case of new staking flow where staking-async pallet is deployed on AH.

The test uses test/fake runtimes for RC and AH-Next. It covers the following scenario:

  • AH and RC networks are started
  • Election is started on AH
  • Election yields the expected number of validators
  • The new active set is delivered to RC
  • On session change the active set on RC is changed and AH is notified

The test takes quite a lot of time (~11 minutes) to execute and requires the chainspecs for fake RC and AH-Next to be prebuilt in the root directory of the test module.

@tdimitrov tdimitrov added R0-silent The change does not warrant a re-release of the modified crates. T10-tests This PR/Issue is related to tests. labels Apr 24, 2025
@tdimitrov tdimitrov requested review from kianenigma and Ank4n April 24, 2025 08:42
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

mod staking_next;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why have you chosen to have these tests to be in ./substrate vs in ./substrate/frame/staking-async?

Also noting the new name is staking-async, not next.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a common pattern to have all zombienet tests in polkadot/zombiened-sdk-tests, substrate/zombienet-sdk-tests, etc.

But I've got no strong preference on this. If you want, I'll move them to to ./substrate/frame/staking-async.

I'll fix the name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both are fixed.


mod tests;

/// Sets `ValidatorCount` in staking pallet to 500.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Sets `ValidatorCount` in staking pallet to 500.
/// Sets `ValidatorCount` in staking pallet to `validator_count`.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also worth adding a comment that this is due to some mysterious bug, otherwise it should not be used/needed.

Has there been any updates on that? do we have any new leads as to why it is needed?

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've added the comment. I still haven't investigated why the value from the chainspec doesn't get set to the storage item.

) -> Result<(), anyhow::Error> {
let set_validator_count = dynamic::tx("Staking", "set_validator_count", vec![validator_count]);
let sudo = dynamic::tx("Sudo", "sudo", vec![set_validator_count.into_value()]);
let alice = dev::alice();
Copy link
Contributor

Choose a reason for hiding this comment

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

This will work fine, but to be more correct you should query Sudo::key here, see who it is, and if it is one of the dev accounts (alice, bob etc.), sign and send it, and if not fail.

In other words, you are assuming alice is sudo, which may or may not be.

})
.with_parachain(|p| {
p.with_id(1100)
.with_chain_spec_path("parachain.json") // TODO: how to autogenerate this?
Copy link
Contributor

Choose a reason for hiding this comment

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

esp if you move it to ./substrate/frame/staking-next, I think it is okay for now to say in the README.md:

please first run build-and-run-zn.sh compile, and tweak this bash script to have an option to just prepare the two chain-specs, and not run ZN.


// Events generated by rc_client. Event here doesn't necessary mean 'event in the substrate
// context'. It can be anything representing a point of interest for the tests.
enum RcClientEvent {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think subxt has a cli which allows you to generate a metadata from the wasm file, and within that you have access to the subxt-compliant version of all of the runtime types, including the concrete event types. So you could, instead of this, assert that some events are emitted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true but in this case this event is not a runtime event.
It's an 'event' such as 'something happened in the test which we want to handle and probably change state. In this test there is 100% match between runtime event in test event but in general this might not be the case.

I should pick a better name since this causes confusion.

Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

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

Would be ideal to simplify the manual-data parsing here, before we extend it to more test scenarios.

Strongly in favor of moving this to staking-async crate, under a new sub-crate over there to keep it more isolated.

@tdimitrov tdimitrov requested a review from a team as a code owner April 25, 2025 07:05
@tdimitrov
Copy link
Contributor Author

Would be ideal to simplify the manual-data parsing here, before we extend it to more test scenarios.

The static interface is problematic for CI since we don't want to commit the metadata and at the same time we need it generated somehow. To avoid complicated build scripts I am sticking with the dynamic subxt interface but with some advise from @jsdw I reworked the parsing. I think it's way better now.

Strongly in favor of moving this to staking-async crate, under a new sub-crate over there to keep it more isolated.

I've also moved the test in staking-async, as an ignored integration test. That way CI won't pick it up but we still can run it manually.

@jsdw
Copy link
Contributor

jsdw commented Apr 25, 2025

The static interface is problematic for CI since we don't want to commit the metadata and at the same time we need it generated somehow.

In case it helps, Subxt does this by spinning up a Substrate node in a build.rs file, downloading metadata from it and then providing an instance of the generated interface from it here:

https://github.com/paritytech/subxt/blob/master/testing/test-runtime/build.rs

(If the node is already spun up at the time the tests start running, you can also generate an interface given a URL to an RPC node ie like this: https://docs.rs/subxt/latest/subxt/attr.subxt.html#connecting-to-a-node-to-download-metadata-via-runtime_metadata_insecure_url--)

But yeah, I appreciate that this adds a little complexity. The static interface def makes life easier though :)

@tdimitrov tdimitrov requested a review from kianenigma April 25, 2025 13:06
pallet-bags-list = { workspace = true, default-features = true }
pallet-balances = { workspace = true, default-features = true }
rand_chacha = { workspace = true, default-features = true }
sp-npos-elections = { workspace = true, default-features = true }
sp-tracing = { workspace = true, default-features = true }
substrate-test-utils = { workspace = true }
subxt = { workspace = true }
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's move them to a separate crate staking-async/zn-test to not increase the compile time of the rust unit tests?

@paritytech-workflow-stopper
Copy link

All GitHub workflows were cancelled due to failure one of the required jobs.
Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/15017687759
Failed job name: test-linux-stable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R0-silent The change does not warrant a re-release of the modified crates. T10-tests This PR/Issue is related to tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants