Migration tests
Verify first, write last ... and always test!
#
GoalWrite tests for a simple storage migration.
#
Use casesTesting a migration module inside a pallet.
#
OverviewWhen writing a runtime migration module it is important to test it to avoid any critical issues caused by mangling storage items. This guide provides a walk through of the tests to include for a simple storage migration of a single pallet, using the Nicks pallet migration from the Basic Storage Migration guide as a reference.
#
Steps#
1. Write mock runtimeRefer to this guide to learn how to set up the dependencies for your test environment.
#
2. Specify unit testsDerive the different tests that need to be included based on your pallet's functions.
For the Nicks pallet migration we need:
fn kill_name_should_work()
fn force_name_should_work()
fn normal_operation_should_work()
fn error_catching_should_work()
Using asset_noop!(...)
, assert_ok!(...)
and assert_eq!(...)
, constructing one of these tests looks like this:
#
Examples- Migrating the Nicks pallet