Skip to content

Commit

Permalink
Merge pull request #1 from mnaamani/migration_improve_tests_and_types
Browse files Browse the repository at this point in the history
Improve tests and types
  • Loading branch information
ignazio-bovo authored Nov 3, 2021
2 parents 80dfbe9 + 88627a7 commit e0bf07c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 19 deletions.
30 changes: 16 additions & 14 deletions runtime-modules/content/src/tests/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions types/augment/all/defs.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 12 additions & 0 deletions types/augment/all/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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>;
Expand Down
11 changes: 7 additions & 4 deletions types/src/content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -219,6 +220,8 @@ export const contentTypes = {
EpisodeParemters,
MaxNumber,
IsCensored,
VideoMigrationConfig,
ChannelMigrationConfig,
}

export default contentTypes

0 comments on commit e0bf07c

Please sign in to comment.