Rework the runtime upgrade test (#727)

* Rework the runtime upgrade test

* Update test/service/tests/runtime_upgrade.rs

* Update test/service/tests/runtime_upgrade.rs

* Update Cargo.lock

* FMT

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Bastian Köcher
2021-11-09 15:02:34 +01:00
committed by GitHub
parent c63c5229ba
commit ae12a80b35
10 changed files with 2610 additions and 1399 deletions
+3 -7
View File
@@ -27,6 +27,7 @@ sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch
sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "master" }
@@ -59,10 +60,5 @@ futures = "0.3.5"
polkadot-test-service = { git = "https://github.com/paritytech/polkadot", branch = "master" }
# Substrate dependencies
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master" }
substrate-test-utils = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-maybe-compressed-blob = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-version = { git = "https://github.com/paritytech/substrate", branch = "master" }
# Cumulus
cumulus-test-runtime-upgrade = { path = "../runtime-upgrade" }
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.12" }
substrate-test-utils = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.12" }
+19 -2
View File
@@ -25,7 +25,24 @@ use sp_core::{sr25519, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};
/// Specialized `ChainSpec` for the normal parachain runtime.
pub type ChainSpec = sc_service::GenericChainSpec<cumulus_test_runtime::GenesisConfig, Extensions>;
pub type ChainSpec = sc_service::GenericChainSpec<GenesisExt, Extensions>;
/// Extension for the genesis config to add custom keys easily.
#[derive(serde::Serialize, serde::Deserialize)]
pub struct GenesisExt {
/// The runtime genesis config.
runtime_genesis_config: cumulus_test_runtime::GenesisConfig,
}
impl sp_runtime::BuildStorage for GenesisExt {
fn assimilate_storage(&self, storage: &mut sp_core::storage::Storage) -> Result<(), String> {
sp_state_machine::BasicExternalities::execute_with_storage(storage, || {
sp_io::storage::set(cumulus_test_runtime::TEST_RUNTIME_UPGRADE_KEY, &vec![1, 2, 3, 4]);
});
self.runtime_genesis_config.assimilate_storage(storage)
}
}
/// Helper function to generate a crypto pair from seed
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
@@ -65,7 +82,7 @@ pub fn get_chain_spec(id: ParaId) -> ChainSpec {
"Local Testnet",
"local_testnet",
ChainType::Local,
move || local_testnet_genesis(),
move || GenesisExt { runtime_genesis_config: local_testnet_genesis() },
vec![],
None,
None,
@@ -73,17 +73,11 @@ async fn test_runtime_upgrade() {
.expect("Runtime version exists");
expected_runtime_version.spec_version += 1;
// Replace the runtime version in the WASM blob to make it look like a new runtime.
let wasm = sp_maybe_compressed_blob::decompress(
cumulus_test_runtime_upgrade::WASM_BINARY.unwrap(),
sp_maybe_compressed_blob::CODE_BLOB_BOMB_LIMIT,
)
.expect("Decompressing the WASM blob works");
let wasm = sp_version::embed::embed_runtime_version(&wasm, expected_runtime_version.clone())
.expect("Embedding the runtime version works");
let wasm = cumulus_test_runtime::wasm_spec_version_incremented::WASM_BINARY
.expect("Wasm binary with incremented spec version should have been built");
// schedule runtime upgrade
charlie.schedule_upgrade(wasm).await.unwrap();
charlie.schedule_upgrade(wasm.into()).await.unwrap();
let mut import_stream = dave.client.import_notification_stream();