try-runtime
How to use `try-runtime` to test a storage migration.
The try-runtime
tool enables you to run tests and verify operations in a simulated environment before launching a runtime to production. This guide demonstrates the basic steps for integrating the try-runtime
tool into a runtime so you can use it to test a storage migration.
In general, adding the try-runtime
tool to your runtime is similar to importing pallets. It involves adding the appropriate dependencies in the correct places and updating the runtime logic to include the try-runtime
features. As with pallets, be sure that you are using the appropriate tag or branch for the try-runtime
tool when adding dependencies to the runtime.
Add runtime dependencies
Open a terminal shell and change to the root directory for the node template.
Open the
runtime/Cargo.toml
configuration file in a text editor.Locate the [dependencies] section and note how other pallets are imported.
Add the
frame-try-runtime
dependency:Note that you should use the same branch and version information for all of the pallets to ensure that the imported pallets are compatible with each other. Using pallets from different branches can result in compiler errors. This example illustrates adding the
frame-try-runtime
pallet to theCargo.toml
file if the other pallets usebranch = "polkadot-v1.0.0"
.Add the
try-runtime-cli
dependency:Add
frame-try-runtime
to the list of standard features:Add or update
try-runtime
in the[features]
section in include every pallet in your runtime.
Implement try-runtime in the runtime api
Add a configuration block for the try-runtime feature.
Add node dependencies
Open the
node/Cargo.toml
configuration file in a text editor.Locate the [dependencies] section and note how other pallets are imported.
Add the
frame-try-runtime
dependency:Add the
try-runtime-cli
dependency:Add or update
cli
andtry-runtime
in the[features]
section.
Add command-line subcommands
Open the
node/src/cli.rs
file in a text editor.
Add commands
Open the
node/src/commands.rs
file in a text editor.Add commands
If you're using custom pallets in your workspace, make sure you included try-runtime
in the dependencies inside the pallets/pallet_name/Cargo.toml
file of your workspace.
Use the try-runtime
Using the try-runtime tool is similar to writing unit tests.
To use try-runtime
:
Create an externalities instance.
Call
execute_with
on instance.
Where to go next
Last updated