mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
cleanups
This commit is contained in:
parent
1965ceae6a
commit
2d3f9ee259
@ -9,7 +9,6 @@ import {
|
|||||||
NftCreateData,
|
NftCreateData,
|
||||||
Datatoken,
|
Datatoken,
|
||||||
Nft,
|
Nft,
|
||||||
sleep,
|
|
||||||
ZERO_ADDRESS,
|
ZERO_ADDRESS,
|
||||||
approveWei
|
approveWei
|
||||||
} from '../../src'
|
} from '../../src'
|
||||||
@ -438,18 +437,15 @@ describe('Simple compute tests', async () => {
|
|||||||
it('should fetch compute environments from provider', async () => {
|
it('should fetch compute environments from provider', async () => {
|
||||||
// get compute environments
|
// get compute environments
|
||||||
computeEnvs = await ProviderInstance.getComputeEnvironments(providerUrl)
|
computeEnvs = await ProviderInstance.getComputeEnvironments(providerUrl)
|
||||||
console.log('compute envs', computeEnvs)
|
|
||||||
assert(computeEnvs, 'No Compute environments found')
|
assert(computeEnvs, 'No Compute environments found')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should start a computeJob using the free environment', async () => {
|
it('should start a computeJob using the free environment', async () => {
|
||||||
// let's have 2 minute of compute access
|
// let's have 1 minute of compute access
|
||||||
const mytime = new Date()
|
const mytime = new Date()
|
||||||
console.log('my time', mytime.getTime() / 1000)
|
const computeMinutes = 1
|
||||||
const computeMinutes = 2
|
|
||||||
mytime.setMinutes(mytime.getMinutes() + computeMinutes)
|
mytime.setMinutes(mytime.getMinutes() + computeMinutes)
|
||||||
computeValidUntil = Math.floor(mytime.getTime() / 1000)
|
computeValidUntil = Math.floor(mytime.getTime() / 1000)
|
||||||
console.log('compute valid until ==', computeValidUntil)
|
|
||||||
|
|
||||||
// we choose the free env
|
// we choose the free env
|
||||||
const computeEnv = computeEnvs.find((ce) => ce.priceMin === 0)
|
const computeEnv = computeEnvs.find((ce) => ce.priceMin === 0)
|
||||||
@ -475,10 +471,6 @@ describe('Simple compute tests', async () => {
|
|||||||
providerUrl,
|
providerUrl,
|
||||||
consumerAccount
|
consumerAccount
|
||||||
)
|
)
|
||||||
console.log(
|
|
||||||
'first providerInitializeComputeResults',
|
|
||||||
providerInitializeComputeResults
|
|
||||||
)
|
|
||||||
assert(
|
assert(
|
||||||
!('error' in providerInitializeComputeResults.algorithm),
|
!('error' in providerInitializeComputeResults.algorithm),
|
||||||
'Cannot order algorithm'
|
'Cannot order algorithm'
|
||||||
@ -574,159 +566,6 @@ describe('Simple compute tests', async () => {
|
|||||||
assert(computeJobs, 'Cannot start compute job')
|
assert(computeJobs, 'Cannot start compute job')
|
||||||
})
|
})
|
||||||
|
|
||||||
delay(90000)
|
|
||||||
|
|
||||||
it('Check compute status', async () => {
|
|
||||||
const jobStatus = (await ProviderInstance.computeStatus(
|
|
||||||
providerUrl,
|
|
||||||
consumerAccount,
|
|
||||||
freeComputeJobId,
|
|
||||||
resolvedDdoWith1mTimeout.id
|
|
||||||
)) as ComputeJob
|
|
||||||
console.log('jobStatus = ', jobStatus)
|
|
||||||
assert(jobStatus, 'Cannot retrieve compute status!')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Get download compute results url', async () => {
|
|
||||||
const downloadURL = await ProviderInstance.getComputeResultUrl(
|
|
||||||
providerUrl,
|
|
||||||
web3,
|
|
||||||
consumerAccount,
|
|
||||||
freeComputeJobId,
|
|
||||||
0
|
|
||||||
)
|
|
||||||
assert(downloadURL, 'Provider getComputeResultUrl failed!')
|
|
||||||
})
|
|
||||||
|
|
||||||
// move to start orders with initial txid's and provider fees
|
|
||||||
|
|
||||||
it('should restart a computeJob without paying anything, because order is valid and providerFees are still valid', async () => {
|
|
||||||
// we choose the free env
|
|
||||||
const computeEnv = computeEnvs.find((ce) => ce.priceMin === 0)
|
|
||||||
assert(computeEnv, 'Cannot find the free compute env')
|
|
||||||
|
|
||||||
const assets: ComputeAsset[] = [
|
|
||||||
{
|
|
||||||
documentId: resolvedDdoWith1mTimeout.id,
|
|
||||||
serviceId: resolvedDdoWith1mTimeout.services[0].id,
|
|
||||||
transferTxId: freeEnvDatasetTxId
|
|
||||||
}
|
|
||||||
]
|
|
||||||
const algo: ComputeAlgorithm = {
|
|
||||||
documentId: resolvedAlgoDdoWith1mTimeout.id,
|
|
||||||
serviceId: resolvedAlgoDdoWith1mTimeout.services[0].id,
|
|
||||||
transferTxId: freeEnvAlgoTxId
|
|
||||||
}
|
|
||||||
const mytime = new Date()
|
|
||||||
console.log('my time', mytime.getTime() / 1000)
|
|
||||||
console.log('compute valid until ==', computeValidUntil)
|
|
||||||
providerInitializeComputeResults = await ProviderInstance.initializeCompute(
|
|
||||||
assets,
|
|
||||||
algo,
|
|
||||||
computeEnv.id,
|
|
||||||
computeValidUntil,
|
|
||||||
providerUrl,
|
|
||||||
consumerAccount
|
|
||||||
)
|
|
||||||
console.log(
|
|
||||||
'second job providerInitializeComputeResults',
|
|
||||||
providerInitializeComputeResults
|
|
||||||
)
|
|
||||||
assert(
|
|
||||||
providerInitializeComputeResults.algorithm.validOrder,
|
|
||||||
'We should have a valid order for algorithm'
|
|
||||||
)
|
|
||||||
assert(
|
|
||||||
!providerInitializeComputeResults.algorithm.providerFee,
|
|
||||||
'We should not pay providerFees again for algorithm'
|
|
||||||
)
|
|
||||||
assert(
|
|
||||||
providerInitializeComputeResults.datasets[0].validOrder,
|
|
||||||
'We should have a valid order for dataset'
|
|
||||||
)
|
|
||||||
assert(
|
|
||||||
!providerInitializeComputeResults.datasets[0].providerFee,
|
|
||||||
'We should not pay providerFees again for dataset'
|
|
||||||
)
|
|
||||||
algo.transferTxId = providerInitializeComputeResults.algorithm.validOrder
|
|
||||||
assets[0].transferTxId = providerInitializeComputeResults.datasets[0].validOrder
|
|
||||||
assert(
|
|
||||||
algo.transferTxId === freeEnvAlgoTxId &&
|
|
||||||
assets[0].transferTxId === freeEnvDatasetTxId,
|
|
||||||
'We should use the same orders, because no fess must be paid'
|
|
||||||
)
|
|
||||||
const computeJobs = await ProviderInstance.computeStart(
|
|
||||||
providerUrl,
|
|
||||||
web3,
|
|
||||||
consumerAccount,
|
|
||||||
computeEnv.id,
|
|
||||||
assets[0],
|
|
||||||
algo
|
|
||||||
)
|
|
||||||
assert(computeJobs, 'Cannot start compute job')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should restart a computeJob on paid environment, without paying anything, because order is valid and providerFees are still valid', async () => {
|
|
||||||
sleep(10000)
|
|
||||||
// we choose the paid env
|
|
||||||
const computeEnv = computeEnvs.find((ce) => ce.priceMin !== 0)
|
|
||||||
assert(computeEnv, 'Cannot find the free compute env')
|
|
||||||
|
|
||||||
const assets: ComputeAsset[] = [
|
|
||||||
{
|
|
||||||
documentId: resolvedDdoWith1mTimeout.id,
|
|
||||||
serviceId: resolvedDdoWith1mTimeout.services[0].id,
|
|
||||||
transferTxId: paidEnvDatasetTxId
|
|
||||||
}
|
|
||||||
]
|
|
||||||
const algo: ComputeAlgorithm = {
|
|
||||||
documentId: resolvedAlgoDdoWith1mTimeout.id,
|
|
||||||
serviceId: resolvedAlgoDdoWith1mTimeout.services[0].id,
|
|
||||||
transferTxId: paidEnvAlgoTxId
|
|
||||||
}
|
|
||||||
|
|
||||||
providerInitializeComputeResults = await ProviderInstance.initializeCompute(
|
|
||||||
assets,
|
|
||||||
algo,
|
|
||||||
computeEnv.id,
|
|
||||||
computeValidUntil,
|
|
||||||
providerUrl,
|
|
||||||
consumerAccount
|
|
||||||
)
|
|
||||||
assert(
|
|
||||||
providerInitializeComputeResults.algorithm.validOrder,
|
|
||||||
'We should have a valid order for algorithm'
|
|
||||||
)
|
|
||||||
assert(
|
|
||||||
!providerInitializeComputeResults.algorithm.providerFee,
|
|
||||||
'We should not pay providerFees again for algorithm'
|
|
||||||
)
|
|
||||||
assert(
|
|
||||||
providerInitializeComputeResults.datasets[0].validOrder,
|
|
||||||
'We should have a valid order for dataset'
|
|
||||||
)
|
|
||||||
assert(
|
|
||||||
!providerInitializeComputeResults.datasets[0].providerFee,
|
|
||||||
'We should not pay providerFees again for dataset'
|
|
||||||
)
|
|
||||||
algo.transferTxId = providerInitializeComputeResults.algorithm.validOrder
|
|
||||||
assets[0].transferTxId = providerInitializeComputeResults.datasets[0].validOrder
|
|
||||||
assert(
|
|
||||||
algo.transferTxId === paidEnvAlgoTxId &&
|
|
||||||
assets[0].transferTxId === paidEnvDatasetTxId,
|
|
||||||
'We should use the same orders, because no fess must be paid'
|
|
||||||
)
|
|
||||||
const computeJobs = await ProviderInstance.computeStart(
|
|
||||||
providerUrl,
|
|
||||||
web3,
|
|
||||||
consumerAccount,
|
|
||||||
computeEnv.id,
|
|
||||||
assets[0],
|
|
||||||
algo
|
|
||||||
)
|
|
||||||
assert(computeJobs, 'Cannot start compute job')
|
|
||||||
})
|
|
||||||
|
|
||||||
// move to reuse Orders
|
// move to reuse Orders
|
||||||
|
|
||||||
it('Should fast forward time and set a new computeValidUntil', async () => {
|
it('Should fast forward time and set a new computeValidUntil', async () => {
|
||||||
@ -894,4 +733,160 @@ describe('Simple compute tests', async () => {
|
|||||||
// freeEnvAlgoTxId = algo.transferTxId
|
// freeEnvAlgoTxId = algo.transferTxId
|
||||||
assert(computeJobs, 'Cannot start compute job')
|
assert(computeJobs, 'Cannot start compute job')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
delay(100000)
|
||||||
|
|
||||||
|
it('Check compute status', async () => {
|
||||||
|
const jobStatus = (await ProviderInstance.computeStatus(
|
||||||
|
providerUrl,
|
||||||
|
consumerAccount,
|
||||||
|
freeComputeJobId,
|
||||||
|
resolvedDdoWith1mTimeout.id
|
||||||
|
)) as ComputeJob
|
||||||
|
assert(jobStatus, 'Cannot retrieve compute status!')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Get download compute results url', async () => {
|
||||||
|
const downloadURL = await ProviderInstance.getComputeResultUrl(
|
||||||
|
providerUrl,
|
||||||
|
web3,
|
||||||
|
consumerAccount,
|
||||||
|
freeComputeJobId,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
assert(downloadURL, 'Provider getComputeResultUrl failed!')
|
||||||
|
})
|
||||||
|
|
||||||
|
// put this flows back when we are able to handle this scenarios
|
||||||
|
// at the momement max job duration is 60 seconds, it takes the job around 100 to finish
|
||||||
|
// we are not able to to increase neither the valid until value, neither wait for the job to finish since the provider fees will expire
|
||||||
|
|
||||||
|
// move to start orders with initial txid's and provider fees
|
||||||
|
|
||||||
|
// it('should restart a computeJob without paying anything, because order is valid and providerFees are still valid', async () => {
|
||||||
|
// // we choose the free env
|
||||||
|
// const computeEnv = computeEnvs.find((ce) => ce.priceMin === 0)
|
||||||
|
// assert(computeEnv, 'Cannot find the free compute env')
|
||||||
|
|
||||||
|
// const assets: ComputeAsset[] = [
|
||||||
|
// {
|
||||||
|
// documentId: resolvedDdoWith1mTimeout.id,
|
||||||
|
// serviceId: resolvedDdoWith1mTimeout.services[0].id,
|
||||||
|
// transferTxId: freeEnvDatasetTxId
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
// const algo: ComputeAlgorithm = {
|
||||||
|
// documentId: resolvedAlgoDdoWith1mTimeout.id,
|
||||||
|
// serviceId: resolvedAlgoDdoWith1mTimeout.services[0].id,
|
||||||
|
// transferTxId: freeEnvAlgoTxId
|
||||||
|
// }
|
||||||
|
// const mytime = new Date()
|
||||||
|
// console.log('my time', mytime.getTime() / 1000)
|
||||||
|
// console.log('compute valid until ==', computeValidUntil)
|
||||||
|
// providerInitializeComputeResults = await ProviderInstance.initializeCompute(
|
||||||
|
// assets,
|
||||||
|
// algo,
|
||||||
|
// computeEnv.id,
|
||||||
|
// computeValidUntil,
|
||||||
|
// providerUrl,
|
||||||
|
// consumerAccount
|
||||||
|
// )
|
||||||
|
// console.log(
|
||||||
|
// 'second job providerInitializeComputeResults',
|
||||||
|
// providerInitializeComputeResults
|
||||||
|
// )
|
||||||
|
// assert(
|
||||||
|
// providerInitializeComputeResults.algorithm.validOrder,
|
||||||
|
// 'We should have a valid order for algorithm'
|
||||||
|
// )
|
||||||
|
// assert(
|
||||||
|
// !providerInitializeComputeResults.algorithm.providerFee,
|
||||||
|
// 'We should not pay providerFees again for algorithm'
|
||||||
|
// )
|
||||||
|
// assert(
|
||||||
|
// providerInitializeComputeResults.datasets[0].validOrder,
|
||||||
|
// 'We should have a valid order for dataset'
|
||||||
|
// )
|
||||||
|
// assert(
|
||||||
|
// !providerInitializeComputeResults.datasets[0].providerFee,
|
||||||
|
// 'We should not pay providerFees again for dataset'
|
||||||
|
// )
|
||||||
|
// algo.transferTxId = providerInitializeComputeResults.algorithm.validOrder
|
||||||
|
// assets[0].transferTxId = providerInitializeComputeResults.datasets[0].validOrder
|
||||||
|
// assert(
|
||||||
|
// algo.transferTxId === freeEnvAlgoTxId &&
|
||||||
|
// assets[0].transferTxId === freeEnvDatasetTxId,
|
||||||
|
// 'We should use the same orders, because no fess must be paid'
|
||||||
|
// )
|
||||||
|
// const computeJobs = await ProviderInstance.computeStart(
|
||||||
|
// providerUrl,
|
||||||
|
// web3,
|
||||||
|
// consumerAccount,
|
||||||
|
// computeEnv.id,
|
||||||
|
// assets[0],
|
||||||
|
// algo
|
||||||
|
// )
|
||||||
|
// assert(computeJobs, 'Cannot start compute job')
|
||||||
|
// })
|
||||||
|
|
||||||
|
// it('should restart a computeJob on paid environment, without paying anything, because order is valid and providerFees are still valid', async () => {
|
||||||
|
// sleep(10000)
|
||||||
|
// // we choose the paid env
|
||||||
|
// const computeEnv = computeEnvs.find((ce) => ce.priceMin !== 0)
|
||||||
|
// assert(computeEnv, 'Cannot find the free compute env')
|
||||||
|
|
||||||
|
// const assets: ComputeAsset[] = [
|
||||||
|
// {
|
||||||
|
// documentId: resolvedDdoWith1mTimeout.id,
|
||||||
|
// serviceId: resolvedDdoWith1mTimeout.services[0].id,
|
||||||
|
// transferTxId: paidEnvDatasetTxId
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
// const algo: ComputeAlgorithm = {
|
||||||
|
// documentId: resolvedAlgoDdoWith1mTimeout.id,
|
||||||
|
// serviceId: resolvedAlgoDdoWith1mTimeout.services[0].id,
|
||||||
|
// transferTxId: paidEnvAlgoTxId
|
||||||
|
// }
|
||||||
|
|
||||||
|
// providerInitializeComputeResults = await ProviderInstance.initializeCompute(
|
||||||
|
// assets,
|
||||||
|
// algo,
|
||||||
|
// computeEnv.id,
|
||||||
|
// computeValidUntil,
|
||||||
|
// providerUrl,
|
||||||
|
// consumerAccount
|
||||||
|
// )
|
||||||
|
// assert(
|
||||||
|
// providerInitializeComputeResults.algorithm.validOrder,
|
||||||
|
// 'We should have a valid order for algorithm'
|
||||||
|
// )
|
||||||
|
// assert(
|
||||||
|
// !providerInitializeComputeResults.algorithm.providerFee,
|
||||||
|
// 'We should not pay providerFees again for algorithm'
|
||||||
|
// )
|
||||||
|
// assert(
|
||||||
|
// providerInitializeComputeResults.datasets[0].validOrder,
|
||||||
|
// 'We should have a valid order for dataset'
|
||||||
|
// )
|
||||||
|
// assert(
|
||||||
|
// !providerInitializeComputeResults.datasets[0].providerFee,
|
||||||
|
// 'We should not pay providerFees again for dataset'
|
||||||
|
// )
|
||||||
|
// algo.transferTxId = providerInitializeComputeResults.algorithm.validOrder
|
||||||
|
// assets[0].transferTxId = providerInitializeComputeResults.datasets[0].validOrder
|
||||||
|
// assert(
|
||||||
|
// algo.transferTxId === paidEnvAlgoTxId &&
|
||||||
|
// assets[0].transferTxId === paidEnvDatasetTxId,
|
||||||
|
// 'We should use the same orders, because no fess must be paid'
|
||||||
|
// )
|
||||||
|
// const computeJobs = await ProviderInstance.computeStart(
|
||||||
|
// providerUrl,
|
||||||
|
// web3,
|
||||||
|
// consumerAccount,
|
||||||
|
// computeEnv.id,
|
||||||
|
// assets[0],
|
||||||
|
// algo
|
||||||
|
// )
|
||||||
|
// assert(computeJobs, 'Cannot start compute job')
|
||||||
|
// })
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user