Browse Source

Content-directory & query node integration: Do not pass lead KeyringPair throughout the api calls, retrieve lead accountId from chain instead

iorveth 4 years ago
parent
commit
defd9c5f50

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

@@ -1926,16 +1926,16 @@ export class Api {
     return this.api.createType('u32', this.api.consts[module].maxWorkerNumberLimit)
   }
 
-  async sendContentDirectoryTransaction(operations: OperationType[], pair: KeyringPair): Promise<void> {
+  async sendContentDirectoryTransaction(operations: OperationType[]): Promise<void> {
     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
     )
-
-    await this.sender.signAndSend(transaction, pair.address, false)
+    const lead = (await this.getGroupLead(WorkingGroups.ContentDirectoryWorkingGroup)) as Worker
+    await this.sender.signAndSend(transaction, lead.role_account_id, false)
   }
 
-  public async createChannelEntity(channel: ChannelEntity, pair: KeyringPair): Promise<void> {
+  public async createChannelEntity(channel: ChannelEntity): Promise<void> {
     // Create the parser with known entity schemas (the ones in content-directory-schemas/inputs)
     const parser = InputParser.createWithKnownSchemas(
       this.api,
@@ -1949,10 +1949,10 @@ export class Api {
     )
     // We parse the input into CreateEntity and AddSchemaSupportToEntity operations
     const operations = await parser.getEntityBatchOperations()
-    return await this.sendContentDirectoryTransaction(operations, pair)
+    return await this.sendContentDirectoryTransaction(operations)
   }
 
-  public async createVideoEntity(video: VideoEntity, pair: KeyringPair): Promise<void> {
+  public async createVideoEntity(video: VideoEntity): Promise<void> {
     // Create the parser with known entity schemas (the ones in content-directory-schemas/inputs)
     const parser = InputParser.createWithKnownSchemas(
       this.api,
@@ -1966,13 +1966,12 @@ export class Api {
     )
     // We parse the input into CreateEntity and AddSchemaSupportToEntity operations
     const operations = await parser.getEntityBatchOperations()
-    return await this.sendContentDirectoryTransaction(operations, pair)
+    return await this.sendContentDirectoryTransaction(operations)
   }
 
   public async updateChannelEntity(
     channelUpdateInput: Record<string, any>,
-    uniquePropValue: Record<string, any>,
-    pair: KeyringPair
+    uniquePropValue: Record<string, any>
   ): Promise<void> {
     // Create the parser with known entity schemas (the ones in content-directory-schemas/inputs)
     const parser = InputParser.createWithKnownSchemas(this.api)
@@ -1985,7 +1984,7 @@ export class Api {
       'Channel', // Class name
       CHANNEL_ID // Id of the entity we want to update
     )
-    return await this.sendContentDirectoryTransaction(updateOperations, pair)
+    return await this.sendContentDirectoryTransaction(updateOperations)
   }
 
   public async initializeContentDirectory(leadKeyPair: KeyringPair) {

+ 6 - 18
tests/network-tests/src/fixtures/contentDirectoryModule.ts

@@ -7,21 +7,18 @@ import { Utils } from '../utils'
 import { Fixture } from '../Fixture'
 import { ChannelEntity } from 'cd-schemas/types/entities/ChannelEntity'
 import { VideoEntity } from 'cd-schemas/types/entities/VideoEntity'
-import { KeyringPair } from '@polkadot/keyring/types'
 
 export class CreateChannelFixture implements Fixture {
   private api: QueryNodeApi
   public channelEntity: ChannelEntity
-  private pair: KeyringPair
 
-  public constructor(api: QueryNodeApi, channelEntity: ChannelEntity, pair: KeyringPair) {
+  public constructor(api: QueryNodeApi, channelEntity: ChannelEntity) {
     this.api = api
-    this.pair = pair
     this.channelEntity = channelEntity
   }
 
   public async runner(expectFailure: boolean): Promise<void> {
-    await this.api.createChannelEntity(this.channelEntity, this.pair)
+    await this.api.createChannelEntity(this.channelEntity)
 
     if (expectFailure) {
       throw new Error('Successful fixture run while expecting failure')
@@ -31,17 +28,15 @@ export class CreateChannelFixture implements Fixture {
 
 export class CreateVideoFixture implements Fixture {
   private api: QueryNodeApi
-  private pair: KeyringPair
   private videoEntity: VideoEntity
 
-  public constructor(api: QueryNodeApi, videoEntity: VideoEntity, pair: KeyringPair) {
+  public constructor(api: QueryNodeApi, videoEntity: VideoEntity) {
     this.api = api
     this.videoEntity = videoEntity
-    this.pair = pair
   }
 
   public async runner(expectFailure: boolean): Promise<void> {
-    await this.api.createVideoEntity(this.videoEntity, this.pair)
+    await this.api.createVideoEntity(this.videoEntity)
 
     if (expectFailure) {
       throw new Error('Successful fixture run while expecting failure')
@@ -51,24 +46,17 @@ export class CreateVideoFixture implements Fixture {
 
 export class UpdateChannelFixture implements Fixture {
   private api: QueryNodeApi
-  private pair: KeyringPair
   private channelUpdateInput: Record<string, any>
   private uniquePropValue: Record<string, any>
 
-  public constructor(
-    api: QueryNodeApi,
-    channelUpdateInput: Record<string, any>,
-    uniquePropValue: Record<string, any>,
-    pair: KeyringPair
-  ) {
+  public constructor(api: QueryNodeApi, channelUpdateInput: Record<string, any>, uniquePropValue: Record<string, any>) {
     this.api = api
     this.channelUpdateInput = channelUpdateInput
     this.uniquePropValue = uniquePropValue
-    this.pair = pair
   }
 
   public async runner(expectFailure: boolean): Promise<void> {
-    await this.api.updateChannelEntity(this.channelUpdateInput, this.uniquePropValue, this.pair)
+    await this.api.updateChannelEntity(this.channelUpdateInput, this.uniquePropValue)
 
     if (expectFailure) {
       throw new Error('Successful fixture run while expecting failure')

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

@@ -5,7 +5,7 @@ import { ChannelEntity } from 'cd-schemas/types/entities/ChannelEntity'
 import { assert } from 'chai'
 import { KeyringPair } from '@polkadot/keyring/types'
 
-export function createSimpleChannelFixture(api: QueryNodeApi, pair: KeyringPair): CreateChannelFixture {
+export function createSimpleChannelFixture(api: QueryNodeApi): CreateChannelFixture {
   const channelEntity: ChannelEntity = {
     title: 'Example channel',
     description: 'This is an example channel',
@@ -17,11 +17,11 @@ export function createSimpleChannelFixture(api: QueryNodeApi, pair: KeyringPair)
     avatarPhotoURL: '',
     isPublic: true,
   }
-  return new CreateChannelFixture(api, channelEntity, pair)
+  return new CreateChannelFixture(api, channelEntity)
 }
 
-export default async function channelCreation(api: QueryNodeApi, pair: KeyringPair) {
-  const createChannelHappyCaseFixture = createSimpleChannelFixture(api, pair)
+export default async function channelCreation(api: QueryNodeApi) {
+  const createChannelHappyCaseFixture = createSimpleChannelFixture(api)
 
   await createChannelHappyCaseFixture.runner(false)
 

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

@@ -2,9 +2,8 @@ import { QueryNodeApi, WorkingGroups } from '../../Api'
 import { CreateVideoFixture } from '../../fixtures/contentDirectoryModule'
 import { VideoEntity } from 'cd-schemas/types/entities/VideoEntity'
 import { assert } from 'chai'
-import { KeyringPair } from '@polkadot/keyring/types'
 
-export function createVideoReferencingChannelFixture(api: QueryNodeApi, pair: KeyringPair): CreateVideoFixture {
+export function createVideoReferencingChannelFixture(api: QueryNodeApi): CreateVideoFixture {
   const videoEntity: VideoEntity = {
     title: 'Example video',
     description: 'This is an example video',
@@ -40,11 +39,11 @@ export function createVideoReferencingChannelFixture(api: QueryNodeApi, pair: Ke
     isExplicit: false,
     isPublic: true,
   }
-  return new CreateVideoFixture(api, videoEntity, pair)
+  return new CreateVideoFixture(api, videoEntity)
 }
 
-export default async function createVideo(api: QueryNodeApi, pair: KeyringPair) {
-  const createVideoHappyCaseFixture = createVideoReferencingChannelFixture(api, pair)
+export default async function createVideo(api: QueryNodeApi) {
+  const createVideoHappyCaseFixture = createVideoReferencingChannelFixture(api)
 
   await createVideoHappyCaseFixture.runner(false)
 }

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

@@ -2,9 +2,8 @@ import { QueryNodeApi, WorkingGroups } from '../../Api'
 import { UpdateChannelFixture } from '../../fixtures/contentDirectoryModule'
 import { ChannelEntity } from 'cd-schemas/types/entities/ChannelEntity'
 import { assert } from 'chai'
-import { KeyringPair } from '@polkadot/keyring/types'
 
-export function createUpdateChannelTitleFixture(api: QueryNodeApi, pair: KeyringPair): UpdateChannelFixture {
+export function createUpdateChannelTitleFixture(api: QueryNodeApi): UpdateChannelFixture {
   // Create partial channel entity, only containing the fields we wish to update
   const channelUpdateInput: Partial<ChannelEntity> = {
     title: 'Updated channel title',
@@ -12,11 +11,11 @@ export function createUpdateChannelTitleFixture(api: QueryNodeApi, pair: Keyring
 
   const uniquePropVal: Record<string, any> = { title: 'Example channel' }
 
-  return new UpdateChannelFixture(api, channelUpdateInput, uniquePropVal, pair)
+  return new UpdateChannelFixture(api, channelUpdateInput, uniquePropVal)
 }
 
-export default async function updateChannel(api: QueryNodeApi, pair: KeyringPair) {
-  const createVideoHappyCaseFixture = createUpdateChannelTitleFixture(api, pair)
+export default async function updateChannel(api: QueryNodeApi) {
+  const createVideoHappyCaseFixture = createUpdateChannelTitleFixture(api)
 
   await createVideoHappyCaseFixture.runner(false)
 }

+ 3 - 3
tests/network-tests/src/scenarios/content-directory.ts

@@ -38,11 +38,11 @@ const scenario = async () => {
 
   await initializeContentDirectory(api, leadKeyPair)
 
-  await createChannel(api, leadKeyPair)
+  await createChannel(api)
 
-  await createVideo(api, leadKeyPair)
+  await createVideo(api)
 
-  await updateChannel(api, leadKeyPair)
+  await updateChannel(api)
 
   // Note: disconnecting and then reconnecting to the chain in the same process
   // doesn't seem to work!

+ 19 - 4
yarn.lock

@@ -1415,7 +1415,7 @@
     typeorm-model-generator "^0.4.2"
     warthog "https://github.com/metmirr/warthog/releases/download/v2.20.0/warthog-v2.20.0.tgz"
 
-"@dzlzv/hydra-indexer-lib@0.0.19-legacy.1.26.1", "@dzlzv/hydra-indexer-lib@^0.0.19-legacy.1.26.1":
+"@dzlzv/hydra-indexer-lib@^0.0.19-legacy.1.26.1":
   version "0.0.19-legacy.1.26.1"
   resolved "https://registry.yarnpkg.com/@dzlzv/hydra-indexer-lib/-/hydra-indexer-lib-0.0.19-legacy.1.26.1.tgz#346b564845b2014f7a4d9b3976c03e30da8dd309"
   integrity sha512-4pwaSDRIo/1MqxjfSotjv91fkIj/bfZcZx5nqjB9gRT85X28b3WqkqTFrzlGsGGbvUFWAx4WIeQKnY1yrpX89Q==
@@ -3400,7 +3400,7 @@
     is-ipfs "^0.6.0"
     recursive-fs "^1.1.2"
 
-"@polkadot/api-contract@1.26.1", "@polkadot/api-contract@^1.26.1":
+"@polkadot/api-contract@^1.26.1":
   version "1.26.1"
   resolved "https://registry.yarnpkg.com/@polkadot/api-contract/-/api-contract-1.26.1.tgz#a8b52ef469ab8bbddb83191f8d451e31ffd76142"
   integrity sha512-zLGA/MHUJf12vanUEUBBRqpHVAONHWztoHS0JTIWUUS2+3GEXk6hGw+7PPtBDfDsLj0LgU/Qna1bLalC/zyl5w==
@@ -7879,11 +7879,21 @@ bluebird@^3.1.1, bluebird@^3.3.5, bluebird@^3.5.1, bluebird@^3.5.3, bluebird@^3.
   resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
   integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==
 
-bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.11.8, bn.js@^4.4.0, bn.js@^5.1.1, bn.js@^5.1.2, bn.js@^5.1.3:
+bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.11.8, bn.js@^4.4.0:
+  version "4.11.9"
+  resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.9.tgz#26d556829458f9d1e81fc48952493d0ba3507828"
+  integrity sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw==
+
+bn.js@^5.1.1, bn.js@^5.1.2:
   version "5.1.2"
   resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.1.2.tgz#c9686902d3c9a27729f43ab10f9d79c2004da7b0"
   integrity sha512-40rZaf3bUNKTVYu9sIeeEGOg7g14Yvnj9kH7b50EiwX0Q7A6umbvfI5tvHaOERH0XigqKkfLkFQxzb4e6CIXnA==
 
+bn.js@^5.1.3:
+  version "5.1.3"
+  resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.1.3.tgz#beca005408f642ebebea80b042b4d18d2ac0ee6b"
+  integrity sha512-GkTiFpjFtUzU9CbMeJ5iazkCzGL3jrhzerzZIuqLABjbwRaFt33I9tUdSNryIptM+RxDet6OKm2WnLXzW51KsQ==
+
 body-parser@1.19.0, body-parser@^1.18.3, body-parser@^1.19.0:
   version "1.19.0"
   resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.19.0.tgz#96b2709e57c9c4e09a6fd66a8fd979844f69f08a"
@@ -28153,7 +28163,12 @@ typescript-formatter@^7.2.2:
     commandpost "^1.0.0"
     editorconfig "^0.15.0"
 
-typescript@3.5.2, typescript@^3.0.3, typescript@^3.7.2, typescript@^3.7.5, typescript@^3.8.3, typescript@^3.9.5, typescript@^3.9.6, typescript@^3.9.7:
+typescript@3.5.2:
+  version "3.5.2"
+  resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.2.tgz#a09e1dc69bc9551cadf17dba10ee42cf55e5d56c"
+  integrity sha512-7KxJovlYhTX5RaRbUdkAXN1KUZ8PwWlTzQdHV6xNqvuFOs7+WBo10TQUqT19Q/Jz2hk5v9TQDIhyLhhJY4p5AA==
+
+typescript@^3.0.3, typescript@^3.7.2, typescript@^3.7.5, typescript@^3.8.3, typescript@^3.9.5, typescript@^3.9.6, typescript@^3.9.7:
   version "3.9.7"
   resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa"
   integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==