mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
wip publish edit consume integration test
This commit is contained in:
parent
77429fd8cb
commit
4cac5395b3
@ -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/PublishFlows.test.ts'",
|
"test:integration": "npm run mocha -- 'test/integration/PublishEditConsume.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",
|
||||||
|
@ -31,9 +31,14 @@ export const configHelperNetworks: Config[] = [
|
|||||||
...configHelperNetworksBase,
|
...configHelperNetworksBase,
|
||||||
chainId: 8996,
|
chainId: 8996,
|
||||||
network: 'development',
|
network: 'development',
|
||||||
metadataCacheUri: 'http://172.15.0.5:5000', // use http://127.0.0.1:5000/ if running on macOS
|
// comment th following configs if running on macOS
|
||||||
providerUri: 'http://172.15.0.4:8030', // use http://127.0.0.1:8030/ if running on macOS
|
// metadataCacheUri: 'http://172.15.0.5:5000',
|
||||||
subgraphUri: 'https://172.15.0.15:8000' // use http://127.0.0.1:9000/ if running on macOS
|
// providerUri: 'http://172.15.0.4:8030',
|
||||||
|
// subgraphUri: 'https://172.15.0.15:8000'
|
||||||
|
// uncomment the following configs if running on macOS
|
||||||
|
metadataCacheUri: 'http://127.0.0.1:5000',
|
||||||
|
providerUri: 'http://127.0.0.1:8030/',
|
||||||
|
subgraphUri: 'http://127.0.0.1:9000/'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
...configHelperNetworksBase,
|
...configHelperNetworksBase,
|
||||||
|
@ -141,7 +141,6 @@ import {
|
|||||||
DDO,
|
DDO,
|
||||||
NftCreateData,
|
NftCreateData,
|
||||||
DatatokenCreateParams,
|
DatatokenCreateParams,
|
||||||
calculateEstimatedGas,
|
|
||||||
sendTx,
|
sendTx,
|
||||||
configHelperNetworks,
|
configHelperNetworks,
|
||||||
ConfigHelper
|
ConfigHelper
|
||||||
|
@ -1,27 +1,26 @@
|
|||||||
import { assert } from 'chai'
|
import { assert } from 'chai'
|
||||||
import { AbiItem } from 'web3-utils'
|
import { ethers, Signer } from 'ethers'
|
||||||
import { web3, getTestConfig, getAddresses } from '../config'
|
import { getTestConfig, getAddresses, provider } from '../config'
|
||||||
import {
|
import {
|
||||||
Config,
|
Config,
|
||||||
ProviderInstance,
|
ProviderInstance,
|
||||||
Aquarius,
|
Aquarius,
|
||||||
Datatoken,
|
Datatoken,
|
||||||
downloadFile,
|
downloadFile,
|
||||||
calculateEstimatedGas,
|
|
||||||
sendTx,
|
sendTx,
|
||||||
transfer,
|
transfer,
|
||||||
SmartContract
|
amountToUnits
|
||||||
} from '../../src'
|
} from '../../src'
|
||||||
import { Files, Smartcontract } from '../../src/@types'
|
import { Files, Smartcontract } from '../../src/@types'
|
||||||
import { createAsset, orderAsset, updateAssetMetadata } from './helpers'
|
import { createAsset } from './helpers'
|
||||||
|
|
||||||
let config: Config
|
let config: Config
|
||||||
|
|
||||||
let aquarius: Aquarius
|
let aquarius: Aquarius
|
||||||
let datatoken: Datatoken
|
let datatoken: Datatoken
|
||||||
let providerUrl: string
|
let providerUrl: string
|
||||||
let consumerAccount: string
|
let consumerAccount: Signer
|
||||||
let publisherAccount: string
|
let publisherAccount: Signer
|
||||||
let addresses: any
|
let addresses: any
|
||||||
|
|
||||||
let urlAssetId
|
let urlAssetId
|
||||||
@ -149,17 +148,13 @@ function delay(interval: number) {
|
|||||||
|
|
||||||
describe('Publish consume test', async () => {
|
describe('Publish consume test', async () => {
|
||||||
before(async () => {
|
before(async () => {
|
||||||
config = await getTestConfig(web3)
|
publisherAccount = (await provider.getSigner(0)) as Signer
|
||||||
addresses = getAddresses()
|
consumerAccount = (await provider.getSigner(1)) as Signer
|
||||||
|
config = await getTestConfig(publisherAccount)
|
||||||
aquarius = new Aquarius(config?.metadataCacheUri)
|
aquarius = new Aquarius(config?.metadataCacheUri)
|
||||||
providerUrl = config?.providerUri
|
providerUrl = config?.providerUri
|
||||||
datatoken = new Datatoken(web3)
|
console.log(config)
|
||||||
})
|
addresses = getAddresses()
|
||||||
|
|
||||||
it('Initialize accounts', async () => {
|
|
||||||
const accounts = await web3.eth.getAccounts()
|
|
||||||
publisherAccount = accounts[0]
|
|
||||||
consumerAccount = accounts[1]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Mint OCEAN to publisher account', async () => {
|
it('Mint OCEAN to publisher account', async () => {
|
||||||
@ -176,27 +171,31 @@ describe('Publish consume test', async () => {
|
|||||||
stateMutability: 'nonpayable',
|
stateMutability: 'nonpayable',
|
||||||
type: 'function'
|
type: 'function'
|
||||||
}
|
}
|
||||||
] as AbiItem[]
|
]
|
||||||
const tokenContract = new web3.eth.Contract(minAbi, addresses.Ocean)
|
|
||||||
const estGas = await calculateEstimatedGas(
|
const tokenContract = new ethers.Contract(addresses.Ocean, minAbi, publisherAccount)
|
||||||
publisherAccount,
|
const estGas = await tokenContract.estimateGas.mint(
|
||||||
tokenContract.methods.mint,
|
await publisherAccount.getAddress(),
|
||||||
publisherAccount,
|
amountToUnits(null, null, '1000', 18)
|
||||||
web3.utils.toWei('1000')
|
|
||||||
)
|
)
|
||||||
await sendTx(
|
await sendTx(
|
||||||
publisherAccount,
|
|
||||||
estGas,
|
estGas,
|
||||||
web3,
|
|
||||||
1,
|
|
||||||
tokenContract.methods.mint,
|
|
||||||
publisherAccount,
|
publisherAccount,
|
||||||
web3.utils.toWei('1000')
|
1,
|
||||||
|
tokenContract.mint,
|
||||||
|
await publisherAccount.getAddress(),
|
||||||
|
amountToUnits(null, null, '1000', 18)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Send some OCEAN to consumer account', async () => {
|
it('Send some OCEAN to consumer account', async () => {
|
||||||
transfer(web3, config, publisherAccount, addresses.Ocean, consumerAccount, '100')
|
transfer(
|
||||||
|
publisherAccount,
|
||||||
|
config,
|
||||||
|
addresses.Ocean,
|
||||||
|
await consumerAccount.getAddress(),
|
||||||
|
'100'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should publish the assets', async () => {
|
it('Should publish the assets', async () => {
|
||||||
@ -294,250 +293,250 @@ describe('Publish consume test', async () => {
|
|||||||
assert(resolvedGraphqlAssetDdo, 'Cannot fetch graphql DDO from Aquarius')
|
assert(resolvedGraphqlAssetDdo, 'Cannot fetch graphql DDO from Aquarius')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Mint datasets datatokens to publisher', async () => {
|
// it('Mint datasets datatokens to publisher', async () => {
|
||||||
const urlMintTx = await datatoken.mint(
|
// const urlMintTx = await datatoken.mint(
|
||||||
resolvedUrlAssetDdo.services[0].datatokenAddress,
|
// resolvedUrlAssetDdo.services[0].datatokenAddress,
|
||||||
publisherAccount,
|
// publisherAccount,
|
||||||
'10',
|
// '10',
|
||||||
consumerAccount
|
// consumerAccount
|
||||||
)
|
// )
|
||||||
assert(urlMintTx, 'Failed minting url datatoken to consumer.')
|
// assert(urlMintTx, 'Failed minting url datatoken to consumer.')
|
||||||
|
|
||||||
const arwaveMintTx = await datatoken.mint(
|
// const arwaveMintTx = await datatoken.mint(
|
||||||
resolvedArweaveAssetDdo.services[0].datatokenAddress,
|
// resolvedArweaveAssetDdo.services[0].datatokenAddress,
|
||||||
publisherAccount,
|
// publisherAccount,
|
||||||
'10',
|
// '10',
|
||||||
consumerAccount
|
// consumerAccount
|
||||||
)
|
// )
|
||||||
assert(arwaveMintTx, 'Failed minting arwave datatoken to consumer.')
|
// assert(arwaveMintTx, 'Failed minting arwave datatoken to consumer.')
|
||||||
|
|
||||||
const ipfsMintTx = await datatoken.mint(
|
// const ipfsMintTx = await datatoken.mint(
|
||||||
resolvedIpfsAssetDdo.services[0].datatokenAddress,
|
// resolvedIpfsAssetDdo.services[0].datatokenAddress,
|
||||||
publisherAccount,
|
// publisherAccount,
|
||||||
'10',
|
// '10',
|
||||||
consumerAccount
|
// consumerAccount
|
||||||
)
|
// )
|
||||||
assert(ipfsMintTx, 'Failed minting ipfs datatoken to consumer.')
|
// assert(ipfsMintTx, 'Failed minting ipfs datatoken to consumer.')
|
||||||
|
|
||||||
const onchainMintTx = await datatoken.mint(
|
// const onchainMintTx = await datatoken.mint(
|
||||||
resolvedOnchainAssetDdo.services[0].datatokenAddress,
|
// resolvedOnchainAssetDdo.services[0].datatokenAddress,
|
||||||
publisherAccount,
|
// publisherAccount,
|
||||||
'10',
|
// '10',
|
||||||
consumerAccount
|
// consumerAccount
|
||||||
)
|
// )
|
||||||
assert(onchainMintTx, 'Failed minting onchain datatoken to consumer.')
|
// assert(onchainMintTx, 'Failed minting onchain datatoken to consumer.')
|
||||||
|
|
||||||
const graphqlMintTx = await datatoken.mint(
|
// const graphqlMintTx = await datatoken.mint(
|
||||||
resolvedGraphqlAssetDdo.services[0].datatokenAddress,
|
// resolvedGraphqlAssetDdo.services[0].datatokenAddress,
|
||||||
publisherAccount,
|
// publisherAccount,
|
||||||
'10',
|
// '10',
|
||||||
consumerAccount
|
// consumerAccount
|
||||||
)
|
// )
|
||||||
assert(graphqlMintTx, 'Failed minting graphql datatoken to consumer.')
|
// assert(graphqlMintTx, 'Failed minting graphql datatoken to consumer.')
|
||||||
})
|
// })
|
||||||
|
|
||||||
it('Should order the datasets', async () => {
|
// it('Should order the datasets', async () => {
|
||||||
urlOrderTx = await orderAsset(
|
// urlOrderTx = await orderAsset(
|
||||||
resolvedUrlAssetDdo.id,
|
// resolvedUrlAssetDdo.id,
|
||||||
resolvedUrlAssetDdo.services[0].datatokenAddress,
|
// resolvedUrlAssetDdo.services[0].datatokenAddress,
|
||||||
consumerAccount,
|
// consumerAccount,
|
||||||
resolvedUrlAssetDdo.services[0].id,
|
// resolvedUrlAssetDdo.services[0].id,
|
||||||
0,
|
// 0,
|
||||||
datatoken,
|
// datatoken,
|
||||||
providerUrl
|
// providerUrl
|
||||||
)
|
// )
|
||||||
assert(urlOrderTx, 'Ordering url dataset failed.')
|
// assert(urlOrderTx, 'Ordering url dataset failed.')
|
||||||
|
|
||||||
arwaveOrderTx = await orderAsset(
|
// arwaveOrderTx = await orderAsset(
|
||||||
resolvedArweaveAssetDdo.id,
|
// resolvedArweaveAssetDdo.id,
|
||||||
resolvedArweaveAssetDdo.services[0].datatokenAddress,
|
// resolvedArweaveAssetDdo.services[0].datatokenAddress,
|
||||||
consumerAccount,
|
// consumerAccount,
|
||||||
resolvedArweaveAssetDdo.services[0].id,
|
// resolvedArweaveAssetDdo.services[0].id,
|
||||||
0,
|
// 0,
|
||||||
datatoken,
|
// datatoken,
|
||||||
providerUrl
|
// providerUrl
|
||||||
)
|
// )
|
||||||
assert(arwaveOrderTx, 'Ordering arwave dataset failed.')
|
// assert(arwaveOrderTx, 'Ordering arwave dataset failed.')
|
||||||
|
|
||||||
onchainOrderTx = await orderAsset(
|
// onchainOrderTx = await orderAsset(
|
||||||
resolvedOnchainAssetDdo.id,
|
// resolvedOnchainAssetDdo.id,
|
||||||
resolvedOnchainAssetDdo.services[0].datatokenAddress,
|
// resolvedOnchainAssetDdo.services[0].datatokenAddress,
|
||||||
consumerAccount,
|
// consumerAccount,
|
||||||
resolvedOnchainAssetDdo.services[0].id,
|
// resolvedOnchainAssetDdo.services[0].id,
|
||||||
0,
|
// 0,
|
||||||
datatoken,
|
// datatoken,
|
||||||
providerUrl
|
// providerUrl
|
||||||
)
|
// )
|
||||||
assert(onchainOrderTx, 'Ordering onchain dataset failed.')
|
// assert(onchainOrderTx, 'Ordering onchain dataset failed.')
|
||||||
|
|
||||||
ipfsOrderTx = await orderAsset(
|
// ipfsOrderTx = await orderAsset(
|
||||||
resolvedIpfsAssetDdo.id,
|
// resolvedIpfsAssetDdo.id,
|
||||||
resolvedIpfsAssetDdo.services[0].datatokenAddress,
|
// resolvedIpfsAssetDdo.services[0].datatokenAddress,
|
||||||
consumerAccount,
|
// consumerAccount,
|
||||||
resolvedIpfsAssetDdo.services[0].id,
|
// resolvedIpfsAssetDdo.services[0].id,
|
||||||
0,
|
// 0,
|
||||||
datatoken,
|
// datatoken,
|
||||||
providerUrl
|
// providerUrl
|
||||||
)
|
// )
|
||||||
assert(ipfsOrderTx, 'Ordering ipfs dataset failed.')
|
// assert(ipfsOrderTx, 'Ordering ipfs dataset failed.')
|
||||||
|
|
||||||
grapqlOrderTx = await orderAsset(
|
// grapqlOrderTx = await orderAsset(
|
||||||
resolvedGraphqlAssetDdo.id,
|
// resolvedGraphqlAssetDdo.id,
|
||||||
resolvedGraphqlAssetDdo.services[0].datatokenAddress,
|
// resolvedGraphqlAssetDdo.services[0].datatokenAddress,
|
||||||
consumerAccount,
|
// consumerAccount,
|
||||||
resolvedGraphqlAssetDdo.services[0].id,
|
// resolvedGraphqlAssetDdo.services[0].id,
|
||||||
0,
|
// 0,
|
||||||
datatoken,
|
// datatoken,
|
||||||
providerUrl
|
// providerUrl
|
||||||
)
|
// )
|
||||||
assert(grapqlOrderTx, 'Ordering graphql dataset failed.')
|
// assert(grapqlOrderTx, 'Ordering graphql dataset failed.')
|
||||||
})
|
// })
|
||||||
|
|
||||||
it('Should download the datasets files', async () => {
|
// it('Should download the datasets files', async () => {
|
||||||
const urlDownloadUrl = await ProviderInstance.getDownloadUrl(
|
// const urlDownloadUrl = await ProviderInstance.getDownloadUrl(
|
||||||
resolvedUrlAssetDdo.id,
|
// resolvedUrlAssetDdo.id,
|
||||||
consumerAccount,
|
// consumerAccount,
|
||||||
resolvedUrlAssetDdo.services[0].id,
|
// resolvedUrlAssetDdo.services[0].id,
|
||||||
0,
|
// 0,
|
||||||
urlOrderTx.transactionHash,
|
// urlOrderTx.transactionHash,
|
||||||
providerUrl,
|
// providerUrl,
|
||||||
web3
|
// web3
|
||||||
)
|
// )
|
||||||
assert(urlDownloadUrl, 'Provider getDownloadUrl failed for url dataset')
|
// assert(urlDownloadUrl, 'Provider getDownloadUrl failed for url dataset')
|
||||||
try {
|
// try {
|
||||||
await downloadFile(urlDownloadUrl)
|
// await downloadFile(urlDownloadUrl)
|
||||||
} catch (e) {
|
// } catch (e) {
|
||||||
assert.fail(`Download url dataset failed: ${e}`)
|
// assert.fail(`Download url dataset failed: ${e}`)
|
||||||
}
|
// }
|
||||||
|
|
||||||
const arwaveDownloadURL = await ProviderInstance.getDownloadUrl(
|
// const arwaveDownloadURL = await ProviderInstance.getDownloadUrl(
|
||||||
resolvedArweaveAssetDdo.id,
|
// resolvedArweaveAssetDdo.id,
|
||||||
consumerAccount,
|
// consumerAccount,
|
||||||
resolvedArweaveAssetDdo.services[0].id,
|
// resolvedArweaveAssetDdo.services[0].id,
|
||||||
0,
|
// 0,
|
||||||
arwaveOrderTx.transactionHash,
|
// arwaveOrderTx.transactionHash,
|
||||||
providerUrl,
|
// providerUrl,
|
||||||
web3
|
// web3
|
||||||
)
|
// )
|
||||||
assert(arwaveDownloadURL, 'Provider getDownloadUrl failed for arwave dataset')
|
// assert(arwaveDownloadURL, 'Provider getDownloadUrl failed for arwave dataset')
|
||||||
try {
|
// try {
|
||||||
await downloadFile(arwaveDownloadURL)
|
// await downloadFile(arwaveDownloadURL)
|
||||||
} catch (e) {
|
// } catch (e) {
|
||||||
assert.fail(`Download arwave dataset failed: ${e}`)
|
// assert.fail(`Download arwave dataset failed: ${e}`)
|
||||||
}
|
// }
|
||||||
|
|
||||||
const ipfsDownloadURL = await ProviderInstance.getDownloadUrl(
|
// const ipfsDownloadURL = await ProviderInstance.getDownloadUrl(
|
||||||
resolvedIpfsAssetDdo.id,
|
// resolvedIpfsAssetDdo.id,
|
||||||
consumerAccount,
|
// consumerAccount,
|
||||||
resolvedIpfsAssetDdo.services[0].id,
|
// resolvedIpfsAssetDdo.services[0].id,
|
||||||
0,
|
// 0,
|
||||||
ipfsOrderTx.transactionHash,
|
// ipfsOrderTx.transactionHash,
|
||||||
providerUrl,
|
// providerUrl,
|
||||||
web3
|
// web3
|
||||||
)
|
// )
|
||||||
assert(ipfsDownloadURL, 'Provider getDownloadUrl failed for ipfs dataset')
|
// assert(ipfsDownloadURL, 'Provider getDownloadUrl failed for ipfs dataset')
|
||||||
try {
|
// try {
|
||||||
await downloadFile(ipfsDownloadURL)
|
// await downloadFile(ipfsDownloadURL)
|
||||||
} catch (e) {
|
// } catch (e) {
|
||||||
assert.fail(`Download ipfs dataset failed ${e}`)
|
// assert.fail(`Download ipfs dataset failed ${e}`)
|
||||||
}
|
// }
|
||||||
|
|
||||||
const onchainDownloadURL = await ProviderInstance.getDownloadUrl(
|
// const onchainDownloadURL = await ProviderInstance.getDownloadUrl(
|
||||||
resolvedOnchainAssetDdo.id,
|
// resolvedOnchainAssetDdo.id,
|
||||||
consumerAccount,
|
// consumerAccount,
|
||||||
resolvedOnchainAssetDdo.services[0].id,
|
// resolvedOnchainAssetDdo.services[0].id,
|
||||||
0,
|
// 0,
|
||||||
onchainOrderTx.transactionHash,
|
// onchainOrderTx.transactionHash,
|
||||||
providerUrl,
|
// providerUrl,
|
||||||
web3
|
// web3
|
||||||
)
|
// )
|
||||||
assert(onchainDownloadURL, 'Provider getDownloadUrl failed for onchain dataset')
|
// assert(onchainDownloadURL, 'Provider getDownloadUrl failed for onchain dataset')
|
||||||
try {
|
// try {
|
||||||
await downloadFile(onchainDownloadURL)
|
// await downloadFile(onchainDownloadURL)
|
||||||
} catch (e) {
|
// } catch (e) {
|
||||||
assert.fail(`Download onchain dataset failed ${e}`)
|
// assert.fail(`Download onchain dataset failed ${e}`)
|
||||||
}
|
// }
|
||||||
|
|
||||||
const graphqlDownloadURL = await ProviderInstance.getDownloadUrl(
|
// const graphqlDownloadURL = await ProviderInstance.getDownloadUrl(
|
||||||
resolvedGraphqlAssetDdo.id,
|
// resolvedGraphqlAssetDdo.id,
|
||||||
consumerAccount,
|
// consumerAccount,
|
||||||
resolvedGraphqlAssetDdo.services[0].id,
|
// resolvedGraphqlAssetDdo.services[0].id,
|
||||||
0,
|
// 0,
|
||||||
grapqlOrderTx.transactionHash,
|
// grapqlOrderTx.transactionHash,
|
||||||
providerUrl,
|
// providerUrl,
|
||||||
web3
|
// web3
|
||||||
)
|
// )
|
||||||
assert(graphqlDownloadURL, 'Provider getDownloadUrl failed for graphql dataset')
|
// assert(graphqlDownloadURL, 'Provider getDownloadUrl failed for graphql dataset')
|
||||||
try {
|
// try {
|
||||||
await downloadFile(graphqlDownloadURL)
|
// await downloadFile(graphqlDownloadURL)
|
||||||
} catch (e) {
|
// } catch (e) {
|
||||||
assert.fail(`Download graphql dataset failed ${e}`)
|
// assert.fail(`Download graphql dataset failed ${e}`)
|
||||||
}
|
// }
|
||||||
})
|
// })
|
||||||
|
|
||||||
it('Should update datasets metadata', async () => {
|
// it('Should update datasets metadata', async () => {
|
||||||
resolvedUrlAssetDdo.metadata.name = 'updated url asset name'
|
// resolvedUrlAssetDdo.metadata.name = 'updated url asset name'
|
||||||
const updateUrlTx = await updateAssetMetadata(
|
// const updateUrlTx = await updateAssetMetadata(
|
||||||
publisherAccount,
|
// publisherAccount,
|
||||||
resolvedUrlAssetDdo,
|
// resolvedUrlAssetDdo,
|
||||||
providerUrl,
|
// providerUrl,
|
||||||
aquarius
|
// aquarius
|
||||||
)
|
// )
|
||||||
assert(updateUrlTx, 'Failed to update url asset metadata')
|
// assert(updateUrlTx, 'Failed to update url asset metadata')
|
||||||
|
|
||||||
resolvedArweaveAssetDdo.metadata.name = 'updated arwave asset name'
|
// resolvedArweaveAssetDdo.metadata.name = 'updated arwave asset name'
|
||||||
const updateArwaveTx = await updateAssetMetadata(
|
// const updateArwaveTx = await updateAssetMetadata(
|
||||||
publisherAccount,
|
// publisherAccount,
|
||||||
resolvedArweaveAssetDdo,
|
// resolvedArweaveAssetDdo,
|
||||||
providerUrl,
|
// providerUrl,
|
||||||
aquarius
|
// aquarius
|
||||||
)
|
// )
|
||||||
assert(updateArwaveTx, 'Failed to update arwave asset metadata')
|
// assert(updateArwaveTx, 'Failed to update arwave asset metadata')
|
||||||
|
|
||||||
resolvedIpfsAssetDdo.metadata.name = 'updated ipfs asset name'
|
// resolvedIpfsAssetDdo.metadata.name = 'updated ipfs asset name'
|
||||||
const updateIpfsTx = await updateAssetMetadata(
|
// const updateIpfsTx = await updateAssetMetadata(
|
||||||
publisherAccount,
|
// publisherAccount,
|
||||||
resolvedIpfsAssetDdo,
|
// resolvedIpfsAssetDdo,
|
||||||
providerUrl,
|
// providerUrl,
|
||||||
aquarius
|
// aquarius
|
||||||
)
|
// )
|
||||||
assert(updateIpfsTx, 'Failed to update ipfs asset metadata')
|
// assert(updateIpfsTx, 'Failed to update ipfs asset metadata')
|
||||||
|
|
||||||
resolvedOnchainAssetDdo.metadata.name = 'updated onchain asset name'
|
// resolvedOnchainAssetDdo.metadata.name = 'updated onchain asset name'
|
||||||
const updateOnchainTx = await updateAssetMetadata(
|
// const updateOnchainTx = await updateAssetMetadata(
|
||||||
publisherAccount,
|
// publisherAccount,
|
||||||
resolvedOnchainAssetDdo,
|
// resolvedOnchainAssetDdo,
|
||||||
providerUrl,
|
// providerUrl,
|
||||||
aquarius
|
// aquarius
|
||||||
)
|
// )
|
||||||
assert(updateOnchainTx, 'Failed to update ipfs asset metadata')
|
// assert(updateOnchainTx, 'Failed to update ipfs asset metadata')
|
||||||
|
|
||||||
resolvedGraphqlAssetDdo.metadata.name = 'updated graphql asset name'
|
// resolvedGraphqlAssetDdo.metadata.name = 'updated graphql asset name'
|
||||||
const updateGraphqlTx = await updateAssetMetadata(
|
// const updateGraphqlTx = await updateAssetMetadata(
|
||||||
publisherAccount,
|
// publisherAccount,
|
||||||
resolvedGraphqlAssetDdo,
|
// resolvedGraphqlAssetDdo,
|
||||||
providerUrl,
|
// providerUrl,
|
||||||
aquarius
|
// aquarius
|
||||||
)
|
// )
|
||||||
assert(updateGraphqlTx, 'Failed to update graphql asset metadata')
|
// assert(updateGraphqlTx, 'Failed to update graphql asset metadata')
|
||||||
})
|
// })
|
||||||
|
|
||||||
delay(10000) // let's wait for aquarius to index the updated ddo's
|
// delay(10000) // let's wait for aquarius to index the updated ddo's
|
||||||
|
|
||||||
it('Should resolve updated datasets', async () => {
|
// it('Should resolve updated datasets', async () => {
|
||||||
resolvedUrlAssetDdoAfterUpdate = await aquarius.waitForAqua(urlAssetId)
|
// resolvedUrlAssetDdoAfterUpdate = await aquarius.waitForAqua(urlAssetId)
|
||||||
assert(resolvedUrlAssetDdoAfterUpdate, 'Cannot fetch url DDO from Aquarius')
|
// assert(resolvedUrlAssetDdoAfterUpdate, 'Cannot fetch url DDO from Aquarius')
|
||||||
|
|
||||||
resolvedArweaveAssetDdoAfterUpdate = await aquarius.waitForAqua(arweaveAssetId)
|
// resolvedArweaveAssetDdoAfterUpdate = await aquarius.waitForAqua(arweaveAssetId)
|
||||||
assert(resolvedArweaveAssetDdoAfterUpdate, 'Cannot fetch arwave DDO from Aquarius')
|
// assert(resolvedArweaveAssetDdoAfterUpdate, 'Cannot fetch arwave DDO from Aquarius')
|
||||||
|
|
||||||
resolvedIpfsAssetDdoAfterUpdate = await aquarius.waitForAqua(ipfsAssetId)
|
// resolvedIpfsAssetDdoAfterUpdate = await aquarius.waitForAqua(ipfsAssetId)
|
||||||
assert(resolvedIpfsAssetDdoAfterUpdate, 'Cannot fetch ipfs DDO from Aquarius')
|
// assert(resolvedIpfsAssetDdoAfterUpdate, 'Cannot fetch ipfs DDO from Aquarius')
|
||||||
|
|
||||||
resolvedOnchainAssetDdoAfterUpdate = await aquarius.waitForAqua(onchainAssetId)
|
// resolvedOnchainAssetDdoAfterUpdate = await aquarius.waitForAqua(onchainAssetId)
|
||||||
assert(resolvedOnchainAssetDdoAfterUpdate, 'Cannot fetch onchain DDO from Aquarius')
|
// assert(resolvedOnchainAssetDdoAfterUpdate, 'Cannot fetch onchain DDO from Aquarius')
|
||||||
|
|
||||||
resolvedGraphqlAssetDdoAfterUpdate = await aquarius.waitForAqua(grapqlAssetId)
|
// resolvedGraphqlAssetDdoAfterUpdate = await aquarius.waitForAqua(grapqlAssetId)
|
||||||
assert(resolvedGraphqlAssetDdoAfterUpdate, 'Cannot fetch onchain DDO from Aquarius')
|
// assert(resolvedGraphqlAssetDdoAfterUpdate, 'Cannot fetch onchain DDO from Aquarius')
|
||||||
})
|
// })
|
||||||
})
|
})
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { SHA256 } from 'crypto-js'
|
import { SHA256 } from 'crypto-js'
|
||||||
|
import { ethers, Signer } from 'ethers'
|
||||||
import {
|
import {
|
||||||
Aquarius,
|
Aquarius,
|
||||||
DatatokenCreateParams,
|
DatatokenCreateParams,
|
||||||
@ -13,24 +14,26 @@ import {
|
|||||||
Datatoken,
|
Datatoken,
|
||||||
Config,
|
Config,
|
||||||
DDO,
|
DDO,
|
||||||
ProviderFees
|
ProviderFees,
|
||||||
|
getEventFromTx
|
||||||
} from '../../src'
|
} from '../../src'
|
||||||
import { web3 } from '../config'
|
|
||||||
|
|
||||||
export async function createAsset(
|
export async function createAsset(
|
||||||
name: string,
|
name: string,
|
||||||
symbol: string,
|
symbol: string,
|
||||||
owner: string,
|
owner: Signer,
|
||||||
assetUrl: any,
|
assetUrl: any,
|
||||||
ddo: any,
|
ddo: any,
|
||||||
providerUrl: string,
|
providerUrl: string,
|
||||||
nftContractAddress: string, // addresses.ERC721Factory,
|
nftContractAddress: string, // addresses.ERC721Factory,
|
||||||
aquariusInstance: Aquarius
|
aquariusInstance: Aquarius
|
||||||
) {
|
) {
|
||||||
const nft = new Nft(web3)
|
const nft = new Nft(owner, 8996)
|
||||||
const Factory = new NftFactory(nftContractAddress, web3)
|
|
||||||
|
const nftFactory = new NftFactory(nftContractAddress, owner)
|
||||||
|
|
||||||
|
const chain = (await owner.provider.getNetwork()).chainId
|
||||||
|
|
||||||
const chain = await web3.eth.getChainId()
|
|
||||||
ddo.chainId = parseInt(chain.toString(10))
|
ddo.chainId = parseInt(chain.toString(10))
|
||||||
const nftParamsAsset: NftCreateData = {
|
const nftParamsAsset: NftCreateData = {
|
||||||
name,
|
name,
|
||||||
@ -38,7 +41,7 @@ export async function createAsset(
|
|||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
tokenURI: 'aaa',
|
tokenURI: 'aaa',
|
||||||
transferable: true,
|
transferable: true,
|
||||||
owner
|
owner: await owner.getAddress()
|
||||||
}
|
}
|
||||||
const datatokenParams: DatatokenCreateParams = {
|
const datatokenParams: DatatokenCreateParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
@ -46,156 +49,157 @@ export async function createAsset(
|
|||||||
feeAmount: '0',
|
feeAmount: '0',
|
||||||
paymentCollector: ZERO_ADDRESS,
|
paymentCollector: ZERO_ADDRESS,
|
||||||
feeToken: ZERO_ADDRESS,
|
feeToken: ZERO_ADDRESS,
|
||||||
minter: owner,
|
minter: await owner.getAddress(),
|
||||||
mpFeeAddress: ZERO_ADDRESS
|
mpFeeAddress: ZERO_ADDRESS
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await Factory.createNftWithDatatoken(
|
const bundleNFT = await nftFactory.createNftWithDatatoken(
|
||||||
owner,
|
|
||||||
nftParamsAsset,
|
nftParamsAsset,
|
||||||
datatokenParams
|
datatokenParams
|
||||||
)
|
)
|
||||||
|
|
||||||
const nftAddress = result.events.NFTCreated.returnValues[0]
|
const trxReceipt = await bundleNFT.wait()
|
||||||
const datatokenAddressAsset = result.events.TokenCreated.returnValues[0]
|
// events have been emitted
|
||||||
ddo.nftAddress = web3.utils.toChecksumAddress(nftAddress)
|
const nftCreatedEvent = getEventFromTx(trxReceipt, 'NFTCreated')
|
||||||
|
const tokenCreatedEvent = getEventFromTx(trxReceipt, 'TokenCreated')
|
||||||
|
|
||||||
|
const nftAddress = nftCreatedEvent.args.newTokenAddress
|
||||||
|
const datatokenAddressAsset = tokenCreatedEvent.args.newTokenAddress
|
||||||
// create the files encrypted string
|
// create the files encrypted string
|
||||||
assetUrl.datatokenAddress = datatokenAddressAsset
|
assetUrl.datatokenAddress = datatokenAddressAsset
|
||||||
assetUrl.nftAddress = ddo.nftAddress
|
assetUrl.nftAddress = ddo.nftAddress
|
||||||
let providerResponse = await ProviderInstance.encrypt(assetUrl, chain, providerUrl)
|
ddo.services[0].files = await ProviderInstance.encrypt(assetUrl, chain, providerUrl)
|
||||||
ddo.services[0].files = await providerResponse
|
|
||||||
ddo.services[0].datatokenAddress = datatokenAddressAsset
|
ddo.services[0].datatokenAddress = datatokenAddressAsset
|
||||||
ddo.services[0].serviceEndpoint = providerUrl
|
ddo.services[0].serviceEndpoint = 'http://172.15.0.4:8030' // put back proviederUrl
|
||||||
// update ddo and set the right did
|
|
||||||
ddo.nftAddress = web3.utils.toChecksumAddress(nftAddress)
|
ddo.nftAddress = nftAddress
|
||||||
ddo.id =
|
ddo.id = 'did:op:' + SHA256(ethers.utils.getAddress(nftAddress) + chain.toString(10))
|
||||||
'did:op:' + SHA256(web3.utils.toChecksumAddress(nftAddress) + chain.toString(10))
|
|
||||||
providerResponse = await ProviderInstance.encrypt(ddo, chain, providerUrl)
|
const encryptedResponse = await ProviderInstance.encrypt(ddo, chain, providerUrl)
|
||||||
const encryptedResponse = await providerResponse
|
|
||||||
const validateResult = await aquariusInstance.validate(ddo)
|
const validateResult = await aquariusInstance.validate(ddo)
|
||||||
await nft.setMetadata(
|
await nft.setMetadata(
|
||||||
nftAddress,
|
nftAddress,
|
||||||
owner,
|
await owner.getAddress(),
|
||||||
0,
|
0,
|
||||||
providerUrl,
|
'http://172.15.0.4:8030', // put back proviederUrl
|
||||||
'',
|
'123',
|
||||||
'0x2',
|
'0x02',
|
||||||
encryptedResponse,
|
encryptedResponse,
|
||||||
validateResult.hash
|
validateResult.hash
|
||||||
)
|
)
|
||||||
return ddo.id
|
return ddo.id
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateAssetMetadata(
|
// export async function updateAssetMetadata(
|
||||||
owner: string,
|
// owner: string,
|
||||||
updatedDdo: DDO,
|
// updatedDdo: DDO,
|
||||||
providerUrl: string,
|
// providerUrl: string,
|
||||||
aquariusInstance: Aquarius
|
// aquariusInstance: Aquarius
|
||||||
) {
|
// ) {
|
||||||
const nft = new Nft(web3)
|
// const nft = new Nft(web3)
|
||||||
const providerResponse = await ProviderInstance.encrypt(
|
// const providerResponse = await ProviderInstance.encrypt(
|
||||||
updatedDdo,
|
// updatedDdo,
|
||||||
updatedDdo.chainId,
|
// updatedDdo.chainId,
|
||||||
providerUrl
|
// providerUrl
|
||||||
)
|
// )
|
||||||
const encryptedResponse = await providerResponse
|
// const encryptedResponse = await providerResponse
|
||||||
const validateResult = await aquariusInstance.validate(updatedDdo)
|
// const validateResult = await aquariusInstance.validate(updatedDdo)
|
||||||
const updateDdoTX = await nft.setMetadata(
|
// const updateDdoTX = await nft.setMetadata(
|
||||||
updatedDdo.nftAddress,
|
// updatedDdo.nftAddress,
|
||||||
owner,
|
// owner,
|
||||||
0,
|
// 0,
|
||||||
providerUrl,
|
// providerUrl,
|
||||||
'',
|
// '',
|
||||||
'0x2',
|
// '0x2',
|
||||||
encryptedResponse,
|
// encryptedResponse,
|
||||||
validateResult.hash
|
// validateResult.hash
|
||||||
)
|
// )
|
||||||
return updateDdoTX
|
// return updateDdoTX
|
||||||
}
|
// }
|
||||||
|
|
||||||
export async function handleComputeOrder(
|
// export async function handleComputeOrder(
|
||||||
order: ProviderComputeInitialize,
|
// order: ProviderComputeInitialize,
|
||||||
datatokenAddress: string,
|
// datatokenAddress: string,
|
||||||
payerAccount: string,
|
// payerAccount: string,
|
||||||
consumerAccount: string,
|
// consumerAccount: string,
|
||||||
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,
|
// web3,
|
||||||
config,
|
// config,
|
||||||
payerAccount,
|
// payerAccount,
|
||||||
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,
|
// payerAccount,
|
||||||
order.validOrder,
|
// order.validOrder,
|
||||||
order.providerFee
|
// order.providerFee
|
||||||
)
|
// )
|
||||||
return tx.transactionHash
|
// return tx.transactionHash
|
||||||
}
|
// }
|
||||||
const tx = await datatoken.startOrder(
|
// const tx = await datatoken.startOrder(
|
||||||
datatokenAddress,
|
// datatokenAddress,
|
||||||
payerAccount,
|
// payerAccount,
|
||||||
consumerAccount,
|
// consumerAccount,
|
||||||
serviceIndex,
|
// serviceIndex,
|
||||||
order.providerFee,
|
// order.providerFee,
|
||||||
consumeMarkerFee
|
// consumeMarkerFee
|
||||||
)
|
// )
|
||||||
return tx.transactionHash
|
// return tx.transactionHash
|
||||||
}
|
// }
|
||||||
|
|
||||||
export async function orderAsset(
|
// export async function orderAsset(
|
||||||
did: string,
|
// did: string,
|
||||||
datatokenAddress: string,
|
// datatokenAddress: string,
|
||||||
consumerAccount: string,
|
// consumerAccount: string,
|
||||||
serviceId: string,
|
// serviceId: string,
|
||||||
serviceIndex: number,
|
// serviceIndex: number,
|
||||||
datatoken: Datatoken,
|
// datatoken: Datatoken,
|
||||||
providerUrl: string
|
// providerUrl: string
|
||||||
) {
|
// ) {
|
||||||
const initializeData = await ProviderInstance.initialize(
|
// const initializeData = await ProviderInstance.initialize(
|
||||||
did, // resolvedDdoAfterUpdate.id,
|
// did, // resolvedDdoAfterUpdate.id,
|
||||||
serviceId, // resolvedDdoAfterUpdate.services[0].id,
|
// serviceId, // resolvedDdoAfterUpdate.services[0].id,
|
||||||
serviceIndex,
|
// serviceIndex,
|
||||||
consumerAccount,
|
// consumerAccount,
|
||||||
providerUrl
|
// providerUrl
|
||||||
)
|
// )
|
||||||
|
|
||||||
console.log(`initializeData fees for did:${did} == ${initializeData.providerFee}`)
|
// console.log(`initializeData fees for did:${did} == ${initializeData.providerFee}`)
|
||||||
|
|
||||||
const providerFees: ProviderFees = {
|
// const providerFees: ProviderFees = {
|
||||||
providerFeeAddress: initializeData.providerFee.providerFeeAddress,
|
// providerFeeAddress: initializeData.providerFee.providerFeeAddress,
|
||||||
providerFeeToken: initializeData.providerFee.providerFeeToken,
|
// providerFeeToken: initializeData.providerFee.providerFeeToken,
|
||||||
providerFeeAmount: initializeData.providerFee.providerFeeAmount,
|
// providerFeeAmount: initializeData.providerFee.providerFeeAmount,
|
||||||
v: initializeData.providerFee.v,
|
// v: initializeData.providerFee.v,
|
||||||
r: initializeData.providerFee.r,
|
// r: initializeData.providerFee.r,
|
||||||
s: initializeData.providerFee.s,
|
// s: initializeData.providerFee.s,
|
||||||
providerData: initializeData.providerFee.providerData,
|
// providerData: initializeData.providerFee.providerData,
|
||||||
validUntil: initializeData.providerFee.validUntil
|
// validUntil: initializeData.providerFee.validUntil
|
||||||
}
|
// }
|
||||||
|
|
||||||
// make the payment
|
// // make the payment
|
||||||
const orderTx = await datatoken.startOrder(
|
// const orderTx = await datatoken.startOrder(
|
||||||
datatokenAddress, // resolvedDdoAfterUpdate.services[0].datatokenAddress,
|
// datatokenAddress, // resolvedDdoAfterUpdate.services[0].datatokenAddress,
|
||||||
consumerAccount,
|
// consumerAccount,
|
||||||
consumerAccount,
|
// consumerAccount,
|
||||||
0,
|
// 0,
|
||||||
providerFees
|
// providerFees
|
||||||
)
|
// )
|
||||||
return orderTx
|
// return orderTx
|
||||||
}
|
// }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user