From 39a7f74808df19d5e72a5e087ba9b3a4815d5f25 Mon Sep 17 00:00:00 2001 From: Aitor <1726644+aaitor@users.noreply.github.com> Date: Mon, 28 Nov 2022 17:39:26 +0100 Subject: [PATCH 01/21] Definition of compute API --- package.json | 2 +- resources/commands.json | 113 +++++++++++++++++++++++++ src/commands/compute/execCompute.ts | 51 +++++++++++ src/commands/compute/logsJob.ts | 36 ++++++++ src/commands/compute/statusJob.ts | 36 ++++++++ src/commands/index.ts | 5 ++ test/integration-tests/Compute.test.ts | 87 +++++++++++++++++++ 7 files changed, 329 insertions(+), 1 deletion(-) create mode 100644 src/commands/compute/execCompute.ts create mode 100644 src/commands/compute/logsJob.ts create mode 100644 src/commands/compute/statusJob.ts create mode 100644 test/integration-tests/Compute.test.ts diff --git a/package.json b/package.json index 1b2a8de..c1ec885 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nevermined-io/cli", - "version": "0.8.0", + "version": "0.9.0-rc0", "main": "index.js", "repository": "git@github.com:nevermined-io/cli.git", "author": "Nevermined", diff --git a/resources/commands.json b/resources/commands.json index 6c29ef4..cf8d020 100644 --- a/resources/commands.json +++ b/resources/commands.json @@ -277,6 +277,44 @@ "description": "The type of the asset to register" } ] + }, { + "name": "register-workflow", + "description": "Register a new workflow", + "details": "This command registers a new workflow on the Nevermined network. The workflow allows to specify a an operation that needs to be executed. This typically involve the execution of an algorithm (referenced by a DID) and the input data that is given to that algorithm (referenced by DIDs too).", + "examples": ["ncli assets register-workflow --name 'Word count of English Enciclopedia' --input did:nv:abc --algorithm did:nv:012 "], + "commandHandler": "registerAsset", + "optionalArguments": [{ + "name": "name", + "type": "string", + "demandOption": true, + "description": "The asset name" + }, + { + "name": "author", + "type": "string", + "demandOption": false, + "description": "The author of the asset" + }, + { + "name": "input", + "type": "array", + "demandOption": true, + "description": "The DID of the input asset" + }, + { + "name": "algorithm", + "type": "string", + "demandOption": true, + "description": "The DID of the algorithm asset to process the input" + }, + { + "name": "assetType", + "type": "string", + "default": "workflow", + "hidden": true, + "description": "The type of the asset to register" + } + ] }, { "name": "import [metadata]", "description": "Import an asset using the metadata in JSON format", @@ -422,6 +460,81 @@ "description": "The asset DID" }] }] + }, { + "name": "compute", + "description": "Allows the execution of remote computation", + "usage": "usage: $0 compute parameters [options]", + "subcommands": [{ + "name": "order [did]", + "description": "Order a compute asset given a DID", + "details": "This method makes the payment and retrieve a serviceAgreementId that can be used later to execute a compute job", + "examples": ["ncli compute order did:nv:912e7a547bcd675ffbc5d2063ef770e15744029f048f706f6bb0281df4f4700f"], + "commandHandler": "orderAsset", + "positionalArguments": [{ + "name": "did", + "type": "string", + "description": "The asset DID" + }], + "optionalArguments": [{ + "name": "orderType", + "type": "string", + "default": "compute", + "hidden": true, + "description": "The type of asset to order" + }] + }, { + "name": "execute [did]", + "description": "Order & download or download directly a previously purchased asset", + "details": "This commands is the best entry point to access the files attached to a Nevermined asset. Depending on the parameters provided, it allows to order and download the files of an asset, or if this was already purchased, provides the service agreement to download them.", + "examples": ["ncli assets get did:nv:912e7a547bcd675ffbc5d2063ef770e15744029f048f706f6bb0281df4f4700f --destination /tmp", "ncli assets get did:nv:912e7a547bcd675ffbc5d2063ef770e15744029f048f706f6bb0281df4f4700f --agreementId 0x412dceaa0c5506095daa6b221be93c680e8a49bfd5b63ce54522d85d2b0e1384 --destination /tmp"], + "commandHandler": "execCompute", + "positionalArguments": [{ + "name": "did", + "type": "string", + "description": "The asset DID" + }], + "optionalArguments": [{ + "name": "agreementId", + "type": "string", + "default": "", + "description": "Agreement Id of a previously purchased asset. If not given a new purchase will be executed" + } + ] + }, { + "name": "status [agreementId] [jobId]", + "description": "Shows the status about the execution of a job", + "details": "When a user triggers an execution Nevermined orchestrates the infrastructure allowing to put together the input data and the algorithm. This process can require some time and this command checks the status of that operation.", + "examples": ["ncli compute status 0xf29bebaeacf865b4f57373aeb84635cc68c7719761607aec2802f1ad87213777 abxckdsaofksdadsa"], + "commandHandler": "statusJob", + "positionalArguments": [{ + "name": "agreementId", + "type": "string", + "default": "", + "description": "Agreement Id of a previously purchased asset" + }, { + "name": "jobId", + "type": "string", + "description": "The id of the user execution" + }], + "optionalArguments": [] + }, { + "name": "logs [agreementId] [jobId]", + "description": "Shows the logs about the execution of a job", + "details": "When a user triggers an execution Nevermined orchestrates the infrastructure allowing to put together the input data and the algorithm. This command fetches the logs generated by the execution of the algorithm.", + "examples": ["ncli compute logs 0xf29bebaeacf865b4f57373aeb84635cc68c7719761607aec2802f1ad87213777 abxckdsaofksdadsa"], + "commandHandler": "logsJob", + "positionalArguments": [{ + "name": "agreementId", + "type": "string", + "default": "", + "description": "Agreement Id of a previously purchased asset" + }, { + "name": "jobId", + "type": "string", + "description": "The id of the user execution" + }], + "optionalArguments": [] + }] }, { "name": "agreements", "description": "Get information about the Service Execution Agreements", diff --git a/src/commands/compute/execCompute.ts b/src/commands/compute/execCompute.ts new file mode 100644 index 0000000..cf4996c --- /dev/null +++ b/src/commands/compute/execCompute.ts @@ -0,0 +1,51 @@ +import { Account, Nevermined } from '@nevermined-io/nevermined-sdk-js' +import { StatusCodes } from '../../utils' +import chalk from 'chalk' +import { Logger } from 'log4js' +import { ExecutionOutput } from '../../models/ExecutionOutput' +import { ConfigEntry } from '../../models/ConfigDefinition' + + +export const execCompute = async ( + nvm: Nevermined, + account: Account, + argv: any, + config: ConfigEntry, + logger: Logger +): Promise => { + const { did } = argv + + let agreementId + + + if (!argv.agreementId) { + logger.info(chalk.dim(`Ordering asset: ${did}`)) + agreementId = await nvm.assets.order(did, 'compute', account) + } else { + agreementId = argv.agreementId + } + + logger.info( + chalk.dim(`Executing asset: ${did} with agreement id: ${agreementId}`) + ) + + /////////////////////////////////////////////// + //////// TODO : /////////// + //////// INTEGRATE COMPUTE SDK HERE /////////// + /////////////////////////////////////////////// + + + + + + const jobId = 'hey sucker!' + + return { + status: StatusCodes.OK, + results: JSON.stringify({ + did, + agreementId, + jobId + }) + } +} diff --git a/src/commands/compute/logsJob.ts b/src/commands/compute/logsJob.ts new file mode 100644 index 0000000..6a68ead --- /dev/null +++ b/src/commands/compute/logsJob.ts @@ -0,0 +1,36 @@ +import { Account, Nevermined } from '@nevermined-io/nevermined-sdk-js' +import { StatusCodes } from '../../utils' +import chalk from 'chalk' +import { Logger } from 'log4js' +import { ExecutionOutput } from '../../models/ExecutionOutput' +import { ConfigEntry } from '../../models/ConfigDefinition' + +export const logsJob = async ( + nvm: Nevermined, + account: Account, + argv: any, + config: ConfigEntry, + logger: Logger +): Promise => { + const { agreementId, jobId } = argv + + logger.info( + chalk.dim(`Fetching logs of jobId: ${jobId} and agreement id: ${agreementId}`) + ) + + /////////////////////////////////////////////// + //////// TODO : /////////// + //////// INTEGRATE COMPUTE SDK HERE /////////// + /////////////////////////////////////////////// + + const computeLogs = {} + + return { + status: StatusCodes.OK, + results: JSON.stringify({ + agreementId, + jobId, + computeLogs + }) + } +} diff --git a/src/commands/compute/statusJob.ts b/src/commands/compute/statusJob.ts new file mode 100644 index 0000000..c602794 --- /dev/null +++ b/src/commands/compute/statusJob.ts @@ -0,0 +1,36 @@ +import { Account, Nevermined } from '@nevermined-io/nevermined-sdk-js' +import { StatusCodes } from '../../utils' +import chalk from 'chalk' +import { Logger } from 'log4js' +import { ExecutionOutput } from '../../models/ExecutionOutput' +import { ConfigEntry } from '../../models/ConfigDefinition' + +export const statusJob = async ( + nvm: Nevermined, + account: Account, + argv: any, + config: ConfigEntry, + logger: Logger +): Promise => { + const { agreementId, jobId } = argv + + logger.info( + chalk.dim(`Fetching status of jobId: ${jobId} and agreement id: ${agreementId}`) + ) + + /////////////////////////////////////////////// + //////// TODO : /////////// + //////// INTEGRATE COMPUTE SDK HERE /////////// + /////////////////////////////////////////////// + + const computeStatus = {} + + return { + status: StatusCodes.OK, + results: JSON.stringify({ + agreementId, + jobId, + computeStatus + }) + } +} diff --git a/src/commands/index.ts b/src/commands/index.ts index c368e10..75b676d 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -19,6 +19,11 @@ export * from './nfts/transferNft' export * from './nfts/downloadNft' export * from './nfts/accessNft' +// compute +export * from './compute/execCompute' +export * from './compute/statusJob' +export * from './compute/logsJob' + // accounts export * from './accounts/new' export * from './accounts/list' diff --git a/test/integration-tests/Compute.test.ts b/test/integration-tests/Compute.test.ts new file mode 100644 index 0000000..3f05b4c --- /dev/null +++ b/test/integration-tests/Compute.test.ts @@ -0,0 +1,87 @@ +import { execOpts, metadataConfig, baseCommands } from '../helpers/Config' +import { + parseDIDFromNewAsset +} from '../helpers/StdoutParser' +import execCommand from '../helpers/ExecCommand' + +describe('Compute e2e Testing', () => { + let did = '' + + beforeAll(async () => { + console.log(`NETWORK: ${execOpts.env.NETWORK}`) + try { + if ( + execOpts.env.NETWORK === 'spree' || + execOpts.env.NETWORK === 'geth-localnet' || + execOpts.env.NETWORK === 'polygon-localnet' + ) { + console.log( + `Funding accounts: ${execOpts.accounts[0]} + ${execOpts.accounts[1]}` + ) + + let fundCommand = `${baseCommands.accounts.fund} "${execOpts.accounts[0]}" --token both` + console.log(fundCommand) + console.log(execCommand(fundCommand, execOpts)) + fundCommand = `${baseCommands.accounts.fund} "${execOpts.accounts[1]}" --token both` + console.log(fundCommand) + console.log(execCommand(fundCommand, execOpts)) + } + } catch (error) { + console.warn(`Unable to fund accounts`) + } + const registerAssetCommand = `${baseCommands.assets.registerAsset} --accountIndex 0 --name "${metadataConfig.name}" --author "${metadataConfig.author}" --price "${metadataConfig.price}" --urls ${metadataConfig.url} --contentType ${metadataConfig.contentType}` + console.debug(`COMMAND: ${registerAssetCommand}`) + + const registerStdout = execCommand(registerAssetCommand, execOpts) + + console.log(`STDOUT: ${registerStdout}`) + did = parseDIDFromNewAsset(registerStdout) + console.log(`DID: ${did}`) + expect(did === '' ? false : did.startsWith('did:nv:')) + }) + + test('Registering a new dataset and resolve the DID', async () => { + const resolveDIDCommand = `${baseCommands.assets.resolveDID} ${did}` + const stdoutResolve = execCommand(resolveDIDCommand, execOpts) + + console.log(`Resolved: ${stdoutResolve}`) + expect(stdoutResolve.includes('DID found')) + expect(stdoutResolve.includes(did)) + }) + + test('Registering a new algorithm', async () => { + const registerAlgorithmCommand = `${baseCommands.assets.registerAlgorithm} --name "Test Algorithm" --author "${metadataConfig.author}" --price "0" --language "python" --entrypoint "python word_count.py" --container "python:3.8-alpine" --urls ${metadataConfig.url} --contentType ${metadataConfig.contentType}` + console.debug(`COMMAND: ${registerAlgorithmCommand}`) + + const stdout = execCommand(registerAlgorithmCommand, execOpts) + + console.log(`STDOUT: ${stdout}`) + const algoDid = parseDIDFromNewAsset(stdout) + console.log(`DID: ${algoDid}`) + expect(algoDid === null ? false : algoDid.startsWith('did:nv:')) + }) + + test('Registering a workflow associating the data and the algorithm', async () => { + console.error(`PENDING TO IMPLEMENT`) + }) + + test('Order a compute job', async () => { + console.error(`PENDING TO IMPLEMENT`) + + }) + + test('Executing a compute job', async () => { + console.error(`PENDING TO IMPLEMENT`) + + }) + + test('Fetching status of a compute job', async () => { + console.error(`PENDING TO IMPLEMENT`) + + }) + + test('Fetching logs of a compute job', async () => { + console.error(`PENDING TO IMPLEMENT`) + + }) +}) From 4fd2652235ccfa44706bd37d28f0713af59e213a Mon Sep 17 00:00:00 2001 From: josepablofm78 Date: Tue, 29 Nov 2022 14:09:45 +0100 Subject: [PATCH 02/21] implementing exec compute command --- package.json | 2 +- src/commands/compute/execCompute.ts | 35 ++++++++++++++--------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index c1ec885..4db9432 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "ncli": "./dist/src/index.js" }, "dependencies": { - "@nevermined-io/nevermined-sdk-js": "0.26.0", + "@nevermined-io/nevermined-sdk-js": "0.27.3", "@nevermined-io/nevermined-sdk-dtp": "0.2.2", "@truffle/hdwallet-provider": "^2.0.9", "chalk": "^4.1.2", diff --git a/src/commands/compute/execCompute.ts b/src/commands/compute/execCompute.ts index cf4996c..1c84d53 100644 --- a/src/commands/compute/execCompute.ts +++ b/src/commands/compute/execCompute.ts @@ -29,23 +29,22 @@ export const execCompute = async ( chalk.dim(`Executing asset: ${did} with agreement id: ${agreementId}`) ) - /////////////////////////////////////////////// - //////// TODO : /////////// - //////// INTEGRATE COMPUTE SDK HERE /////////// - /////////////////////////////////////////////// - - - - - - const jobId = 'hey sucker!' - - return { - status: StatusCodes.OK, - results: JSON.stringify({ - did, - agreementId, - jobId - }) + try { + const jobId = nvm.assets.execute(agreementId, did, account) + return { + status: StatusCodes.OK, + results: JSON.stringify({ + did, + agreementId, + jobId + }) + } + } catch (error) { + return { + status: StatusCodes.ERROR, + errorMessage: `Unable to execute the asset: ${ + (error as Error).message + }` + } } } From 350ec670798a52fa715d8ff0aea252f9254119f3 Mon Sep 17 00:00:00 2001 From: josepablofm78 Date: Tue, 29 Nov 2022 14:13:42 +0100 Subject: [PATCH 03/21] implementing compute logs command --- src/commands/compute/execCompute.ts | 2 +- src/commands/compute/logsJob.ts | 31 ++++++++++++++++------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/commands/compute/execCompute.ts b/src/commands/compute/execCompute.ts index 1c84d53..2c66c75 100644 --- a/src/commands/compute/execCompute.ts +++ b/src/commands/compute/execCompute.ts @@ -42,7 +42,7 @@ export const execCompute = async ( } catch (error) { return { status: StatusCodes.ERROR, - errorMessage: `Unable to execute the asset: ${ + errorMessage: `Unable to execute the asset ${did} with agreement id: ${agreementId}: ${ (error as Error).message }` } diff --git a/src/commands/compute/logsJob.ts b/src/commands/compute/logsJob.ts index 6a68ead..7973f54 100644 --- a/src/commands/compute/logsJob.ts +++ b/src/commands/compute/logsJob.ts @@ -18,19 +18,22 @@ export const logsJob = async ( chalk.dim(`Fetching logs of jobId: ${jobId} and agreement id: ${agreementId}`) ) - /////////////////////////////////////////////// - //////// TODO : /////////// - //////// INTEGRATE COMPUTE SDK HERE /////////// - /////////////////////////////////////////////// - - const computeLogs = {} - - return { - status: StatusCodes.OK, - results: JSON.stringify({ - agreementId, - jobId, - computeLogs - }) + try { + const computeLogs = nvm.assets.computeLogs(agreementId, jobId, account) + return { + status: StatusCodes.OK, + results: JSON.stringify({ + agreementId, + jobId, + computeLogs + }) + } + }catch (error) { + return { + status: StatusCodes.ERROR, + errorMessage: `Unable to fetch the logs of jobId: ${jobId} and agreement id: ${agreementId}: ${ + (error as Error).message + }` + } } } From 77f3686441868410e23568d3b6e1c5327e01c1a7 Mon Sep 17 00:00:00 2001 From: josepablofm78 Date: Tue, 29 Nov 2022 14:16:48 +0100 Subject: [PATCH 04/21] implementing compute status command --- src/commands/compute/statusJob.ts | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/commands/compute/statusJob.ts b/src/commands/compute/statusJob.ts index c602794..b83c387 100644 --- a/src/commands/compute/statusJob.ts +++ b/src/commands/compute/statusJob.ts @@ -18,19 +18,24 @@ export const statusJob = async ( chalk.dim(`Fetching status of jobId: ${jobId} and agreement id: ${agreementId}`) ) - /////////////////////////////////////////////// - //////// TODO : /////////// - //////// INTEGRATE COMPUTE SDK HERE /////////// - /////////////////////////////////////////////// + try{ - const computeStatus = {} + const computeStatus = nvm.assets.computeStatus(agreementId, jobId, account) - return { - status: StatusCodes.OK, - results: JSON.stringify({ - agreementId, - jobId, - computeStatus - }) + return { + status: StatusCodes.OK, + results: JSON.stringify({ + agreementId, + jobId, + computeStatus + }) + } + } catch (error) { + return { + status: StatusCodes.ERROR, + errorMessage: `Unable to fetch the status of jobId: ${jobId} and agreement id: ${agreementId}: ${ + (error as Error).message + }` + } } } From 7d2c6518712b9a9c68ad7b94cc91c61717afd214 Mon Sep 17 00:00:00 2001 From: josepablofm78 Date: Thu, 1 Dec 2022 13:42:19 +0100 Subject: [PATCH 05/21] dependencies to latest sdk and dtp versions --- package.json | 2 +- src/commands/compute/execCompute.ts | 2 +- src/commands/compute/logsJob.ts | 2 +- src/commands/compute/statusJob.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 4db9432..0fabcbc 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ }, "dependencies": { "@nevermined-io/nevermined-sdk-js": "0.27.3", - "@nevermined-io/nevermined-sdk-dtp": "0.2.2", + "@nevermined-io/nevermined-sdk-dtp": "0.2.4", "@truffle/hdwallet-provider": "^2.0.9", "chalk": "^4.1.2", "cross-fetch": "~3.1.5", diff --git a/src/commands/compute/execCompute.ts b/src/commands/compute/execCompute.ts index 2c66c75..3d6ac16 100644 --- a/src/commands/compute/execCompute.ts +++ b/src/commands/compute/execCompute.ts @@ -30,7 +30,7 @@ export const execCompute = async ( ) try { - const jobId = nvm.assets.execute(agreementId, did, account) + const jobId = await nvm.assets.execute(agreementId, did, account) return { status: StatusCodes.OK, results: JSON.stringify({ diff --git a/src/commands/compute/logsJob.ts b/src/commands/compute/logsJob.ts index 7973f54..59697d1 100644 --- a/src/commands/compute/logsJob.ts +++ b/src/commands/compute/logsJob.ts @@ -19,7 +19,7 @@ export const logsJob = async ( ) try { - const computeLogs = nvm.assets.computeLogs(agreementId, jobId, account) + const computeLogs = await nvm.assets.computeLogs(agreementId, jobId, account) return { status: StatusCodes.OK, results: JSON.stringify({ diff --git a/src/commands/compute/statusJob.ts b/src/commands/compute/statusJob.ts index b83c387..273ea63 100644 --- a/src/commands/compute/statusJob.ts +++ b/src/commands/compute/statusJob.ts @@ -20,7 +20,7 @@ export const statusJob = async ( try{ - const computeStatus = nvm.assets.computeStatus(agreementId, jobId, account) + const computeStatus = await nvm.assets.computeStatus(agreementId, jobId, account) return { status: StatusCodes.OK, From bd5a022910fe21351212d51e07b4e9ba077cca1f Mon Sep 17 00:00:00 2001 From: josepablofm78 Date: Thu, 1 Dec 2022 14:40:26 +0100 Subject: [PATCH 06/21] adding compute tests --- test/helpers/Config.ts | 6 ++++ test/integration-tests/Compute.test.ts | 43 ++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/test/helpers/Config.ts b/test/helpers/Config.ts index 34a93ed..a6a3c84 100644 --- a/test/helpers/Config.ts +++ b/test/helpers/Config.ts @@ -109,5 +109,11 @@ export const baseCommands = { decrypt: `${BASE_COMMAND} ${VERBOSE} utils decrypt `, publishMetadata: `${BASE_COMMAND} ${VERBOSE} utils publish-nft-metadata `, getMetadata: `${BASE_COMMAND} ${VERBOSE} utils get-nft-metadata ` + }, + compute: { + order: `${BASE_COMMAND} ${VERBOSE} compute order`, + execute: `${BASE_COMMAND} ${VERBOSE} compute execute`, + status: `${BASE_COMMAND} ${VERBOSE} compute status`, + logs: `${BASE_COMMAND} ${VERBOSE} compute logs` } } diff --git a/test/integration-tests/Compute.test.ts b/test/integration-tests/Compute.test.ts index 3f05b4c..189524b 100644 --- a/test/integration-tests/Compute.test.ts +++ b/test/integration-tests/Compute.test.ts @@ -1,11 +1,16 @@ import { execOpts, metadataConfig, baseCommands } from '../helpers/Config' import { - parseDIDFromNewAsset + parseDIDFromNewAsset, + parseServiceAgreementId } from '../helpers/StdoutParser' import execCommand from '../helpers/ExecCommand' describe('Compute e2e Testing', () => { let did = '' + let algoDid = '' + let workflowDid = '' + let agreementId: string | null= '' + let jobId = '' beforeAll(async () => { console.log(`NETWORK: ${execOpts.env.NETWORK}`) @@ -56,22 +61,48 @@ describe('Compute e2e Testing', () => { const stdout = execCommand(registerAlgorithmCommand, execOpts) console.log(`STDOUT: ${stdout}`) - const algoDid = parseDIDFromNewAsset(stdout) + algoDid = parseDIDFromNewAsset(stdout) console.log(`DID: ${algoDid}`) expect(algoDid === null ? false : algoDid.startsWith('did:nv:')) }) test('Registering a workflow associating the data and the algorithm', async () => { - console.error(`PENDING TO IMPLEMENT`) + + const registerWorkflowCommand = `${baseCommands.assets.registerWorkflow} --name "Test Worfklow" --author "${metadataConfig.author}" --input ${did} --algorithm ${algoDid}` + + const stdout = execCommand(registerWorkflowCommand, execOpts) + + console.log(`STDOUT: ${stdout}`) + workflowDid = parseDIDFromNewAsset(stdout) + console.log(`DID: ${workflowDid}`) + expect(workflowDid === null ? false : workflowDid.startsWith('did:nv:')) + }) test('Order a compute job', async () => { - console.error(`PENDING TO IMPLEMENT`) - + + const orderComputeCommand = `${baseCommands.compute.order} ${did}` + + const stdout = execCommand(orderComputeCommand, execOpts) + + console.log(`STDOUT: ${stdout}`) + agreementId = parseServiceAgreementId(stdout) + console.log(`Agreement Id: ${agreementId}`) + expect(agreementId === null ? false : agreementId.startsWith('0x')) + }) test('Executing a compute job', async () => { - console.error(`PENDING TO IMPLEMENT`) + + const execComputeCommand = `${baseCommands.compute.execute} ${did} --agremmentId ${agreementId}` + + const stdout = execCommand(execComputeCommand, execOpts) + + console.log(`STDOUT: ${stdout}`) + //jobId = parseServiceAgreementId(stdout) + console.log(`jobId: ${jobId}`) + expect(jobId !== null) + }) From 37d249eeb1259180b6549304b4f06702d34dd407 Mon Sep 17 00:00:00 2001 From: josepablofm78 Date: Fri, 2 Dec 2022 09:52:18 +0100 Subject: [PATCH 07/21] register workflow --- src/commands/assets/registerAsset.ts | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/commands/assets/registerAsset.ts b/src/commands/assets/registerAsset.ts index a7f9b81..ae67fe8 100644 --- a/src/commands/assets/registerAsset.ts +++ b/src/commands/assets/registerAsset.ts @@ -113,6 +113,43 @@ export const registerAsset = async ( } } } + + // TODO Add support for multiple stages/inputs when ComputePods does + if (assetType === 'workflow') { + const input = argv.input + const algorithm = argv.algorithm + ddoMetadata.main.workflow = { + coordinationType: 'argo', + stages: [ + { + index: 0, + // TODO - irrelevant. this info is included in algorithm ddo. update sdk-js to remove this from metadata + requirements: { + container: { + image: '', + tag: '', + checksum: + '' + } + }, + input: [ + { + index: 0, + id: input + } + ], + transformation: { + id: algorithm + }, + output: { + metadataUrl: `${config.nvm.marketplaceUri}/api/v1/metadata/assets/ddo/`, + accessProxyUrl: `${config.nvm.neverminedNodeUri}/api/v1/node/`, + metadata: {} as any + } + } + ] + } + } } else { ddoMetadata = JSON.parse(fs.readFileSync(metadata).toString()) } From 7dad24176c1d0b9f0a2cb7826cbba3a28db5ace6 Mon Sep 17 00:00:00 2001 From: josepablofm78 Date: Fri, 2 Dec 2022 09:52:46 +0100 Subject: [PATCH 08/21] adding console output with results --- src/commands/compute/execCompute.ts | 5 +++++ src/commands/compute/logsJob.ts | 5 +++++ src/commands/compute/statusJob.ts | 4 ++++ test/integration-tests/Compute.test.ts | 2 +- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/commands/compute/execCompute.ts b/src/commands/compute/execCompute.ts index 3d6ac16..76ec58a 100644 --- a/src/commands/compute/execCompute.ts +++ b/src/commands/compute/execCompute.ts @@ -31,6 +31,11 @@ export const execCompute = async ( try { const jobId = await nvm.assets.execute(agreementId, did, account) + + logger.info( + chalk.dim(`Created Job ${jobId}.`) + ) + return { status: StatusCodes.OK, results: JSON.stringify({ diff --git a/src/commands/compute/logsJob.ts b/src/commands/compute/logsJob.ts index 59697d1..5244142 100644 --- a/src/commands/compute/logsJob.ts +++ b/src/commands/compute/logsJob.ts @@ -20,6 +20,11 @@ export const logsJob = async ( try { const computeLogs = await nvm.assets.computeLogs(agreementId, jobId, account) + + logger.info( + chalk.dim(`Logs for ${jobId} fetched correctly`) + ) + return { status: StatusCodes.OK, results: JSON.stringify({ diff --git a/src/commands/compute/statusJob.ts b/src/commands/compute/statusJob.ts index 273ea63..9b670fe 100644 --- a/src/commands/compute/statusJob.ts +++ b/src/commands/compute/statusJob.ts @@ -22,6 +22,10 @@ export const statusJob = async ( const computeStatus = await nvm.assets.computeStatus(agreementId, jobId, account) + logger.info( + chalk.dim(`Status fetched: ${computeStatus}`) + ) + return { status: StatusCodes.OK, results: JSON.stringify({ diff --git a/test/integration-tests/Compute.test.ts b/test/integration-tests/Compute.test.ts index 189524b..b74da7d 100644 --- a/test/integration-tests/Compute.test.ts +++ b/test/integration-tests/Compute.test.ts @@ -94,7 +94,7 @@ describe('Compute e2e Testing', () => { test('Executing a compute job', async () => { - const execComputeCommand = `${baseCommands.compute.execute} ${did} --agremmentId ${agreementId}` + const execComputeCommand = `${baseCommands.compute.execute} ${workflowDid} --agremmentId ${agreementId}` const stdout = execCommand(execComputeCommand, execOpts) From affe092180403a53934f50ce871b8138e3097d83 Mon Sep 17 00:00:00 2001 From: josepablofm78 Date: Fri, 2 Dec 2022 10:27:21 +0100 Subject: [PATCH 09/21] no files for workflow asset --- src/commands/assets/registerAsset.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/commands/assets/registerAsset.ts b/src/commands/assets/registerAsset.ts index ae67fe8..4f56d99 100644 --- a/src/commands/assets/registerAsset.ts +++ b/src/commands/assets/registerAsset.ts @@ -68,14 +68,16 @@ export const registerAsset = async ( }) _fileIndex++ } - argv.urls.forEach((_url: string) => { - _files.push({ - index: _fileIndex, - url: _url, - contentType: argv.contentType + if (assetType!== 'workflow') { + argv.urls.forEach((_url: string) => { + _files.push({ + index: _fileIndex, + url: _url, + contentType: argv.contentType + }) + _fileIndex++ }) - _fileIndex++ - }) + } ddoMetadata = { main: { From 6a0017568094f77da28253ae53db0c718e8325ba Mon Sep 17 00:00:00 2001 From: josepablofm78 Date: Fri, 2 Dec 2022 11:12:44 +0100 Subject: [PATCH 10/21] support for registering compute ddos --- src/commands/assets/registerAsset.ts | 2 +- test/integration-tests/Compute.test.ts | 41 ++++++++++++++------------ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/commands/assets/registerAsset.ts b/src/commands/assets/registerAsset.ts index 4f56d99..1b789a9 100644 --- a/src/commands/assets/registerAsset.ts +++ b/src/commands/assets/registerAsset.ts @@ -174,7 +174,7 @@ export const registerAsset = async ( ddoMetadata, account, assetRewards, - ['access'], + assetType ==='compute'?['compute']:['access'], [], DEFAULT_ENCRYPTION_METHOD, // eslint-disable-next-line @typescript-eslint/no-non-null-assertion diff --git a/test/integration-tests/Compute.test.ts b/test/integration-tests/Compute.test.ts index b74da7d..28ca76a 100644 --- a/test/integration-tests/Compute.test.ts +++ b/test/integration-tests/Compute.test.ts @@ -34,7 +34,12 @@ describe('Compute e2e Testing', () => { } catch (error) { console.warn(`Unable to fund accounts`) } - const registerAssetCommand = `${baseCommands.assets.registerAsset} --accountIndex 0 --name "${metadataConfig.name}" --author "${metadataConfig.author}" --price "${metadataConfig.price}" --urls ${metadataConfig.url} --contentType ${metadataConfig.contentType}` + + }) + + test('Registering a new compute asset and resolve the DID', async () => { + + const registerAssetCommand = `${baseCommands.assets.registerAsset} --assetType compute --accountIndex 0 --name "${metadataConfig.name}" --author "${metadataConfig.author}" --price "${metadataConfig.price}" --urls ${metadataConfig.url} --contentType ${metadataConfig.contentType}` console.debug(`COMMAND: ${registerAssetCommand}`) const registerStdout = execCommand(registerAssetCommand, execOpts) @@ -43,9 +48,7 @@ describe('Compute e2e Testing', () => { did = parseDIDFromNewAsset(registerStdout) console.log(`DID: ${did}`) expect(did === '' ? false : did.startsWith('did:nv:')) - }) - test('Registering a new dataset and resolve the DID', async () => { const resolveDIDCommand = `${baseCommands.assets.resolveDID} ${did}` const stdoutResolve = execCommand(resolveDIDCommand, execOpts) @@ -54,6 +57,19 @@ describe('Compute e2e Testing', () => { expect(stdoutResolve.includes(did)) }) + test('Order a compute DDO', async () => { + + const orderComputeCommand = `${baseCommands.compute.order} ${did}` + + const stdout = execCommand(orderComputeCommand, execOpts) + + console.log(`STDOUT: ${stdout}`) + agreementId = parseServiceAgreementId(stdout) + console.log(`Agreement Id: ${agreementId}`) + expect(agreementId === null ? false : agreementId.startsWith('0x')) + + }) + test('Registering a new algorithm', async () => { const registerAlgorithmCommand = `${baseCommands.assets.registerAlgorithm} --name "Test Algorithm" --author "${metadataConfig.author}" --price "0" --language "python" --entrypoint "python word_count.py" --container "python:3.8-alpine" --urls ${metadataConfig.url} --contentType ${metadataConfig.contentType}` console.debug(`COMMAND: ${registerAlgorithmCommand}`) @@ -62,7 +78,7 @@ describe('Compute e2e Testing', () => { console.log(`STDOUT: ${stdout}`) algoDid = parseDIDFromNewAsset(stdout) - console.log(`DID: ${algoDid}`) + console.log(`ALGO DID: ${algoDid}`) expect(algoDid === null ? false : algoDid.startsWith('did:nv:')) }) @@ -74,24 +90,12 @@ describe('Compute e2e Testing', () => { console.log(`STDOUT: ${stdout}`) workflowDid = parseDIDFromNewAsset(stdout) - console.log(`DID: ${workflowDid}`) + console.log(`WORKFLOW DID: ${workflowDid}`) expect(workflowDid === null ? false : workflowDid.startsWith('did:nv:')) }) - test('Order a compute job', async () => { - - const orderComputeCommand = `${baseCommands.compute.order} ${did}` - - const stdout = execCommand(orderComputeCommand, execOpts) - - console.log(`STDOUT: ${stdout}`) - agreementId = parseServiceAgreementId(stdout) - console.log(`Agreement Id: ${agreementId}`) - expect(agreementId === null ? false : agreementId.startsWith('0x')) - - }) - + test('Executing a compute job', async () => { const execComputeCommand = `${baseCommands.compute.execute} ${workflowDid} --agremmentId ${agreementId}` @@ -102,7 +106,6 @@ describe('Compute e2e Testing', () => { //jobId = parseServiceAgreementId(stdout) console.log(`jobId: ${jobId}`) expect(jobId !== null) - }) From 3dbd4174981382e459ac08b67b73cff465d495af Mon Sep 17 00:00:00 2001 From: josepablofm78 Date: Fri, 2 Dec 2022 11:13:51 +0100 Subject: [PATCH 11/21] skiping tests --- test/integration-tests/Compute.test.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/integration-tests/Compute.test.ts b/test/integration-tests/Compute.test.ts index 28ca76a..063f18d 100644 --- a/test/integration-tests/Compute.test.ts +++ b/test/integration-tests/Compute.test.ts @@ -37,7 +37,7 @@ describe('Compute e2e Testing', () => { }) - test('Registering a new compute asset and resolve the DID', async () => { + test.skip('Registering a new compute asset and resolve the DID', async () => { const registerAssetCommand = `${baseCommands.assets.registerAsset} --assetType compute --accountIndex 0 --name "${metadataConfig.name}" --author "${metadataConfig.author}" --price "${metadataConfig.price}" --urls ${metadataConfig.url} --contentType ${metadataConfig.contentType}` console.debug(`COMMAND: ${registerAssetCommand}`) @@ -57,7 +57,7 @@ describe('Compute e2e Testing', () => { expect(stdoutResolve.includes(did)) }) - test('Order a compute DDO', async () => { + test.skip('Order a compute DDO', async () => { const orderComputeCommand = `${baseCommands.compute.order} ${did}` @@ -70,7 +70,7 @@ describe('Compute e2e Testing', () => { }) - test('Registering a new algorithm', async () => { + test.skip('Registering a new algorithm', async () => { const registerAlgorithmCommand = `${baseCommands.assets.registerAlgorithm} --name "Test Algorithm" --author "${metadataConfig.author}" --price "0" --language "python" --entrypoint "python word_count.py" --container "python:3.8-alpine" --urls ${metadataConfig.url} --contentType ${metadataConfig.contentType}` console.debug(`COMMAND: ${registerAlgorithmCommand}`) @@ -82,7 +82,7 @@ describe('Compute e2e Testing', () => { expect(algoDid === null ? false : algoDid.startsWith('did:nv:')) }) - test('Registering a workflow associating the data and the algorithm', async () => { + test.skip('Registering a workflow associating the data and the algorithm', async () => { const registerWorkflowCommand = `${baseCommands.assets.registerWorkflow} --name "Test Worfklow" --author "${metadataConfig.author}" --input ${did} --algorithm ${algoDid}` @@ -96,7 +96,7 @@ describe('Compute e2e Testing', () => { }) - test('Executing a compute job', async () => { + test.skip('Executing a compute job', async () => { const execComputeCommand = `${baseCommands.compute.execute} ${workflowDid} --agremmentId ${agreementId}` @@ -109,12 +109,12 @@ describe('Compute e2e Testing', () => { }) - test('Fetching status of a compute job', async () => { + test.skip('Fetching status of a compute job', async () => { console.error(`PENDING TO IMPLEMENT`) }) - test('Fetching logs of a compute job', async () => { + test.skip('Fetching logs of a compute job', async () => { console.error(`PENDING TO IMPLEMENT`) }) From 24d02830e2e210511912cbfd294b3ac073b5aaab Mon Sep 17 00:00:00 2001 From: josepablofm78 Date: Fri, 2 Dec 2022 11:37:21 +0100 Subject: [PATCH 12/21] support to order a compute ddo --- src/commands/assets/orderAsset.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/commands/assets/orderAsset.ts b/src/commands/assets/orderAsset.ts index 946d636..51aa9fd 100644 --- a/src/commands/assets/orderAsset.ts +++ b/src/commands/assets/orderAsset.ts @@ -19,7 +19,7 @@ export const orderAsset = async ( config: ConfigEntry, logger: Logger ): Promise => { - const { did } = argv + const { did, orderType } = argv // TODO: Enable DTP when `sdk-dtp` is ready // const keyTransfer = await makeKeyTransfer() @@ -28,7 +28,10 @@ export const orderAsset = async ( logger.debug(chalk.dim(`Using account: '${account.getId()}'`)) - const agreementId = await nvm.assets.order(did, 'access', account) + const agreementId = await nvm.assets.order( + did, + orderType === 'compute'?'compute':'access', + account) // } logger.info(chalk.dim(`Agreement Id: ${agreementId}`)) From 7bc57231a39e41a3620ce5a75fcd42cdcbd88a47 Mon Sep 17 00:00:00 2001 From: josepablofm78 Date: Fri, 2 Dec 2022 11:57:50 +0100 Subject: [PATCH 13/21] fix typo --- test/integration-tests/Compute.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration-tests/Compute.test.ts b/test/integration-tests/Compute.test.ts index 063f18d..2efa4d6 100644 --- a/test/integration-tests/Compute.test.ts +++ b/test/integration-tests/Compute.test.ts @@ -98,7 +98,7 @@ describe('Compute e2e Testing', () => { test.skip('Executing a compute job', async () => { - const execComputeCommand = `${baseCommands.compute.execute} ${workflowDid} --agremmentId ${agreementId}` + const execComputeCommand = `${baseCommands.compute.execute} ${workflowDid} --agreementId ${agreementId}` const stdout = execCommand(execComputeCommand, execOpts) From ef24d0ea2041dd28ef342eeb4319dff02235585a Mon Sep 17 00:00:00 2001 From: josepablofm78 Date: Fri, 2 Dec 2022 11:59:01 +0100 Subject: [PATCH 14/21] fix typo --- src/commands/compute/execCompute.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/compute/execCompute.ts b/src/commands/compute/execCompute.ts index 76ec58a..1b6f051 100644 --- a/src/commands/compute/execCompute.ts +++ b/src/commands/compute/execCompute.ts @@ -33,7 +33,7 @@ export const execCompute = async ( const jobId = await nvm.assets.execute(agreementId, did, account) logger.info( - chalk.dim(`Created Job ${jobId}.`) + chalk.dim(`Created Job ${jobId}`) ) return { From b47a307429fd22abef5e8710d2eac707b6b97fc0 Mon Sep 17 00:00:00 2001 From: josepablofm78 Date: Fri, 2 Dec 2022 15:01:39 +0100 Subject: [PATCH 15/21] parsing jobId in compute test --- test/helpers/StdoutParser.ts | 12 ++++++++++++ test/integration-tests/Compute.test.ts | 20 ++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/test/helpers/StdoutParser.ts b/test/helpers/StdoutParser.ts index 2867e84..a01b3bd 100644 --- a/test/helpers/StdoutParser.ts +++ b/test/helpers/StdoutParser.ts @@ -30,6 +30,9 @@ export const commandRegex = { }, utils: { upload: new RegExp('URL: (.*)\\nPassword: (.*)\\n', 'gm') + }, + compute: { + execute: new RegExp('.*Created Job (.*)', 'gm') } } @@ -149,3 +152,12 @@ export const parseAddressOfContractDeployed = (stdout: string): string => { } return '' } + +export const parseComputeJobId = (stdout: string): string => { + const jobId = commandRegex.compute.execute.exec(stdout) + if (jobId != null) { + return jobId[1] + } + return '' +} + diff --git a/test/integration-tests/Compute.test.ts b/test/integration-tests/Compute.test.ts index 2efa4d6..b592de6 100644 --- a/test/integration-tests/Compute.test.ts +++ b/test/integration-tests/Compute.test.ts @@ -1,7 +1,8 @@ import { execOpts, metadataConfig, baseCommands } from '../helpers/Config' import { parseDIDFromNewAsset, - parseServiceAgreementId + parseServiceAgreementId, + parseComputeJobId } from '../helpers/StdoutParser' import execCommand from '../helpers/ExecCommand' @@ -103,19 +104,30 @@ describe('Compute e2e Testing', () => { const stdout = execCommand(execComputeCommand, execOpts) console.log(`STDOUT: ${stdout}`) - //jobId = parseServiceAgreementId(stdout) + jobId = parseComputeJobId(stdout) console.log(`jobId: ${jobId}`) expect(jobId !== null) }) + const sleep = (ms: number) => new Promise(r => setTimeout(r, ms)); + test.skip('Fetching status of a compute job', async () => { - console.error(`PENDING TO IMPLEMENT`) + + // wait a couple of seconds to make sure the status of the job is created + await sleep(2000); + + const execComputeCommand = `${baseCommands.compute.status} ${agreementId} ${jobId}` + const stdout = execCommand(execComputeCommand, execOpts) + expect(stdout.includes('Status fetched:')) }) test.skip('Fetching logs of a compute job', async () => { - console.error(`PENDING TO IMPLEMENT`) + + const execComputeCommand = `${baseCommands.compute.logs} ${agreementId} ${jobId}` + const stdout = execCommand(execComputeCommand, execOpts) + expect(stdout.includes(`Logs for ${jobId} fetched correctly`)) }) }) From 8427cffb6c04246f259623ecb8a12992cef56576 Mon Sep 17 00:00:00 2001 From: josepablofm78 Date: Fri, 2 Dec 2022 15:19:44 +0100 Subject: [PATCH 16/21] params in test --- test/integration-tests/Compute.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration-tests/Compute.test.ts b/test/integration-tests/Compute.test.ts index b592de6..bab15c7 100644 --- a/test/integration-tests/Compute.test.ts +++ b/test/integration-tests/Compute.test.ts @@ -115,9 +115,9 @@ describe('Compute e2e Testing', () => { test.skip('Fetching status of a compute job', async () => { // wait a couple of seconds to make sure the status of the job is created - await sleep(2000); + await sleep(4000); - const execComputeCommand = `${baseCommands.compute.status} ${agreementId} ${jobId}` + const execComputeCommand = `${baseCommands.compute.status} --jobId ${jobId} --agreementId ${agreementId}` const stdout = execCommand(execComputeCommand, execOpts) expect(stdout.includes('Status fetched:')) @@ -125,7 +125,7 @@ describe('Compute e2e Testing', () => { test.skip('Fetching logs of a compute job', async () => { - const execComputeCommand = `${baseCommands.compute.logs} ${agreementId} ${jobId}` + const execComputeCommand = `${baseCommands.compute.logs} --jobId ${jobId} --agreementId ${agreementId}` const stdout = execCommand(execComputeCommand, execOpts) expect(stdout.includes(`Logs for ${jobId} fetched correctly`)) From a89534eb290b5d0d11513e37df3dbe9ea5d58775 Mon Sep 17 00:00:00 2001 From: josepablofm78 Date: Fri, 2 Dec 2022 16:09:13 +0100 Subject: [PATCH 17/21] parsers for compute tests --- test/helpers/StdoutParser.ts | 20 +++++++++++++++++++- test/integration-tests/Compute.test.ts | 10 ++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/test/helpers/StdoutParser.ts b/test/helpers/StdoutParser.ts index a01b3bd..7d061fa 100644 --- a/test/helpers/StdoutParser.ts +++ b/test/helpers/StdoutParser.ts @@ -32,7 +32,9 @@ export const commandRegex = { upload: new RegExp('URL: (.*)\\nPassword: (.*)\\n', 'gm') }, compute: { - execute: new RegExp('.*Created Job (.*)', 'gm') + execute: new RegExp('.*Created Job (.*)', 'gm'), + algorithm: new RegExp('.*Created Asset.(.{71}).*', 'g'), + workflow: new RegExp('.*Created Asset.(.{71}).*', 'g') } } @@ -161,3 +163,19 @@ export const parseComputeJobId = (stdout: string): string => { return '' } +export const parseDIDFromNewAlgorithm = (stdout: string): string => { + const did = commandRegex.compute.algorithm.exec(stdout) + if (did != null) { + return did[1] + } + return '' +} + +export const parseDIDFromNewWorkflow = (stdout: string): string => { + const did = commandRegex.compute.workflow.exec(stdout) + if (did != null) { + return did[1] + } + return '' +} + diff --git a/test/integration-tests/Compute.test.ts b/test/integration-tests/Compute.test.ts index bab15c7..663b3ec 100644 --- a/test/integration-tests/Compute.test.ts +++ b/test/integration-tests/Compute.test.ts @@ -2,7 +2,9 @@ import { execOpts, metadataConfig, baseCommands } from '../helpers/Config' import { parseDIDFromNewAsset, parseServiceAgreementId, - parseComputeJobId + parseComputeJobId, + parseDIDFromNewAlgorithm, + parseDIDFromNewWorkflow } from '../helpers/StdoutParser' import execCommand from '../helpers/ExecCommand' @@ -78,19 +80,19 @@ describe('Compute e2e Testing', () => { const stdout = execCommand(registerAlgorithmCommand, execOpts) console.log(`STDOUT: ${stdout}`) - algoDid = parseDIDFromNewAsset(stdout) + algoDid = parseDIDFromNewAlgorithm(stdout) console.log(`ALGO DID: ${algoDid}`) expect(algoDid === null ? false : algoDid.startsWith('did:nv:')) }) test.skip('Registering a workflow associating the data and the algorithm', async () => { - const registerWorkflowCommand = `${baseCommands.assets.registerWorkflow} --name "Test Worfklow" --author "${metadataConfig.author}" --input ${did} --algorithm ${algoDid}` + const registerWorkflowCommand = `${baseCommands.assets.registerWorkflow} --name "Test Worfklow" --author "${metadataConfig.author}" --price "0" --input ${did} --algorithm ${algoDid}` const stdout = execCommand(registerWorkflowCommand, execOpts) console.log(`STDOUT: ${stdout}`) - workflowDid = parseDIDFromNewAsset(stdout) + workflowDid = parseDIDFromNewWorkflow(stdout) console.log(`WORKFLOW DID: ${workflowDid}`) expect(workflowDid === null ? false : workflowDid.startsWith('did:nv:')) From ae6a873bd1e5aa284f80f5ed6053f494408102b5 Mon Sep 17 00:00:00 2001 From: josepablofm78 Date: Fri, 9 Dec 2022 12:08:06 +0100 Subject: [PATCH 18/21] lint --- test/integration-tests/Compute.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration-tests/Compute.test.ts b/test/integration-tests/Compute.test.ts index 663b3ec..dab00a5 100644 --- a/test/integration-tests/Compute.test.ts +++ b/test/integration-tests/Compute.test.ts @@ -112,12 +112,12 @@ describe('Compute e2e Testing', () => { }) - const sleep = (ms: number) => new Promise(r => setTimeout(r, ms)); + const sleep = (ms: number) => new Promise(r => setTimeout(r, ms)) test.skip('Fetching status of a compute job', async () => { // wait a couple of seconds to make sure the status of the job is created - await sleep(4000); + await sleep(4000) const execComputeCommand = `${baseCommands.compute.status} --jobId ${jobId} --agreementId ${agreementId}` const stdout = execCommand(execComputeCommand, execOpts) From 76d4ef15c11ee1a2ced8cb5dc8537d1ca12e1d60 Mon Sep 17 00:00:00 2001 From: Aitor <1726644+aaitor@users.noreply.github.com> Date: Fri, 16 Dec 2022 15:04:04 +0100 Subject: [PATCH 19/21] format --- src/commands/assets/registerAsset.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/commands/assets/registerAsset.ts b/src/commands/assets/registerAsset.ts index 1b789a9..78c79b4 100644 --- a/src/commands/assets/registerAsset.ts +++ b/src/commands/assets/registerAsset.ts @@ -1,4 +1,4 @@ -import { Account, Nevermined } from '@nevermined-io/nevermined-sdk-js' +import { Account, Nevermined, StageInput } from '@nevermined-io/nevermined-sdk-js' import { StatusCodes, printTokenBanner, @@ -118,8 +118,9 @@ export const registerAsset = async ( // TODO Add support for multiple stages/inputs when ComputePods does if (assetType === 'workflow') { - const input = argv.input + const argvInput = argv.input as string const algorithm = argv.algorithm + ddoMetadata.main.workflow = { coordinationType: 'argo', stages: [ @@ -130,16 +131,13 @@ export const registerAsset = async ( container: { image: '', tag: '', - checksum: - '' + checksum: '' } }, - input: [ - { - index: 0, - id: input - } - ], + input: [{ + index: 0, + id: argvInput + }], transformation: { id: algorithm }, From 350157d1a19e671d1329e6c3366aaa8583d366be Mon Sep 17 00:00:00 2001 From: Aitor <1726644+aaitor@users.noreply.github.com> Date: Fri, 16 Dec 2022 15:04:38 +0100 Subject: [PATCH 20/21] lint --- src/commands/assets/registerAsset.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/assets/registerAsset.ts b/src/commands/assets/registerAsset.ts index 78c79b4..8546e2e 100644 --- a/src/commands/assets/registerAsset.ts +++ b/src/commands/assets/registerAsset.ts @@ -1,4 +1,4 @@ -import { Account, Nevermined, StageInput } from '@nevermined-io/nevermined-sdk-js' +import { Account, Nevermined } from '@nevermined-io/nevermined-sdk-js' import { StatusCodes, printTokenBanner, From e3b714146d79bdc0d9e418ab434b3db3a32804c2 Mon Sep 17 00:00:00 2001 From: Aitor <1726644+aaitor@users.noreply.github.com> Date: Fri, 16 Dec 2022 15:24:17 +0100 Subject: [PATCH 21/21] updating HDWallet --- package.json | 2 +- src/utils/config.ts | 52 +++++++++++++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index cc1fce7..a8c1601 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "dependencies": { "@nevermined-io/nevermined-sdk-js": "0.27.3", "@nevermined-io/nevermined-sdk-dtp": "0.2.4", - "@truffle/hdwallet-provider": "^2.0.9", + "@truffle/hdwallet-provider": "^2.1.3", "chalk": "^4.1.2", "cross-fetch": "~3.1.5", "dotenv": "^16.0.1", diff --git a/src/utils/config.ts b/src/utils/config.ts index 95a7fa0..ade55ed 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -178,32 +178,52 @@ export function getConfig( process.env.KEYFILE_PATH!, process.env.KEYFILE_PASSWORD! ) - hdWalletProvider = new HDWalletProvider( - [ + hdWalletProvider = new HDWalletProvider({ + privateKeys: [ getPrivateKey( process.env.KEYFILE_PATH!, process.env.KEYFILE_PASSWORD! ) ], - config.nvm.web3ProviderUri - ) + providerOrUrl: config.nvm.web3ProviderUri, + }) + // hdWalletProvider = new HDWalletProvider( + // [ + // getPrivateKey( + // process.env.KEYFILE_PATH!, + // process.env.KEYFILE_PASSWORD! + // ) + // ], + // config.nvm.web3ProviderUri + // ) } else { signer = Wallet.fromMnemonic(config.seed!) - hdWalletProvider = new HDWalletProvider( - config.seed!, - config.nvm.web3ProviderUri, - accountIndex, - 10 - ) + hdWalletProvider = new HDWalletProvider({ + mnemonic: config.seed!, + providerOrUrl: config.nvm.web3ProviderUri, + addressIndex: accountIndex, + numberOfAddresses: 10 + }) + // hdWalletProvider = new HDWalletProvider( + // config.seed!, + // config.nvm.web3ProviderUri, + // accountIndex, + // 10 + // ) } } else { signer = Wallet.fromMnemonic(DUMMY_SEED_WORDS) - hdWalletProvider = new HDWalletProvider( - DUMMY_SEED_WORDS, - config.nvm.web3ProviderUri, - 0, - 1 - ) + hdWalletProvider = new HDWalletProvider({ + mnemonic: DUMMY_SEED_WORDS, + providerOrUrl: config.nvm.web3ProviderUri, + addressIndex: 0, + numberOfAddresses: 1 + }) + // DUMMY_SEED_WORDS, + // config.nvm.web3ProviderUri, + // 0, + // 1 + // ) } return {