mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
add provider compute mock
This commit is contained in:
parent
1b61723dba
commit
60c406bcea
@ -19,7 +19,7 @@
|
|||||||
"changelog": "auto-changelog -p",
|
"changelog": "auto-changelog -p",
|
||||||
"prepublishOnly": "npm run build",
|
"prepublishOnly": "npm run build",
|
||||||
"test:unit": "mocha --config=test/unit/.mocharc.json --node-env=test --exit test/unit/**/*.ts",
|
"test:unit": "mocha --config=test/unit/.mocharc.json --node-env=test --exit test/unit/**/*.ts",
|
||||||
"test:integration": "mocha --config=test/integration/.mocharc.json --node-env=test --exit test/integration/**/*.ts",
|
"test:integration": "mocha --config=test/integration/.mocharc.json --node-env=test --exit test/integration/*.ts",
|
||||||
"test:cover": "nyc --report-dir coverage/unit npm run test:unit"
|
"test:cover": "nyc --report-dir coverage/unit npm run test:unit"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
116
test/integration/__mocks__/Provider.Mock.ts
Normal file
116
test/integration/__mocks__/Provider.Mock.ts
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
import Account from '../../../src/ocean/Account'
|
||||||
|
import { Provider } from '../../../src/provider/Provider'
|
||||||
|
import { noZeroX } from '../../../src/utils'
|
||||||
|
import { ComputeJob } from '../../../src/ocean/interfaces/ComputeJob'
|
||||||
|
import { Output } from '../../../src/ocean/interfaces/ComputeOutput'
|
||||||
|
import { MetadataAlgorithm } from '../../../src/ddo/interfaces/MetadataAlgorithm'
|
||||||
|
|
||||||
|
export default class ProviderMock extends Provider {
|
||||||
|
public async compute(
|
||||||
|
method: string,
|
||||||
|
did: string,
|
||||||
|
consumerAccount: Account,
|
||||||
|
algorithmDid?: string,
|
||||||
|
algorithmMeta?: MetadataAlgorithm,
|
||||||
|
jobId?: string,
|
||||||
|
output?: Output,
|
||||||
|
txId?: string,
|
||||||
|
serviceIndex?: string,
|
||||||
|
serviceType?: string,
|
||||||
|
tokenAddress?: string
|
||||||
|
): Promise<ComputeJob | ComputeJob[]> {
|
||||||
|
const address = consumerAccount.getId()
|
||||||
|
|
||||||
|
let signatureMessage = address
|
||||||
|
signatureMessage += jobId || ''
|
||||||
|
signatureMessage += (did && `${noZeroX(did)}`) || ''
|
||||||
|
const signature = await this.createHashSignature(
|
||||||
|
consumerAccount,
|
||||||
|
signatureMessage
|
||||||
|
)
|
||||||
|
|
||||||
|
// construct Brizo URL
|
||||||
|
let url = this.getComputeEndpoint()
|
||||||
|
url += `?signature=${signature}`
|
||||||
|
url += `&documentId=${noZeroX(did)}`
|
||||||
|
url += (output && `&output=${JSON.stringify(output)}`) || ''
|
||||||
|
url += (algorithmDid && `&algorithmDid=${algorithmDid}`) || ''
|
||||||
|
url +=
|
||||||
|
(algorithmMeta &&
|
||||||
|
`&algorithmMeta=${encodeURIComponent(JSON.stringify(algorithmMeta))}`) ||
|
||||||
|
''
|
||||||
|
url += (jobId && `&jobId=${jobId}`) || ''
|
||||||
|
url += `&consumerAddress=${address}`
|
||||||
|
url += `&transferTxId=${txId}` || ''
|
||||||
|
url += `&serviceId=${serviceIndex}` || ''
|
||||||
|
url += `&serviceType=${serviceType}` || ''
|
||||||
|
url += `&dataToken=${tokenAddress}` || ''
|
||||||
|
url += `&consumerAddress=${consumerAccount.getId()}` || ''
|
||||||
|
|
||||||
|
// switch fetch method
|
||||||
|
let fetch
|
||||||
|
|
||||||
|
switch (method) {
|
||||||
|
case 'post': // start
|
||||||
|
fetch = Promise.resolve({
|
||||||
|
jobId: '0x1111:001',
|
||||||
|
status: 1,
|
||||||
|
statusText: 'Job started'
|
||||||
|
})
|
||||||
|
break
|
||||||
|
case 'put': // stop
|
||||||
|
fetch = Promise.resolve([
|
||||||
|
{
|
||||||
|
status: 7,
|
||||||
|
statusText: 'Job stopped'
|
||||||
|
}
|
||||||
|
])
|
||||||
|
break
|
||||||
|
case 'delete':
|
||||||
|
fetch = Promise.resolve([
|
||||||
|
{
|
||||||
|
status: 8,
|
||||||
|
statusText: 'Job deleted successfully'
|
||||||
|
}
|
||||||
|
])
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
// status
|
||||||
|
fetch = Promise.resolve([
|
||||||
|
{
|
||||||
|
owner: '0x1111',
|
||||||
|
documentId: 'did:op:2222',
|
||||||
|
jobId: '3333',
|
||||||
|
dateCreated: '2020-10-01T01:00:00Z',
|
||||||
|
dateFinished: '2020-10-01T01:00:00Z',
|
||||||
|
status: 5,
|
||||||
|
statusText: 'Job finished',
|
||||||
|
algorithmLogUrl: 'http://example.net/logs/algo.log',
|
||||||
|
resultsUrls: [
|
||||||
|
'http://example.net/logs/output/0',
|
||||||
|
'http://example.net/logs/output/1'
|
||||||
|
],
|
||||||
|
resultsDid:
|
||||||
|
'did:op:87bdaabb33354d2eb014af5091c604fb4b0f67dc6cca4d18a96547bffdc27bcf'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
owner: '0x1111',
|
||||||
|
documentId: 'did:op:2222',
|
||||||
|
jobId: '3334',
|
||||||
|
dateCreated: '2020-10-01T01:00:00Z',
|
||||||
|
dateFinished: '2020-10-01T01:00:00Z',
|
||||||
|
status: 5,
|
||||||
|
statusText: 'Job finished',
|
||||||
|
algorithmLogUrl: 'http://example.net/logs2/algo.log',
|
||||||
|
resultsUrls: [
|
||||||
|
'http://example.net/logs2/output/0',
|
||||||
|
'http://example.net/logs2/output/1'
|
||||||
|
],
|
||||||
|
resultsDid: ''
|
||||||
|
}
|
||||||
|
])
|
||||||
|
break
|
||||||
|
}
|
||||||
|
return await fetch
|
||||||
|
}
|
||||||
|
}
|
@ -41,166 +41,26 @@
|
|||||||
{
|
{
|
||||||
"type": "access",
|
"type": "access",
|
||||||
"index": 0,
|
"index": 0,
|
||||||
"serviceEndpoint": "http://mybrizo.org/api/v1/brizo/services/consume?pubKey=${pubKey}&serviceId={serviceId}&url={url}",
|
"serviceEndpoint": "http://myprovider.org/api/v1/services/consume?pubKey=${pubKey}&serviceId={serviceId}&url={url}",
|
||||||
"templateId": "044852b2a670ade5407e78fb2863c51000000000000000000000000000000000",
|
"templateId": "044852b2a670ade5407e78fb2863c51000000000000000000000000000000000",
|
||||||
"attributes": {
|
"attributes": {
|
||||||
"main": {
|
"main": {
|
||||||
"name": "dataAssetAccessServiceAgreement",
|
"name": "dataAssetAccess",
|
||||||
"creator": "0x36A7f3383A63279cDaF4DfC0F3ABc07d90252C6b",
|
"creator": "0x36A7f3383A63279cDaF4DfC0F3ABc07d90252C6b",
|
||||||
"datePublished": "2019-11-15T14:11:23Z",
|
"datePublished": "2019-11-15T14:11:23Z",
|
||||||
"price": "",
|
"price": "",
|
||||||
"timeout": 36000
|
"timeout": 36000
|
||||||
},
|
|
||||||
"serviceAgreementTemplate": {
|
|
||||||
"contractName": "EscrowAccessSecretStoreTemplate",
|
|
||||||
"events": [
|
|
||||||
{
|
|
||||||
"name": "AgreementCreated",
|
|
||||||
"actorType": "consumer",
|
|
||||||
"handler": {
|
|
||||||
"moduleName": "escrowAccessSecretStoreTemplate",
|
|
||||||
"functionName": "fulfillLockRewardCondition",
|
|
||||||
"version": "0.1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"fulfillmentOrder": [
|
|
||||||
"lockReward.fulfill",
|
|
||||||
"accessSecretStore.fulfill",
|
|
||||||
"escrowReward.fulfill"
|
|
||||||
],
|
|
||||||
"conditionDependency": {
|
|
||||||
"lockReward": [],
|
|
||||||
"accessSecretStore": [],
|
|
||||||
"escrowReward": ["lockReward", "accessSecretStore"]
|
|
||||||
},
|
|
||||||
"conditions": [
|
|
||||||
{
|
|
||||||
"name": "lockReward",
|
|
||||||
"timelock": 0,
|
|
||||||
"timeout": 0,
|
|
||||||
"contractName": "LockRewardCondition",
|
|
||||||
"functionName": "fulfill",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "_rewardAddress",
|
|
||||||
"type": "address",
|
|
||||||
"value": "0x36A7f3383A63279cDaF4DfC0F3ABc07d90252C6b"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "_amount",
|
|
||||||
"type": "uint256",
|
|
||||||
"value": "0"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"events": [
|
|
||||||
{
|
|
||||||
"name": "Fulfilled",
|
|
||||||
"actorType": "publisher",
|
|
||||||
"handler": {
|
|
||||||
"moduleName": "lockRewardCondition",
|
|
||||||
"functionName": "fulfillAccessSecretStoreCondition",
|
|
||||||
"version": "0.1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "accessSecretStore",
|
|
||||||
"timelock": 0,
|
|
||||||
"timeout": 0,
|
|
||||||
"contractName": "AccessSecretStoreCondition",
|
|
||||||
"functionName": "fulfill",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "_documentId",
|
|
||||||
"type": "bytes32",
|
|
||||||
"value": "c678e7e5963d4fdc99afea49ac221d4d4177790f30204417823319d4d35f851f"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "_grantee",
|
|
||||||
"type": "address",
|
|
||||||
"value": ""
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"events": [
|
|
||||||
{
|
|
||||||
"name": "Fulfilled",
|
|
||||||
"actorType": "publisher",
|
|
||||||
"handler": {
|
|
||||||
"moduleName": "accessSecretStore",
|
|
||||||
"functionName": "fulfillEscrowRewardCondition",
|
|
||||||
"version": "0.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "TimedOut",
|
|
||||||
"actorType": "consumer",
|
|
||||||
"handler": {
|
|
||||||
"moduleName": "accessSecretStore",
|
|
||||||
"functionName": "refundReward",
|
|
||||||
"version": "0.1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "escrowReward",
|
|
||||||
"timelock": 0,
|
|
||||||
"timeout": 0,
|
|
||||||
"contractName": "EscrowReward",
|
|
||||||
"functionName": "fulfill",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "_amount",
|
|
||||||
"type": "uint256",
|
|
||||||
"value": "0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "_receiver",
|
|
||||||
"type": "address",
|
|
||||||
"value": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "_sender",
|
|
||||||
"type": "address",
|
|
||||||
"value": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "_lockCondition",
|
|
||||||
"type": "bytes32",
|
|
||||||
"value": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "_releaseCondition",
|
|
||||||
"type": "bytes32",
|
|
||||||
"value": ""
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"events": [
|
|
||||||
{
|
|
||||||
"name": "Fulfilled",
|
|
||||||
"actorType": "publisher",
|
|
||||||
"handler": {
|
|
||||||
"moduleName": "escrowRewardCondition",
|
|
||||||
"functionName": "verifyRewardTokens",
|
|
||||||
"version": "0.1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "compute",
|
"type": "compute",
|
||||||
"index": 1,
|
"index": 1,
|
||||||
"serviceEndpoint": "http://localhost:8030/api/v1/brizo/services/compute",
|
"serviceEndpoint": "http://localhost:8030/api/v1/services/compute",
|
||||||
"templateId": "",
|
"templateId": "",
|
||||||
"attributes": {
|
"attributes": {
|
||||||
"main": {
|
"main": {
|
||||||
"name": "dataAssetComputingServiceAgreement",
|
"name": "dataAssetComputing",
|
||||||
"creator": "0x36A7f3383A63279cDaF4DfC0F3ABc07d90252C6b",
|
"creator": "0x36A7f3383A63279cDaF4DfC0F3ABc07d90252C6b",
|
||||||
"datePublished": "2019-04-09T19:02:11Z",
|
"datePublished": "2019-04-09T19:02:11Z",
|
||||||
"price": "10",
|
"price": "10",
|
||||||
@ -250,147 +110,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalInformation": {},
|
"additionalInformation": {}
|
||||||
"serviceAgreementTemplate": {
|
|
||||||
"contractName": "EscrowComputeExecutionTemplate",
|
|
||||||
"events": [
|
|
||||||
{
|
|
||||||
"name": "AgreementActorAdded",
|
|
||||||
"actorType": "provider",
|
|
||||||
"handler": {
|
|
||||||
"moduleName": "",
|
|
||||||
"functionName": "fulfillLockRewardCondition",
|
|
||||||
"version": "0.1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"fulfillmentOrder": [
|
|
||||||
"lockReward.fulfill",
|
|
||||||
"computeExecution.fulfill",
|
|
||||||
"escrowReward.fulfill"
|
|
||||||
],
|
|
||||||
"conditionDependency": {
|
|
||||||
"lockReward": [],
|
|
||||||
"computeExecution": [],
|
|
||||||
"releaseReward": ["lockReward", "computeExecution"]
|
|
||||||
},
|
|
||||||
"conditions": [
|
|
||||||
{
|
|
||||||
"name": "lockReward",
|
|
||||||
"timelock": 0,
|
|
||||||
"timeout": 0,
|
|
||||||
"contractName": "LockRewardCondition",
|
|
||||||
"functionName": "fulfill",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "_rewardAddress",
|
|
||||||
"type": "address",
|
|
||||||
"value": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "_amount",
|
|
||||||
"type": "uint256",
|
|
||||||
"value": ""
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"events": [
|
|
||||||
{
|
|
||||||
"name": "Fulfilled",
|
|
||||||
"actorType": "provider",
|
|
||||||
"handler": {
|
|
||||||
"moduleName": "lockRewardExecutionCondition",
|
|
||||||
"functionName": "fulfillComputeExecutionCondition",
|
|
||||||
"version": "0.1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "computeExecution",
|
|
||||||
"timelock": 0,
|
|
||||||
"timeout": 0,
|
|
||||||
"contractName": "ComputeExecutionCondition",
|
|
||||||
"functionName": "fulfill",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "_documentId",
|
|
||||||
"type": "bytes32",
|
|
||||||
"value": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "_grantee",
|
|
||||||
"type": "address",
|
|
||||||
"value": ""
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"events": [
|
|
||||||
{
|
|
||||||
"name": "Fulfilled",
|
|
||||||
"actorType": "provider",
|
|
||||||
"handler": {
|
|
||||||
"moduleName": "accessSecretStore",
|
|
||||||
"functionName": "fulfillEscrowRewardCondition",
|
|
||||||
"version": "0.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "TimedOut",
|
|
||||||
"actorType": "consumer",
|
|
||||||
"handler": {
|
|
||||||
"moduleName": "accessSecretStore",
|
|
||||||
"functionName": "refundReward",
|
|
||||||
"version": "0.1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "escrowReward",
|
|
||||||
"timelock": 0,
|
|
||||||
"timeout": 0,
|
|
||||||
"contractName": "EscrowReward",
|
|
||||||
"functionName": "fulfill",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "_amount",
|
|
||||||
"type": "uint256",
|
|
||||||
"value": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "_receiver",
|
|
||||||
"type": "address",
|
|
||||||
"value": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "_sender",
|
|
||||||
"type": "address",
|
|
||||||
"value": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "_lockCondition",
|
|
||||||
"type": "bytes32",
|
|
||||||
"value": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "_releaseCondition",
|
|
||||||
"type": "bytes32",
|
|
||||||
"value": ""
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"events": [
|
|
||||||
{
|
|
||||||
"name": "Fulfilled",
|
|
||||||
"actorType": "provider",
|
|
||||||
"handler": {
|
|
||||||
"moduleName": "escrowRewardCondition",
|
|
||||||
"functionName": "verifyRewardTokens",
|
|
||||||
"version": "0.1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user