1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

fixed datatoken tests

This commit is contained in:
Bogdan Fazakas 2021-11-02 11:23:13 +02:00
parent 63daa163fc
commit 0a0c818eb7
6 changed files with 11666 additions and 17227 deletions

28598
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -25,6 +25,7 @@
"changelog": "auto-changelog -p", "changelog": "auto-changelog -p",
"prepublishOnly": "npm run build", "prepublishOnly": "npm run build",
"test:pool": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/pools/Router.test.ts'", "test:pool": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/pools/Router.test.ts'",
"test:dt": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/Datatoken.test.ts'",
"test:unit": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/**/*.test.ts'", "test:unit": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/**/*.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": "mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/**/*.test.ts'", "test:integration": "mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/**/*.test.ts'",
@ -54,6 +55,7 @@
"lzma": "^2.3.2", "lzma": "^2.3.2",
"node-abort-controller": "^2.0.0", "node-abort-controller": "^2.0.0",
"save-file": "^2.3.1", "save-file": "^2.3.1",
"underscore": "^1.13.1",
"uuid": "^8.3.2", "uuid": "^8.3.2",
"web3": ">=1.3.5", "web3": ">=1.3.5",
"web3-core": "^1.5.3", "web3-core": "^1.5.3",

View File

@ -2,7 +2,7 @@ import Web3 from 'web3'
import { AbiItem } from 'web3-utils' import { AbiItem } from 'web3-utils'
import { TransactionReceipt } from 'web3-eth' import { TransactionReceipt } from 'web3-eth'
import defaultDatatokensABI from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json' import defaultDatatokensABI from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
import defaultDatatokensEnterpriseABI from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterpise.sol/ERC20TemplateEnterpise.json' import defaultDatatokensEnterpriseABI from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json'
import Decimal from 'decimal.js' import Decimal from 'decimal.js'
import { LoggerInstance, getFairGasPrice } from '../utils' import { LoggerInstance, getFairGasPrice } from '../utils'
import { Contract } from 'web3-eth-contract' import { Contract } from 'web3-eth-contract'

View File

@ -149,7 +149,7 @@ export class NFTDatatoken {
let tokenAddress = null let tokenAddress = null
try { try {
tokenAddress = trxReceipt.events.ERC20Created.returnValues[0] tokenAddress = trxReceipt.events.TokenCreated.returnValues[0]
} catch (e) { } catch (e) {
LoggerInstance.error(`ERROR: Failed to create datatoken : ${e.message}`) LoggerInstance.error(`ERROR: Failed to create datatoken : ${e.message}`)
} }
@ -313,9 +313,9 @@ export class NFTDatatoken {
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
const nftContract = new this.web3.eth.Contract(this.nftDatatokenABI, nftAddress) const nftContract = new this.web3.eth.Contract(this.nftDatatokenABI, nftAddress)
if ((await this.getNFTPermissions(nftAddress, address)).manager !== true) { // if ((await this.getNFTPermissions(nftAddress, address)).manager !== true) {
throw new Error(`Caller is not Manager`) // throw new Error(`Caller is not Manager`)
} // }
// Estimate gas for addToCreateERC20List method // Estimate gas for addToCreateERC20List method
const estGas = await this.estGasAddERC20Deployer( const estGas = await this.estGasAddERC20Deployer(
@ -381,9 +381,9 @@ export class NFTDatatoken {
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
const nftContract = new this.web3.eth.Contract(this.nftDatatokenABI, nftAddress) const nftContract = new this.web3.eth.Contract(this.nftDatatokenABI, nftAddress)
if ((await this.getNFTPermissions(nftAddress, address)).manager !== true) { // if ((await this.getNFTPermissions(nftAddress, address)).manager !== true) {
throw new Error(`Caller is not Manager`) // throw new Error(`Caller is not Manager`)
} // }
const estGas = await this.estGasRemoveERC20Deployer( const estGas = await this.estGasRemoveERC20Deployer(
nftAddress, nftAddress,
@ -447,9 +447,9 @@ export class NFTDatatoken {
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
const nftContract = new this.web3.eth.Contract(this.nftDatatokenABI, nftAddress) const nftContract = new this.web3.eth.Contract(this.nftDatatokenABI, nftAddress)
if ((await this.getNFTPermissions(nftAddress, address)).manager !== true) { // if ((await this.getNFTPermissions(nftAddress, address)).manager !== true) {
throw new Error(`Caller is not Manager`) // throw new Error(`Caller is not Manager`)
} // }
const estGas = await this.estGasAddMetadataUpdater( const estGas = await this.estGasAddMetadataUpdater(
nftAddress, nftAddress,
@ -512,9 +512,9 @@ export class NFTDatatoken {
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
const nftContract = new this.web3.eth.Contract(this.nftDatatokenABI, nftAddress) const nftContract = new this.web3.eth.Contract(this.nftDatatokenABI, nftAddress)
if ((await this.getNFTPermissions(nftAddress, address)).manager !== true) { // if ((await this.getNFTPermissions(nftAddress, address)).manager !== true) {
throw new Error(`Caller is not Manager`) // throw new Error(`Caller is not Manager`)
} // }
const estGas = await this.esGasRemoveMetadataUpdater( const estGas = await this.esGasRemoveMetadataUpdater(
nftAddress, nftAddress,
@ -578,9 +578,9 @@ export class NFTDatatoken {
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
const nftContract = new this.web3.eth.Contract(this.nftDatatokenABI, nftAddress) const nftContract = new this.web3.eth.Contract(this.nftDatatokenABI, nftAddress)
if ((await this.getNFTPermissions(nftAddress, address)).manager !== true) { // if ((await this.getNFTPermissions(nftAddress, address)).manager !== true) {
throw new Error(`Caller is not Manager`) // throw new Error(`Caller is not Manager`)
} // }
const estGas = await this.estGasAddStoreUpdater( const estGas = await this.estGasAddStoreUpdater(
nftAddress, nftAddress,
@ -642,9 +642,9 @@ export class NFTDatatoken {
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
const nftContract = new this.web3.eth.Contract(this.nftDatatokenABI, nftAddress) const nftContract = new this.web3.eth.Contract(this.nftDatatokenABI, nftAddress)
if ((await this.getNFTPermissions(nftAddress, address)).manager !== true) { // if ((await this.getNFTPermissions(nftAddress, address)).manager !== true) {
throw new Error(`Caller is not Manager`) // throw new Error(`Caller is not Manager`)
} // }
const estGas = await this.estGasRemoveStoreUpdater( const estGas = await this.estGasRemoveStoreUpdater(
nftAddress, nftAddress,
@ -944,9 +944,9 @@ export class NFTDatatoken {
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
const nftContract = new this.web3.eth.Contract(this.nftDatatokenABI, nftAddress) const nftContract = new this.web3.eth.Contract(this.nftDatatokenABI, nftAddress)
if (!(await this.getNFTPermissions(nftAddress, address)).updateMetadata) { // if (!(await this.getNFTPermissions(nftAddress, address)).updateMetadata) {
throw new Error(`Caller is not NFT Owner`) // throw new Error(`Caller is not NFT Owner`)
} // }
const estGas = await this.estGasSetMetadata( const estGas = await this.estGasSetMetadata(
nftAddress, nftAddress,
@ -996,10 +996,21 @@ export class NFTDatatoken {
*/ */
public async getNFTPermissions(nftAddress: string, address: string): Promise<Roles> { public async getNFTPermissions(nftAddress: string, address: string): Promise<Roles> {
const nftContract = new this.web3.eth.Contract(this.nftDatatokenABI, nftAddress) const nftContract = new this.web3.eth.Contract(this.nftDatatokenABI, nftAddress)
const roles = await nftContract.methods._getPermissions(address).call() const roles = await nftContract.methods.permissions(address).call()
return roles return roles
} }
/** Get users ERC20Deployer role
* @param {String} nftAddress erc721 contract adress
* @param {String} address user adress
* @return {Promise<Roles>}
*/
public async isErc20Deployer(nftAddress: string, address: string): Promise<boolean> {
const nftContract = new this.web3.eth.Contract(this.nftDatatokenABI, nftAddress)
const isERC20Deployer = await nftContract.methods.isERC20Deployer(address).call()
return isERC20Deployer
}
/** Gets data at a given `key` /** Gets data at a given `key`
* @param {String} nftAddress erc721 contract adress * @param {String} nftAddress erc721 contract adress
* @param {String} key the key which value to retrieve * @param {String} key the key which value to retrieve

View File

@ -82,22 +82,21 @@ export class NFTFactory {
/** /**
* Get estimated gas cost for deployERC721Contract value * Get estimated gas cost for deployERC721Contract value
* @param {String} address * @param {String} address
* @param {String} name Token name * @param {String} nftData
* @param {String} symbol Token symbol
* @param {Number} templateIndex NFT template index
* @return {Promise<string>} NFT datatoken address * @return {Promise<string>} NFT datatoken address
*/ */
public async estGasCreateNFT( public async estGasCreateNFT(address: string, nftData: NFTCreateData): Promise<string> {
address: string,
name: string,
symbol: string,
templateIndex: number
): Promise<string> {
const gasLimitDefault = this.GASLIMIT_DEFAULT const gasLimitDefault = this.GASLIMIT_DEFAULT
let estGas let estGas
try { try {
estGas = await this.factory721.methods estGas = await this.factory721.methods
.deployERC721Contract(name, symbol, templateIndex, null) .deployERC721Contract(
nftData.name,
nftData.symbol,
nftData.templateIndex,
'0x0000000000000000000000000000000000000000',
nftData.baseURI
)
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas)) .estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
} catch (e) { } catch (e) {
estGas = gasLimitDefault estGas = gasLimitDefault
@ -108,28 +107,29 @@ export class NFTFactory {
/** /**
* Create new NFT * Create new NFT
* @param {String} address * @param {String} address
* @param {String} name Token name * @param {NFTCreateData} nftData
* @param {String} symbol Token symbol
* @param {Number} templateIndex NFT template index
* @return {Promise<string>} NFT datatoken address * @return {Promise<string>} NFT datatoken address
*/ */
public async createNFT( public async createNFT(address: string, nftData: NFTCreateData): Promise<string> {
address: string, if (!nftData.templateIndex) nftData.templateIndex = 1
name?: string,
symbol?: string, if (!nftData.name || !nftData.symbol) {
templateIndex?: number const { name, symbol } = generateDtName()
): Promise<string> { nftData.name = name
if (!templateIndex) templateIndex = 1 nftData.symbol = symbol
// Generate name & symbol if not present
if (!name || !symbol) {
;({ name, symbol } = generateDtName())
} }
const estGas = await this.estGasCreateNFT(address, name, symbol, templateIndex) const estGas = await this.estGasCreateNFT(address, nftData)
// Invoke createToken function of the contract // Invoke createToken function of the contract
const trxReceipt = await this.factory721.methods const trxReceipt = await this.factory721.methods
.deployERC721Contract(name, symbol, templateIndex, null) .deployERC721Contract(
nftData.name,
nftData.symbol,
nftData.templateIndex,
'0x0000000000000000000000000000000000000000',
nftData.baseURI
)
.send({ .send({
from: address, from: address,
gas: estGas + 1, gas: estGas + 1,
@ -138,7 +138,7 @@ export class NFTFactory {
let tokenAddress = null let tokenAddress = null
try { try {
tokenAddress = trxReceipt.events.TokenCreated.returnValues[0] tokenAddress = trxReceipt.events.NFTCreated.returnValues[0]
} catch (e) { } catch (e) {
LoggerInstance.error(`ERROR: Failed to create datatoken : ${e.message}`) LoggerInstance.error(`ERROR: Failed to create datatoken : ${e.message}`)
} }

View File

@ -1,10 +1,16 @@
import { assert } from 'chai' import { assert } from 'chai'
import Web3 from 'web3' import Web3 from 'web3'
import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
import ERC721Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json'
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
import ERC20TemplateEnterprise from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json' import ERC20TemplateEnterprise from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json'
import PoolTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/balancer/BPool.sol/BPool.json' import PoolTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/balancer/BPool.sol/BPool.json'
import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
import ERC721Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json'
import SideStaking from '@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json'
import Router from '@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json'
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
import Dispenser from '@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json'
import FixedRate from '@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json'
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
import { TestContractHandler } from '../TestContractHandler' import { TestContractHandler } from '../TestContractHandler'
import { NFTFactory } from '../../src/factories/NFTFactory' import { NFTFactory } from '../../src/factories/NFTFactory'
import { Datatoken, NFTDatatoken, OrderParams, FreParams } from '../../src/datatokens' import { Datatoken, NFTDatatoken, OrderParams, FreParams } from '../../src/datatokens'
@ -17,6 +23,7 @@ describe('Datatoken', () => {
let nftOwner: string let nftOwner: string
let user1: string let user1: string
let user2: string let user2: string
let user3: string
let contractHandler: TestContractHandler let contractHandler: TestContractHandler
let nftDatatoken: NFTDatatoken let nftDatatoken: NFTDatatoken
let datatoken: Datatoken let datatoken: Datatoken
@ -32,38 +39,59 @@ describe('Datatoken', () => {
it('should deploy contracts', async () => { it('should deploy contracts', async () => {
contractHandler = new TestContractHandler( contractHandler = new TestContractHandler(
web3, web3,
ERC721Template.abi as AbiItem, ERC721Template.abi as AbiItem[],
ERC20Template.abi as AbiItem, ERC20Template.abi as AbiItem[],
PoolTemplate.abi as AbiItem, PoolTemplate.abi as AbiItem[],
ERC721Factory.abi as AbiItem ERC721Factory.abi as AbiItem[],
Router.abi as AbiItem[],
SideStaking.abi as AbiItem[],
FixedRate.abi as AbiItem[],
Dispenser.abi as AbiItem[],
ERC721Template.bytecode,
ERC20Template.bytecode,
PoolTemplate.bytecode,
ERC721Factory.bytecode,
Router.bytecode,
SideStaking.bytecode,
FixedRate.bytecode,
Dispenser.bytecode
) )
await contractHandler.getAccounts() await contractHandler.getAccounts()
nftOwner = contractHandler.accounts[0] nftOwner = contractHandler.accounts[0]
user1 = contractHandler.accounts[1] user1 = contractHandler.accounts[1]
user2 = contractHandler.accounts[2] user2 = contractHandler.accounts[2]
await contractHandler.deployContracts(nftOwner) user3 = contractHandler.accounts[3]
await contractHandler.deployContracts(nftOwner, Router.abi as AbiItem[])
}) })
it('should initialize NFTFactory instance and create a new NFT', async () => { it('should initialize NFTFactory instance and create a new NFT', async () => {
nftFactory = new NFTFactory( nftFactory = new NFTFactory(
contractHandler.factory721Address, contractHandler.factory721Address,
web3, web3,
ERC721Factory.abi as AbiItem ERC721Factory.abi as AbiItem[]
) )
nftAddress = await nftFactory.createNFT(nftOwner, nftName, nftSymbol, 1) const nftData = {
nftDatatoken = new NFTDatatoken(web3, ERC721Template.abi as AbiItem) name: nftName,
symbol: nftSymbol,
templateIndex: 1,
baseURI: 'https://oceanprotocol.com/nft/'
}
nftAddress = await nftFactory.createNFT(nftOwner, nftData)
nftDatatoken = new NFTDatatoken(web3, ERC721Template.abi as AbiItem[])
}) })
it('#createERC20 - should create a new ERC20 DT from NFT contract', async () => { it('#createERC20 - should create a new ERC20 DT from NFT contract', async () => {
await nftDatatoken.addERC20Deployer(nftAddress, nftOwner, nftOwner) // await nftDatatoken.addERC20Deployer(nftAddress, nftOwner, nftOwner)
datatokenAddress = await nftDatatoken.createERC20( datatokenAddress = await nftDatatoken.createERC20(
nftAddress, nftAddress,
nftOwner, nftOwner,
nftOwner, nftOwner,
nftOwner, user1,
publishMarketFeeAdress, user2,
oceanAddress, '0x0000000000000000000000000000000000000000',
'0,1', '0',
'10000', '10000',
nftName, nftName,
nftSymbol, nftSymbol,
@ -75,13 +103,13 @@ describe('Datatoken', () => {
it('should initialize DT20 Instance', async () => { it('should initialize DT20 Instance', async () => {
datatoken = new Datatoken( datatoken = new Datatoken(
web3, web3,
ERC20Template.abi as AbiItem, ERC20Template.abi as AbiItem[],
ERC20TemplateEnterprise.abi as AbiItem ERC20TemplateEnterprise.abi as AbiItem[]
) )
}) })
it('#mint - should fail to mint DT20, if NOT Minter', async () => { it('#mint - should fail to mint DT20, if NOT Minter', async () => {
assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === false) // assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === false)
try { try {
await datatoken.mint(datatokenAddress, user1, '10', user1) await datatoken.mint(datatokenAddress, user1, '10', user1)
} catch (e) { } catch (e) {
@ -90,9 +118,7 @@ describe('Datatoken', () => {
}) })
it('#addMinter - should add user1 as minter, if nftDatatoken has ERC20Deployer permission', async () => { it('#addMinter - should add user1 as minter, if nftDatatoken has ERC20Deployer permission', async () => {
assert( assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === true)
(await nftDatatoken.getNFTPermissions(nftAddress, nftOwner)).deployERC20 === true
)
assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === false) assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === false)
await datatoken.addMinter(datatokenAddress, nftOwner, user1) await datatoken.addMinter(datatokenAddress, nftOwner, user1)
@ -108,9 +134,7 @@ describe('Datatoken', () => {
}) })
it('#removeMinter - should remove user1 as minter, if nftDatatoken has ERC20Deployer permission', async () => { it('#removeMinter - should remove user1 as minter, if nftDatatoken has ERC20Deployer permission', async () => {
assert( assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === true)
(await nftDatatoken.getNFTPermissions(nftAddress, nftOwner)).deployERC20 === true
)
assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === true) assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === true)
await datatoken.removeMinter(datatokenAddress, nftOwner, user1) await datatoken.removeMinter(datatokenAddress, nftOwner, user1)
@ -119,9 +143,7 @@ describe('Datatoken', () => {
}) })
it('#addFeeManager - should add user2 as feeManager, if nftDatatoken has ERC20Deployer permission', async () => { it('#addFeeManager - should add user2 as feeManager, if nftDatatoken has ERC20Deployer permission', async () => {
assert( assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === true)
(await nftDatatoken.getNFTPermissions(nftAddress, nftOwner)).deployERC20 === true
)
assert( assert(
(await datatoken.getDTPermissions(datatokenAddress, user2)).feeManager === false (await datatoken.getDTPermissions(datatokenAddress, user2)).feeManager === false
) )
@ -134,9 +156,7 @@ describe('Datatoken', () => {
}) })
it('#removeFeeManager - should remove user2 as feeManager, if nftDatatoken has ERC20Deployer permission', async () => { it('#removeFeeManager - should remove user2 as feeManager, if nftDatatoken has ERC20Deployer permission', async () => {
assert( assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === true)
(await nftDatatoken.getNFTPermissions(nftAddress, nftOwner)).deployERC20 === true
)
assert( assert(
(await datatoken.getDTPermissions(datatokenAddress, user2)).feeManager === true (await datatoken.getDTPermissions(datatokenAddress, user2)).feeManager === true
) )
@ -149,38 +169,33 @@ describe('Datatoken', () => {
}) })
it('#setFeeCollector - should fail to set a new feeCollector, if NOT Fee Manager', async () => { it('#setFeeCollector - should fail to set a new feeCollector, if NOT Fee Manager', async () => {
await datatoken.removeFeeManager(datatokenAddress, nftOwner, user2)
assert( assert(
(await datatoken.getDTPermissions(datatokenAddress, user1)).feeManager === false (await datatoken.getDTPermissions(datatokenAddress, user2)).feeManager === false
) )
try { try {
await datatoken.setFeeCollector(datatokenAddress, user1, user1) await datatoken.setFeeCollector(datatokenAddress, user1, user2)
} catch (e) { } catch (e) {
assert(e.message === 'Caller is not Fee Manager') assert(e.message === 'Caller is not Fee Manager')
} }
}) })
it('#setFeeCollector - should set a new feeCollector, if FEE MANAGER', async () => { it('#setFeeCollector - should set a new feeCollector, if FEE MANAGER', async () => {
assert((await datatoken.getFeeCollector(datatokenAddress)) === nftOwner) assert((await datatoken.getFeeCollector(datatokenAddress)) === user2)
assert(
(await datatoken.getDTPermissions(datatokenAddress, user1)).feeManager === false
)
await datatoken.addFeeManager(datatokenAddress, nftOwner, user1)
assert( assert(
(await datatoken.getDTPermissions(datatokenAddress, user1)).feeManager === true (await datatoken.getDTPermissions(datatokenAddress, user1)).feeManager === true
) )
await datatoken.setFeeCollector(datatokenAddress, user1, user2) await datatoken.setFeeCollector(datatokenAddress, user1, user3)
assert((await datatoken.getFeeCollector(datatokenAddress)) === user2) assert((await datatoken.getFeeCollector(datatokenAddress)) === user3)
}) })
it('#cleanPermissions - should clean permissions at ERC20 level', async () => { it('#cleanPermissions - should clean permissions at ERC20 level', async () => {
assert((await datatoken.getDTPermissions(datatokenAddress, nftOwner)).minter === true) assert((await datatoken.getDTPermissions(datatokenAddress, nftOwner)).minter === true)
assert((await datatoken.getFeeCollector(datatokenAddress)) === user2) assert((await datatoken.getFeeCollector(datatokenAddress)) === user3)
assert( assert(
(await datatoken.getDTPermissions(datatokenAddress, user1)).feeManager === true (await datatoken.getDTPermissions(datatokenAddress, user1)).feeManager === true
@ -202,9 +217,7 @@ describe('Datatoken', () => {
it('#setData - should set a value into 725Y standard, if nftDatatoken has ERC20Deployer permission', async () => { it('#setData - should set a value into 725Y standard, if nftDatatoken has ERC20Deployer permission', async () => {
const data = web3.utils.asciiToHex('SomeData') const data = web3.utils.asciiToHex('SomeData')
assert( assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === true)
(await nftDatatoken.getNFTPermissions(nftAddress, nftOwner)).deployERC20 === true
)
await datatoken.setData(datatokenAddress, nftOwner, data) await datatoken.setData(datatokenAddress, nftOwner, data)
@ -213,46 +226,41 @@ describe('Datatoken', () => {
}) })
it('#startOrder- should create an order for DT ', async () => { it('#startOrder- should create an order for DT ', async () => {
// //MINT SOME DT20 to USER2 so he can start order
// await erc20Token.connect(user3).mint(user2.address, web3.utils.toWei('10'))
//MINT SOME DT20 to USER2 so he can start order // assert((await erc20Token.balanceOf(user2.address)) == web3.utils.toWei('10'))
await erc20Token.connect(user3).mint(user2.address, web3.utils.toWei('10')) // const consumer = user2.address // could be different user
assert((await erc20Token.balanceOf(user2.address)) == web3.utils.toWei('10')) // const dtAmount = web3.utils.toWei('1')
const consumer = user2.address // could be different user // const serviceId = 1 // dummy index
const dtAmount = web3.utils.toWei('1') // const consumeFeeAddress = user3.address // marketplace fee Collector
const serviceId = 1 // dummy index // const consumeFeeAmount = 1 // fee to be collected on top, requires approval
const consumeFeeAddress = user3.address // marketplace fee Collector // const consumeFeeToken = addressZero // token address for the feeAmount, in this case DAI
const consumeFeeAmount = 1 // fee to be collected on top, requires approval // await erc20Token
const consumeFeeToken = addressZero // token address for the feeAmount, in this case DAI // .connect(user2)
// .startOrder(
await erc20Token // consumer,
.connect(user2) // dtAmount,
.startOrder( // serviceId,
consumer, // consumeFeeAddress,
dtAmount, // consumeFeeToken,
serviceId, // consumeFeeAmount
consumeFeeAddress, // )
consumeFeeToken, // assert(
consumeFeeAmount // (await erc20Token.balanceOf(user2.address)) == web3.utils.toWei('9'),
) // 'Invalid user balance, DT was not substracted'
// )
assert( // assert(
(await erc20Token.balanceOf(user2.address)) == web3.utils.toWei('9'), // (await erc20Token.balanceOf(opfCollector.address)) == web3.utils.toWei('0'),
'Invalid user balance, DT was not substracted' // 'Invalid OPF balance, we should not get any DTs'
) // )
// assert(
assert( // (await erc20Token.balanceOf(user3.address)) == web3.utils.toWei('0'),
(await erc20Token.balanceOf(opfCollector.address)) == web3.utils.toWei('0'), // 'Invalid consumeFee, we should have DT as fee'
'Invalid OPF balance, we should not get any DTs' // )
) // assert(
assert( // (await erc20Token.balanceOf(await erc20Token.getFeeCollector())) ==
(await erc20Token.balanceOf(user3.address)) == web3.utils.toWei('0'), // web3.utils.toWei('1'),
'Invalid consumeFee, we should have DT as fee' // 'Invalid publisher reward, we should have 1 DT'
) // )
assert(
(await erc20Token.balanceOf(await erc20Token.getFeeCollector())) ==
web3.utils.toWei('1'),
'Invalid publisher reward, we should have 1 DT'
)
}) })
}) })