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

try-runtime-cli: execute-block & create-snapshot tests #14343

Merged
merged 24 commits into from
Jun 24, 2023

Conversation

Szegoo
Copy link
Contributor

@Szegoo Szegoo commented Jun 11, 2023

This PR adds tests for the following try-runtime commands:

  • execute-block
  • create-snapshot

Part of: #13796

Kusama address: DfqY6XQUSETTszBQ1juocTcG9iiDoXhvq1CoVadBSUqTGJS

@Szegoo Szegoo changed the title execute-block & create-snapshot tests try-runtime-cli: execute-block & create-snapshot tests Jun 11, 2023
@Szegoo Szegoo marked this pull request as ready for review June 12, 2023 06:47
@Szegoo
Copy link
Contributor Author

Szegoo commented Jun 12, 2023

@liamaharon Could you review this?

@liamaharon liamaharon self-requested a review June 12, 2023 08:04
@liamaharon liamaharon added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit T1-runtime This PR/Issue is related to the topic “runtime”. labels Jun 12, 2023
Copy link
Contributor

@liamaharon liamaharon left a comment

Choose a reason for hiding this comment

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

Looking good, thanks for this!

utils/frame/try-runtime/cli/tests/create_snapshot.rs Outdated Show resolved Hide resolved
utils/frame/try-runtime/cli/tests/create_snapshot.rs Outdated Show resolved Hide resolved
utils/frame/try-runtime/cli/tests/create_snapshot.rs Outdated Show resolved Hide resolved
utils/frame/try-runtime/cli/tests/create_snapshot.rs Outdated Show resolved Hide resolved
utils/frame/try-runtime/cli/tests/follow_chain.rs Outdated Show resolved Hide resolved
utils/frame/try-runtime/cli/tests/execute_block.rs Outdated Show resolved Hide resolved
Szegoo and others added 5 commits June 15, 2023 09:04
Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
@Szegoo Szegoo requested review from a team and liamaharon June 15, 2023 08:07
@paritytech-ci paritytech-ci requested a review from a team June 15, 2023 09:57
Copy link
Contributor

@liamaharon liamaharon left a comment

Choose a reason for hiding this comment

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

LGTM

utils/frame/try-runtime/cli/tests/create_snapshot.rs Outdated Show resolved Hide resolved
utils/frame/try-runtime/cli/tests/execute_block.rs Outdated Show resolved Hide resolved
Szegoo and others added 2 commits June 16, 2023 12:39
Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
Command::new(cargo_bin("substrate"))
.stdout(process::Stdio::piped())
.stderr(process::Stdio::piped())
.args(&["try-runtime", "--runtime=existing"])
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI, the need for --runtime for this subcommand was a fundamental mistake that I added at some point @liamaharon 🙈

Copy link
Contributor

@liamaharon liamaharon Jun 16, 2023

Choose a reason for hiding this comment

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

wdyt about existing always being a default?

.stderr(process::Stdio::piped())
.args(&["try-runtime", "--runtime=existing"])
.args(&["execute-block"])
.args(&["live", format!("--uri={}", ws_url).as_str()])
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 only execute the latest block. Would be interesting if you also think about incorporating --at, if reasonably possible.

Same applies to the other one as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I will do that.

test-utils/cli/src/lib.rs Outdated Show resolved Hide resolved
@kianenigma kianenigma added A3-in_progress Pull request is in progress. No review needed at this stage. and removed A0-please_review Pull request needs code review. labels Jun 20, 2023
@kianenigma
Copy link
Contributor

@liamaharon Don't merge this yet :P I am working on incorporating --at into the tests.

Please let us know once ready for final review.

@Szegoo
Copy link
Contributor Author

Szegoo commented Jun 21, 2023

@liamaharon I realised that the problem I encountered was not in the block_hash function. It seems like there isn't an issue, but I am a bit confused.

In the execute_block function why don't we execute the block we specified with the --at option? The code will do execute_block for the next block.

let executor = build_executor::<HostFns>(&shared);
let ext = command.state.into_ext::<Block, HostFns>(&shared, &executor, None, true).await?;
// get the block number associated with this block.
let block_ws_uri = command.block_ws_uri::<Block>();
let rpc = ws_client(&block_ws_uri).await?;
let next_hash = next_hash_of::<Block>(&rpc, ext.block_hash).await?;
log::info!(target: LOG_TARGET, "fetching next block: {:?} ", next_hash);

@liamaharon
Copy link
Contributor

Hmm.. Intuitively I would also expect execute_block to re-execute the block at rather than at + 1. @kianenigma do you remember if this behavior is intentional?

utils/frame/try-runtime/cli/tests/create_snapshot.rs Outdated Show resolved Hide resolved
#[tokio::test]
async fn create_snapshot_works() {
// Build substrate so binaries used in the test use the latest code.
common::build_substrate(&["--features=try-runtime"]);
Copy link
Member

Choose a reason for hiding this comment

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

I now understood why we have to build again. Just very annoying and slow…
Maybe we can somehow inherit the build args in this function, so that it re-uses the cargo cache.

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 would be great. It does take quite some time to run all of these tests.

Copy link
Member

Choose a reason for hiding this comment

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

Yea that would be a follow up as well; debug that build_substrate function and check if we can make it re-use the already existing build artifacts by using the same compile args that were used for the test.

utils/frame/try-runtime/cli/tests/create_snapshot.rs Outdated Show resolved Hide resolved
utils/frame/try-runtime/cli/tests/execute_block.rs Outdated Show resolved Hide resolved
@@ -332,6 +332,12 @@ where
);
}

frame_support::log::info!(
target: LOG_TARGET,
"try-runtime: Block #{:?} successfully executed",
Copy link
Member

@ggwpez ggwpez Jun 21, 2023

Choose a reason for hiding this comment

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

Just some ideas, we could do stuff here like:

  • State trace (output of all modified storage keys)
  • Print all executed calls + Events
  • Consumed weight
  • Block size etc

Probably most of it in JSON, so we can render it eventually (like chopsticks already does for state changes).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this be done in this PR?

Copy link
Member

Choose a reason for hiding this comment

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

No. Just some ideas for the future 😄

Szegoo and others added 3 commits June 21, 2023 13:30
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
@ggwpez
Copy link
Member

ggwpez commented Jun 21, 2023

Needs to merge master to make the CI happy.

@ggwpez
Copy link
Member

ggwpez commented Jun 24, 2023

Going to merge this. We can investigate afterwards if this --at needs a fix. This way we already have some tests.

@ggwpez ggwpez added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Jun 24, 2023
@ggwpez
Copy link
Member

ggwpez commented Jun 24, 2023

bot merge

@paritytech-processbot
Copy link

Waiting for commit status.

@paritytech-processbot paritytech-processbot bot merged commit 0d09a26 into paritytech:master Jun 24, 2023
nathanwhit pushed a commit to nathanwhit/substrate that referenced this pull request Jul 19, 2023
…h#14343)

* execute-block test

* test create-snapshot

* oops

* Update utils/frame/try-runtime/cli/tests/create_snapshot.rs

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>

* Update utils/frame/try-runtime/cli/tests/create_snapshot.rs

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>

* Update utils/frame/try-runtime/cli/tests/create_snapshot.rs

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>

* remove snapshot

* execute block: new log

* use prefix & make tempfile a dev dependencie

* Update utils/frame/try-runtime/cli/tests/execute_block.rs

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>

* Update utils/frame/try-runtime/cli/tests/create_snapshot.rs

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>

* ".git/.scripts/commands/fmt/fmt.sh"

* --at option in execute-block test

* fixes & use --at option in create-snapshot test

* hmm

* fmt

* remove nonsense

* Update utils/frame/try-runtime/cli/tests/create_snapshot.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update utils/frame/try-runtime/cli/tests/execute_block.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* remove unnecessary test modules

* try to load snapshot file

* fix

---------

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
Co-authored-by: command-bot <>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
@kianenigma kianenigma mentioned this pull request Aug 14, 2023
6 tasks
@kianenigma
Copy link
Contributor

/tip small

@substrate-tip-bot
Copy link

@kianenigma A small (2 KSM) tip was successfully submitted for @Szegoo (DfqY6XQUSETTszBQ1juocTcG9iiDoXhvq1CoVadBSUqTGJS on kusama).

https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fkusama-rpc.polkadot.io#/referenda tip

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 C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit T1-runtime This PR/Issue is related to the topic “runtime”.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants