mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
more tests
This commit is contained in:
parent
2cbc02e1d5
commit
228c01c98f
@ -140,6 +140,7 @@ export class Compute extends Instantiable {
|
|||||||
additionalInputs
|
additionalInputs
|
||||||
)
|
)
|
||||||
if (computeJobsList) return computeJobsList[0] as ComputeJob
|
if (computeJobsList) return computeJobsList[0] as ComputeJob
|
||||||
|
else return null
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@ -162,7 +163,8 @@ export class Compute extends Instantiable {
|
|||||||
const provider = await Provider.getInstance(this.instanceConfig)
|
const provider = await Provider.getInstance(this.instanceConfig)
|
||||||
await provider.setBaseUrl(serviceEndpoint)
|
await provider.setBaseUrl(serviceEndpoint)
|
||||||
const computeJobsList = await provider.computeStop(did, consumerAccount, jobId)
|
const computeJobsList = await provider.computeStop(did, consumerAccount, jobId)
|
||||||
return computeJobsList[0] as ComputeJob
|
if (computeJobsList) return computeJobsList[0] as ComputeJob
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -183,7 +185,8 @@ export class Compute extends Instantiable {
|
|||||||
const provider = await Provider.getInstance(this.instanceConfig)
|
const provider = await Provider.getInstance(this.instanceConfig)
|
||||||
await provider.setBaseUrl(serviceEndpoint)
|
await provider.setBaseUrl(serviceEndpoint)
|
||||||
const computeJobsList = await provider.computeDelete(did, consumerAccount, jobId)
|
const computeJobsList = await provider.computeDelete(did, consumerAccount, jobId)
|
||||||
return computeJobsList[0] as ComputeJob
|
if (computeJobsList) return computeJobsList[0] as ComputeJob
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -220,7 +223,6 @@ export class Compute extends Instantiable {
|
|||||||
txId,
|
txId,
|
||||||
sign
|
sign
|
||||||
)
|
)
|
||||||
|
|
||||||
return computeJobsList as ComputeJob[]
|
return computeJobsList as ComputeJob[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,9 +115,11 @@ export class Provider extends Instantiable {
|
|||||||
document: JSON.stringify(document),
|
document: JSON.stringify(document),
|
||||||
publisherAddress: account.getId()
|
publisherAddress: account.getId()
|
||||||
}
|
}
|
||||||
|
const path = this.getEncryptEndpoint() ? this.getEncryptEndpoint().urlPath : null
|
||||||
|
if (!path) return null
|
||||||
try {
|
try {
|
||||||
const response = await this.ocean.utils.fetch.post(
|
const response = await this.ocean.utils.fetch.post(
|
||||||
this.getEncryptEndpoint().urlPath,
|
path,
|
||||||
decodeURI(JSON.stringify(args))
|
decodeURI(JSON.stringify(args))
|
||||||
)
|
)
|
||||||
return (await response.json()).encryptedDocument
|
return (await response.json()).encryptedDocument
|
||||||
@ -137,11 +139,10 @@ export class Provider extends Instantiable {
|
|||||||
if (url instanceof DID) {
|
if (url instanceof DID) {
|
||||||
args = { did: url.getDid() }
|
args = { did: url.getDid() }
|
||||||
} else args = { url }
|
} else args = { url }
|
||||||
|
const path = this.getFileinfoEndpoint() ? this.getFileinfoEndpoint().urlPath : null
|
||||||
|
if (!path) return null
|
||||||
try {
|
try {
|
||||||
const response = await this.ocean.utils.fetch.post(
|
const response = await this.ocean.utils.fetch.post(path, JSON.stringify(args))
|
||||||
this.getFileinfoEndpoint().urlPath,
|
|
||||||
JSON.stringify(args)
|
|
||||||
)
|
|
||||||
const results: File[] = await response.json()
|
const results: File[] = await response.json()
|
||||||
for (const result of results) {
|
for (const result of results) {
|
||||||
files.push(result)
|
files.push(result)
|
||||||
@ -157,10 +158,12 @@ export class Provider extends Instantiable {
|
|||||||
* @return {Promise<string>} string
|
* @return {Promise<string>} string
|
||||||
*/
|
*/
|
||||||
public async getNonce(consumerAddress: string): Promise<string> {
|
public async getNonce(consumerAddress: string): Promise<string> {
|
||||||
let initializeUrl = this.getNonceEndpoint().urlPath
|
const path = this.getNonceEndpoint() ? this.getNonceEndpoint().urlPath : null
|
||||||
initializeUrl += `?userAddress=${consumerAddress}`
|
if (!path) return null
|
||||||
try {
|
try {
|
||||||
const response = await this.ocean.utils.fetch.get(initializeUrl)
|
const response = await this.ocean.utils.fetch.get(
|
||||||
|
path + `?userAddress=${consumerAddress}`
|
||||||
|
)
|
||||||
this.nonce = String((await response.json()).nonce)
|
this.nonce = String((await response.json()).nonce)
|
||||||
return this.nonce
|
return this.nonce
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -183,8 +186,10 @@ export class Provider extends Instantiable {
|
|||||||
this.logger.error(e)
|
this.logger.error(e)
|
||||||
throw new Error('Failed to resolve DID')
|
throw new Error('Failed to resolve DID')
|
||||||
}
|
}
|
||||||
|
let initializeUrl = this.getInitializeEndpoint()
|
||||||
let initializeUrl = this.getInitializeEndpoint().urlPath
|
? this.getInitializeEndpoint().urlPath
|
||||||
|
: null
|
||||||
|
if (!initializeUrl) return null
|
||||||
initializeUrl += `?documentId=${did}`
|
initializeUrl += `?documentId=${did}`
|
||||||
initializeUrl += `&serviceId=${serviceIndex}`
|
initializeUrl += `&serviceId=${serviceIndex}`
|
||||||
initializeUrl += `&serviceType=${serviceType}`
|
initializeUrl += `&serviceType=${serviceType}`
|
||||||
@ -212,10 +217,12 @@ export class Provider extends Instantiable {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
await this.getNonce(account.getId())
|
await this.getNonce(account.getId())
|
||||||
const signature = await this.createSignature(account, did + this.nonce)
|
const signature = await this.createSignature(account, did + this.nonce)
|
||||||
|
const path = this.getDownloadEndpoint() ? this.getDownloadEndpoint().urlPath : null
|
||||||
|
if (!path) return null
|
||||||
const filesPromises = files
|
const filesPromises = files
|
||||||
.filter((_, i) => index === -1 || i === index)
|
.filter((_, i) => index === -1 || i === index)
|
||||||
.map(async ({ index: i }) => {
|
.map(async ({ index: i }) => {
|
||||||
let consumeUrl = this.getDownloadEndpoint().urlPath
|
let consumeUrl = path
|
||||||
consumeUrl += `?fileIndex=${i}`
|
consumeUrl += `?fileIndex=${i}`
|
||||||
consumeUrl += `&documentId=${did}`
|
consumeUrl += `&documentId=${did}`
|
||||||
consumeUrl += `&serviceId=${serviceIndex}`
|
consumeUrl += `&serviceId=${serviceIndex}`
|
||||||
@ -282,10 +289,11 @@ export class Provider extends Instantiable {
|
|||||||
if (tokenAddress) payload.dataToken = tokenAddress
|
if (tokenAddress) payload.dataToken = tokenAddress
|
||||||
|
|
||||||
if (additionalInputs) payload.additionalInputs = additionalInputs
|
if (additionalInputs) payload.additionalInputs = additionalInputs
|
||||||
|
const path = this.getComputeStartEndpoint()
|
||||||
|
? this.getComputeStartEndpoint().urlPath
|
||||||
|
: null
|
||||||
|
if (!path) return null
|
||||||
try {
|
try {
|
||||||
let path = null
|
|
||||||
if (this.getComputeStartEndpoint().urlPath)
|
|
||||||
path = this.getComputeStartEndpoint().urlPath
|
|
||||||
const response = await this.ocean.utils.fetch.post(path, JSON.stringify(payload))
|
const response = await this.ocean.utils.fetch.post(path, JSON.stringify(payload))
|
||||||
if (response?.ok) {
|
if (response?.ok) {
|
||||||
const params = await response.json()
|
const params = await response.json()
|
||||||
@ -321,10 +329,11 @@ export class Provider extends Instantiable {
|
|||||||
payload.signature = signature
|
payload.signature = signature
|
||||||
payload.jobId = jobId
|
payload.jobId = jobId
|
||||||
payload.consumerAddress = address
|
payload.consumerAddress = address
|
||||||
|
const path = this.getComputeStopEndpoint()
|
||||||
|
? this.getComputeStopEndpoint().urlPath
|
||||||
|
: null
|
||||||
|
if (!path) return null
|
||||||
try {
|
try {
|
||||||
let path = null
|
|
||||||
if (this.getComputeStopEndpoint().urlPath)
|
|
||||||
path = this.getComputeStopEndpoint().urlPath
|
|
||||||
const response = await this.ocean.utils.fetch.put(path, JSON.stringify(payload))
|
const response = await this.ocean.utils.fetch.put(path, JSON.stringify(payload))
|
||||||
if (response?.ok) {
|
if (response?.ok) {
|
||||||
const params = await response.json()
|
const params = await response.json()
|
||||||
@ -360,10 +369,11 @@ export class Provider extends Instantiable {
|
|||||||
payload.signature = signature
|
payload.signature = signature
|
||||||
payload.jobId = jobId
|
payload.jobId = jobId
|
||||||
payload.consumerAddress = address
|
payload.consumerAddress = address
|
||||||
|
const path = this.getComputeDeleteEndpoint()
|
||||||
|
? this.getComputeDeleteEndpoint().urlPath
|
||||||
|
: null
|
||||||
|
if (!path) return null
|
||||||
try {
|
try {
|
||||||
let path = null
|
|
||||||
if (this.getComputeDeleteEndpoint().urlPath)
|
|
||||||
path = this.getComputeDeleteEndpoint().urlPath
|
|
||||||
const response = await this.ocean.utils.fetch.delete(path, JSON.stringify(payload))
|
const response = await this.ocean.utils.fetch.delete(path, JSON.stringify(payload))
|
||||||
if (response?.ok) {
|
if (response?.ok) {
|
||||||
const params = await response.json()
|
const params = await response.json()
|
||||||
@ -407,11 +417,11 @@ export class Provider extends Instantiable {
|
|||||||
url += (jobId && `&jobId=${jobId}`) || ''
|
url += (jobId && `&jobId=${jobId}`) || ''
|
||||||
url += `&consumerAddress=${address}`
|
url += `&consumerAddress=${address}`
|
||||||
url += (txId && `&transferTxId=${txId}`) || ''
|
url += (txId && `&transferTxId=${txId}`) || ''
|
||||||
|
const path = this.getComputeStatusEndpoint()
|
||||||
|
? this.getComputeStatusEndpoint().urlPath
|
||||||
|
: null
|
||||||
|
if (!path) return null
|
||||||
try {
|
try {
|
||||||
let path = null
|
|
||||||
if (this.getComputeStatusEndpoint().urlPath)
|
|
||||||
path = this.getComputeStatusEndpoint().urlPath
|
|
||||||
const response = await this.ocean.utils.fetch.get(path + url)
|
const response = await this.ocean.utils.fetch.get(path + url)
|
||||||
/* response = await fetch(this.getComputeEndpoint() + url, {
|
/* response = await fetch(this.getComputeEndpoint() + url, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user