Browse Source

integration-tests: factor out QueryNodeApi

Mokhtar Naamani 4 years ago
parent
commit
26ec6705f2

+ 1 - 0
tests/network-tests/run-storage-node-tests.sh

@@ -37,6 +37,7 @@ docker-compose up -d processor
 yarn workspace @joystream/cd-schemas initialize:dev
 
 # Fixes Error: No active storage providers available
+echo "Waiting for ipfs name registration"
 sleep 3m
 
 echo "Creating channel..."

+ 9 - 130
tests/network-tests/src/Api.ts

@@ -34,7 +34,6 @@ import { ChannelEntity } from '@joystream/cd-schemas/types/entities/ChannelEntit
 import { VideoEntity } from '@joystream/cd-schemas/types/entities/VideoEntity'
 import { initializeContentDir, InputParser } from '@joystream/cd-schemas'
 import { OperationType } from '@joystream/types/content-directory'
-import { gql, ApolloClient, ApolloQueryResult, NormalizedCacheObject } from '@apollo/client'
 import { ContentId, DataObject } from '@joystream/types/media'
 
 import Debugger from 'debug'
@@ -1700,16 +1699,16 @@ export class Api {
     return this.api.createType('u32', this.api.consts[module].maxWorkerNumberLimit)
   }
 
-  async sendContentDirectoryTransaction(operations: OperationType[]): Promise<void> {
+  async sendContentDirectoryTransaction(operations: OperationType[]): Promise<ISubmittableResult> {
     const transaction = this.api.tx.contentDirectory.transaction(
       { Lead: null }, // We use member with id 0 as actor (in this case we assume this is Alice)
       operations // We provide parsed operations as second argument
     )
     const lead = (await this.getGroupLead(WorkingGroups.ContentDirectoryWorkingGroup)) as Worker
-    await this.sender.signAndSend(transaction, lead.role_account_id)
+    return this.sender.signAndSend(transaction, lead.role_account_id)
   }
 
-  public async createChannelEntity(channel: ChannelEntity): Promise<void> {
+  public async createChannelEntity(channel: ChannelEntity): Promise<ISubmittableResult> {
     // Create the parser with known entity schemas (the ones in content-directory-schemas/inputs)
     const parser = InputParser.createWithKnownSchemas(
       this.api,
@@ -1723,10 +1722,10 @@ export class Api {
     )
     // We parse the input into CreateEntity and AddSchemaSupportToEntity operations
     const operations = await parser.getEntityBatchOperations()
-    return await this.sendContentDirectoryTransaction(operations)
+    return this.sendContentDirectoryTransaction(operations)
   }
 
-  public async createVideoEntity(video: VideoEntity): Promise<void> {
+  public async createVideoEntity(video: VideoEntity): Promise<ISubmittableResult> {
     // Create the parser with known entity schemas (the ones in content-directory-schemas/inputs)
     const parser = InputParser.createWithKnownSchemas(
       this.api,
@@ -1740,13 +1739,13 @@ export class Api {
     )
     // We parse the input into CreateEntity and AddSchemaSupportToEntity operations
     const operations = await parser.getEntityBatchOperations()
-    return await this.sendContentDirectoryTransaction(operations)
+    return this.sendContentDirectoryTransaction(operations)
   }
 
   public async updateChannelEntity(
     channelUpdateInput: Record<string, any>,
     uniquePropValue: Record<string, any>
-  ): Promise<void> {
+  ): Promise<ISubmittableResult> {
     // Create the parser with known entity schemas (the ones in content-directory-schemas/inputs)
     const parser = InputParser.createWithKnownSchemas(this.api)
 
@@ -1758,7 +1757,7 @@ export class Api {
       'Channel', // Class name
       CHANNEL_ID // Id of the entity we want to update
     )
-    return await this.sendContentDirectoryTransaction(updateOperations)
+    return this.sendContentDirectoryTransaction(updateOperations)
   }
 
   async getDataObjectByContentId(contentId: ContentId): Promise<DataObject | null> {
@@ -1767,126 +1766,6 @@ export class Api {
   }
 
   public async initializeContentDirectory(leadKeyPair: KeyringPair): Promise<void> {
-    await initializeContentDir(this.api, leadKeyPair)
-  }
-}
-
-export class QueryNodeApi extends Api {
-  private readonly queryNodeProvider: ApolloClient<NormalizedCacheObject>
-
-  public static async new(
-    provider: WsProvider,
-    queryNodeProvider: ApolloClient<NormalizedCacheObject>,
-    treasuryAccountUri: string,
-    sudoAccountUri: string
-  ): Promise<QueryNodeApi> {
-    let connectAttempts = 0
-    while (true) {
-      connectAttempts++
-      debug(`Connecting to chain, attempt ${connectAttempts}..`)
-      try {
-        const api = await ApiPromise.create({ provider, types })
-
-        // Wait for api to be connected and ready
-        await api.isReady
-
-        // If a node was just started up it might take a few seconds to start producing blocks
-        // Give it a few seconds to be ready.
-        await Utils.wait(5000)
-
-        return new QueryNodeApi(api, queryNodeProvider, treasuryAccountUri, sudoAccountUri)
-      } catch (err) {
-        if (connectAttempts === 3) {
-          throw new Error('Unable to connect to chain')
-        }
-      }
-      await Utils.wait(5000)
-    }
-  }
-
-  constructor(
-    api: ApiPromise,
-    queryNodeProvider: ApolloClient<NormalizedCacheObject>,
-    treasuryAccountUri: string,
-    sudoAccountUri: string
-  ) {
-    super(api, treasuryAccountUri, sudoAccountUri)
-    this.queryNodeProvider = queryNodeProvider
-  }
-
-  public async getChannelbyHandle(handle: string): Promise<ApolloQueryResult<any>> {
-    const GET_CHANNEL_BY_TITLE = gql`
-      query($handle: String!) {
-        channels(where: { handle_eq: $handle }) {
-          handle
-          description
-          coverPhotoUrl
-          avatarPhotoUrl
-          isPublic
-          isCurated
-          videos {
-            title
-            description
-            duration
-            thumbnailUrl
-            isExplicit
-            isPublic
-          }
-        }
-      }
-    `
-
-    return await this.queryNodeProvider.query({ query: GET_CHANNEL_BY_TITLE, variables: { handle } })
-  }
-
-  public async performFullTextSearchOnChannelTitle(text: string): Promise<ApolloQueryResult<any>> {
-    const FULL_TEXT_SEARCH_ON_CHANNEL_TITLE = gql`
-      query($text: String!) {
-        search(text: $text) {
-          item {
-            ... on Channel {
-              handle
-              description
-            }
-          }
-        }
-      }
-    `
-
-    return await this.queryNodeProvider.query({ query: FULL_TEXT_SEARCH_ON_CHANNEL_TITLE, variables: { text } })
-  }
-
-  public async performFullTextSearchOnVideoTitle(text: string): Promise<ApolloQueryResult<any>> {
-    const FULL_TEXT_SEARCH_ON_VIDEO_TITLE = gql`
-      query($text: String!) {
-        search(text: $text) {
-          item {
-            ... on Video {
-              title
-            }
-          }
-        }
-      }
-    `
-
-    return await this.queryNodeProvider.query({ query: FULL_TEXT_SEARCH_ON_VIDEO_TITLE, variables: { text } })
-  }
-
-  public async performWhereQueryByVideoTitle(title: string): Promise<ApolloQueryResult<any>> {
-    const WHERE_QUERY_ON_VIDEO_TITLE = gql`
-      query($title: String!) {
-        videos(where: { title_eq: $title }) {
-          media {
-            location {
-              __typename
-              ... on JoystreamMediaLocation {
-                dataObjectId
-              }
-            }
-          }
-        }
-      }
-    `
-    return await this.queryNodeProvider.query({ query: WHERE_QUERY_ON_VIDEO_TITLE, variables: { title } })
+    return initializeContentDir(this.api, leadKeyPair)
   }
 }

+ 1 - 1
tests/network-tests/src/Fixture.ts

@@ -8,7 +8,7 @@ export interface Fixture {
   // executionError(): Error | undefined
 }
 
-export class BaseFixture implements Fixture {
+export class BaseFixture {
   protected api: Api
   private executed = false
   // The reason of the "Unexpected" failure of running the fixture

+ 85 - 0
tests/network-tests/src/QueryNodeApi.ts

@@ -0,0 +1,85 @@
+import { gql, ApolloClient, ApolloQueryResult, NormalizedCacheObject } from '@apollo/client'
+
+export class QueryNodeApi {
+  private readonly queryNodeProvider: ApolloClient<NormalizedCacheObject>
+
+  constructor(queryNodeProvider: ApolloClient<NormalizedCacheObject>) {
+    this.queryNodeProvider = queryNodeProvider
+  }
+
+  public async getChannelbyHandle(handle: string): Promise<ApolloQueryResult<any>> {
+    const GET_CHANNEL_BY_TITLE = gql`
+      query($handle: String!) {
+        channels(where: { handle_eq: $handle }) {
+          handle
+          description
+          coverPhotoUrl
+          avatarPhotoUrl
+          isPublic
+          isCurated
+          videos {
+            title
+            description
+            duration
+            thumbnailUrl
+            isExplicit
+            isPublic
+          }
+        }
+      }
+    `
+
+    return await this.queryNodeProvider.query({ query: GET_CHANNEL_BY_TITLE, variables: { handle } })
+  }
+
+  public async performFullTextSearchOnChannelTitle(text: string): Promise<ApolloQueryResult<any>> {
+    const FULL_TEXT_SEARCH_ON_CHANNEL_TITLE = gql`
+      query($text: String!) {
+        search(text: $text) {
+          item {
+            ... on Channel {
+              handle
+              description
+            }
+          }
+        }
+      }
+    `
+
+    return await this.queryNodeProvider.query({ query: FULL_TEXT_SEARCH_ON_CHANNEL_TITLE, variables: { text } })
+  }
+
+  public async performFullTextSearchOnVideoTitle(text: string): Promise<ApolloQueryResult<any>> {
+    const FULL_TEXT_SEARCH_ON_VIDEO_TITLE = gql`
+      query($text: String!) {
+        search(text: $text) {
+          item {
+            ... on Video {
+              title
+            }
+          }
+        }
+      }
+    `
+
+    return await this.queryNodeProvider.query({ query: FULL_TEXT_SEARCH_ON_VIDEO_TITLE, variables: { text } })
+  }
+
+  public async performWhereQueryByVideoTitle(title: string): Promise<ApolloQueryResult<any>> {
+    const WHERE_QUERY_ON_VIDEO_TITLE = gql`
+      query($title: String!) {
+        videos(where: { title_eq: $title }) {
+          media {
+            location {
+              __typename
+              ... on JoystreamMediaLocation {
+                dataObjectId
+              }
+            }
+          }
+        }
+      }
+    `
+    return await this.queryNodeProvider.query({ query: WHERE_QUERY_ON_VIDEO_TITLE, variables: { title } })
+  }
+}

+ 20 - 17
tests/network-tests/src/fixtures/contentDirectoryModule.ts

@@ -1,48 +1,51 @@
-import { QueryNodeApi } from '../Api'
-import { Fixture } from '../Fixture'
+import { Api } from '../Api'
+import { BaseFixture } from '../Fixture'
 import { ChannelEntity } from '@joystream/cd-schemas/types/entities/ChannelEntity'
 import { VideoEntity } from '@joystream/cd-schemas/types/entities/VideoEntity'
 
-export class CreateChannelFixture implements Fixture {
-  private api: QueryNodeApi
+export class CreateChannelFixture extends BaseFixture {
   public channelEntity: ChannelEntity
 
-  public constructor(api: QueryNodeApi, channelEntity: ChannelEntity) {
-    this.api = api
+  public constructor(api: Api, channelEntity: ChannelEntity) {
+    super(api)
     this.channelEntity = channelEntity
   }
 
   public async runner(): Promise<void> {
-    await this.api.createChannelEntity(this.channelEntity)
+    await this.expectDispatchSuccess(
+      this.api.createChannelEntity(this.channelEntity),
+      'Create Channel should have succeeded'
+    )
   }
 }
 
-export class CreateVideoFixture implements Fixture {
-  private api: QueryNodeApi
+export class CreateVideoFixture extends BaseFixture {
   public videoEntity: VideoEntity
 
-  public constructor(api: QueryNodeApi, videoEntity: VideoEntity) {
-    this.api = api
+  public constructor(api: Api, videoEntity: VideoEntity) {
+    super(api)
     this.videoEntity = videoEntity
   }
 
   public async runner(): Promise<void> {
-    await this.api.createVideoEntity(this.videoEntity)
+    await this.expectDispatchSuccess(this.api.createVideoEntity(this.videoEntity), 'Create Video should have succeeded')
   }
 }
 
-export class UpdateChannelFixture implements Fixture {
-  private api: QueryNodeApi
+export class UpdateChannelFixture extends BaseFixture {
   private channelUpdateInput: Record<string, any>
   private uniquePropValue: Record<string, any>
 
-  public constructor(api: QueryNodeApi, channelUpdateInput: Record<string, any>, uniquePropValue: Record<string, any>) {
-    this.api = api
+  public constructor(api: Api, channelUpdateInput: Record<string, any>, uniquePropValue: Record<string, any>) {
+    super(api)
     this.channelUpdateInput = channelUpdateInput
     this.uniquePropValue = uniquePropValue
   }
 
   public async runner(): Promise<void> {
-    await this.api.updateChannelEntity(this.channelUpdateInput, this.uniquePropValue)
+    await this.expectDispatchSuccess(
+      this.api.updateChannelEntity(this.channelUpdateInput, this.uniquePropValue),
+      'Update Channel should have succeeded'
+    )
   }
 }

+ 5 - 4
tests/network-tests/src/flows/contentDirectory/creatingChannel.ts

@@ -1,10 +1,11 @@
-import { QueryNodeApi } from '../../Api'
+import { Api } from '../../Api'
+import { QueryNodeApi } from '../../QueryNodeApi'
 import { Utils } from '../../utils'
 import { CreateChannelFixture } from '../../fixtures/contentDirectoryModule'
 import { ChannelEntity } from '@joystream/cd-schemas/types/entities/ChannelEntity'
 import { assert } from 'chai'
 
-export function createSimpleChannelFixture(api: QueryNodeApi): CreateChannelFixture {
+export function createSimpleChannelFixture(api: Api): CreateChannelFixture {
   const channelEntity: ChannelEntity = {
     handle: 'New channel example',
     description: 'This is an example channel',
@@ -27,7 +28,7 @@ function assertChannelMatchQueriedResult(queriedChannel: any, channel: ChannelEn
   assert.equal(queriedChannel.isPublic, channel.isPublic, 'Should be equal')
 }
 
-export default async function channelCreation(api: QueryNodeApi) {
+export default async function channelCreation(api: Api, query: QueryNodeApi) {
   const createChannelHappyCaseFixture = createSimpleChannelFixture(api)
 
   await createChannelHappyCaseFixture.runner()
@@ -36,7 +37,7 @@ export default async function channelCreation(api: QueryNodeApi) {
   await Utils.wait(120000)
 
   // Ensure newly created channel was parsed by query node
-  const result = await api.getChannelbyHandle(createChannelHappyCaseFixture.channelEntity.handle)
+  const result = await query.getChannelbyHandle(createChannelHappyCaseFixture.channelEntity.handle)
 
   assertChannelMatchQueriedResult(result.data.channels[0], createChannelHappyCaseFixture.channelEntity)
 }

+ 13 - 12
tests/network-tests/src/flows/contentDirectory/creatingVideo.ts

@@ -1,10 +1,11 @@
-import { QueryNodeApi } from '../../Api'
+import { Api } from '../../Api'
+import { QueryNodeApi } from '../../QueryNodeApi'
 import { CreateVideoFixture } from '../../fixtures/contentDirectoryModule'
 import { VideoEntity } from '@joystream/cd-schemas/types/entities/VideoEntity'
 import { assert } from 'chai'
 import { Utils } from '../../utils'
 
-export function createVideoReferencingChannelFixture(api: QueryNodeApi, handle: string): CreateVideoFixture {
+export function createVideoReferencingChannelFixture(api: Api, handle: string): CreateVideoFixture {
   const videoEntity: VideoEntity = {
     title: 'Example video',
     description: 'This is an example video',
@@ -52,7 +53,7 @@ function assertVideoMatchQueriedResult(queriedVideo: any, video: VideoEntity) {
   assert.equal(queriedVideo.isPublic, video.isPublic, 'Should be equal')
 }
 
-export default async function createVideo(api: QueryNodeApi) {
+export default async function createVideo(api: Api, query: QueryNodeApi) {
   const channelTitle = 'New channel example'
   const createVideoHappyCaseFixture = createVideoReferencingChannelFixture(api, channelTitle)
 
@@ -62,46 +63,46 @@ export default async function createVideo(api: QueryNodeApi) {
   await Utils.wait(120000)
 
   // Perform number of full text searches on Channel title, that is a slight variation on title that one expects would return the video.
-  let channelFullTextSearchResult = await api.performFullTextSearchOnChannelTitle('video')
+  let channelFullTextSearchResult = await query.performFullTextSearchOnChannelTitle('video')
 
   assert(channelFullTextSearchResult.data.search.length === 1, 'Should contain exactly one entry')
 
   // Both channel and video title starts with `Example`
-  channelFullTextSearchResult = await api.performFullTextSearchOnChannelTitle('Example')
+  channelFullTextSearchResult = await query.performFullTextSearchOnChannelTitle('Example')
 
   assert(channelFullTextSearchResult.data.search.length === 2, 'Should contain two entries')
 
   // Perform number full text searches on Channel title, that absolutely should NOT return the video.
-  channelFullTextSearchResult = await api.performFullTextSearchOnChannelTitle('First')
+  channelFullTextSearchResult = await query.performFullTextSearchOnChannelTitle('First')
 
   assert(channelFullTextSearchResult.data.search.length === 0, 'Should be empty')
 
-  channelFullTextSearchResult = await api.performFullTextSearchOnChannelTitle('vid')
+  channelFullTextSearchResult = await query.performFullTextSearchOnChannelTitle('vid')
 
   assert(channelFullTextSearchResult.data.search.length === 0, 'Should be empty')
 
   // Ensure channel contains only one video with right data
-  const channelResult = await api.getChannelbyHandle(channelTitle)
+  const channelResult = await query.getChannelbyHandle(channelTitle)
 
   assert(channelResult.data.channels[0].videos.length === 1, 'Given channel should contain exactly one video')
 
   assertVideoMatchQueriedResult(channelResult.data.channels[0].videos[0], createVideoHappyCaseFixture.videoEntity)
 
   // Perform number of full text searches on Video title, that is a slight variation on title that one expects would return the video.
-  let videoFullTextSearchResult = await api.performFullTextSearchOnVideoTitle('Example')
+  let videoFullTextSearchResult = await query.performFullTextSearchOnVideoTitle('Example')
 
   assert(videoFullTextSearchResult.data.search.length === 2, 'Should contain two entries')
 
-  videoFullTextSearchResult = await api.performFullTextSearchOnVideoTitle('Example video')
+  videoFullTextSearchResult = await query.performFullTextSearchOnVideoTitle('Example video')
 
   assert(videoFullTextSearchResult.data.search.length === 1, 'Should contain exactly one video')
 
   // Perform number full text searches on Video title, that absolutely should NOT return the video.
-  videoFullTextSearchResult = await api.performFullTextSearchOnVideoTitle('unknown')
+  videoFullTextSearchResult = await query.performFullTextSearchOnVideoTitle('unknown')
 
   assert(videoFullTextSearchResult.data.search.length === 0, 'Should be empty')
 
-  videoFullTextSearchResult = await api.performFullTextSearchOnVideoTitle('MediaVideo')
+  videoFullTextSearchResult = await query.performFullTextSearchOnVideoTitle('MediaVideo')
 
   assert(videoFullTextSearchResult.data.search.length === 0, 'Should be empty')
 }

+ 6 - 9
tests/network-tests/src/flows/contentDirectory/updatingChannel.ts

@@ -1,14 +1,11 @@
-import { QueryNodeApi } from '../../Api'
+import { Api } from '../../Api'
+import { QueryNodeApi } from '../../QueryNodeApi'
 import { UpdateChannelFixture } from '../../fixtures/contentDirectoryModule'
 import { ChannelEntity } from '@joystream/cd-schemas/types/entities/ChannelEntity'
 import { assert } from 'chai'
 import { Utils } from '../../utils'
 
-export function createUpdateChannelHandleFixture(
-  api: QueryNodeApi,
-  handle: string,
-  description: string
-): UpdateChannelFixture {
+export function createUpdateChannelHandleFixture(api: Api, handle: string, description: string): UpdateChannelFixture {
   // Create partial channel entity, only containing the fields we wish to update
   const channelUpdateInput: Partial<ChannelEntity> = {
     description,
@@ -19,9 +16,9 @@ export function createUpdateChannelHandleFixture(
   return new UpdateChannelFixture(api, channelUpdateInput, uniquePropVal)
 }
 
-export default async function updateChannel(api: QueryNodeApi) {
+export default async function updateChannel(api: Api, query: QueryNodeApi) {
   const handle = 'New channel example'
-  const channelResult = await api.getChannelbyHandle(handle)
+  const channelResult = await query.getChannelbyHandle(handle)
   const channel = channelResult.data.channels[0]
 
   const description = 'Updated description'
@@ -32,7 +29,7 @@ export default async function updateChannel(api: QueryNodeApi) {
   // Temporary solution (wait 2 minutes)
   await Utils.wait(120000)
 
-  const channelAfterUpdateResult = await api.getChannelbyHandle(handle)
+  const channelAfterUpdateResult = await query.getChannelbyHandle(handle)
   const channelAfterUpdate = channelAfterUpdateResult.data.channels[0]
 
   // description field should be updated to provided one

+ 4 - 3
tests/network-tests/src/flows/storageNode/getContentFromStorageNode.ts

@@ -3,17 +3,18 @@ import { assert } from 'chai'
 import { ContentId } from '@joystream/types/media'
 import { registry } from '@joystream/types'
 
-import { QueryNodeApi } from '../../Api'
+import { Api } from '../../Api'
+import { QueryNodeApi } from '../../QueryNodeApi'
 import { Utils } from '../../utils'
 
-export default async function getContentFromStorageNode(api: QueryNodeApi): Promise<void> {
+export default async function getContentFromStorageNode(api: Api, query: QueryNodeApi): Promise<void> {
   const videoTitle = 'Storage node test'
 
   // Temporary solution (wait 2 minutes)
   await Utils.wait(120000)
 
   // Query video by title with where expression
-  const videoWhereQueryResult = await api.performWhereQueryByVideoTitle(videoTitle)
+  const videoWhereQueryResult = await query.performWhereQueryByVideoTitle(videoTitle)
 
   assert.equal(1, videoWhereQueryResult.data.videos.length, 'Should fetch only one video')
 

+ 8 - 10
tests/network-tests/src/scenarios/content-directory.ts

@@ -1,5 +1,6 @@
 import { WsProvider } from '@polkadot/api'
-import { Api, QueryNodeApi, WorkingGroups } from '../Api'
+import { Api, WorkingGroups } from '../Api'
+import { QueryNodeApi } from '../QueryNodeApi'
 import { config } from 'dotenv'
 import leaderSetup from '../flows/workingGroup/leaderSetup'
 import initializeContentDirectory from '../flows/contentDirectory/contentDirectoryInitialization'
@@ -17,6 +18,8 @@ const scenario = async () => {
   const nodeUrl: string = env.NODE_URL || 'ws://127.0.0.1:9944'
   const provider = new WsProvider(nodeUrl)
 
+  const api = await Api.create(provider, env.TREASURY_ACCOUNT_URI || '//Alice', env.SUDO_ACCOUNT_URI || '//Alice')
+
   const queryNodeUrl: string = env.QUERY_NODE_URL || 'http://127.0.0.1:8081/graphql'
 
   const queryNodeProvider = new ApolloClient({
@@ -25,12 +28,7 @@ const scenario = async () => {
     defaultOptions: { query: { fetchPolicy: 'no-cache', errorPolicy: 'all' } },
   })
 
-  const api: QueryNodeApi = await QueryNodeApi.new(
-    provider,
-    queryNodeProvider,
-    env.TREASURY_ACCOUNT_URI || '//Alice',
-    env.SUDO_ACCOUNT_URI || '//Alice'
-  )
+  const query = new QueryNodeApi(queryNodeProvider)
 
   const leadKeyPair = await leaderSetup(api, env, WorkingGroups.ContentDirectoryWorkingGroup)
 
@@ -39,11 +37,11 @@ const scenario = async () => {
 
   await initializeContentDirectory(api, leadKeyPair)
 
-  await createChannel(api)
+  await createChannel(api, query)
 
-  await createVideo(api)
+  await createVideo(api, query)
 
-  await updateChannel(api)
+  await updateChannel(api, query)
 
   // Note: disconnecting and then reconnecting to the chain in the same process
   // doesn't seem to work!

+ 13 - 9
tests/network-tests/src/scenarios/storage-node.ts

@@ -2,7 +2,8 @@ import { config } from 'dotenv'
 import { WsProvider } from '@polkadot/api'
 import { ApolloClient, InMemoryCache } from '@apollo/client'
 
-import { QueryNodeApi } from '../Api'
+import { Api } from '../Api'
+import { QueryNodeApi } from '../QueryNodeApi'
 import getContentFromStorageNode from '../flows/storageNode/getContentFromStorageNode'
 
 const scenario = async () => {
@@ -10,20 +11,23 @@ const scenario = async () => {
   config()
   const env = process.env
 
+  // Connect api to the chain
+  const nodeUrl: string = env.NODE_URL || 'ws://127.0.0.1:9944'
+  const provider = new WsProvider(nodeUrl)
+
+  const api = await Api.create(provider, env.TREASURY_ACCOUNT_URI || '//Alice', env.SUDO_ACCOUNT_URI || '//Alice')
+
+  const queryNodeUrl: string = env.QUERY_NODE_URL || 'http://127.0.0.1:8081/graphql'
+
   const queryNodeProvider = new ApolloClient({
-    uri: env.QUERY_NODE_URL,
+    uri: queryNodeUrl,
     cache: new InMemoryCache(),
     defaultOptions: { query: { fetchPolicy: 'no-cache', errorPolicy: 'all' } },
   })
 
-  const api: QueryNodeApi = await QueryNodeApi.new(
-    new WsProvider(env.NODE_URL),
-    queryNodeProvider,
-    env.TREASURY_ACCOUNT_URI || '//Alice',
-    env.SUDO_ACCOUNT_URI || '//Alice'
-  )
+  const query = new QueryNodeApi(queryNodeProvider)
 
-  await getContentFromStorageNode(api)
+  await getContentFromStorageNode(api, query)
 
   // Note: disconnecting and then reconnecting to the chain in the same process
   // doesn't seem to work!