mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Merge pull request #1460 from oceanprotocol/issue-1342-rewrite-publish-flow-test
Issue-#1342: Rewrite publish flow test
This commit is contained in:
commit
9e3a945753
@ -1,15 +1,5 @@
|
|||||||
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
|
|
||||||
import { assert } from 'chai'
|
import { assert } from 'chai'
|
||||||
import { SHA256 } from 'crypto-js'
|
import { SHA256 } from 'crypto-js'
|
||||||
import { AbiItem } from 'web3-utils'
|
|
||||||
import {
|
|
||||||
ValidateMetadata,
|
|
||||||
DDO,
|
|
||||||
Erc20CreateParams,
|
|
||||||
PoolCreationParams,
|
|
||||||
FreCreationParams,
|
|
||||||
DispenserCreationParams
|
|
||||||
} from '../../src/@types'
|
|
||||||
import { web3, getTestConfig, getAddresses } from '../config'
|
import { web3, getTestConfig, getAddresses } from '../config'
|
||||||
import {
|
import {
|
||||||
Config,
|
Config,
|
||||||
@ -19,102 +9,120 @@ import {
|
|||||||
NftCreateData,
|
NftCreateData,
|
||||||
getHash,
|
getHash,
|
||||||
ZERO_ADDRESS,
|
ZERO_ADDRESS,
|
||||||
Nft
|
Nft,
|
||||||
|
approve
|
||||||
} from '../../src'
|
} from '../../src'
|
||||||
|
import {
|
||||||
let nft: Nft
|
ValidateMetadata,
|
||||||
let factory: NftFactory
|
DDO,
|
||||||
let accounts: string[]
|
Erc20CreateParams,
|
||||||
|
PoolCreationParams,
|
||||||
const files = [
|
FreCreationParams,
|
||||||
{
|
DispenserCreationParams
|
||||||
type: 'url',
|
} from '../../src/@types'
|
||||||
url: 'https://raw.githubusercontent.com/oceanprotocol/testdatasets/main/shs_dataset_test.txt',
|
|
||||||
method: 'GET'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
const genericAsset: DDO = {
|
|
||||||
'@context': ['https://w3id.org/did/v1'],
|
|
||||||
id: 'testFakeDid',
|
|
||||||
version: '4.0.0',
|
|
||||||
chainId: 4,
|
|
||||||
nftAddress: '0x0',
|
|
||||||
metadata: {
|
|
||||||
created: '2021-12-20T14:35:20Z',
|
|
||||||
updated: '2021-12-20T14:35:20Z',
|
|
||||||
name: 'dataset-name',
|
|
||||||
type: 'dataset',
|
|
||||||
description: 'Ocean protocol test dataset description',
|
|
||||||
author: 'oceanprotocol-team',
|
|
||||||
license: 'MIT',
|
|
||||||
tags: ['white-papers'],
|
|
||||||
additionalInformation: { 'test-key': 'test-value' },
|
|
||||||
links: ['http://data.ceda.ac.uk/badc/ukcp09/']
|
|
||||||
},
|
|
||||||
services: [
|
|
||||||
{
|
|
||||||
id: 'testFakeId',
|
|
||||||
type: 'access',
|
|
||||||
description: 'Download service',
|
|
||||||
files: '',
|
|
||||||
datatokenAddress: '0xa15024b732A8f2146423D14209eFd074e61964F3',
|
|
||||||
serviceEndpoint: 'https://providerv4.rinkeby.oceanprotocol.com',
|
|
||||||
timeout: 0
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('Publish tests', async () => {
|
describe('Publish tests', async () => {
|
||||||
let config: Config
|
let config: Config
|
||||||
let addresses: any
|
let addresses: any
|
||||||
let aquarius: Aquarius
|
let aquarius: Aquarius
|
||||||
let providerUrl: any
|
let providerUrl: any
|
||||||
|
let nft: Nft
|
||||||
|
let factory: NftFactory
|
||||||
|
let publisherAccount: string
|
||||||
|
|
||||||
|
const assetUrl = [
|
||||||
|
{
|
||||||
|
type: 'url',
|
||||||
|
url: 'https://raw.githubusercontent.com/oceanprotocol/testdatasets/main/shs_dataset_test.txt',
|
||||||
|
method: 'GET'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
const genericAsset: 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',
|
||||||
|
tags: ['white-papers'],
|
||||||
|
additionalInformation: { 'test-key': 'test-value' },
|
||||||
|
links: ['http://data.ceda.ac.uk/badc/ukcp09/']
|
||||||
|
},
|
||||||
|
services: [
|
||||||
|
{
|
||||||
|
id: 'testFakeId',
|
||||||
|
type: 'access',
|
||||||
|
description: 'Download service',
|
||||||
|
files: '',
|
||||||
|
datatokenAddress: '0x0',
|
||||||
|
serviceEndpoint: 'https://providerv4.rinkeby.oceanprotocol.com',
|
||||||
|
timeout: 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
config = await getTestConfig(web3)
|
config = await getTestConfig(web3)
|
||||||
addresses = getAddresses()
|
|
||||||
aquarius = new Aquarius(config.metadataCacheUri)
|
aquarius = new Aquarius(config.metadataCacheUri)
|
||||||
providerUrl = config.providerUri
|
providerUrl = config.providerUri
|
||||||
|
|
||||||
|
addresses = getAddresses()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('initialise testes classes', async () => {
|
it('initialize accounts', async () => {
|
||||||
|
const accounts = await web3.eth.getAccounts()
|
||||||
|
publisherAccount = accounts[0]
|
||||||
|
})
|
||||||
|
|
||||||
|
it('initialize test classes', async () => {
|
||||||
nft = new Nft(web3)
|
nft = new Nft(web3)
|
||||||
factory = new NftFactory(addresses.ERC721Factory, web3)
|
factory = new NftFactory(addresses.ERC721Factory, web3)
|
||||||
accounts = await web3.eth.getAccounts()
|
|
||||||
const daiContract = new web3.eth.Contract(
|
await approve(
|
||||||
MockERC20.abi as AbiItem[],
|
web3,
|
||||||
addresses.MockDAI
|
publisherAccount,
|
||||||
|
addresses.MockDAI,
|
||||||
|
addresses.ERC721Factory,
|
||||||
|
'100000'
|
||||||
)
|
)
|
||||||
await daiContract.methods
|
|
||||||
.approve(addresses.ERC721Factory, web3.utils.toWei('100000'))
|
|
||||||
.send({ from: accounts[0] })
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should publish a dataset with pool (create NFT + ERC20 + pool) and with Metdata proof', async () => {
|
it('should publish a dataset with pool (create NFT + ERC20 + pool) and with Metdata proof', async () => {
|
||||||
const poolDdo: DDO = { ...genericAsset }
|
const poolDdo: DDO = { ...genericAsset }
|
||||||
|
|
||||||
const nftParams: NftCreateData = {
|
const nftParams: NftCreateData = {
|
||||||
name: 'testNftPool',
|
name: 'testNftPool',
|
||||||
symbol: 'TSTP',
|
symbol: 'TSTP',
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
tokenURI: '',
|
tokenURI: '',
|
||||||
transferable: true,
|
transferable: true,
|
||||||
owner: accounts[0]
|
owner: publisherAccount
|
||||||
}
|
}
|
||||||
|
|
||||||
const erc20Params: Erc20CreateParams = {
|
const erc20Params: Erc20CreateParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
cap: '100000',
|
cap: '100000',
|
||||||
feeAmount: '0',
|
feeAmount: '0',
|
||||||
paymentCollector: ZERO_ADDRESS,
|
paymentCollector: ZERO_ADDRESS,
|
||||||
feeToken: ZERO_ADDRESS,
|
feeToken: ZERO_ADDRESS,
|
||||||
minter: accounts[0],
|
minter: publisherAccount,
|
||||||
mpFeeAddress: ZERO_ADDRESS
|
mpFeeAddress: ZERO_ADDRESS
|
||||||
}
|
}
|
||||||
|
|
||||||
const poolParams: PoolCreationParams = {
|
const poolParams: PoolCreationParams = {
|
||||||
ssContract: addresses.Staking,
|
ssContract: addresses.Staking,
|
||||||
baseTokenAddress: addresses.MockDAI,
|
baseTokenAddress: addresses.MockDAI,
|
||||||
baseTokenSender: addresses.ERC721Factory,
|
baseTokenSender: addresses.ERC721Factory,
|
||||||
publisherAddress: accounts[0],
|
publisherAddress: publisherAccount,
|
||||||
marketFeeCollector: accounts[0],
|
marketFeeCollector: publisherAccount,
|
||||||
poolTemplateAddress: addresses.poolTemplate,
|
poolTemplateAddress: addresses.poolTemplate,
|
||||||
rate: '1',
|
rate: '1',
|
||||||
baseTokenDecimals: 18,
|
baseTokenDecimals: 18,
|
||||||
@ -124,8 +132,9 @@ describe('Publish tests', async () => {
|
|||||||
swapFeeLiquidityProvider: '0.001',
|
swapFeeLiquidityProvider: '0.001',
|
||||||
swapFeeMarketRunner: '0.001'
|
swapFeeMarketRunner: '0.001'
|
||||||
}
|
}
|
||||||
|
|
||||||
const bundleNFT = await factory.createNftErc20WithPool(
|
const bundleNFT = await factory.createNftErc20WithPool(
|
||||||
accounts[0],
|
publisherAccount,
|
||||||
nftParams,
|
nftParams,
|
||||||
erc20Params,
|
erc20Params,
|
||||||
poolParams
|
poolParams
|
||||||
@ -133,9 +142,8 @@ describe('Publish tests', async () => {
|
|||||||
|
|
||||||
const nftAddress = bundleNFT.events.NFTCreated.returnValues[0]
|
const nftAddress = bundleNFT.events.NFTCreated.returnValues[0]
|
||||||
const datatokenAddress = bundleNFT.events.TokenCreated.returnValues[0]
|
const datatokenAddress = bundleNFT.events.TokenCreated.returnValues[0]
|
||||||
const poolAdress = bundleNFT.events.NewPool.returnValues[0]
|
|
||||||
|
|
||||||
const encryptedFiles = await ProviderInstance.encrypt(files, providerUrl)
|
const encryptedFiles = await ProviderInstance.encrypt(assetUrl, providerUrl)
|
||||||
|
|
||||||
poolDdo.metadata.name = 'test-dataset-pool'
|
poolDdo.metadata.name = 'test-dataset-pool'
|
||||||
poolDdo.services[0].files = await encryptedFiles
|
poolDdo.services[0].files = await encryptedFiles
|
||||||
@ -155,9 +163,9 @@ describe('Publish tests', async () => {
|
|||||||
const metadataHash = getHash(JSON.stringify(poolDdo))
|
const metadataHash = getHash(JSON.stringify(poolDdo))
|
||||||
// just to make sure that our hash matches one computed by aquarius
|
// just to make sure that our hash matches one computed by aquarius
|
||||||
assert(AssetValidation.hash === '0x' + metadataHash, 'Metadata hash is a missmatch')
|
assert(AssetValidation.hash === '0x' + metadataHash, 'Metadata hash is a missmatch')
|
||||||
const tx = await nft.setMetadata(
|
await nft.setMetadata(
|
||||||
nftAddress,
|
nftAddress,
|
||||||
accounts[0],
|
publisherAccount,
|
||||||
0,
|
0,
|
||||||
providerUrl,
|
providerUrl,
|
||||||
'',
|
'',
|
||||||
@ -173,39 +181,41 @@ describe('Publish tests', async () => {
|
|||||||
|
|
||||||
it('should publish a dataset with fixed price (create NFT + ERC20 + fixed price) with an explicit empty Metadata Proof', async () => {
|
it('should publish a dataset with fixed price (create NFT + ERC20 + fixed price) with an explicit empty Metadata Proof', async () => {
|
||||||
const fixedPriceDdo: DDO = { ...genericAsset }
|
const fixedPriceDdo: DDO = { ...genericAsset }
|
||||||
|
|
||||||
const nftParams: NftCreateData = {
|
const nftParams: NftCreateData = {
|
||||||
name: 'testNftFre',
|
name: 'testNftFre',
|
||||||
symbol: 'TSTF',
|
symbol: 'TSTF',
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
tokenURI: '',
|
tokenURI: '',
|
||||||
transferable: true,
|
transferable: true,
|
||||||
owner: accounts[0]
|
owner: publisherAccount
|
||||||
}
|
}
|
||||||
|
|
||||||
const erc20Params: Erc20CreateParams = {
|
const erc20Params: Erc20CreateParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
cap: '100000',
|
cap: '100000',
|
||||||
feeAmount: '0',
|
feeAmount: '0',
|
||||||
paymentCollector: ZERO_ADDRESS,
|
paymentCollector: ZERO_ADDRESS,
|
||||||
feeToken: ZERO_ADDRESS,
|
feeToken: ZERO_ADDRESS,
|
||||||
minter: accounts[0],
|
minter: publisherAccount,
|
||||||
mpFeeAddress: ZERO_ADDRESS
|
mpFeeAddress: ZERO_ADDRESS
|
||||||
}
|
}
|
||||||
|
|
||||||
const fixedPriceParams: FreCreationParams = {
|
const fixedPriceParams: FreCreationParams = {
|
||||||
fixedRateAddress: addresses.FixedPrice,
|
fixedRateAddress: addresses.FixedPrice,
|
||||||
baseTokenAddress: addresses.MockDAI,
|
baseTokenAddress: addresses.MockDAI,
|
||||||
owner: accounts[0],
|
owner: publisherAccount,
|
||||||
marketFeeCollector: accounts[0],
|
marketFeeCollector: publisherAccount,
|
||||||
baseTokenDecimals: 18,
|
baseTokenDecimals: 18,
|
||||||
datatokenDecimals: 18,
|
datatokenDecimals: 18,
|
||||||
fixedRate: '1',
|
fixedRate: '1',
|
||||||
marketFee: '0',
|
marketFee: '0',
|
||||||
allowedConsumer: accounts[0],
|
allowedConsumer: publisherAccount,
|
||||||
withMint: false
|
withMint: false
|
||||||
}
|
}
|
||||||
|
|
||||||
const bundleNFT = await factory.createNftErc20WithFixedRate(
|
const bundleNFT = await factory.createNftErc20WithFixedRate(
|
||||||
accounts[0],
|
publisherAccount,
|
||||||
nftParams,
|
nftParams,
|
||||||
erc20Params,
|
erc20Params,
|
||||||
fixedPriceParams
|
fixedPriceParams
|
||||||
@ -213,9 +223,8 @@ describe('Publish tests', async () => {
|
|||||||
|
|
||||||
const nftAddress = bundleNFT.events.NFTCreated.returnValues[0]
|
const nftAddress = bundleNFT.events.NFTCreated.returnValues[0]
|
||||||
const datatokenAddress = bundleNFT.events.TokenCreated.returnValues[0]
|
const datatokenAddress = bundleNFT.events.TokenCreated.returnValues[0]
|
||||||
const fixedPrice = bundleNFT.events.NewFixedRate.returnValues[0]
|
|
||||||
|
|
||||||
const encryptedFiles = await ProviderInstance.encrypt(files, providerUrl)
|
const encryptedFiles = await ProviderInstance.encrypt(assetUrl, providerUrl)
|
||||||
|
|
||||||
fixedPriceDdo.metadata.name = 'test-dataset-fixedPrice'
|
fixedPriceDdo.metadata.name = 'test-dataset-fixedPrice'
|
||||||
fixedPriceDdo.services[0].files = await encryptedFiles
|
fixedPriceDdo.services[0].files = await encryptedFiles
|
||||||
@ -234,9 +243,9 @@ describe('Publish tests', async () => {
|
|||||||
const encryptedResponse = await encryptedDdo
|
const encryptedResponse = await encryptedDdo
|
||||||
const metadataHash = getHash(JSON.stringify(fixedPriceDdo))
|
const metadataHash = getHash(JSON.stringify(fixedPriceDdo))
|
||||||
// this is publishing with an explicit empty metadataProofs
|
// this is publishing with an explicit empty metadataProofs
|
||||||
const res = await nft.setMetadata(
|
await nft.setMetadata(
|
||||||
nftAddress,
|
nftAddress,
|
||||||
accounts[0],
|
publisherAccount,
|
||||||
0,
|
0,
|
||||||
providerUrl,
|
providerUrl,
|
||||||
'',
|
'',
|
||||||
@ -251,21 +260,23 @@ describe('Publish tests', async () => {
|
|||||||
|
|
||||||
it('should publish a dataset with dispenser (create NFT + ERC20 + dispenser) with no defined MetadataProof', async () => {
|
it('should publish a dataset with dispenser (create NFT + ERC20 + dispenser) with no defined MetadataProof', async () => {
|
||||||
const dispenserDdo: DDO = { ...genericAsset }
|
const dispenserDdo: DDO = { ...genericAsset }
|
||||||
|
|
||||||
const nftParams: NftCreateData = {
|
const nftParams: NftCreateData = {
|
||||||
name: 'testNftDispenser',
|
name: 'testNftDispenser',
|
||||||
symbol: 'TSTD',
|
symbol: 'TSTD',
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
tokenURI: '',
|
tokenURI: '',
|
||||||
transferable: true,
|
transferable: true,
|
||||||
owner: accounts[0]
|
owner: publisherAccount
|
||||||
}
|
}
|
||||||
|
|
||||||
const erc20Params: Erc20CreateParams = {
|
const erc20Params: Erc20CreateParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
cap: '100000',
|
cap: '100000',
|
||||||
feeAmount: '0',
|
feeAmount: '0',
|
||||||
paymentCollector: ZERO_ADDRESS,
|
paymentCollector: ZERO_ADDRESS,
|
||||||
feeToken: ZERO_ADDRESS,
|
feeToken: ZERO_ADDRESS,
|
||||||
minter: accounts[0],
|
minter: publisherAccount,
|
||||||
mpFeeAddress: ZERO_ADDRESS
|
mpFeeAddress: ZERO_ADDRESS
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,7 +289,7 @@ describe('Publish tests', async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const bundleNFT = await factory.createNftErc20WithDispenser(
|
const bundleNFT = await factory.createNftErc20WithDispenser(
|
||||||
accounts[0],
|
publisherAccount,
|
||||||
nftParams,
|
nftParams,
|
||||||
erc20Params,
|
erc20Params,
|
||||||
dispenserParams
|
dispenserParams
|
||||||
@ -286,9 +297,8 @@ describe('Publish tests', async () => {
|
|||||||
|
|
||||||
const nftAddress = bundleNFT.events.NFTCreated.returnValues[0]
|
const nftAddress = bundleNFT.events.NFTCreated.returnValues[0]
|
||||||
const datatokenAddress = bundleNFT.events.TokenCreated.returnValues[0]
|
const datatokenAddress = bundleNFT.events.TokenCreated.returnValues[0]
|
||||||
const dispenserAddress = bundleNFT.events.DispenserCreated.returnValues[0]
|
|
||||||
|
|
||||||
const encryptedFiles = await ProviderInstance.encrypt(files, providerUrl)
|
const encryptedFiles = await ProviderInstance.encrypt(assetUrl, providerUrl)
|
||||||
dispenserDdo.metadata.name = 'test-dataset-dispenser'
|
dispenserDdo.metadata.name = 'test-dataset-dispenser'
|
||||||
dispenserDdo.services[0].files = await encryptedFiles
|
dispenserDdo.services[0].files = await encryptedFiles
|
||||||
dispenserDdo.services[0].datatokenAddress = datatokenAddress
|
dispenserDdo.services[0].datatokenAddress = datatokenAddress
|
||||||
@ -306,9 +316,9 @@ describe('Publish tests', async () => {
|
|||||||
const encryptedResponse = await encryptedDdo
|
const encryptedResponse = await encryptedDdo
|
||||||
const metadataHash = getHash(JSON.stringify(dispenserDdo))
|
const metadataHash = getHash(JSON.stringify(dispenserDdo))
|
||||||
// this is publishing with any explicit metadataProofs
|
// this is publishing with any explicit metadataProofs
|
||||||
const res = await nft.setMetadata(
|
await nft.setMetadata(
|
||||||
nftAddress,
|
nftAddress,
|
||||||
accounts[0],
|
publisherAccount,
|
||||||
0,
|
0,
|
||||||
providerUrl,
|
providerUrl,
|
||||||
'',
|
'',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user