Browse Source

added post migration assertions

ignazio 3 years ago
parent
commit
3a0e0c93c2

+ 8 - 9
tests/network-tests/run-migration-tests.sh

@@ -15,9 +15,9 @@ PRE_MIGRATION_CLI_SETUP=${PRE_MIGRATION_CLI_SETUP:=$true}
 # If state modification by means of typescript scenarios are required before migration
 PRE_MIGRATION_ASYNC_SETUP=${PRE_MIGRATION_ASYNC_SETUP:=$false}
 # Post migration assertions by means of joystream-cli required
-POST_MIGRATION_CLI_ASSERTIONS=${POST_MIGRATION_CLI_ASSERTIONS=$true}
+POST_MIGRATION_CLI_ASSERTIONS=${POST_MIGRATION_CLI_ASSERTIONS=$false}
 # Post migration assertions by means of typescript scenarios required
-POST_MIGRATION_ASYNC_ASSERTIONS=${POST_MIGRATION_ASYNC_ASSERTIONS=$false}
+POST_MIGRATION_ASYNC_ASSERTIONS=${POST_MIGRATION_ASYNC_ASSERTIONS=$true}
 
 export WS_RPC_ENDPOINT="wss://testnet-rpc-3-uk.joystream.org"
     
@@ -271,8 +271,6 @@ function post_migration_cli() {
 
 # entrypoint
 function main {
-    # Section A: pre migration
-
     CONTAINER_ID=""
 
     echo "**** CREATING EMPTY CHAINSPEC ****"
@@ -282,13 +280,12 @@ function main {
     echo "**** EMPTY CHAINSPEC CREATED SUCCESSFULLY ****"
 
     # use forkoff to update chainspec with the live state + update runtime code
-    # fork_off_init
+    #fork_off_init
 
     echo "***** STARTING NODE WITH FORKED STATE *****"
     JOYSTREAM_NODE_TAG=$TARGET_RUNTIME_TAG
     CONTAINER_ID=$(start_node)
 
-    # Section C: assertions
     # verify that the number of outstanding channels & videos == 0
     if ( $POST_MIGRATION_CLI_ASSERTIONS ); then
 	# verify assertion using cli
@@ -296,9 +293,11 @@ function main {
 	post_migration_cli
     fi
     
-    # if [[ $POST_MIGRATION_ASYNC_ASSERTION]]; then
-    # 	# verify assertion using scenarios
-    # fi
+    if ( $POST_MIGRATION_ASYNC_ASSERTIONS ); then
+	# verify assertion using typsecript	
+	echo "***** POST MIGRATION TYPESCRIPT *****"	
+	yarn workspace network-tests node-ts-strict src/scenarios/post-migration.ts
+    fi
 }
 
 # main entrypoint

+ 15 - 2
tests/network-tests/src/Api.ts

@@ -32,7 +32,7 @@ import { FillOpeningParameters, ProposalId } from '@joystream/types/proposals'
 // import { v4 as uuid } from 'uuid'
 import { extendDebug } from './Debugger'
 import { InvertedPromise } from './InvertedPromise'
-import { VideoId } from '@joystream/types/content'
+import { VideoId, VideoCategoryId, } from '@joystream/types/content'
 import { ChannelId } from '@joystream/types/common'
 import { ChannelCategoryMetadata, VideoCategoryMetadata } from '@joystream/metadata-protobuf'
 import { metadataToBytes } from '../../../cli/lib/helpers/serialization'
@@ -1713,7 +1713,7 @@ export class Api {
     return this.api.query[module].applicationById<Application>(id)
   }
 
-  public async getApplicantRoleAccounts(filterActiveIds: ApplicationId[], module: WorkingGroups): Promise<string[]> {
+  public async getApplicantRoleAccnounts(filterActiveIds: ApplicationId[], module: WorkingGroups): Promise<string[]> {
     const entries: [StorageKey, Application][] = await this.api.query[module].applicationById.entries<Application>()
 
     const applications = entries
@@ -1789,6 +1789,19 @@ export class Api {
   async getMemberControllerAccount(memberId: number): Promise<string | undefined> {
     return (await this.api.query.members.membershipById(memberId))?.controller_account.toString()
   }
+    
+  public async getNumberOfOutstandingVideos(): Promise<number> {
+      return (await this.api.query.content.videoById.entries<VideoId>()).length
+  }
+
+  public async getNumberOfOutstandingChannels(): Promise<number> {
+      return (await this.api.query.content.channelById.entries<ChannelId>()).length
+  }
+
+  public async getNumberOfOutstandingVideoCategories(): Promise<number> {
+      return (await this.api.query.content.videoCategoryById.entries<VideoCategoryId>()).length
+  }
+    
 
   // Create a mock channel, throws on failure
   async createMockChannel(memberId: number, memberControllerAccount?: string): Promise<ChannelId> {

+ 10 - 4
tests/network-tests/src/misc/postMigrationAssertionsFlow.ts

@@ -1,9 +1,8 @@
 import { assert } from 'chai'
 import { FlowProps } from '../Flow'
-import { FixtureRunner } from '../Fixture'
 import { extendDebug } from '../Debugger'
 
-export default async function mockContent({ api }: FlowProps): Promise<void> {
+export default async function postMigrationAssertions({ api }: FlowProps): Promise<void> {
     const debug = extendDebug('flow:postMigrationAssertions')
     debug('Started')
 
@@ -11,16 +10,23 @@ export default async function mockContent({ api }: FlowProps): Promise<void> {
     debug('Checking that Video, Channel, Categories  counters have not been re-set')
 
     const nextVideoCategoryId = await api.query.content.nextVideoCategoryId()
-    const nextChannelCategoryId = await api.query.content.nextVideoCategoryId()
     const nextVideoId = await api.query.content.nextVideoId()
     const nextChannelId = await api.query.content.nextChannelId()
 
+    const num_channels = await api.getNumberOfOutstandingChannels()
+    const num_videos = await api.getNumberOfOutstandingVideos()
+    const num_categories = await api.getNumberOfOutstandingVideoCategories()
 
     assert(nextVideoCategoryId.toNumber() > 1);
-    assert(nextChannelCategoryId.toNumber() > 1);
     assert(nextVideoId.toNumber() > 1);
     assert(nextChannelId.toNumber() > 1);
 
+    // asserting the number of outstanding channel & videos is 0
+    debug('Checking that number of outstanding channels & videos == 0');
+
+    assert(num_channels === 0);
+    assert(num_videos === 0);
+    assert(num_categories === 0);
 
     debug('Done')
 }

+ 9 - 0
tests/network-tests/src/scenarios/post-migration.ts

@@ -0,0 +1,9 @@
+import postMigrationAssertions from '../misc/postMigrationAssertionsFlow'
+import { scenario } from '../Scenario'
+
+scenario(async ({ job }) => {
+    job(
+        'Verify post-migration chain state',
+        postMigrationAssertions
+    )
+})