Browse Source

storage-node-cli: update to use discovery client and fix minor bug in command line args

Mokhtar Naamani 4 years ago
parent
commit
7fb3cd51a0

+ 5 - 3
.github/workflows/run-network-tests.yml

@@ -158,6 +158,8 @@ jobs:
         run: docker-compose --file docker-compose-with-storage.yml up -d
       - name: Add development storage node and initialize content directory
         run: DEBUG=* yarn storage-cli dev-init
-      # - name: Execute tests
-      #   run: Upload/Download assets to/from storage node
-      #        Test querying discovery
+      - name: Wait for storage-node to publish identity
+        run: sleep 90
+        # Better would be poll `http://localhost:3001/discover/v0/1` until we get 200 Response
+      - name: Execute tests
+        run: DEBUG=joystream:* yarn storage-cli upload ./pioneer/packages/apps/public/images/default-thumbnail.png 1 0

+ 3 - 3
storage-node/packages/cli/src/cli.ts

@@ -77,11 +77,11 @@ const commands = {
     api: any,
     filePath: string,
     dataObjectTypeId: string,
+    memberId: string,
     keyFile: string,
-    passPhrase: string,
-    memberId: string
+    passPhrase: string
   ) => {
-    const uploadCmd = new UploadCommand(api, filePath, dataObjectTypeId, keyFile, passPhrase, memberId)
+    const uploadCmd = new UploadCommand(api, filePath, dataObjectTypeId, memberId, keyFile, passPhrase)
 
     await uploadCmd.run()
   },

+ 2 - 3
storage-node/packages/cli/src/commands/dev.ts

@@ -100,9 +100,8 @@ const init = async (api: RuntimeApi): Promise<any> => {
     debug('Alice is already a member.')
   }
 
-  debug('Setting Alice as content working group lead.')
-  await api.signAndSend(alice, api.api.tx.sudo.sudo(api.api.tx.contentWorkingGroup.replaceLead([aliceMemberId, alice])))
-
+  // debug('Setting Alice as content working group lead.')
+  // await api.signAndSend(alice, api.api.tx.sudo.sudo(api.api.tx.contentWorkingGroup.replaceLead([aliceMemberId, alice])))
   // Initialize classes and entities in the content-directory
   // TODO: when cli tools are ready re-use here
 

+ 4 - 2
storage-node/packages/cli/src/commands/upload.ts

@@ -5,7 +5,7 @@ import { ContentId, DataObject } from '@joystream/types/media'
 import BN from 'bn.js'
 import { Option } from '@polkadot/types/codec'
 import { BaseCommand } from './base'
-import { discover } from '@joystream/service-discovery/discover'
+import { DiscoveryClient } from '@joystream/service-discovery'
 import Debug from 'debug'
 import chalk from 'chalk'
 import { aliceKeyPair } from './dev'
@@ -32,6 +32,7 @@ export class UploadCommand extends BaseCommand {
   private readonly keyFile: string
   private readonly passPhrase: string
   private readonly memberId: string
+  private readonly discoveryClient: DiscoveryClient
 
   constructor(
     api: any,
@@ -44,6 +45,7 @@ export class UploadCommand extends BaseCommand {
     super()
 
     this.api = api
+    this.discoveryClient = new DiscoveryClient(undefined, api)
     this.mediaSourceFilePath = mediaSourceFilePath
     this.dataObjectTypeId = dataObjectTypeId
     this.memberId = memberId
@@ -153,7 +155,7 @@ export class UploadCommand extends BaseCommand {
   // Requests the runtime and obtains the storage node endpoint URL.
   private async discoverStorageProviderEndpoint(storageProviderId: string): Promise<string> {
     try {
-      const serviceInfo = await discover(storageProviderId, this.api)
+      const serviceInfo = await this.discoveryClient.discover(storageProviderId, this.api)
 
       if (serviceInfo === null) {
         this.fail('Storage node discovery failed.')