From 88929021c92db5b849b5bd828e142d0078dd773c Mon Sep 17 00:00:00 2001 From: Chralt98 Date: Wed, 14 Aug 2024 12:35:28 +0200 Subject: [PATCH] update migration and it tests --- Makefile | 2 +- integration-tests/moonwall.config.json | 4 ++-- zrml/market-commons/src/lib.rs | 2 +- zrml/market-commons/src/migrations.rs | 23 ++++++++++++++++++++++- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index c4b4241c1..d6887defc 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ try-runtime-upgrade-battery-station: --execute-try-runtime try-runtime-upgrade-zeitgeist: - @$(MAKE) TRYRUNTIME_URL="wss://zeitgeist-rpc.dwellir.com:443" \ + @$(MAKE) TRYRUNTIME_URL="wss://zeitgeist.api.onfinality.io:443/public-ws" \ RUNTIME_PATH="./target/release/wbuild/zeitgeist-runtime/zeitgeist_runtime.compact.compressed.wasm" \ -- \ --execute-try-runtime diff --git a/integration-tests/moonwall.config.json b/integration-tests/moonwall.config.json index 18cec7399..55da73649 100644 --- a/integration-tests/moonwall.config.json +++ b/integration-tests/moonwall.config.json @@ -61,7 +61,7 @@ } ] }, - "envVars": ["LOG_LEVEL=debug", "VERBOSE_LOG"], + "envVars": ["LOG_LEVEL=debug", "VERBOSE_LOG=true"], "buildBlockMode": "manual", "connections": [ { @@ -106,7 +106,7 @@ } ] }, - "envVars": ["LOG_LEVEL=debug", "VERBOSE_LOG"], + "envVars": ["LOG_LEVEL=debug", "VERBOSE_LOG=true"], "buildBlockMode": "manual", "connections": [ { diff --git a/zrml/market-commons/src/lib.rs b/zrml/market-commons/src/lib.rs index cce65a670..8a3deb0f9 100644 --- a/zrml/market-commons/src/lib.rs +++ b/zrml/market-commons/src/lib.rs @@ -57,7 +57,7 @@ mod pallet { }; /// The current storage version. - const STORAGE_VERSION: StorageVersion = StorageVersion::new(11); + const STORAGE_VERSION: StorageVersion = StorageVersion::new(12); pub(crate) type AccountIdOf = ::AccountId; pub(crate) type AssetOf = Asset>; diff --git a/zrml/market-commons/src/migrations.rs b/zrml/market-commons/src/migrations.rs index adf04862f..d21f20c54 100644 --- a/zrml/market-commons/src/migrations.rs +++ b/zrml/market-commons/src/migrations.rs @@ -26,7 +26,7 @@ use frame_support::{ use frame_system::pallet_prelude::BlockNumberFor; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; -use sp_runtime::{Perbill, RuntimeDebug, Saturating}; +use sp_runtime::{Perbill, RuntimeDebug, SaturatedConversion, Saturating}; use zeitgeist_primitives::types::{ Asset, Deadlines, EarlyClose, Market, MarketBonds, MarketCreation, MarketDisputeMechanism, MarketPeriod, MarketStatus, MarketType, OutcomeReport, Report, ScoringRule, @@ -98,6 +98,8 @@ pub enum OldMarketDisputeMechanism { const MARKET_COMMONS_REQUIRED_STORAGE_VERSION: u16 = 11; const MARKET_COMMONS_NEXT_STORAGE_VERSION: u16 = 12; +const CORRUPTED_MARKET_IDS_BATTERY_STATION: [u32; 5] = [879u32, 877u32, 878u32, 880u32, 882u32]; + #[cfg(feature = "try-runtime")] #[frame_support::storage_alias] pub(crate) type Markets = @@ -125,6 +127,18 @@ where } log::info!("MigrateDisputeMechanism: Starting..."); + // 879, 877, 878, 880, 882 markets on Battery Station + // each have a campaign asset as the base asset, which is invalid + for market_id in CORRUPTED_MARKET_IDS_BATTERY_STATION { + let market_id = market_id.saturated_into::>(); + if crate::Markets::::contains_key(market_id) + // this produces a decoding error for the corrupted markets + && crate::Markets::::try_get(market_id).is_err() + { + crate::Markets::::remove(market_id); + } + } + let mut translated = 0u64; crate::Markets::::translate::, _>(|_, old_market| { translated.saturating_inc(); @@ -213,6 +227,13 @@ where assert_eq!(old_market.bonds, new_market.bonds); assert_eq!(old_market.early_close, new_market.early_close); } + + for market_id in CORRUPTED_MARKET_IDS_BATTERY_STATION { + let market_id = market_id.saturated_into::>(); + assert!(!crate::Markets::::contains_key(market_id)); + assert!(crate::Markets::::try_get(market_id).is_err()); + } + log::info!("MigrateDisputeMechanism: Post-upgrade market count is {}!", new_market_count); Ok(()) }