Browse Source

Merge pull request #1 from mnaamani/migration_improve_tests_and_types

Improve tests and types
Ignazio Bovo 3 years ago
parent
commit
e0bf07cc87

+ 16 - 14
runtime-modules/content/src/tests/migration.rs

@@ -172,36 +172,38 @@ fn setup_scenario_with(n_videos: u64, n_channels: u64) -> (u64, u64) {
 #[test]
 fn migration_test() {
     with_default_mock_builder(|| {
-        run_to_block(1);
+        const START_MIGRATION_AT_BLOCK: u64 = 1;
+        run_to_block(START_MIGRATION_AT_BLOCK);
 
         // setup scenario
         let (blocks_channels, blocks_videos) = setup_scenario_with(100u64, 100u64);
 
+        // block at which all migrations should be completed
+        let last_migration_block = std::cmp::max(blocks_channels, blocks_videos);
+
+        // ensure we have setup scenario to properly test migration over multiple blocks
+        assert!(last_migration_block > START_MIGRATION_AT_BLOCK);
+
         // triggering migration
         Content::on_runtime_upgrade();
 
-        // only 20 videos & 10 channels migrated so far
-        run_to_block(blocks_videos);
+        // migration should have started
         assert!(!Content::is_migration_done());
 
-        // migration not done yet : test all relevant extrinsics
+        // migration is not complete all extrinsics should fail
         assert_video_and_channel_existrinsics_with(Err(Error::<Test>::MigrationNotFinished.into()));
 
-        // video migration is finished but channel migration isn't
-        run_to_block(1 + blocks_videos);
+        // make progress with migration but should not be complete yet
+        run_to_block(last_migration_block);
         assert!(!Content::is_migration_done());
-
-        // migration not done yet: test all relevant extrinsics
         assert_video_and_channel_existrinsics_with(Err(Error::<Test>::MigrationNotFinished.into()));
 
-        // assert that video map is cleared
-        assert_eq!(VideoById::<Test>::iter().count(), 0);
-
-        // channel & video migration finished 10 blocks later
-        run_to_block(1 + blocks_channels);
+        // run migration to expected completion block
+        run_to_block(last_migration_block + 1);
 
-        // assert that channel map is cleared & migration is done
+        // assert that maps are cleared & migration is done
         assert!(Content::is_migration_done());
+        assert_eq!(VideoById::<Test>::iter().count(), 0);
         assert_eq!(ChannelById::<Test>::iter().count(), 0);
 
         // video and channel extr. now succeed

+ 0 - 1
runtime/src/lib.rs

@@ -431,7 +431,6 @@ parameter_types! {
     pub const ChannelOwnershipPaymentEscrowId: [u8; 8] = *b"chescrow";
     pub const VideosMigrationsEachBlock: u64 = 20;
     pub const ChannelsMigrationsEachBlock: u64 = 10;
-
 }
 
 impl content::Trait for Runtime {

+ 8 - 0
types/augment/all/defs.json

@@ -903,5 +903,13 @@
     },
     "MaxNumber": "u32",
     "IsCensored": "bool",
+    "VideoMigrationConfig": {
+        "current_id": "VideoId",
+        "final_id": "VideoId"
+    },
+    "ChannelMigrationConfig": {
+        "current_id": "ChannelId",
+        "final_id": "ChannelId"
+    },
     "AccountInfo": "AccountInfoWithRefCount"
 }

+ 12 - 0
types/augment/all/types.ts

@@ -245,6 +245,12 @@ export interface ChannelCurationStatus extends Null {}
 /** @name ChannelId */
 export interface ChannelId extends u64 {}
 
+/** @name ChannelMigrationConfig */
+export interface ChannelMigrationConfig extends Struct {
+  readonly current_id: ChannelId;
+  readonly final_id: ChannelId;
+}
+
 /** @name ChannelOwner */
 export interface ChannelOwner extends Enum {
   readonly isMember: boolean;
@@ -1381,6 +1387,12 @@ export interface VideoCreationParameters extends Struct {
 /** @name VideoId */
 export interface VideoId extends u64 {}
 
+/** @name VideoMigrationConfig */
+export interface VideoMigrationConfig extends Struct {
+  readonly current_id: VideoId;
+  readonly final_id: VideoId;
+}
+
 /** @name VideoUpdateParameters */
 export interface VideoUpdateParameters extends Struct {
   readonly assets_to_upload: Option<StorageAssets>;

+ 7 - 4
types/src/content/index.ts

@@ -170,13 +170,14 @@ export class PersonActor extends JoyEnum({
 }) {}
 
 export class VideoMigrationConfig extends JoyStructDecorated({
-    current_id: VideoId,
-    final_id: VideoId,    
+  current_id: VideoId,
+  final_id: VideoId,
 }) {}
 export class ChannelMigrationConfig extends JoyStructDecorated({
-    current_id: ChannelId,
-    final_id: ChannelId,    
+  current_id: ChannelId,
+  final_id: ChannelId,
 }) {}
+
 export const contentTypes = {
   CuratorId,
   CuratorGroupId,
@@ -219,6 +220,8 @@ export const contentTypes = {
   EpisodeParemters,
   MaxNumber,
   IsCensored,
+  VideoMigrationConfig,
+  ChannelMigrationConfig,
 }
 
 export default contentTypes