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