Skip to content

Commit

Permalink
improve tests and remove logs.
Browse files Browse the repository at this point in the history
  • Loading branch information
mariacarmina committed Feb 27, 2024
1 parent f8e139e commit 1dbc24a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 19 deletions.
17 changes: 0 additions & 17 deletions src/components/core/utils/feesHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -188,31 +187,15 @@ 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,
envId,
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]
Expand Down
51 changes: 49 additions & 2 deletions src/test/integration/computeFees.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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', () => {
Expand All @@ -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 () => {
Expand Down

0 comments on commit 1dbc24a

Please sign in to comment.