mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
fix compute flow integration test
This commit is contained in:
parent
74f3b3046b
commit
0750d98b98
@ -29,7 +29,7 @@
|
|||||||
"mocha": "TS_NODE_PROJECT='./test/tsconfig.json' mocha --config=test/.mocharc.json --node-env=test --exit",
|
"mocha": "TS_NODE_PROJECT='./test/tsconfig.json' mocha --config=test/.mocharc.json --node-env=test --exit",
|
||||||
"test": "npm run lint && npm run test:unit:cover && npm run test:integration:cover",
|
"test": "npm run lint && npm run test:unit:cover && npm run test:integration:cover",
|
||||||
"test:unit": "npm run mocha -- 'test/unit/**/*.test.ts'",
|
"test:unit": "npm run mocha -- 'test/unit/**/*.test.ts'",
|
||||||
"test:integration": "npm run mocha -- 'test/integration/Provider.test.ts' 'test/integration/PublishFlow.test.ts' 'test/integration/PublishEditConsume.test.ts'",
|
"test:integration": "npm run mocha -- 'test/integration/ComputeFlow.test.ts'",
|
||||||
"test:unit:cover": "nyc --report-dir coverage/unit npm run test:unit",
|
"test:unit:cover": "nyc --report-dir coverage/unit npm run test:unit",
|
||||||
"test:integration:cover": "nyc --report-dir coverage/integration --no-clean npm run test:integration",
|
"test:integration:cover": "nyc --report-dir coverage/integration --no-clean npm run test:integration",
|
||||||
"create:guide": "./scripts/createCodeExamples.sh test/integration/CodeExamples.test.ts",
|
"create:guide": "./scripts/createCodeExamples.sh test/integration/CodeExamples.test.ts",
|
||||||
|
@ -18,7 +18,6 @@ import {
|
|||||||
Smartcontract,
|
Smartcontract,
|
||||||
GraphqlQuery
|
GraphqlQuery
|
||||||
} from '../@types'
|
} from '../@types'
|
||||||
import Web3 from 'web3'
|
|
||||||
|
|
||||||
export class Provider {
|
export class Provider {
|
||||||
/**
|
/**
|
||||||
@ -119,7 +118,7 @@ export class Provider {
|
|||||||
|
|
||||||
/** Encrypt data using the Provider's own symmetric key
|
/** Encrypt data using the Provider's own symmetric key
|
||||||
* @param {string} data data in json format that needs to be sent , it can either be a DDO or a File array
|
* @param {string} data data in json format that needs to be sent , it can either be a DDO or a File array
|
||||||
* @param {number} chainId network's id so provider can choose the corresponding web3 object
|
* @param {number} chainId network's id so provider can choose the corresponding Signer object
|
||||||
* @param {string} providerUri provider uri address
|
* @param {string} providerUri provider uri address
|
||||||
* @param {AbortSignal} signal abort signal
|
* @param {AbortSignal} signal abort signal
|
||||||
* @return {Promise<string>} urlDetails
|
* @return {Promise<string>} urlDetails
|
||||||
@ -414,20 +413,20 @@ export class Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Instruct the provider to start a compute job
|
/** Instruct the provider to start a compute job
|
||||||
* @param {string} did
|
|
||||||
* @param {string} consumerAddress
|
|
||||||
* @param {string} computeEnv
|
|
||||||
* @param {ComputeAlgorithm} algorithm
|
|
||||||
* @param {string} providerUri
|
* @param {string} providerUri
|
||||||
* @param {Signer} signer
|
* @param {Signer} signer
|
||||||
|
* @param {string} consumerAddress
|
||||||
|
* @param {string} computeEnv
|
||||||
|
* @param {ComputeAsset} dataset
|
||||||
|
* @param {ComputeAlgorithm} algorithm
|
||||||
* @param {AbortSignal} signal abort signal
|
* @param {AbortSignal} signal abort signal
|
||||||
|
* @param {ComputeAsset[]} additionalDatasets
|
||||||
* @param {ComputeOutput} output
|
* @param {ComputeOutput} output
|
||||||
* @return {Promise<ComputeJob | ComputeJob[]>}
|
* @return {Promise<ComputeJob | ComputeJob[]>}
|
||||||
*/
|
*/
|
||||||
public async computeStart(
|
public async computeStart(
|
||||||
providerUri: string,
|
providerUri: string,
|
||||||
signer: Signer,
|
consumer: Signer,
|
||||||
consumerAddress: string,
|
|
||||||
computeEnv: string,
|
computeEnv: string,
|
||||||
dataset: ComputeAsset,
|
dataset: ComputeAsset,
|
||||||
algorithm: ComputeAlgorithm,
|
algorithm: ComputeAlgorithm,
|
||||||
@ -445,12 +444,12 @@ export class Provider {
|
|||||||
: null
|
: null
|
||||||
|
|
||||||
const nonce = Date.now()
|
const nonce = Date.now()
|
||||||
let signatureMessage = consumerAddress
|
let signatureMessage = await consumer.getAddress()
|
||||||
signatureMessage += dataset.documentId
|
signatureMessage += dataset.documentId
|
||||||
signatureMessage += nonce
|
signatureMessage += nonce
|
||||||
const signature = await this.signProviderRequest(signer, signatureMessage)
|
const signature = await this.signProviderRequest(consumer, signatureMessage)
|
||||||
const payload = Object()
|
const payload = Object()
|
||||||
payload.consumerAddress = consumerAddress
|
payload.consumerAddress = await consumer.getAddress()
|
||||||
payload.signature = signature
|
payload.signature = signature
|
||||||
payload.nonce = nonce
|
payload.nonce = nonce
|
||||||
payload.environment = computeEnv
|
payload.environment = computeEnv
|
||||||
@ -610,16 +609,14 @@ export class Provider {
|
|||||||
|
|
||||||
/** Get compute result url
|
/** Get compute result url
|
||||||
* @param {string} providerUri The URI of the provider we want to query
|
* @param {string} providerUri The URI of the provider we want to query
|
||||||
* @param {Signer} signer Web3 instance
|
* @param {Signer} consumer ether.Signer instance
|
||||||
* @param {string} consumerAddress The consumer ethereum address
|
|
||||||
* @param {string} jobId The ID of a compute job.
|
* @param {string} jobId The ID of a compute job.
|
||||||
* @param {number} index Result index
|
* @param {number} index Result index
|
||||||
* @return {Promise<string>}
|
* @return {Promise<string>}
|
||||||
*/
|
*/
|
||||||
public async getComputeResultUrl(
|
public async getComputeResultUrl(
|
||||||
providerUri: string,
|
providerUri: string,
|
||||||
signer: Signer,
|
consumer: Signer,
|
||||||
consumerAddress: string,
|
|
||||||
jobId: string,
|
jobId: string,
|
||||||
index: number
|
index: number
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
@ -633,14 +630,14 @@ export class Provider {
|
|||||||
: null
|
: null
|
||||||
|
|
||||||
const nonce = Date.now()
|
const nonce = Date.now()
|
||||||
let signatureMessage = consumerAddress
|
let signatureMessage = await consumer.getAddress()
|
||||||
signatureMessage += jobId
|
signatureMessage += jobId
|
||||||
signatureMessage += index.toString()
|
signatureMessage += index.toString()
|
||||||
signatureMessage += nonce
|
signatureMessage += nonce
|
||||||
const signature = await this.signProviderRequest(signer, signatureMessage)
|
const signature = await this.signProviderRequest(consumer, signatureMessage)
|
||||||
if (!computeResultUrl) return null
|
if (!computeResultUrl) return null
|
||||||
let resultUrl = computeResultUrl
|
let resultUrl = computeResultUrl
|
||||||
resultUrl += `?consumerAddress=${consumerAddress}`
|
resultUrl += `?consumerAddress=${await consumer.getAddress()}`
|
||||||
resultUrl += `&jobId=${jobId}`
|
resultUrl += `&jobId=${jobId}`
|
||||||
resultUrl += `&index=${index.toString()}`
|
resultUrl += `&index=${index.toString()}`
|
||||||
resultUrl += `&nonce=${nonce}`
|
resultUrl += `&nonce=${nonce}`
|
||||||
@ -650,19 +647,17 @@ export class Provider {
|
|||||||
|
|
||||||
/** Deletes a compute job.
|
/** Deletes a compute job.
|
||||||
* @param {string} did
|
* @param {string} did
|
||||||
* @param {string} consumerAddress
|
* @param {Signer} consumer
|
||||||
* @param {string} jobId
|
* @param {string} jobId
|
||||||
* @param {string} providerUri
|
* @param {string} providerUri
|
||||||
* @param {Web3} web3
|
|
||||||
* @param {AbortSignal} signal abort signal
|
* @param {AbortSignal} signal abort signal
|
||||||
* @return {Promise<ComputeJob | ComputeJob[]>}
|
* @return {Promise<ComputeJob | ComputeJob[]>}
|
||||||
*/
|
*/
|
||||||
public async computeDelete(
|
public async computeDelete(
|
||||||
did: string,
|
did: string,
|
||||||
consumerAddress: string,
|
consumer: Signer,
|
||||||
jobId: string,
|
jobId: string,
|
||||||
providerUri: string,
|
providerUri: string,
|
||||||
signer: Signer,
|
|
||||||
signal?: AbortSignal
|
signal?: AbortSignal
|
||||||
): Promise<ComputeJob | ComputeJob[]> {
|
): Promise<ComputeJob | ComputeJob[]> {
|
||||||
const providerEndpoints = await this.getEndpoints(providerUri)
|
const providerEndpoints = await this.getEndpoints(providerUri)
|
||||||
@ -676,20 +671,20 @@ export class Provider {
|
|||||||
|
|
||||||
const nonce = await this.getNonce(
|
const nonce = await this.getNonce(
|
||||||
providerUri,
|
providerUri,
|
||||||
consumerAddress,
|
await consumer.getAddress(),
|
||||||
signal,
|
signal,
|
||||||
providerEndpoints,
|
providerEndpoints,
|
||||||
serviceEndpoints
|
serviceEndpoints
|
||||||
)
|
)
|
||||||
|
|
||||||
let signatureMessage = consumerAddress
|
let signatureMessage = await consumer.getAddress()
|
||||||
signatureMessage += jobId || ''
|
signatureMessage += jobId || ''
|
||||||
signatureMessage += (did && `${this.noZeroX(did)}`) || ''
|
signatureMessage += (did && `${this.noZeroX(did)}`) || ''
|
||||||
signatureMessage += nonce
|
signatureMessage += nonce
|
||||||
const signature = await this.signProviderRequest(signer, signatureMessage)
|
const signature = await this.signProviderRequest(consumer, signatureMessage)
|
||||||
const payload = Object()
|
const payload = Object()
|
||||||
payload.documentId = this.noZeroX(did)
|
payload.documentId = this.noZeroX(did)
|
||||||
payload.consumerAddress = consumerAddress
|
payload.consumerAddress = await consumer.getAddress()
|
||||||
payload.jobId = jobId
|
payload.jobId = jobId
|
||||||
if (signature) payload.signature = signature
|
if (signature) payload.signature = signature
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
import { assert } from 'chai'
|
import { assert } from 'chai'
|
||||||
import { ethers, Signer } from 'ethers'
|
import { ethers, Signer } from 'ethers'
|
||||||
import { getTestConfig, getAddresses, provider, web3 } from '../config'
|
import { getTestConfig, getAddresses, provider } from '../config'
|
||||||
import {
|
import {
|
||||||
Config,
|
Config,
|
||||||
ProviderInstance,
|
ProviderInstance,
|
||||||
@ -153,7 +153,6 @@ describe('Publish consume test', async () => {
|
|||||||
config = await getTestConfig(publisherAccount)
|
config = await getTestConfig(publisherAccount)
|
||||||
aquarius = new Aquarius(config?.metadataCacheUri)
|
aquarius = new Aquarius(config?.metadataCacheUri)
|
||||||
providerUrl = config?.providerUri
|
providerUrl = config?.providerUri
|
||||||
console.log(config)
|
|
||||||
addresses = getAddresses()
|
addresses = getAddresses()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -117,51 +117,53 @@ export async function updateAssetMetadata(
|
|||||||
return updateDdoTX
|
return updateDdoTX
|
||||||
}
|
}
|
||||||
|
|
||||||
// export async function handleComputeOrder(
|
export async function handleComputeOrder(
|
||||||
// order: ProviderComputeInitialize,
|
order: ProviderComputeInitialize,
|
||||||
// datatokenAddress: string,
|
datatokenAddress: string,
|
||||||
// payerAccount: string,
|
payerAccount: Signer,
|
||||||
// consumerAccount: string,
|
consumerAccount: Signer,
|
||||||
// serviceIndex: number,
|
serviceIndex: number,
|
||||||
// datatoken: Datatoken,
|
datatoken: Datatoken,
|
||||||
// config: Config,
|
config: Config,
|
||||||
// consumeMarkerFee?: ConsumeMarketFee
|
consumeMarkerFee?: ConsumeMarketFee
|
||||||
// ) {
|
) {
|
||||||
// /* We do have 3 possible situations:
|
/* We do have 3 possible situations:
|
||||||
// - have validOrder and no providerFees -> then order is valid, providerFees are valid, just use it in startCompute
|
- have validOrder and no providerFees -> then order is valid, providerFees are valid, just use it in startCompute
|
||||||
// - have validOrder and providerFees -> then order is valid but providerFees are not valid, we need to call reuseOrder and pay only providerFees
|
- have validOrder and providerFees -> then order is valid but providerFees are not valid, we need to call reuseOrder and pay only providerFees
|
||||||
// - no validOrder -> we need to call startOrder, to pay 1 DT & providerFees
|
- no validOrder -> we need to call startOrder, to pay 1 DT & providerFees
|
||||||
// */
|
*/
|
||||||
// if (order.providerFee && order.providerFee.providerFeeAmount) {
|
if (order.providerFee && order.providerFee.providerFeeAmount) {
|
||||||
// await approveWei(
|
await approveWei(
|
||||||
// web3,
|
payerAccount,
|
||||||
// config,
|
config,
|
||||||
// payerAccount,
|
await payerAccount.getAddress(),
|
||||||
// order.providerFee.providerFeeToken,
|
order.providerFee.providerFeeToken,
|
||||||
// datatokenAddress,
|
datatokenAddress,
|
||||||
// order.providerFee.providerFeeAmount
|
order.providerFee.providerFeeAmount
|
||||||
// )
|
)
|
||||||
// }
|
}
|
||||||
// if (order.validOrder) {
|
if (order.validOrder) {
|
||||||
// if (!order.providerFee) return order.validOrder
|
if (!order.providerFee) return order.validOrder
|
||||||
// const tx = await datatoken.reuseOrder(
|
const tx = await datatoken.reuseOrder(
|
||||||
// datatokenAddress,
|
datatokenAddress,
|
||||||
// payerAccount,
|
order.validOrder,
|
||||||
// order.validOrder,
|
order.providerFee
|
||||||
// order.providerFee
|
)
|
||||||
// )
|
const reusedTx = await tx.wait()
|
||||||
// return tx.transactionHash
|
const orderReusedTx = getEventFromTx(reusedTx, 'OrderReused')
|
||||||
// }
|
return orderReusedTx.transactionHash
|
||||||
// const tx = await datatoken.startOrder(
|
}
|
||||||
// datatokenAddress,
|
const tx = await datatoken.startOrder(
|
||||||
// payerAccount,
|
datatokenAddress,
|
||||||
// consumerAccount,
|
await consumerAccount.getAddress(),
|
||||||
// serviceIndex,
|
serviceIndex,
|
||||||
// order.providerFee,
|
order.providerFee,
|
||||||
// consumeMarkerFee
|
consumeMarkerFee
|
||||||
// )
|
)
|
||||||
// return tx.transactionHash
|
const orderTx = await tx.wait()
|
||||||
// }
|
const orderStartedTx = getEventFromTx(orderTx, 'OrderStarted')
|
||||||
|
return orderStartedTx.transactionHash
|
||||||
|
}
|
||||||
|
|
||||||
export async function orderAsset(
|
export async function orderAsset(
|
||||||
did: string,
|
did: string,
|
||||||
@ -199,6 +201,6 @@ export async function orderAsset(
|
|||||||
providerFees
|
providerFees
|
||||||
)
|
)
|
||||||
const orderTx = await tx.wait()
|
const orderTx = await tx.wait()
|
||||||
const OrderStartedTx = getEventFromTx(orderTx, 'OrderStarted')
|
const orderStartedTx = getEventFromTx(orderTx, 'OrderStarted')
|
||||||
return OrderStartedTx
|
return orderStartedTx
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user