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 { 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 {
|
||||
Config,
|
||||
@ -19,102 +9,120 @@ import {
|
||||
NftCreateData,
|
||||
getHash,
|
||||
ZERO_ADDRESS,
|
||||
Nft
|
||||
Nft,
|
||||
approve
|
||||
} from '../../src'
|
||||
|
||||
let nft: Nft
|
||||
let factory: NftFactory
|
||||
let accounts: string[]
|
||||
|
||||
const files = [
|
||||
{
|
||||
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: '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
|
||||
}
|
||||
]
|
||||
}
|
||||
import {
|
||||
ValidateMetadata,
|
||||
DDO,
|
||||
Erc20CreateParams,
|
||||
PoolCreationParams,
|
||||
FreCreationParams,
|
||||
DispenserCreationParams
|
||||
} from '../../src/@types'
|
||||
|
||||
describe('Publish tests', async () => {
|
||||
let config: Config
|
||||
let addresses: any
|
||||
let aquarius: Aquarius
|
||||
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 () => {
|
||||
config = await getTestConfig(web3)
|
||||
addresses = getAddresses()
|
||||
aquarius = new Aquarius(config.metadataCacheUri)
|
||||
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)
|
||||
factory = new NftFactory(addresses.ERC721Factory, web3)
|
||||
accounts = await web3.eth.getAccounts()
|
||||
const daiContract = new web3.eth.Contract(
|
||||
MockERC20.abi as AbiItem[],
|
||||
addresses.MockDAI
|
||||
|
||||
await approve(
|
||||
web3,
|
||||
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 () => {
|
||||
const poolDdo: DDO = { ...genericAsset }
|
||||
|
||||
const nftParams: NftCreateData = {
|
||||
name: 'testNftPool',
|
||||
symbol: 'TSTP',
|
||||
templateIndex: 1,
|
||||
tokenURI: '',
|
||||
transferable: true,
|
||||
owner: accounts[0]
|
||||
owner: publisherAccount
|
||||
}
|
||||
|
||||
const erc20Params: Erc20CreateParams = {
|
||||
templateIndex: 1,
|
||||
cap: '100000',
|
||||
feeAmount: '0',
|
||||
paymentCollector: ZERO_ADDRESS,
|
||||
feeToken: ZERO_ADDRESS,
|
||||
minter: accounts[0],
|
||||
minter: publisherAccount,
|
||||
mpFeeAddress: ZERO_ADDRESS
|
||||
}
|
||||
|
||||
const poolParams: PoolCreationParams = {
|
||||
ssContract: addresses.Staking,
|
||||
baseTokenAddress: addresses.MockDAI,
|
||||
baseTokenSender: addresses.ERC721Factory,
|
||||
publisherAddress: accounts[0],
|
||||
marketFeeCollector: accounts[0],
|
||||
publisherAddress: publisherAccount,
|
||||
marketFeeCollector: publisherAccount,
|
||||
poolTemplateAddress: addresses.poolTemplate,
|
||||
rate: '1',
|
||||
baseTokenDecimals: 18,
|
||||
@ -124,8 +132,9 @@ describe('Publish tests', async () => {
|
||||
swapFeeLiquidityProvider: '0.001',
|
||||
swapFeeMarketRunner: '0.001'
|
||||
}
|
||||
|
||||
const bundleNFT = await factory.createNftErc20WithPool(
|
||||
accounts[0],
|
||||
publisherAccount,
|
||||
nftParams,
|
||||
erc20Params,
|
||||
poolParams
|
||||
@ -133,9 +142,8 @@ describe('Publish tests', async () => {
|
||||
|
||||
const nftAddress = bundleNFT.events.NFTCreated.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.services[0].files = await encryptedFiles
|
||||
@ -155,9 +163,9 @@ describe('Publish tests', async () => {
|
||||
const metadataHash = getHash(JSON.stringify(poolDdo))
|
||||
// just to make sure that our hash matches one computed by aquarius
|
||||
assert(AssetValidation.hash === '0x' + metadataHash, 'Metadata hash is a missmatch')
|
||||
const tx = await nft.setMetadata(
|
||||
await nft.setMetadata(
|
||||
nftAddress,
|
||||
accounts[0],
|
||||
publisherAccount,
|
||||
0,
|
||||
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 () => {
|
||||
const fixedPriceDdo: DDO = { ...genericAsset }
|
||||
|
||||
const nftParams: NftCreateData = {
|
||||
name: 'testNftFre',
|
||||
symbol: 'TSTF',
|
||||
templateIndex: 1,
|
||||
tokenURI: '',
|
||||
transferable: true,
|
||||
owner: accounts[0]
|
||||
owner: publisherAccount
|
||||
}
|
||||
|
||||
const erc20Params: Erc20CreateParams = {
|
||||
templateIndex: 1,
|
||||
cap: '100000',
|
||||
feeAmount: '0',
|
||||
paymentCollector: ZERO_ADDRESS,
|
||||
feeToken: ZERO_ADDRESS,
|
||||
minter: accounts[0],
|
||||
minter: publisherAccount,
|
||||
mpFeeAddress: ZERO_ADDRESS
|
||||
}
|
||||
|
||||
const fixedPriceParams: FreCreationParams = {
|
||||
fixedRateAddress: addresses.FixedPrice,
|
||||
baseTokenAddress: addresses.MockDAI,
|
||||
owner: accounts[0],
|
||||
marketFeeCollector: accounts[0],
|
||||
owner: publisherAccount,
|
||||
marketFeeCollector: publisherAccount,
|
||||
baseTokenDecimals: 18,
|
||||
datatokenDecimals: 18,
|
||||
fixedRate: '1',
|
||||
marketFee: '0',
|
||||
allowedConsumer: accounts[0],
|
||||
allowedConsumer: publisherAccount,
|
||||
withMint: false
|
||||
}
|
||||
|
||||
const bundleNFT = await factory.createNftErc20WithFixedRate(
|
||||
accounts[0],
|
||||
publisherAccount,
|
||||
nftParams,
|
||||
erc20Params,
|
||||
fixedPriceParams
|
||||
@ -213,9 +223,8 @@ describe('Publish tests', async () => {
|
||||
|
||||
const nftAddress = bundleNFT.events.NFTCreated.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.services[0].files = await encryptedFiles
|
||||
@ -234,9 +243,9 @@ describe('Publish tests', async () => {
|
||||
const encryptedResponse = await encryptedDdo
|
||||
const metadataHash = getHash(JSON.stringify(fixedPriceDdo))
|
||||
// this is publishing with an explicit empty metadataProofs
|
||||
const res = await nft.setMetadata(
|
||||
await nft.setMetadata(
|
||||
nftAddress,
|
||||
accounts[0],
|
||||
publisherAccount,
|
||||
0,
|
||||
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 () => {
|
||||
const dispenserDdo: DDO = { ...genericAsset }
|
||||
|
||||
const nftParams: NftCreateData = {
|
||||
name: 'testNftDispenser',
|
||||
symbol: 'TSTD',
|
||||
templateIndex: 1,
|
||||
tokenURI: '',
|
||||
transferable: true,
|
||||
owner: accounts[0]
|
||||
owner: publisherAccount
|
||||
}
|
||||
|
||||
const erc20Params: Erc20CreateParams = {
|
||||
templateIndex: 1,
|
||||
cap: '100000',
|
||||
feeAmount: '0',
|
||||
paymentCollector: ZERO_ADDRESS,
|
||||
feeToken: ZERO_ADDRESS,
|
||||
minter: accounts[0],
|
||||
minter: publisherAccount,
|
||||
mpFeeAddress: ZERO_ADDRESS
|
||||
}
|
||||
|
||||
@ -278,7 +289,7 @@ describe('Publish tests', async () => {
|
||||
}
|
||||
|
||||
const bundleNFT = await factory.createNftErc20WithDispenser(
|
||||
accounts[0],
|
||||
publisherAccount,
|
||||
nftParams,
|
||||
erc20Params,
|
||||
dispenserParams
|
||||
@ -286,9 +297,8 @@ describe('Publish tests', async () => {
|
||||
|
||||
const nftAddress = bundleNFT.events.NFTCreated.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.services[0].files = await encryptedFiles
|
||||
dispenserDdo.services[0].datatokenAddress = datatokenAddress
|
||||
@ -306,9 +316,9 @@ describe('Publish tests', async () => {
|
||||
const encryptedResponse = await encryptedDdo
|
||||
const metadataHash = getHash(JSON.stringify(dispenserDdo))
|
||||
// this is publishing with any explicit metadataProofs
|
||||
const res = await nft.setMetadata(
|
||||
await nft.setMetadata(
|
||||
nftAddress,
|
||||
accounts[0],
|
||||
publisherAccount,
|
||||
0,
|
||||
providerUrl,
|
||||
'',
|
||||
|
Loading…
x
Reference in New Issue
Block a user