mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
parent
9142c354f0
commit
ee7a45e17a
32
.github/workflows/ci.yml
vendored
32
.github/workflows/ci.yml
vendored
@ -57,10 +57,17 @@ jobs:
|
|||||||
- name: Run Ganache with Barge
|
- name: Run Ganache with Barge
|
||||||
working-directory: ${{ github.workspace }}/barge
|
working-directory: ${{ github.workspace }}/barge
|
||||||
run: |
|
run: |
|
||||||
bash -x start_ocean.sh --no-aquarius --no-elasticsearch --no-provider --no-dashboard --skip-deploy 2>&1 > start_ocean.log &
|
bash -x start_ocean.sh --no-aquarius --no-elasticsearch --no-provider --no-dashboard 2>&1 > start_ocean.log &
|
||||||
cd ..
|
|
||||||
|
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
|
- name: Wait for contracts deployment
|
||||||
|
working-directory: ${{ github.workspace }}/barge
|
||||||
|
run: |
|
||||||
|
for i in $(seq 1 250); do
|
||||||
|
sleep 5
|
||||||
|
[ -f "$HOME/.ocean/ocean-contracts/artifacts/ready" ] && break
|
||||||
|
done
|
||||||
|
ls -la "$HOME/.ocean/ocean-contracts/artifacts/"
|
||||||
- run: npm run build:metadata
|
- run: npm run build:metadata
|
||||||
- run: npm run test:unit:cover
|
- run: npm run test:unit:cover
|
||||||
- uses: actions/upload-artifact@v2
|
- uses: actions/upload-artifact@v2
|
||||||
@ -84,8 +91,6 @@ jobs:
|
|||||||
path: ~/.npm
|
path: ~/.npm
|
||||||
key: ${{ runner.os }}-test-integration-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
|
key: ${{ runner.os }}-test-integration-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
|
||||||
restore-keys: ${{ runner.os }}-test-integration-${{ env.cache-name }}-
|
restore-keys: ${{ runner.os }}-test-integration-${{ env.cache-name }}-
|
||||||
- run: npm ci
|
|
||||||
- run: npm run build:metadata
|
|
||||||
|
|
||||||
# Env var expansion workaround
|
# Env var expansion workaround
|
||||||
# https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
|
# https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
|
||||||
@ -109,14 +114,29 @@ jobs:
|
|||||||
|
|
||||||
- name: Run Barge
|
- name: Run Barge
|
||||||
working-directory: ${{ github.workspace }}/barge
|
working-directory: ${{ github.workspace }}/barge
|
||||||
|
env:
|
||||||
|
OPERATOR_SERVICE_VERSION: compute_envs
|
||||||
|
OPERATOR_ENGINE_VERSION: compute_envs
|
||||||
|
PROVIDER_VERSION: compute_envs
|
||||||
run: |
|
run: |
|
||||||
bash -x start_ocean.sh --with-provider2 --no-dashboard --with-c2d 2>&1 > start_ocean.log &
|
bash -x start_ocean.sh --with-provider2 --no-dashboard --with-c2d 2>&1 > start_ocean.log &
|
||||||
cd .. && ./scripts/waitforcontracts.sh
|
|
||||||
|
- run: npm ci
|
||||||
|
- run: npm run build:metadata
|
||||||
|
|
||||||
|
- name: Wait for contracts deployment and C2D cluster to be ready
|
||||||
|
working-directory: ${{ github.workspace }}/barge
|
||||||
|
run: |
|
||||||
|
for i in $(seq 1 250); do
|
||||||
|
sleep 10
|
||||||
|
[ -f "$HOME/.ocean/ocean-contracts/artifacts/ready" -a -f "$HOME/.ocean/ocean-c2d/ready" ] && break
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
- name: integration
|
- name: integration
|
||||||
run: npm run test:integration:cover
|
run: npm run test:integration:cover
|
||||||
- name: docker logs
|
- name: docker logs
|
||||||
run: docker logs ocean_aquarius_1 && docker logs ocean_provider_1 && docker logs ocean_provider2_1
|
run: docker logs ocean_aquarius_1 && docker logs ocean_provider_1 && docker logs ocean_provider2_1 && docker logs ocean_computetodata_1
|
||||||
if: ${{ failure() }}
|
if: ${{ failure() }}
|
||||||
- name: Upload coverage
|
- name: Upload coverage
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v2
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
while [ ! -f "$HOME/.ocean/ocean-contracts/artifacts/ready" ] || [ ! -f "$HOME/.ocean/ocean-c2d/ready" ]; do
|
while [ ! -f "$HOME/.ocean/ocean-contracts/artifacts/ready" ] || [ ! -f "$HOME/.ocean/ocean-c2d/ready" ]; do
|
||||||
sleep 2
|
sleep 2
|
||||||
done
|
done
|
||||||
|
#wait for c2d
|
||||||
|
sleep 10
|
||||||
#cat "barge/start_ocean.log"
|
#cat "barge/start_ocean.log"
|
||||||
ls -lh "${HOME}/.ocean/ocean-contracts/"
|
ls -lh "${HOME}/.ocean/ocean-contracts/"
|
||||||
ls -lh "${HOME}/.ocean/ocean-contracts/artifacts/"
|
ls -lh "${HOME}/.ocean/ocean-contracts/artifacts/"
|
||||||
|
@ -2,6 +2,24 @@ import { Metadata, MetadataAlgorithm } from './DDO/Metadata'
|
|||||||
|
|
||||||
export type ComputeResultType = 'algorithmLog' | 'output'
|
export type ComputeResultType = 'algorithmLog' | 'output'
|
||||||
|
|
||||||
|
export interface ComputeEnvironment {
|
||||||
|
id: string
|
||||||
|
cpuNumber: number
|
||||||
|
cpuType: string
|
||||||
|
gpuNumber: number
|
||||||
|
gpuType: string
|
||||||
|
ramGB: number
|
||||||
|
diskGB: number
|
||||||
|
priceMin: number
|
||||||
|
desc: string
|
||||||
|
currentJobs: number
|
||||||
|
maxJobs: number
|
||||||
|
consumerAddress: string
|
||||||
|
storageExpiry: number
|
||||||
|
maxJobDuration: number
|
||||||
|
lastSeen: number
|
||||||
|
}
|
||||||
|
|
||||||
export interface ComputeResult {
|
export interface ComputeResult {
|
||||||
filename: string
|
filename: string
|
||||||
filesize: number
|
filesize: number
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { LoggerInstance } from '../utils'
|
import { LoggerInstance, sleep } from '../utils'
|
||||||
import { Asset, DDO, ValidateMetadata } from '../@types/'
|
import { Asset, DDO, ValidateMetadata } from '../@types/'
|
||||||
import fetch from 'cross-fetch'
|
import fetch from 'cross-fetch'
|
||||||
export class Aquarius {
|
export class Aquarius {
|
||||||
@ -39,15 +39,6 @@ export class Aquarius {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Simple blocking sleep function
|
|
||||||
*/
|
|
||||||
public sleep(ms: number) {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
setTimeout(resolve, ms)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Blocks until Aqua will cache the did (or the update for that did) or timeouts
|
* Blocks until Aqua will cache the did (or the update for that did) or timeouts
|
||||||
|
|
||||||
@ -82,7 +73,7 @@ export class Aquarius {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
await this.sleep(1500)
|
await sleep(1500)
|
||||||
tries++
|
tries++
|
||||||
} while (tries < 100)
|
} while (tries < 100)
|
||||||
return null
|
return null
|
||||||
|
@ -6,6 +6,7 @@ import {
|
|||||||
ComputeOutput,
|
ComputeOutput,
|
||||||
ComputeAlgorithm,
|
ComputeAlgorithm,
|
||||||
ComputeAsset,
|
ComputeAsset,
|
||||||
|
ComputeEnvironment,
|
||||||
ProviderInitialize
|
ProviderInitialize
|
||||||
} from '../@types/'
|
} from '../@types/'
|
||||||
import { noZeroX } from '../utils/ConversionTypeHelper'
|
import { noZeroX } from '../utils/ConversionTypeHelper'
|
||||||
@ -245,6 +246,36 @@ export class Provider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Get Compute Environments
|
||||||
|
* @return {Promise<ComputeEnvironment[]>} urlDetails
|
||||||
|
*/
|
||||||
|
public async getComputeEnvironments(
|
||||||
|
providerUri: string,
|
||||||
|
signal?: AbortSignal
|
||||||
|
): Promise<ComputeEnvironment[]> {
|
||||||
|
const providerEndpoints = await this.getEndpoints(providerUri)
|
||||||
|
const serviceEndpoints = await this.getServiceEndpoints(
|
||||||
|
providerUri,
|
||||||
|
providerEndpoints
|
||||||
|
)
|
||||||
|
const path = this.getEndpointURL(serviceEndpoints, 'computeEnvironments')?.urlPath
|
||||||
|
if (!path) return null
|
||||||
|
try {
|
||||||
|
const response = await fetch(path, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
signal: signal
|
||||||
|
})
|
||||||
|
const envs: ComputeEnvironment[] = await response.json()
|
||||||
|
return envs
|
||||||
|
} catch (e) {
|
||||||
|
LoggerInstance.error(e.message)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Initialize a service request.
|
/** Initialize a service request.
|
||||||
* @param {DDO | string} asset
|
* @param {DDO | string} asset
|
||||||
* @param {number} serviceIndex
|
* @param {number} serviceIndex
|
||||||
@ -282,7 +313,7 @@ export class Provider {
|
|||||||
initializeUrl += `&consumerAddress=${consumerAddress}`
|
initializeUrl += `&consumerAddress=${consumerAddress}`
|
||||||
if (userCustomParameters)
|
if (userCustomParameters)
|
||||||
initializeUrl += '&userdata=' + encodeURI(JSON.stringify(userCustomParameters))
|
initializeUrl += '&userdata=' + encodeURI(JSON.stringify(userCustomParameters))
|
||||||
if (computeEnv) initializeUrl += '&computeEnv=' + encodeURI(computeEnv)
|
if (computeEnv) initializeUrl += '&environment=' + encodeURI(computeEnv)
|
||||||
if (validUntil) initializeUrl += '&validUntil=' + validUntil
|
if (validUntil) initializeUrl += '&validUntil=' + validUntil
|
||||||
try {
|
try {
|
||||||
const response = await fetch(initializeUrl, {
|
const response = await fetch(initializeUrl, {
|
||||||
@ -348,6 +379,7 @@ export class Provider {
|
|||||||
/** Instruct the provider to start a compute job
|
/** Instruct the provider to start a compute job
|
||||||
* @param {string} did
|
* @param {string} did
|
||||||
* @param {string} consumerAddress
|
* @param {string} consumerAddress
|
||||||
|
* @param {string} computeEnv
|
||||||
* @param {ComputeAlgorithm} algorithm
|
* @param {ComputeAlgorithm} algorithm
|
||||||
* @param {string} providerUri
|
* @param {string} providerUri
|
||||||
* @param {Web3} web3
|
* @param {Web3} web3
|
||||||
@ -389,7 +421,7 @@ export class Provider {
|
|||||||
payload.consumerAddress = consumerAddress
|
payload.consumerAddress = consumerAddress
|
||||||
payload.signature = signature
|
payload.signature = signature
|
||||||
payload.nonce = nonce
|
payload.nonce = nonce
|
||||||
payload.computeEnv = computeEnv
|
payload.environment = computeEnv
|
||||||
payload.dataset = dataset
|
payload.dataset = dataset
|
||||||
payload.algorithm = algorithm
|
payload.algorithm = algorithm
|
||||||
if (payload.additionalDatasets) payload.additionalDatasets = additionalDatasets
|
if (payload.additionalDatasets) payload.additionalDatasets = additionalDatasets
|
||||||
@ -526,7 +558,7 @@ export class Provider {
|
|||||||
: null
|
: null
|
||||||
|
|
||||||
let url = '?documentId=' + noZeroX(did)
|
let url = '?documentId=' + noZeroX(did)
|
||||||
url += `&consumerAddress=${consumerAddress}`
|
url += (consumerAddress && `&consumerAddress=${consumerAddress}`) || ''
|
||||||
url += (jobId && `&jobId=${jobId}`) || ''
|
url += (jobId && `&jobId=${jobId}`) || ''
|
||||||
|
|
||||||
if (!computeStatusUrl) return null
|
if (!computeStatusUrl) return null
|
||||||
@ -538,7 +570,6 @@ export class Provider {
|
|||||||
},
|
},
|
||||||
signal: signal
|
signal: signal
|
||||||
})
|
})
|
||||||
|
|
||||||
if (response?.ok) {
|
if (response?.ok) {
|
||||||
const params = await response.json()
|
const params = await response.json()
|
||||||
return params
|
return params
|
||||||
|
8
src/utils/General.ts
Normal file
8
src/utils/General.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* Simple blocking sleep function
|
||||||
|
*/
|
||||||
|
export async function sleep(ms: number) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, ms)
|
||||||
|
})
|
||||||
|
}
|
@ -7,3 +7,4 @@ export * from './DdoHelpers'
|
|||||||
export * from './Constants'
|
export * from './Constants'
|
||||||
export * from './SignatureUtils'
|
export * from './SignatureUtils'
|
||||||
export * from './TokenUtils'
|
export * from './TokenUtils'
|
||||||
|
export * from './General'
|
||||||
|
@ -4,7 +4,7 @@ import Aquarius from '../../src/aquarius/Aquarius'
|
|||||||
import { assert } from 'chai'
|
import { assert } from 'chai'
|
||||||
import { NftFactory, NftCreateData } from '../../src/factories/index'
|
import { NftFactory, NftCreateData } from '../../src/factories/index'
|
||||||
import { Datatoken } from '../../src/tokens/Datatoken'
|
import { Datatoken } from '../../src/tokens/Datatoken'
|
||||||
import { getHash } from '../../src/utils'
|
import { getHash, sleep } from '../../src/utils'
|
||||||
import { Nft } from '../../src/tokens/NFT'
|
import { Nft } from '../../src/tokens/NFT'
|
||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import { SHA256 } from 'crypto-js'
|
import { SHA256 } from 'crypto-js'
|
||||||
@ -236,13 +236,27 @@ describe('Simple compute tests', async () => {
|
|||||||
await datatoken.mint(datatokenAddressAsset, publisherAccount, '1', consumerAccount)
|
await datatoken.mint(datatokenAddressAsset, publisherAccount, '1', consumerAccount)
|
||||||
await datatoken.mint(datatokenAddressAlgo, publisherAccount, '1', consumerAccount)
|
await datatoken.mint(datatokenAddressAlgo, publisherAccount, '1', consumerAccount)
|
||||||
|
|
||||||
|
// get compute environments
|
||||||
|
const computeEnvs = await ProviderInstance.getComputeEnvironments(providerUrl)
|
||||||
|
assert(computeEnvs, 'No Compute environments found')
|
||||||
|
// we choose the first env
|
||||||
|
const computeEnv = computeEnvs[0].id
|
||||||
|
const computeConsumerAddress = computeEnvs[0].consumerAddress
|
||||||
|
// let's have 60 seconds of compute access
|
||||||
|
const mytime = new Date()
|
||||||
|
mytime.setMinutes(mytime.getMinutes() + 1)
|
||||||
|
const computeValidUntil = mytime.getTime()
|
||||||
// initialize provider orders for algo
|
// initialize provider orders for algo
|
||||||
const initializeDataAlgo = await ProviderInstance.initialize(
|
const initializeDataAlgo = await ProviderInstance.initialize(
|
||||||
resolvedDDOAlgo.id,
|
resolvedDDOAlgo.id,
|
||||||
resolvedDDOAlgo.services[0].id,
|
resolvedDDOAlgo.services[0].id,
|
||||||
0,
|
0,
|
||||||
consumerAccount,
|
consumerAccount,
|
||||||
providerUrl
|
providerUrl,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
computeEnv,
|
||||||
|
computeValidUntil
|
||||||
)
|
)
|
||||||
const providerAlgoFees: ProviderFees = {
|
const providerAlgoFees: ProviderFees = {
|
||||||
providerFeeAddress: initializeDataAlgo.providerFee.providerFeeAddress,
|
providerFeeAddress: initializeDataAlgo.providerFee.providerFeeAddress,
|
||||||
@ -259,7 +273,7 @@ describe('Simple compute tests', async () => {
|
|||||||
const txidAlgo = await datatoken.startOrder(
|
const txidAlgo = await datatoken.startOrder(
|
||||||
datatokenAddressAlgo,
|
datatokenAddressAlgo,
|
||||||
consumerAccount,
|
consumerAccount,
|
||||||
initializeDataAlgo.computeAddress,
|
computeConsumerAddress, // this is important because the c2d is the consumer, and user is the payer. Otherwise, c2d will have no access to the asset
|
||||||
0,
|
0,
|
||||||
providerAlgoFees
|
providerAlgoFees
|
||||||
)
|
)
|
||||||
@ -277,8 +291,8 @@ describe('Simple compute tests', async () => {
|
|||||||
providerUrl,
|
providerUrl,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
'env1',
|
computeEnv,
|
||||||
providerValidUntil.getTime()
|
computeValidUntil
|
||||||
)
|
)
|
||||||
const providerDatasetFees: ProviderFees = {
|
const providerDatasetFees: ProviderFees = {
|
||||||
providerFeeAddress: initializeData.providerFee.providerFeeAddress,
|
providerFeeAddress: initializeData.providerFee.providerFeeAddress,
|
||||||
@ -294,7 +308,7 @@ describe('Simple compute tests', async () => {
|
|||||||
const txidAsset = await datatoken.startOrder(
|
const txidAsset = await datatoken.startOrder(
|
||||||
datatokenAddressAsset,
|
datatokenAddressAsset,
|
||||||
consumerAccount,
|
consumerAccount,
|
||||||
initializeDataAlgo.computeAddress,
|
computeConsumerAddress, // this is important because the c2d is the consumer, and user is the payer. Otherwise, c2d will have no access to the asset
|
||||||
0,
|
0,
|
||||||
providerDatasetFees
|
providerDatasetFees
|
||||||
)
|
)
|
||||||
@ -304,7 +318,7 @@ describe('Simple compute tests', async () => {
|
|||||||
providerUrl,
|
providerUrl,
|
||||||
web3,
|
web3,
|
||||||
consumerAccount,
|
consumerAccount,
|
||||||
'env1',
|
computeEnv,
|
||||||
{
|
{
|
||||||
documentId: resolvedDDOAsset.id,
|
documentId: resolvedDDOAsset.id,
|
||||||
serviceId: resolvedDDOAsset.services[0].id,
|
serviceId: resolvedDDOAsset.services[0].id,
|
||||||
@ -320,7 +334,9 @@ describe('Simple compute tests', async () => {
|
|||||||
const jobStatus = await ProviderInstance.computeStatus(
|
const jobStatus = await ProviderInstance.computeStatus(
|
||||||
providerUrl,
|
providerUrl,
|
||||||
null,
|
null,
|
||||||
computeJobs[0].jobId
|
computeJobs[0].jobId,
|
||||||
|
resolvedDDOAsset.id,
|
||||||
|
consumerAccount
|
||||||
)
|
)
|
||||||
assert(jobStatus)
|
assert(jobStatus)
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user