From 1dbc24a2639ee42d3913d13d6e2251925e5b89e1 Mon Sep 17 00:00:00 2001 From: Maria Carmina Date: Tue, 27 Feb 2024 16:26:02 +0200 Subject: [PATCH] improve tests and remove logs. --- src/components/core/utils/feesHandler.ts | 17 -------- src/test/integration/computeFees.test.ts | 51 +++++++++++++++++++++++- 2 files changed, 49 insertions(+), 19 deletions(-) diff --git a/src/components/core/utils/feesHandler.ts b/src/components/core/utils/feesHandler.ts index 0a857b25e..b50d707f6 100644 --- a/src/components/core/utils/feesHandler.ts +++ b/src/components/core/utils/feesHandler.ts @@ -83,7 +83,6 @@ export async function calculateComputeProviderFee( const validUntilDateTime = new Date(validUntil).getTime() const seconds: number = (now - validUntilDateTime) / 1000 const env = await getEnv(asset, computeEnv) - CORE_LOGGER.logMessage(`env : ${JSON.stringify(env)}, computeEnv: ${computeEnv}`) if (!env) { CORE_LOGGER.log(LOG_LEVELS_STR.LEVEL_ERROR, `Env could not be found.`, true) @@ -188,10 +187,8 @@ export async function validateComputeProviderFee( `Provider fees for this env have expired or tx ID was not provided -> reuse order.`, true ) - CORE_LOGGER.log(LOG_LEVELS_STR.LEVEL_INFO, `Compute env ${computeEnv}.`, true) const regex = /[^-]*-(ocean-[^-]*)/ const envId = computeEnv.match(regex)[1] - CORE_LOGGER.log(LOG_LEVELS_STR.LEVEL_INFO, `envId ${envId}.`, true) const newProviderFee = await calculateComputeProviderFee( asset, validUntil, @@ -199,20 +196,6 @@ export async function validateComputeProviderFee( service, provider ) - CORE_LOGGER.log( - LOG_LEVELS_STR.LEVEL_INFO, - `newProviderFee: ${JSON.stringify( - newProviderFee, - (key, value) => { - if (typeof value === 'bigint') { - return value.toString() // Convert BigInt to string - } - return value - }, - 4 - )}`, - true - ) return [false, newProviderFee] } else { return [true, validationResult.message] diff --git a/src/test/integration/computeFees.test.ts b/src/test/integration/computeFees.test.ts index 2ad4555c6..a15140b55 100644 --- a/src/test/integration/computeFees.test.ts +++ b/src/test/integration/computeFees.test.ts @@ -391,7 +391,6 @@ describe('Compute provider fees', async () => { const resp = await new InitializeComputeHandler(oceanNode).handle( initializeComputeTask ) - console.log(`resp: ${JSON.stringify(resp)}`) assert(resp, 'Failed to get response') assert(resp.status.httpStatus === 200, 'Failed to get 200 response') @@ -402,7 +401,7 @@ describe('Compute provider fees', async () => { // Consume the stream resp.stream.on('data', (chunk) => { - receivedData += chunk.toString() // Concatenate the chunk to the received data + receivedData += chunk.toString() }) resp.stream.on('end', () => { @@ -412,6 +411,54 @@ describe('Compute provider fees', async () => { resp.stream.on('error', (err) => { console.error('Stream error:', err) }) + const receivedDataParsed = JSON.parse(receivedData) + assert(receivedDataParsed.algorithm, 'algorithm does not exist') + assert( + receivedDataParsed.algorithm.providerFeeAddress, + 'algorithm providerFeeAddress does not exist' + ) + assert( + receivedDataParsed.algorithm.providerFeeToken, + 'algorithm providerFeeToken does not exist' + ) + assert( + receivedDataParsed.algorithm.providerFeeAmount === 0, + 'algorithm providerFeeToken does not exist' + ) // it uses the free env + assert( + receivedDataParsed.algorithm.providerFeeData, + 'algorithm providerFeeData does not exist' + ) + + assert( + receivedDataParsed.algorithm.validUntil === + initializeComputeTask.compute.validUntil / 1000, + 'algorithm providerFeeData does not exist' + ) + + assert(receivedDataParsed.datasets.length > 0, 'datasets key does not exist') + assert( + receivedDataParsed.datasets[0].providerFeeAddress, + 'algorithm providerFeeAddress does not exist' + ) + assert( + receivedDataParsed.datasets[0].providerFeeToken, + 'algorithm providerFeeToken does not exist' + ) + assert( + receivedDataParsed.datasets[0].providerFeeAmount === 0, + 'algorithm providerFeeToken does not exist' + ) // it uses the free env + assert( + receivedDataParsed.datasets[0].providerFeeData, + 'algorithm providerFeeData does not exist' + ) + + assert( + receivedDataParsed.datasets[0].validUntil === + initializeComputeTask.compute.validUntil / 1000, + 'algorithm providerFeeData does not exist' + ) }) after(async () => {