add unit tests to run runtime migrations (#5865)

* add unit tests to run runtime migrations

* Update runtime/westend/src/lib.rs

Co-authored-by: Mara Robin B. <mara@broda.me>

* fix

* fmt

* Update runtime/westend/src/lib.rs

Co-authored-by: Mara Robin B. <mara@broda.me>
This commit is contained in:
Kian Paimani
2022-08-11 07:24:11 +01:00
committed by GitHub
parent f1dce2f548
commit 1ad7de583f
7 changed files with 123 additions and 0 deletions
+9
View File
@@ -3231,6 +3231,7 @@ dependencies = [
"polkadot-primitives",
"polkadot-runtime-common",
"polkadot-runtime-parachains",
"remote-externalities",
"rustc-hex",
"scale-info",
"separator",
@@ -3254,12 +3255,14 @@ dependencies = [
"sp-session",
"sp-staking",
"sp-std",
"sp-tracing",
"sp-transaction-pool",
"sp-trie",
"sp-version",
"static_assertions",
"substrate-wasm-builder",
"tiny-keccak",
"tokio",
"xcm",
"xcm-builder",
"xcm-executor",
@@ -6975,6 +6978,7 @@ dependencies = [
"polkadot-runtime-common",
"polkadot-runtime-constants",
"polkadot-runtime-parachains",
"remote-externalities",
"rustc-hex",
"scale-info",
"separator",
@@ -6997,12 +7001,14 @@ dependencies = [
"sp-session",
"sp-staking",
"sp-std",
"sp-tracing",
"sp-transaction-pool",
"sp-trie",
"sp-version",
"static_assertions",
"substrate-wasm-builder",
"tiny-keccak",
"tokio",
"trie-db",
"xcm",
"xcm-builder",
@@ -12243,6 +12249,7 @@ dependencies = [
"polkadot-primitives",
"polkadot-runtime-common",
"polkadot-runtime-parachains",
"remote-externalities",
"rustc-hex",
"scale-info",
"serde",
@@ -12264,11 +12271,13 @@ dependencies = [
"sp-session",
"sp-staking",
"sp-std",
"sp-tracing",
"sp-transaction-pool",
"sp-trie",
"sp-version",
"substrate-wasm-builder",
"tiny-keccak",
"tokio",
"westend-runtime-constants",
"xcm",
"xcm-builder",
+3
View File
@@ -104,6 +104,9 @@ keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substra
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" }
separator = "0.4.1"
serde_json = "1.0.81"
remote-externalities = { git = "https://github.com/paritytech/substrate", branch = "master" }
tokio = { version = "1.18.2", features = ["macros"] }
sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
[build-dependencies]
substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "master" }
+35
View File
@@ -2308,3 +2308,38 @@ mod multiplier_tests {
}
}
}
#[cfg(all(test, feature = "try-runtime"))]
mod remote_tests {
use super::*;
use frame_try_runtime::runtime_decl_for_TryRuntime::TryRuntime;
use remote_externalities::{
Builder, Mode, OfflineConfig, OnlineConfig, SnapshotConfig, Transport,
};
use std::env::var;
#[tokio::test]
async fn run_migrations() {
sp_tracing::try_init_simple();
let transport: Transport =
var("WS").unwrap_or("wss://kusama-rpc.polkadot.io:443".to_string()).into();
let maybe_state_snapshot: Option<SnapshotConfig> = var("SNAP").map(|s| s.into()).ok();
let mut ext = Builder::<Block>::default()
.mode(if let Some(state_snapshot) = maybe_state_snapshot {
Mode::OfflineOrElseOnline(
OfflineConfig { state_snapshot: state_snapshot.clone() },
OnlineConfig {
transport,
state_snapshot: Some(state_snapshot),
..Default::default()
},
)
} else {
Mode::Online(OnlineConfig { transport, ..Default::default() })
})
.build()
.await
.unwrap();
ext.execute_with(|| Runtime::on_runtime_upgrade());
}
}
+3
View File
@@ -97,6 +97,9 @@ sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" }
trie-db = "0.23.1"
serde_json = "1.0.81"
separator = "0.4.1"
remote-externalities = { git = "https://github.com/paritytech/substrate", branch = "master" }
tokio = { version = "1.18.2", features = ["macros"] }
sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
[build-dependencies]
substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "master" }
+35
View File
@@ -2305,3 +2305,38 @@ mod multiplier_tests {
}
}
}
#[cfg(all(test, feature = "try-runtime"))]
mod remote_tests {
use super::*;
use frame_try_runtime::runtime_decl_for_TryRuntime::TryRuntime;
use remote_externalities::{
Builder, Mode, OfflineConfig, OnlineConfig, SnapshotConfig, Transport,
};
use std::env::var;
#[tokio::test]
async fn run_migrations() {
sp_tracing::try_init_simple();
let transport: Transport =
var("WS").unwrap_or("wss://rpc.polkadot.io:443".to_string()).into();
let maybe_state_snapshot: Option<SnapshotConfig> = var("SNAP").map(|s| s.into()).ok();
let mut ext = Builder::<Block>::default()
.mode(if let Some(state_snapshot) = maybe_state_snapshot {
Mode::OfflineOrElseOnline(
OfflineConfig { state_snapshot: state_snapshot.clone() },
OnlineConfig {
transport,
state_snapshot: Some(state_snapshot),
..Default::default()
},
)
} else {
Mode::Online(OnlineConfig { transport, ..Default::default() })
})
.build()
.await
.unwrap();
ext.execute_with(|| Runtime::on_runtime_upgrade());
}
}
+3
View File
@@ -99,6 +99,9 @@ tiny-keccak = { version = "2.0.2", features = ["keccak"] }
keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" }
serde_json = "1.0.81"
remote-externalities = { git = "https://github.com/paritytech/substrate", branch = "master" }
tokio = { version = "1.18.2", features = ["macros"] }
sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
[build-dependencies]
substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "master" }
+35
View File
@@ -1748,3 +1748,38 @@ sp_api::impl_runtime_apis! {
}
}
}
#[cfg(all(test, feature = "try-runtime"))]
mod remote_tests {
use super::*;
use frame_try_runtime::runtime_decl_for_TryRuntime::TryRuntime;
use remote_externalities::{
Builder, Mode, OfflineConfig, OnlineConfig, SnapshotConfig, Transport,
};
use std::env::var;
#[tokio::test]
async fn run_migrations() {
sp_tracing::try_init_simple();
let transport: Transport =
var("WS").unwrap_or("wss://westend-rpc.polkadot.io:443".to_string()).into();
let maybe_state_snapshot: Option<SnapshotConfig> = var("SNAP").map(|s| s.into()).ok();
let mut ext = Builder::<Block>::default()
.mode(if let Some(state_snapshot) = maybe_state_snapshot {
Mode::OfflineOrElseOnline(
OfflineConfig { state_snapshot: state_snapshot.clone() },
OnlineConfig {
transport,
state_snapshot: Some(state_snapshot),
..Default::default()
},
)
} else {
Mode::Online(OnlineConfig { transport, ..Default::default() })
})
.build()
.await
.unwrap();
ext.execute_with(|| Runtime::on_runtime_upgrade());
}
}