Skip to content

Commit

Permalink
integration tests publish all methods (#1197)
Browse files Browse the repository at this point in the history
* added pool fixed rate and dispenser publish

* add validate method update publish tests

* update tests asset metadata

* update validate method

* fix lint

* update validate ussage

* send metadata to validate as object and removed some console logs

* fixed validate method update publish all tests

* fix validate aqua method

* update provider url

* update service timeout and add doc for validate method

* add MetadataProofs

Co-authored-by: alexcos20 <alex.coseru@gmail.com>
  • Loading branch information
bogdanfazakas and alexcos20 committed Jan 7, 2022
1 parent 4dc8898 commit 04d850b
Show file tree
Hide file tree
Showing 8 changed files with 459 additions and 180 deletions.
219 changes: 49 additions & 170 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"test:nftDt": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/Nft.test.ts'",
"test:factory": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/NftFactory.test.ts'",
"test:router": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/pools/Router.test.ts'",
"test:publishAll": "mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/PublishFlows.test.ts'",
"test:unit": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/**/*.test.ts'",
"test:unit:cover": "nyc --report-dir coverage/unit npm run test:unit",
"test:integration": "mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/**/*.test.ts'",
Expand Down
13 changes: 13 additions & 0 deletions src/@types/DDO/Metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,16 @@ export interface Metadata {
*/
additionalInformation?: any
}

export interface MetadataProof {
validatorAddress?: string
r?: string
s?: string
v?: number
}
export interface ValidateMetadata {
valid: Boolean
errors?: Object
hash?: string
proof?: MetadataProof
}
4 changes: 2 additions & 2 deletions src/@types/DDO/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ export interface Service {

/**
* Describing how long the service can be used after consumption is initiated.
* @type {string}
* @type {number}
*/
timeout: string
timeout: number

/**
* Service friendly name
Expand Down
41 changes: 39 additions & 2 deletions src/aquarius/Aquarius.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LoggerInstance } from '../utils'
import { Asset, DDO } from '../@types/'
import { Asset, DDO, Metadata, ValidateMetadata } from '../@types/'
import { json } from 'stream/consumers'

export class Aquarius {
public aquariusURL
Expand Down Expand Up @@ -43,9 +44,9 @@ export class Aquarius {

/**
* Blocks until Aqua will cache the did (or the update for that did) or timeouts
* @param {string} fetchMethod fetch client instance
* @param {string} did DID of the asset.
* @param {string} txid used when the did exists and we expect an update with that txid.
* @param {string} fetchMethod fetch client instance
* @return {Promise<DDO>} DDO of the asset.
*/
public async waitForAqua(fetchMethod: any, did: string, txid?: string): Promise<Asset> {
Expand All @@ -69,6 +70,42 @@ export class Aquarius {
} while (tries < 100)
return null
}

/**
* Validate DDO content
* @param {string} fetchMethod fetch client instance
* @param {DDO} ddo DID Descriptor Object content.
* @return {Promise<ValidateMetadata>}.
*/
public async validate(fetchMethod: any, ddo: DDO): Promise<ValidateMetadata> {
const status: ValidateMetadata = {
valid: false
}
let jsonResponse
try {
const path = this.aquariusURL + '/api/aquarius/assets/ddo/validate'
const response = await fetchMethod('POST', path, JSON.stringify(ddo), {
'Content-Type': 'application/octet-stream'
})
jsonResponse = await response.json()
if (response.status === 200) {
status.valid = true
status.hash = jsonResponse.hash
status.proof = {
validatorAddress: jsonResponse.publicKey,
r: jsonResponse.r[0],
s: jsonResponse.s[0],
v: jsonResponse.v
}
} else {
status.errors = jsonResponse
LoggerInstance.error('validate Metadata failed:', response.status, status.errors)
}
} catch (error) {
LoggerInstance.error('Error validating metadata: ', error)
}
return status
}
}

export default Aquarius
13 changes: 8 additions & 5 deletions src/tokens/NFT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TransactionReceipt } from 'web3-eth'
import defaultNftAbi from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json'
import { LoggerInstance, getFairGasPrice, generateDtName } from '../utils'
import { Contract } from 'web3-eth-contract'
import { MetadataProof } from '../../src/@types'

/**
* ERC721 ROLES
Expand Down Expand Up @@ -912,6 +913,7 @@ export class Nft {
flags: string,
data: string,
metadataHash: string,
metadataProofs?: MetadataProof[],
contractInstance?: Contract
): Promise<any> {
const nftContract =
Expand All @@ -928,7 +930,7 @@ export class Nft {
flags,
data,
metadataHash,
[]
metadataProofs
)
.estimateGas({ from: metadataUpdater }, (err, estGas) =>
err ? gasLimitDefault : estGas
Expand All @@ -955,14 +957,14 @@ export class Nft {
metaDataDecryptorAddress: string,
flags: string,
data: string,
metadataHash: string
metadataHash: string,
metadataProofs?: MetadataProof[]
): Promise<TransactionReceipt> {
const nftContract = new this.web3.eth.Contract(this.nftAbi, nftAddress)

if (!metadataProofs) metadataProofs = []
if (!(await this.getNftPermissions(nftAddress, address)).updateMetadata) {
throw new Error(`Caller is not Metadata updater`)
}

const estGas = await this.estGasSetMetadata(
nftAddress,
address,
Expand All @@ -972,6 +974,7 @@ export class Nft {
flags,
data,
metadataHash,
metadataProofs,
nftContract
)
const trxReceipt = await nftContract.methods
Expand All @@ -982,7 +985,7 @@ export class Nft {
flags,
data,
metadataHash,
[]
metadataProofs
)
.send({
from: address,
Expand Down

0 comments on commit 04d850b

Please sign in to comment.