From c97f7503133986c4a6165c4ddcb7f54e5afdc2fe Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Thu, 5 May 2022 13:39:41 +0200 Subject: [PATCH 1/3] refactor SimplePublishConsumeFlow.test.ts file --- .../SimplePublishConsumeFlow.test.ts | 135 ++++++++++-------- 1 file changed, 74 insertions(+), 61 deletions(-) diff --git a/test/integration/SimplePublishConsumeFlow.test.ts b/test/integration/SimplePublishConsumeFlow.test.ts index 99b4e87fd..1e5b324c2 100644 --- a/test/integration/SimplePublishConsumeFlow.test.ts +++ b/test/integration/SimplePublishConsumeFlow.test.ts @@ -1,6 +1,6 @@ import { assert } from 'chai' import { SHA256 } from 'crypto-js' -import { web3, getTestConfig, getAddresses } from '../config' +import { web3, getTestConfig } from '../config' import { Config, ProviderInstance, @@ -10,92 +10,98 @@ import { Datatoken, getHash, Nft, - downloadFile + downloadFile, + ZERO_ADDRESS } from '../../src' import { ProviderFees, Erc20CreateParams } from '../../src/@types' - -const assetUrl = [ - { - type: 'url', - url: 'https://raw.githubusercontent.com/oceanprotocol/testdatasets/main/shs_dataset_test.txt', - method: 'GET' - } -] -const ddo = { - '@context': ['https://w3id.org/did/v1'], - id: 'did:op:efba17455c127a885ec7830d687a8f6e64f5ba559f8506f8723c1f10f05c049c', - version: '4.0.0', - chainId: 4, - nftAddress: '0x0', - metadata: { - created: '2021-12-20T14:35:20Z', - updated: '2021-12-20T14:35:20Z', - type: 'dataset', - name: 'dfgdfgdg', - description: 'd dfgd fgd dfg dfgdfgd dfgdf', - tags: [''], - author: 'dd', - license: 'https://market.oceanprotocol.com/terms', - additionalInformation: { - termsAndConditions: true - } - }, - services: [ - { - id: 'notAnId', - type: 'access', - files: '', - datatokenAddress: '0xa15024b732A8f2146423D14209eFd074e61964F3', - serviceEndpoint: 'https://providerv4.rinkeby.oceanprotocol.com', - timeout: 0 - } - ] -} +import { Addresses, deployContracts } from '../TestContractHandler' describe('Simple Publish & consume test', async () => { let config: Config - let addresses: any + let contracts: Addresses let aquarius: Aquarius let providerUrl: any + let publisherAccount: string + let consumerAccount: string + + const assetUrl = [ + { + type: 'url', + url: 'https://raw.githubusercontent.com/oceanprotocol/testdatasets/main/shs_dataset_test.txt', + method: 'GET' + } + ] + + const ddo = { + '@context': ['https://w3id.org/did/v1'], + id: '', + version: '4.0.0', + chainId: 4, + nftAddress: '0x0', + metadata: { + created: '2021-12-20T14:35:20Z', + updated: '2021-12-20T14:35:20Z', + type: 'dataset', + name: 'dataset-name', + description: 'Ocean protocol test dataset description', + author: 'oceanprotocol-team', + license: 'MIT' + }, + services: [ + { + id: 'testFakeId', + type: 'access', + files: '', + datatokenAddress: '0x0', + serviceEndpoint: 'https://providerv4.rinkeby.oceanprotocol.com', + timeout: 0 + } + ] + } before(async () => { config = await getTestConfig(web3) - addresses = getAddresses() aquarius = new Aquarius(config.metadataCacheUri) providerUrl = config.providerUri }) + it('Initialize accounts', async () => { + const accounts = await web3.eth.getAccounts() + publisherAccount = accounts[0] + consumerAccount = accounts[1] + }) + + it('Deploy contracts', async () => { + contracts = await deployContracts(web3, publisherAccount) + }) + it('should publish a dataset (create NFT + ERC20)', async () => { const nft = new Nft(web3) const datatoken = new Datatoken(web3) - const Factory = new NftFactory(addresses.ERC721Factory, web3) - const accounts = await web3.eth.getAccounts() - const publisherAccount = accounts[0] - const consumerAccount = accounts[1] + const Factory = new NftFactory(contracts.erc721FactoryAddress, web3) + const nftParams: NftCreateData = { - name: 'testNFT', - symbol: 'TST', + name: '72120Bundle', + symbol: '72Bundle', templateIndex: 1, - tokenURI: '', + tokenURI: 'https://oceanprotocol.com/nft/', transferable: true, owner: publisherAccount } + const erc20Params: Erc20CreateParams = { templateIndex: 1, cap: '100000', feeAmount: '0', - paymentCollector: '0x0000000000000000000000000000000000000000', - feeToken: '0x0000000000000000000000000000000000000000', + paymentCollector: ZERO_ADDRESS, + feeToken: ZERO_ADDRESS, minter: publisherAccount, - mpFeeAddress: '0x0000000000000000000000000000000000000000' + mpFeeAddress: ZERO_ADDRESS } - const result = await Factory.createNftWithErc20( - publisherAccount, - nftParams, - erc20Params - ) - const erc721Address = result.events.NFTCreated.returnValues[0] - const datatokenAddress = result.events.TokenCreated.returnValues[0] + + const tx = await Factory.createNftWithErc20(publisherAccount, nftParams, erc20Params) + const erc721Address = tx.events.NFTCreated.returnValues[0] + const datatokenAddress = tx.events.TokenCreated.returnValues[0] // create the files encrypted string let providerResponse = await ProviderInstance.encrypt(assetUrl, providerUrl) @@ -110,7 +116,7 @@ describe('Simple Publish & consume test', async () => { providerResponse = await ProviderInstance.encrypt(ddo, providerUrl) const encryptedResponse = await providerResponse const metadataHash = getHash(JSON.stringify(ddo)) - const res = await nft.setMetadata( + await nft.setMetadata( erc721Address, publisherAccount, 0, @@ -120,10 +126,13 @@ describe('Simple Publish & consume test', async () => { encryptedResponse, '0x' + metadataHash ) + const resolvedDDO = await aquarius.waitForAqua(ddo.id) assert(resolvedDDO, 'Cannot fetch DDO from Aquarius') + // mint 1 ERC20 and send it to the consumer await datatoken.mint(datatokenAddress, publisherAccount, '1', consumerAccount) + // initialize provider const initializeData = await ProviderInstance.initialize( resolvedDDO.id, @@ -132,6 +141,7 @@ describe('Simple Publish & consume test', async () => { consumerAccount, providerUrl ) + const providerFees: ProviderFees = { providerFeeAddress: initializeData.providerFee.providerFeeAddress, providerFeeToken: initializeData.providerFee.providerFeeToken, @@ -142,6 +152,7 @@ describe('Simple Publish & consume test', async () => { providerData: initializeData.providerFee.providerData, validUntil: initializeData.providerFee.validUntil } + // make the payment const txid = await datatoken.startOrder( datatokenAddress, @@ -150,6 +161,7 @@ describe('Simple Publish & consume test', async () => { 0, providerFees ) + // get the url const downloadURL = await ProviderInstance.getDownloadUrl( ddo.id, @@ -160,9 +172,10 @@ describe('Simple Publish & consume test', async () => { providerUrl, web3 ) + assert(downloadURL, 'Provider getDownloadUrl failed') try { - const fileData = await downloadFile(downloadURL) + await downloadFile(downloadURL) } catch (e) { assert.fail('Download failed') } From a75ca34e9e5245cfdbb670f1c23c91d96c57ec30 Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Fri, 6 May 2022 10:43:44 +0200 Subject: [PATCH 2/3] don't deploy smart contracts --- test/integration/SimplePublishConsumeFlow.test.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/test/integration/SimplePublishConsumeFlow.test.ts b/test/integration/SimplePublishConsumeFlow.test.ts index 1e5b324c2..9f4feedc2 100644 --- a/test/integration/SimplePublishConsumeFlow.test.ts +++ b/test/integration/SimplePublishConsumeFlow.test.ts @@ -1,6 +1,6 @@ import { assert } from 'chai' import { SHA256 } from 'crypto-js' -import { web3, getTestConfig } from '../config' +import { web3, getTestConfig, getAddresses } from '../config' import { Config, ProviderInstance, @@ -14,11 +14,10 @@ import { ZERO_ADDRESS } from '../../src' import { ProviderFees, Erc20CreateParams } from '../../src/@types' -import { Addresses, deployContracts } from '../TestContractHandler' describe('Simple Publish & consume test', async () => { let config: Config - let contracts: Addresses + let addresses: any let aquarius: Aquarius let providerUrl: any let publisherAccount: string @@ -63,6 +62,8 @@ describe('Simple Publish & consume test', async () => { config = await getTestConfig(web3) aquarius = new Aquarius(config.metadataCacheUri) providerUrl = config.providerUri + + addresses = getAddresses() }) it('Initialize accounts', async () => { @@ -71,14 +72,10 @@ describe('Simple Publish & consume test', async () => { consumerAccount = accounts[1] }) - it('Deploy contracts', async () => { - contracts = await deployContracts(web3, publisherAccount) - }) - it('should publish a dataset (create NFT + ERC20)', async () => { const nft = new Nft(web3) const datatoken = new Datatoken(web3) - const Factory = new NftFactory(contracts.erc721FactoryAddress, web3) + const Factory = new NftFactory(addresses.ERC721Factory, web3) const nftParams: NftCreateData = { name: '72120Bundle', From 11508b7794048dc5f81fc4aba4c3a5b551c9e18c Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Fri, 6 May 2022 11:14:39 +0200 Subject: [PATCH 3/3] add DDO type --- test/integration/SimplePublishConsumeFlow.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/SimplePublishConsumeFlow.test.ts b/test/integration/SimplePublishConsumeFlow.test.ts index 9f4feedc2..1036ed69a 100644 --- a/test/integration/SimplePublishConsumeFlow.test.ts +++ b/test/integration/SimplePublishConsumeFlow.test.ts @@ -13,7 +13,7 @@ import { downloadFile, ZERO_ADDRESS } from '../../src' -import { ProviderFees, Erc20CreateParams } from '../../src/@types' +import { ProviderFees, Erc20CreateParams, DDO } from '../../src/@types' describe('Simple Publish & consume test', async () => { let config: Config @@ -31,7 +31,7 @@ describe('Simple Publish & consume test', async () => { } ] - const ddo = { + const ddo: DDO = { '@context': ['https://w3id.org/did/v1'], id: '', version: '4.0.0',