From e770c53c8265f0b46f1386852e2f083edb3c956b Mon Sep 17 00:00:00 2001 From: Enrique Ruiz Date: Tue, 29 Oct 2024 10:03:55 +0100 Subject: [PATCH] feat: support join rooms on reconnect (#79) * feat: support join rooms on reconnect * fix: format: * fix: send step as step type * fix: start listen event before * fix: format * feat: bumpversion --- package.json | 2 +- src/api/nvm-backend.ts | 23 +- src/api/query-api.ts | 12 +- tests/e2e/payments.e2e.test.ts | 458 ++++++++++++++++++--------------- 4 files changed, 256 insertions(+), 239 deletions(-) diff --git a/package.json b/package.json index 1a3dd7f..3496655 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nevermined-io/payments", - "version": "0.6.0", + "version": "0.6.1", "description": "Typescript SDK to interact with the Nevermined Payments Protocol", "main": "./dist/index.js", "types": "./dist/index.d.ts", diff --git a/src/api/nvm-backend.ts b/src/api/nvm-backend.ts index 67b0723..265c196 100644 --- a/src/api/nvm-backend.ts +++ b/src/api/nvm-backend.ts @@ -1,9 +1,9 @@ import axios from 'axios' -import { io } from 'socket.io-client' import { decodeJwt } from 'jose' +import { io } from 'socket.io-client' +import { sleep } from '../common/helper' import { AgentExecutionStatus } from '../common/types' import { isEthereumAddress } from '../utils' -import { sleep } from '../common/helper' export interface BackendApiOptions { /** @@ -157,7 +157,7 @@ export class NVMBackendApi { } } - private async connectSocket() { + public async connectSocket(_callback: (err?: any) => any, opts: SubscriptionOptions) { if (!this.hasKey) throw new Error('Unable to subscribe to the server becase a key was not provided') @@ -169,6 +169,9 @@ export class NVMBackendApi { // nvm-backend:: Connecting to websocket server: ${this.opts.webSocketHost} this.socketClient = io(this.opts.webSocketHost!, this.opts.webSocketOptions) await this.socketClient.connect() + await this.socketClient.on('_connected', async () => { + this._subscribe(_callback, opts) + }) for (let i = 0; i < 5; i++) { await sleep(1_000) if (this.socketClient.connected) { @@ -200,22 +203,17 @@ export class NVMBackendApi { if (!opts.joinAccountRoom && opts.joinAgentRooms.length === 0) { throw new Error('No rooms to join in configuration') } - await this.connectSocket() - // await this.socketClient.emit('subscribe-agent', '') - await this.socketClient.on('connect', async () => { - // nvm-backend:: On:: ${this.socketClient.id} Connected to the server - }) + await this.socketClient.emit('_join-rooms', JSON.stringify(opts)) - // await this.socketClient.on('task-updated', (data: any) => { - // console.log(`RECEIVED TASK data: ${JSON.stringify(data)}`) - // _callback(data) - // }) opts.subscribeEventTypes.forEach(async (eventType) => { await this.socketClient.on(eventType, (data: any) => { _callback(data) }) }) + if (opts.getPendingEventsOnSubscribe) { + await this._emitStepEvents(AgentExecutionStatus.Pending, opts.joinAgentRooms) + } } private async eventHandler(data: any, _callback: (err?: any) => any, _opts: SubscriptionOptions) { @@ -226,7 +224,6 @@ export class NVMBackendApi { status: AgentExecutionStatus = AgentExecutionStatus.Pending, dids: string[] = [], ) { - await this.connectSocket() const message = { status, dids, diff --git a/src/api/query-api.ts b/src/api/query-api.ts index 4f78fa7..374cc89 100644 --- a/src/api/query-api.ts +++ b/src/api/query-api.ts @@ -78,17 +78,7 @@ export class AIQueryApi extends NVMBackendApi { _callback: (err?: any) => any, opts: SubscriptionOptions = DefaultSubscriptionOptions, ) { - await super._subscribe(_callback, opts).then(() => { - // query-api:: Subscribed to server - }) - try { - if (opts.getPendingEventsOnSubscribe) { - // query-api:: Emitting pending events - await super._emitStepEvents(AgentExecutionStatus.Pending, opts.joinAgentRooms) - } - } catch { - // query-api:: Unable to get pending events - } + await super.connectSocket(_callback, opts) } /** diff --git a/tests/e2e/payments.e2e.test.ts b/tests/e2e/payments.e2e.test.ts index f1294c5..7ecff1c 100644 --- a/tests/e2e/payments.e2e.test.ts +++ b/tests/e2e/payments.e2e.test.ts @@ -1,16 +1,19 @@ -import { EnvironmentName } from "../../src/environments" -import { Payments } from "../../src/payments" -import { sleep } from "../../src/common/helper" -import { AgentExecutionStatus } from "../../src/common/types" +import { sleep } from '../../src/common/helper' +import { AgentExecutionStatus, Step } from '../../src/common/types' +import { EnvironmentName } from '../../src/environments' +import { Payments } from '../../src/payments' // import { getQueryProtocolEndpoints } from "../../src/utils" -import { io } from "socket.io-client" +import { io } from 'socket.io-client' describe('Payments API (e2e)', () => { - const TEST_TIMEOUT = 30_000 // To configure the test gets the API Keys for the subscriber and the builder from the https://staging.nevermined.app website - const subscriberNvmApiKeyHash = process.env.TEST_SUBSCRIBER_API_KEY || 'eyJhbGciOiJFUzI1NksifQ.eyJpc3MiOiIweDU4MzhCNTUxMmNGOWYxMkZFOWYyYmVjY0IyMGViNDcyMTFGOUIwYmMiLCJzdWIiOiIweDFCMDZDRkIyMkYwODMyZmI5MjU1NDE1MmRiYjVGOWM5NzU2ZTkzN2QiLCJqdGkiOiIweDlmMGRkNmZhODNkMDY3ZDRiYzFkNzEyN2Q3ZWE0M2EwYmUwNzc1NWJmNjMxMTVmYzJhODhmOTQwZmY4MjQ1NGQiLCJleHAiOjE3NTk4NzQwMDEsImlhdCI6MTcyODMxNjQwMn0.SqlcnMvdIjpZdBDs8FBsruYUIVpS75My-l5VfVwsFdU_3Xz5DuYt1frdF0QZq8isx9NOsNgRSeG8sBVtvAl-vRw' - const builderNvmApiKeyHash = process.env.TEST_BUILDER_API_KEY || 'eyJhbGciOiJFUzI1NksifQ.eyJpc3MiOiIweDU4MzhCNTUxMmNGOWYxMkZFOWYyYmVjY0IyMGViNDcyMTFGOUIwYmMiLCJzdWIiOiIweDdmRTNFZTA4OGQwY2IzRjQ5ZmREMjBlMTk0RjIzRDY4MzhhY2NjODIiLCJqdGkiOiIweGY2ZDcyMmIzYWY5ZmNhOWY2MTQ2OGI5YjlhNGNmZjk3Yjg5NjE5Yzc1ZjRkYWEyMmY4NTA3Yjc2ODQzM2JkYWQiLCJleHAiOjE3NTk2MDU0MTMsImlhdCI6MTcyODA0NzgxNn0.1JDNV7yT8i1_1DXxC4z_jzMLJQns4XqujaJOEFmLdtwFam7bi-3s8oOF-dbTBObzNY98ddZZFifaCEvJUImYOBw' + const subscriberNvmApiKeyHash = + process.env.TEST_SUBSCRIBER_API_KEY || + 'eyJhbGciOiJFUzI1NksifQ.eyJpc3MiOiIweDU4MzhCNTUxMmNGOWYxMkZFOWYyYmVjY0IyMGViNDcyMTFGOUIwYmMiLCJzdWIiOiIweDFCMDZDRkIyMkYwODMyZmI5MjU1NDE1MmRiYjVGOWM5NzU2ZTkzN2QiLCJqdGkiOiIweDlmMGRkNmZhODNkMDY3ZDRiYzFkNzEyN2Q3ZWE0M2EwYmUwNzc1NWJmNjMxMTVmYzJhODhmOTQwZmY4MjQ1NGQiLCJleHAiOjE3NTk4NzQwMDEsImlhdCI6MTcyODMxNjQwMn0.SqlcnMvdIjpZdBDs8FBsruYUIVpS75My-l5VfVwsFdU_3Xz5DuYt1frdF0QZq8isx9NOsNgRSeG8sBVtvAl-vRw' + const builderNvmApiKeyHash = + process.env.TEST_BUILDER_API_KEY || + 'eyJhbGciOiJFUzI1NksifQ.eyJpc3MiOiIweDU4MzhCNTUxMmNGOWYxMkZFOWYyYmVjY0IyMGViNDcyMTFGOUIwYmMiLCJzdWIiOiIweDdmRTNFZTA4OGQwY2IzRjQ5ZmREMjBlMTk0RjIzRDY4MzhhY2NjODIiLCJqdGkiOiIweGY2ZDcyMmIzYWY5ZmNhOWY2MTQ2OGI5YjlhNGNmZjk3Yjg5NjE5Yzc1ZjRkYWEyMmY4NTA3Yjc2ODQzM2JkYWQiLCJleHAiOjE3NTk2MDU0MTMsImlhdCI6MTcyODA0NzgxNn0.1JDNV7yT8i1_1DXxC4z_jzMLJQns4XqujaJOEFmLdtwFam7bi-3s8oOF-dbTBObzNY98ddZZFifaCEvJUImYOBw' const testingEnvironment = process.env.TEST_ENVIRONMENT || 'staging' const _SLEEP_DURATION = 3_000 const ERC20_ADDRESS = '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d' @@ -19,7 +22,6 @@ describe('Payments API (e2e)', () => { // // { 'GET': `https://one-backend.${testingEnvironment}.nevermined.app/api/v1/agents/(.*)/tasks/(.*)` } // ] - let paymentsSubscriber: Payments let paymentsBuilder: Payments @@ -36,16 +38,16 @@ describe('Payments API (e2e)', () => { let failedTaskDID: string describe('Payments Setup', () => { it('The Payments client can be initialized correctly', () => { - paymentsSubscriber = Payments.getInstance({ + paymentsSubscriber = Payments.getInstance({ nvmApiKey: subscriberNvmApiKeyHash, - environment: testingEnvironment as EnvironmentName, + environment: testingEnvironment as EnvironmentName, }) expect(paymentsSubscriber).toBeDefined() expect(paymentsSubscriber.query).toBeDefined() - paymentsBuilder = Payments.getInstance({ + paymentsBuilder = Payments.getInstance({ nvmApiKey: builderNvmApiKeyHash, - environment: testingEnvironment as EnvironmentName, + environment: testingEnvironment as EnvironmentName, }) expect(paymentsBuilder).toBeDefined() expect(paymentsBuilder.query).toBeDefined() @@ -57,11 +59,11 @@ describe('Payments API (e2e)', () => { transports: ['websocket'], transportOptions: { websocket: { - extraHeaders: { - Authorization: `Bearer ${builderNvmApiKeyHash}`, - } - } - } + extraHeaders: { + Authorization: `Bearer ${builderNvmApiKeyHash}`, + }, + }, + }, } const client = io('wss://one-backend.staging.nevermined.app', socketOptions) expect(client).toBeDefined() @@ -81,20 +83,20 @@ describe('Payments API (e2e)', () => { }, } client.emit('subscribe-agent', '') - + client.emit(room, '{"event": "test", "data": ""}') - + let received = false client.on(room, (data) => { console.log('RECEIVED Websocket data:', data) received = true - expect(data).toBeDefined() + expect(data).toBeDefined() // return data }) - + client.emit(room, message) - await sleep(1000) + await sleep(1000) client.disconnect() expect(received).toBe(true) @@ -110,82 +112,101 @@ describe('Payments API (e2e)', () => { // } // const accessConfig = await paymentsSubscriber.getServiceAccessConfig(agentDID) - // const queryOpts = { + // const queryOpts = { // accessToken: accessConfig.accessToken, // proxyHost: accessConfig.neverminedProxyUri - // } + // } // const taskResult = await paymentsSubscriber.query.createTask(agentDID, aiTask, queryOpts) - // expect(taskResult).toBeDefined() + // expect(taskResult).toBeDefined() // expect(taskResult.status).toBe(201) // console.log('Task Result', taskResult.data) // }, TEST_TIMEOUT) - }) describe('AI Builder Publication', () => { - it('I should be able to register a new credits Payment Plan', async () => { - planDID = (await paymentsBuilder.createCreditsPlan({ - name: 'E2E Payments Plan', - description: 'description', - price: 0n, - tokenAddress: ERC20_ADDRESS, - amountOfCredits: 100 - })).did - - expect(planDID).toBeDefined() - expect(planDID.startsWith('did:nv:')).toBeTruthy() - console.log('Plan DID', planDID) - - }, TEST_TIMEOUT) - - it('I should be able to register a new Agent running on NVM Infrastructure', async () => { - // const endpoints = getQueryProtocolEndpoints('https://one-backend.staging.nevermined.app') - - agentDID = (await paymentsBuilder.createAgent({ - planDID, - name: 'E2E Payments Agent', - description: 'description', - serviceChargeType: 'fixed', - amountOfCredits: 1, - usesAIHub: true, - })).did - - expect(agentDID).toBeDefined() - expect(agentDID.startsWith('did:nv:')).toBeTruthy() - console.log('Agent DID', agentDID) - }, TEST_TIMEOUT) - - it.skip('I should be able to register a new File', async () => { - const file = { - index: 0, - contentType: 'application/json', - name: 'ddo-example.json', - url: 'https://storage.googleapis.com/nvm-static-assets/files/ci/ddo-example.json', - } - const fileDID = (await paymentsBuilder.createFile({ - planDID: planDID, - name: 'E2E Payments File', - description: 'description', - assetType: 'dataset', - files: [file] - })).did - - expect(fileDID).toBeDefined() - expect(fileDID.startsWith('did:nv:')).toBeTruthy() - console.log('File DID', agentDID) - - }, TEST_TIMEOUT) -}) + it( + 'I should be able to register a new credits Payment Plan', + async () => { + planDID = ( + await paymentsBuilder.createCreditsPlan({ + name: 'E2E Payments Plan', + description: 'description', + price: 0n, + tokenAddress: ERC20_ADDRESS, + amountOfCredits: 100, + }) + ).did + + expect(planDID).toBeDefined() + expect(planDID.startsWith('did:nv:')).toBeTruthy() + console.log('Plan DID', planDID) + }, + TEST_TIMEOUT, + ) + + it( + 'I should be able to register a new Agent running on NVM Infrastructure', + async () => { + // const endpoints = getQueryProtocolEndpoints('https://one-backend.staging.nevermined.app') + + agentDID = ( + await paymentsBuilder.createAgent({ + planDID, + name: 'E2E Payments Agent', + description: 'description', + serviceChargeType: 'fixed', + amountOfCredits: 1, + usesAIHub: true, + }) + ).did + + expect(agentDID).toBeDefined() + expect(agentDID.startsWith('did:nv:')).toBeTruthy() + console.log('Agent DID', agentDID) + }, + TEST_TIMEOUT, + ) + + it.skip( + 'I should be able to register a new File', + async () => { + const file = { + index: 0, + contentType: 'application/json', + name: 'ddo-example.json', + url: 'https://storage.googleapis.com/nvm-static-assets/files/ci/ddo-example.json', + } + const fileDID = ( + await paymentsBuilder.createFile({ + planDID: planDID, + name: 'E2E Payments File', + description: 'description', + assetType: 'dataset', + files: [file], + }) + ).did + + expect(fileDID).toBeDefined() + expect(fileDID.startsWith('did:nv:')).toBeTruthy() + console.log('File DID', agentDID) + }, + TEST_TIMEOUT, + ) + }) describe('Subscriber Order', () => { - it('I should be able to order an Agent', async () => { - const orderResult = await paymentsSubscriber.orderPlan(planDID) - expect(orderResult).toBeDefined() - expect(orderResult.success).toBeTruthy() - expect(orderResult.agreementId).toBeDefined() - console.log('Order Result', orderResult) - }, TEST_TIMEOUT * 2) + it( + 'I should be able to order an Agent', + async () => { + const orderResult = await paymentsSubscriber.orderPlan(planDID) + expect(orderResult).toBeDefined() + expect(orderResult.success).toBeTruthy() + expect(orderResult.agreementId).toBeDefined() + console.log('Order Result', orderResult) + }, + TEST_TIMEOUT * 2, + ) it('I should be able to check the credits I own', async () => { const balanceResult = await paymentsSubscriber.getPlanBalance(planDID) @@ -196,32 +217,38 @@ describe('Payments API (e2e)', () => { balanceBefore = BigInt(balanceResult.balance) }) - it('I should be able to create a AI Task', async () => { - const aiTask = { - query: "https://www.youtube.com/watch?v=0tZFQs7qBfQ", - name: "transcribe", - "additional_params": [], - "artifacts": [] - } - subscriberQueryOpts = await paymentsSubscriber.getServiceAccessConfig(agentDID) - // accessToken = accessConfig.accessToken - // proxyHost = accessConfig.neverminedProxyUri - // subscriberQueryOpts = { - // accessToken, - // proxyHost - // } - - const taskResult = await paymentsSubscriber.query.createTask(agentDID, aiTask, subscriberQueryOpts) - - expect(taskResult).toBeDefined() - expect(taskResult.status).toBe(201) - console.log('Task Result', taskResult.data) - }, TEST_TIMEOUT) - + it( + 'I should be able to create a AI Task', + async () => { + const aiTask = { + query: 'https://www.youtube.com/watch?v=0tZFQs7qBfQ', + name: 'transcribe', + additional_params: [], + artifacts: [], + } + subscriberQueryOpts = await paymentsSubscriber.getServiceAccessConfig(agentDID) + // accessToken = accessConfig.accessToken + // proxyHost = accessConfig.neverminedProxyUri + // subscriberQueryOpts = { + // accessToken, + // proxyHost + // } + + const taskResult = await paymentsSubscriber.query.createTask( + agentDID, + aiTask, + subscriberQueryOpts, + ) + + expect(taskResult).toBeDefined() + expect(taskResult.status).toBe(201) + console.log('Task Result', taskResult.data) + }, + TEST_TIMEOUT, + ) }) - - describe('AI Builder Agent', () => { + describe('AI Builder Agent', () => { let taskCost: bigint it('Builder should be able to fetch pending tasks', async () => { const steps = await paymentsBuilder.query.getSteps(AgentExecutionStatus.Pending) @@ -230,92 +257,96 @@ describe('Payments API (e2e)', () => { expect(steps.data.steps.length).toBeGreaterThan(0) }) - it('I should be able to subscribe and process pending tasks', async () => { - let stepsReceived = 0 - const opts = { - joinAccountRoom: true, - joinAgentRooms: [], - subscribeEventTypes: ['step-updated'], - getPendingEventsOnSubscribe: false - } - await paymentsBuilder.query.subscribe(async (data) => { - console.log('TEST:: Step received', data) - expect(data).toBeDefined() - const eventData = JSON.parse(data) - expect(eventData.step_id).toBeDefined() - - stepsReceived++ - let result - const searchResult = await paymentsBuilder.query.searchSteps({ step_id: eventData.step_id }) - expect(searchResult.data.steps).toBeDefined() - const step = searchResult.data.steps[0] - if (step.input_query.startsWith('http')) { - console.log(`LISTENER :: Received URL ${step.input_query}`) - result = await paymentsBuilder.query.updateStep(step.did, { - step_id: step.step_id, - task_id: step.task_id, - step_status: AgentExecutionStatus.Completed, - is_last: true, - output: 'LFG!', - cost: 1 + it( + 'I should be able to subscribe and process pending tasks', + async () => { + let stepsReceived = 0 + const opts = { + joinAccountRoom: true, + joinAgentRooms: [], + subscribeEventTypes: ['step-updated'], + getPendingEventsOnSubscribe: false, + } + await paymentsBuilder.query.subscribe(async (data) => { + console.log('TEST:: Step received', data) + expect(data).toBeDefined() + const eventData = JSON.parse(data) + expect(eventData.step_id).toBeDefined() + + stepsReceived++ + let result + const searchResult = await paymentsBuilder.query.searchSteps({ + step_id: eventData.step_id, }) - // expect(result.status).toBe(201) - if (result.status === 201) { - completedTaskId = step.task_id - completedTaskDID = step.did + expect(searchResult.data.steps).toBeDefined() + const step = searchResult.data.steps[0] + if (step.input_query.startsWith('http')) { + console.log(`LISTENER :: Received URL ${step.input_query}`) + result = await paymentsBuilder.query.updateStep(step.did, { + step_id: step.step_id, + task_id: step.task_id, + step_status: AgentExecutionStatus.Completed, + is_last: true, + output: 'LFG!', + cost: 1, + } as Step) + // expect(result.status).toBe(201) + if (result.status === 201) { + completedTaskId = step.task_id + completedTaskDID = step.did + } + } else { + console.log(`LISTENER :: Received Invalid URL ${step.input_query}`) + result = await paymentsBuilder.query.updateStep(step.did, { + step_id: step.step_id, + task_id: step.task_id, + step_status: AgentExecutionStatus.Failed, + is_last: true, + output: 'Invalid URL', + cost: 0, + } as Step) } - } else { - console.log(`LISTENER :: Received Invalid URL ${step.input_query}`) - result = await paymentsBuilder.query.updateStep(step.did, { - step_id: step.step_id, - task_id: step.task_id, - step_status: AgentExecutionStatus.Failed, - is_last: true, - output: 'Invalid URL', - cost: 0 - }) + }, opts) + + const aiTask = { + query: 'https://www.youtube.com/watch?v=0tZFQs7qBfQ', + name: 'transcribe', + additional_params: [], + artifacts: [], + } + const accessConfig = await paymentsSubscriber.getServiceAccessConfig(agentDID) + const queryOpts = { + accessToken: accessConfig.accessToken, + proxyHost: accessConfig.neverminedProxyUri, } - - }, opts) - - - const aiTask = { - query: "https://www.youtube.com/watch?v=0tZFQs7qBfQ", - name: "transcribe", - "additional_params": [], - "artifacts": [] - } - const accessConfig = await paymentsSubscriber.getServiceAccessConfig(agentDID) - const queryOpts = { - accessToken: accessConfig.accessToken, - proxyHost: accessConfig.neverminedProxyUri - } - const taskResult = await paymentsSubscriber.query.createTask(agentDID, aiTask, queryOpts) + const taskResult = await paymentsSubscriber.query.createTask(agentDID, aiTask, queryOpts) - expect(taskResult).toBeDefined() - expect(taskResult.status).toBe(201) + expect(taskResult).toBeDefined() + expect(taskResult.status).toBe(201) - console.log(`TEST:: Sleeping for 10 seconds: ${new Date().toLocaleTimeString()}`) - await sleep(10_000) - console.log(`TEST:: Awaiting: ${new Date().toLocaleTimeString()}`) + console.log(`TEST:: Sleeping for 10 seconds: ${new Date().toLocaleTimeString()}`) + await sleep(10_000) + console.log(`TEST:: Awaiting: ${new Date().toLocaleTimeString()}`) - expect(stepsReceived).toBeGreaterThan(0) - expect(completedTaskId).toBeDefined() - console.log(`Completed Task ID: ${completedTaskId}`) - }, TEST_TIMEOUT) + expect(stepsReceived).toBeGreaterThan(0) + expect(completedTaskId).toBeDefined() + console.log(`Completed Task ID: ${completedTaskId}`) + }, + TEST_TIMEOUT, + ) it('I should be able to validate an AI task is completed', async () => { console.log(`@@@@@ getting task with steps: ${completedTaskDID} - ${completedTaskId}`) console.log(JSON.stringify(subscriberQueryOpts)) const result = await paymentsSubscriber.query.getTaskWithSteps( - completedTaskDID, - completedTaskId, - subscriberQueryOpts + completedTaskDID, + completedTaskId, + subscriberQueryOpts, ) expect(result).toBeDefined() console.log('Task with Steps', result.data) - expect(result.status).toBe(200) + expect(result.status).toBe(200) expect(result.data.task.cost).toBeDefined() taskCost = BigInt(result.data.task.cost) expect(taskCost).toBeGreaterThan(0) @@ -326,50 +357,53 @@ describe('Payments API (e2e)', () => { expect(balanceResult).toBeDefined() const balanceAfter = BigInt(balanceResult.balance) - expect(balanceAfter).toBeDefined() console.log(`Balance Before: ${balanceBefore}`) console.log(`Balance After: ${balanceAfter}`) console.log(`Task Cost: ${taskCost}`) - expect(balanceAfter).toBeLessThan(balanceBefore) - }) - - it.skip('I should be able to end a task with a failure', () => { + expect(balanceAfter).toBeLessThan(balanceBefore) }) + it.skip('I should be able to end a task with a failure', () => {}) }) - - describe('Failed tasks are free of charge', () => { - it('I should be able to create a wrong AI Task', async () => { - const aiTask = { - query: "this is not a URL !!!!", - name: "transcribe", - "additional_params": [], - "artifacts": [] - } - const taskResult = await paymentsSubscriber.query.createTask(agentDID, aiTask, subscriberQueryOpts) - - expect(taskResult).toBeDefined() - expect(taskResult.status).toBe(201) - console.log('Task Result', taskResult.data) - failedTaskDID = taskResult.data.task.did - failedTaskId = taskResult.data.task.task_id - console.log(`Failed Task DID: ${failedTaskDID}`) - console.log(`Failed TaskId: ${failedTaskId}`) - }, TEST_TIMEOUT) + it( + 'I should be able to create a wrong AI Task', + async () => { + const aiTask = { + query: 'this is not a URL !!!!', + name: 'transcribe', + additional_params: [], + artifacts: [], + } + const taskResult = await paymentsSubscriber.query.createTask( + agentDID, + aiTask, + subscriberQueryOpts, + ) + + expect(taskResult).toBeDefined() + expect(taskResult.status).toBe(201) + console.log('Task Result', taskResult.data) + failedTaskDID = taskResult.data.task.did + failedTaskId = taskResult.data.task.task_id + console.log(`Failed Task DID: ${failedTaskDID}`) + console.log(`Failed TaskId: ${failedTaskId}`) + }, + TEST_TIMEOUT, + ) it('I should be able to validate an AI task Failed', async () => { const result = await paymentsSubscriber.query.getTaskWithSteps( - failedTaskDID, - failedTaskId, - subscriberQueryOpts + failedTaskDID, + failedTaskId, + subscriberQueryOpts, ) expect(result).toBeDefined() - console.log('Task with Steps', result) + console.log('Task with Steps', result) expect(result.status).toBe(200) // console.log('Task with Steps', result.data) // expect(result.data.task.cost).toBeDefined() @@ -399,10 +433,6 @@ describe('Payments API (e2e)', () => { expect(paymentsBuilder.query.isWebSocketConnected()).toBeFalsy() }) }) - - - - }) const stepReceived = (data: any) => {