mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Merge pull request #1377 from oceanprotocol/issue-1346-rewrite-datatoken-test
Issue-#1346: Rewrite Datatoken test
This commit is contained in:
commit
1ef7aa7027
@ -1,11 +1,5 @@
|
|||||||
import { assert } from 'chai'
|
import { assert } from 'chai'
|
||||||
import ERC20TemplateEnterprise from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.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 ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
|
||||||
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
|
|
||||||
import { deployContracts, Addresses } from '../../TestContractHandler'
|
import { deployContracts, Addresses } from '../../TestContractHandler'
|
||||||
import { AbiItem } from 'web3-utils'
|
|
||||||
import { web3 } from '../../config'
|
import { web3 } from '../../config'
|
||||||
import {
|
import {
|
||||||
NftFactory,
|
NftFactory,
|
||||||
@ -17,7 +11,7 @@ import {
|
|||||||
ZERO_ADDRESS,
|
ZERO_ADDRESS,
|
||||||
signHash
|
signHash
|
||||||
} from '../../../src'
|
} from '../../../src'
|
||||||
import { ProviderFees, FreCreationParams, FreOrderParams } from '../../../src/@types/'
|
import { ProviderFees, FreCreationParams, FreOrderParams } from '../../../src/@types'
|
||||||
|
|
||||||
describe('Datatoken', () => {
|
describe('Datatoken', () => {
|
||||||
let nftOwner: string
|
let nftOwner: string
|
||||||
@ -33,9 +27,16 @@ describe('Datatoken', () => {
|
|||||||
let datatokenAddress: string
|
let datatokenAddress: string
|
||||||
let fixedRateAddress: string
|
let fixedRateAddress: string
|
||||||
let exchangeId: string
|
let exchangeId: string
|
||||||
|
let freParams: FreCreationParams
|
||||||
|
|
||||||
const nftName = 'NFTName'
|
const nftData: NftCreateData = {
|
||||||
const nftSymbol = 'NFTSymbol'
|
name: 'NFTName',
|
||||||
|
symbol: 'NFTSymbol',
|
||||||
|
templateIndex: 1,
|
||||||
|
tokenURI: 'https://oceanprotocol.com/nft/',
|
||||||
|
transferable: true,
|
||||||
|
owner: null
|
||||||
|
}
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const accounts = await web3.eth.getAccounts()
|
const accounts = await web3.eth.getAccounts()
|
||||||
@ -44,38 +45,30 @@ describe('Datatoken', () => {
|
|||||||
user2 = accounts[2]
|
user2 = accounts[2]
|
||||||
user3 = accounts[3]
|
user3 = accounts[3]
|
||||||
erc20DeployerUser = accounts[4]
|
erc20DeployerUser = accounts[4]
|
||||||
|
|
||||||
|
nftData.owner = nftOwner
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contracts = await deployContracts(web3, nftOwner)
|
contracts = await deployContracts(web3, nftOwner)
|
||||||
|
|
||||||
const daiContract = new web3.eth.Contract(
|
freParams = {
|
||||||
MockERC20.abi as AbiItem[],
|
fixedRateAddress: contracts.fixedRateAddress,
|
||||||
contracts.daiAddress
|
baseTokenAddress: contracts.daiAddress,
|
||||||
)
|
owner: nftOwner,
|
||||||
await daiContract.methods
|
marketFeeCollector: nftOwner,
|
||||||
.approve(contracts.erc721FactoryAddress, web3.utils.toWei('10000'))
|
baseTokenDecimals: 18,
|
||||||
.send({ from: nftOwner })
|
datatokenDecimals: 18,
|
||||||
|
fixedRate: web3.utils.toWei('1'),
|
||||||
|
marketFee: '0'
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
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(contracts.erc721FactoryAddress, web3, 8996)
|
||||||
contracts.erc721FactoryAddress,
|
|
||||||
web3,
|
|
||||||
8996,
|
|
||||||
ERC721Factory.abi as AbiItem[]
|
|
||||||
)
|
|
||||||
const nftData: NftCreateData = {
|
|
||||||
name: nftName,
|
|
||||||
symbol: nftSymbol,
|
|
||||||
templateIndex: 1,
|
|
||||||
tokenURI: 'https://oceanprotocol.com/nft/',
|
|
||||||
transferable: true,
|
|
||||||
owner: nftOwner
|
|
||||||
}
|
|
||||||
|
|
||||||
nftAddress = await nftFactory.createNFT(nftOwner, nftData)
|
nftAddress = await nftFactory.createNFT(nftOwner, nftData)
|
||||||
nftDatatoken = new Nft(web3, 8996, ERC721Template.abi as AbiItem[])
|
nftDatatoken = new Nft(web3, 8996)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#createERC20 - should create a new ERC20 DT from NFT contract', async () => {
|
it('#createERC20 - should create a new ERC20 DT from NFT contract', async () => {
|
||||||
@ -86,29 +79,24 @@ describe('Datatoken', () => {
|
|||||||
nftOwner,
|
nftOwner,
|
||||||
user1,
|
user1,
|
||||||
user2,
|
user2,
|
||||||
'0x0000000000000000000000000000000000000000',
|
ZERO_ADDRESS,
|
||||||
'0',
|
'0',
|
||||||
'10000',
|
'10000',
|
||||||
nftName,
|
'ERC20B1',
|
||||||
nftSymbol,
|
'ERC20DT1Symbol'
|
||||||
1
|
|
||||||
)
|
)
|
||||||
assert(datatokenAddress !== null)
|
assert(datatokenAddress !== null)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should initialize DT20 Instance', async () => {
|
it('should initialize DT20 Instance', async () => {
|
||||||
datatoken = new Datatoken(
|
datatoken = new Datatoken(web3, 8996)
|
||||||
web3,
|
|
||||||
8996,
|
|
||||||
ERC20Template.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)
|
||||||
|
assert(false)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assert(e.message === 'Caller is not Minter')
|
assert(e.message === 'Caller is not Minter')
|
||||||
}
|
}
|
||||||
@ -129,6 +117,7 @@ describe('Datatoken', () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await datatoken.addMinter(datatokenAddress, user3, user2)
|
await datatoken.addMinter(datatokenAddress, user3, user2)
|
||||||
|
assert(false)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assert(e.message === 'Caller is not ERC20Deployer')
|
assert(e.message === 'Caller is not ERC20Deployer')
|
||||||
}
|
}
|
||||||
@ -144,16 +133,6 @@ describe('Datatoken', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#createFixedRate - should create FRE for the erc20 dt', async () => {
|
it('#createFixedRate - should create FRE for the erc20 dt', async () => {
|
||||||
const freParams: FreCreationParams = {
|
|
||||||
fixedRateAddress: contracts.fixedRateAddress,
|
|
||||||
baseTokenAddress: contracts.daiAddress,
|
|
||||||
owner: nftOwner,
|
|
||||||
marketFeeCollector: nftOwner,
|
|
||||||
baseTokenDecimals: 18,
|
|
||||||
datatokenDecimals: 18,
|
|
||||||
fixedRate: web3.utils.toWei('1'),
|
|
||||||
marketFee: '0'
|
|
||||||
}
|
|
||||||
const fre = await datatoken.createFixedRate(datatokenAddress, nftOwner, freParams)
|
const fre = await datatoken.createFixedRate(datatokenAddress, nftOwner, freParams)
|
||||||
assert(fre !== null)
|
assert(fre !== null)
|
||||||
fixedRateAddress = fre.events.NewFixedRate.address
|
fixedRateAddress = fre.events.NewFixedRate.address
|
||||||
@ -162,18 +141,9 @@ describe('Datatoken', () => {
|
|||||||
|
|
||||||
it('#createFixedRate - should FAIL create FRE if NOT ERC20Deployer', async () => {
|
it('#createFixedRate - should FAIL create FRE if NOT ERC20Deployer', async () => {
|
||||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, user3)) === false)
|
assert((await nftDatatoken.isErc20Deployer(nftAddress, user3)) === false)
|
||||||
const freParams: FreCreationParams = {
|
|
||||||
fixedRateAddress: contracts.fixedRateAddress,
|
|
||||||
baseTokenAddress: contracts.daiAddress,
|
|
||||||
owner: nftOwner,
|
|
||||||
marketFeeCollector: nftOwner,
|
|
||||||
baseTokenDecimals: 18,
|
|
||||||
datatokenDecimals: 18,
|
|
||||||
fixedRate: web3.utils.toWei('1'),
|
|
||||||
marketFee: '0'
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
await datatoken.createFixedRate(datatokenAddress, user3, freParams)
|
await datatoken.createFixedRate(datatokenAddress, user3, freParams)
|
||||||
|
assert(false)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assert(e.message === 'User is not ERC20 Deployer')
|
assert(e.message === 'User is not ERC20 Deployer')
|
||||||
}
|
}
|
||||||
@ -207,6 +177,7 @@ describe('Datatoken', () => {
|
|||||||
contracts.dispenserAddress,
|
contracts.dispenserAddress,
|
||||||
dispenserParams
|
dispenserParams
|
||||||
)
|
)
|
||||||
|
assert(false)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assert(e.message === 'User is not ERC20 Deployer')
|
assert(e.message === 'User is not ERC20 Deployer')
|
||||||
}
|
}
|
||||||
@ -218,6 +189,7 @@ describe('Datatoken', () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await datatoken.removeMinter(datatokenAddress, user2, user1)
|
await datatoken.removeMinter(datatokenAddress, user2, user1)
|
||||||
|
assert(false)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assert(e.message === 'Caller is not ERC20Deployer')
|
assert(e.message === 'Caller is not ERC20Deployer')
|
||||||
}
|
}
|
||||||
@ -241,6 +213,7 @@ describe('Datatoken', () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await datatoken.addPaymentManager(datatokenAddress, user1, user2)
|
await datatoken.addPaymentManager(datatokenAddress, user1, user2)
|
||||||
|
assert(false)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assert(e.message === 'Caller is not ERC20Deployer')
|
assert(e.message === 'Caller is not ERC20Deployer')
|
||||||
}
|
}
|
||||||
@ -269,6 +242,7 @@ describe('Datatoken', () => {
|
|||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
await datatoken.removePaymentManager(datatokenAddress, user1, user2)
|
await datatoken.removePaymentManager(datatokenAddress, user1, user2)
|
||||||
|
assert(false)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assert(e.message === 'Caller is not ERC20Deployer')
|
assert(e.message === 'Caller is not ERC20Deployer')
|
||||||
}
|
}
|
||||||
@ -298,6 +272,7 @@ describe('Datatoken', () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await datatoken.setPaymentCollector(datatokenAddress, user1, user2)
|
await datatoken.setPaymentCollector(datatokenAddress, user1, user2)
|
||||||
|
assert(false)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assert(e.message === 'Caller is not Fee Manager, owner or erc20 Deployer')
|
assert(e.message === 'Caller is not Fee Manager, owner or erc20 Deployer')
|
||||||
}
|
}
|
||||||
@ -435,7 +410,6 @@ describe('Datatoken', () => {
|
|||||||
const providerData = JSON.stringify({ timeout: 0 })
|
const providerData = JSON.stringify({ timeout: 0 })
|
||||||
const providerFeeToken = ZERO_ADDRESS
|
const providerFeeToken = ZERO_ADDRESS
|
||||||
const providerFeeAmount = '0'
|
const providerFeeAmount = '0'
|
||||||
const dtAmount = web3.utils.toWei('1')
|
|
||||||
const message = web3.utils.soliditySha3(
|
const message = web3.utils.soliditySha3(
|
||||||
{ t: 'bytes', v: web3.utils.toHex(web3.utils.asciiToHex(providerData)) },
|
{ t: 'bytes', v: web3.utils.toHex(web3.utils.asciiToHex(providerData)) },
|
||||||
{ t: 'address', v: user3 },
|
{ t: 'address', v: user3 },
|
||||||
@ -455,8 +429,8 @@ describe('Datatoken', () => {
|
|||||||
validUntil: providerValidUntil
|
validUntil: providerValidUntil
|
||||||
}
|
}
|
||||||
const consumeMarketFee = {
|
const consumeMarketFee = {
|
||||||
consumeMarketFeeAddress: '0x0000000000000000000000000000000000000000',
|
consumeMarketFeeAddress: ZERO_ADDRESS,
|
||||||
consumeMarketFeeToken: '0x0000000000000000000000000000000000000000',
|
consumeMarketFeeToken: ZERO_ADDRESS,
|
||||||
consumeMarketFeeAmount: '0'
|
consumeMarketFeeAmount: '0'
|
||||||
}
|
}
|
||||||
const order: OrderParams = {
|
const order: OrderParams = {
|
||||||
@ -497,8 +471,8 @@ describe('Datatoken', () => {
|
|||||||
validUntil: providerValidUntil
|
validUntil: providerValidUntil
|
||||||
}
|
}
|
||||||
const consumeMarketFee = {
|
const consumeMarketFee = {
|
||||||
consumeMarketFeeAddress: '0x0000000000000000000000000000000000000000',
|
consumeMarketFeeAddress: ZERO_ADDRESS,
|
||||||
consumeMarketFeeToken: '0x0000000000000000000000000000000000000000',
|
consumeMarketFeeToken: ZERO_ADDRESS,
|
||||||
consumeMarketFeeAmount: '0'
|
consumeMarketFeeAmount: '0'
|
||||||
}
|
}
|
||||||
const order: OrderParams = {
|
const order: OrderParams = {
|
||||||
@ -513,7 +487,7 @@ describe('Datatoken', () => {
|
|||||||
exchangeId: exchangeId,
|
exchangeId: exchangeId,
|
||||||
maxBaseTokenAmount: '1',
|
maxBaseTokenAmount: '1',
|
||||||
swapMarketFee: '0.1',
|
swapMarketFee: '0.1',
|
||||||
marketFeeAddress: '0x0000000000000000000000000000000000000000'
|
marketFeeAddress: ZERO_ADDRESS
|
||||||
}
|
}
|
||||||
|
|
||||||
const buyTx = await datatoken.buyFromFreAndOrder(datatokenAddress, user1, order, fre)
|
const buyTx = await datatoken.buyFromFreAndOrder(datatokenAddress, user1, order, fre)
|
||||||
@ -531,6 +505,7 @@ describe('Datatoken', () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await datatoken.cleanPermissions(datatokenAddress, user2)
|
await datatoken.cleanPermissions(datatokenAddress, user2)
|
||||||
|
assert(false)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assert(e.message === 'Caller is NOT Nft Owner')
|
assert(e.message === 'Caller is NOT Nft Owner')
|
||||||
}
|
}
|
||||||
@ -589,6 +564,7 @@ describe('Datatoken', () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await datatoken.setData(datatokenAddress, user1, data)
|
await datatoken.setData(datatokenAddress, user1, data)
|
||||||
|
assert(false)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assert(e.message === 'User is not ERC20 Deployer')
|
assert(e.message === 'User is not ERC20 Deployer')
|
||||||
}
|
}
|
||||||
@ -596,6 +572,24 @@ describe('Datatoken', () => {
|
|||||||
assert((await nftDatatoken.getData(nftAddress, key)) === OldData)
|
assert((await nftDatatoken.getData(nftAddress, key)) === OldData)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('#getDecimals - should return the number of decimals of the datatoken', async () => {
|
||||||
|
const decimals = await datatoken.getDecimals(datatokenAddress)
|
||||||
|
assert(decimals === '18')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('#transfer - we can transfer the datatoken', async () => {
|
||||||
|
const balance1before = await datatoken.balance(datatokenAddress, user1)
|
||||||
|
const balance2before = await datatoken.balance(datatokenAddress, user2)
|
||||||
|
|
||||||
|
await datatoken.transfer(datatokenAddress, user2, '1', user1)
|
||||||
|
|
||||||
|
const balance1after = await datatoken.balance(datatokenAddress, user1)
|
||||||
|
const balance2after = await datatoken.balance(datatokenAddress, user2)
|
||||||
|
|
||||||
|
assert(+balance1after === +balance1before - 1)
|
||||||
|
assert(+balance2after === +balance2before + 1)
|
||||||
|
})
|
||||||
|
|
||||||
it('#setPublishingMarketFee - User should not be able to set the Publishing Market Fee', async () => {
|
it('#setPublishingMarketFee - User should not be able to set the Publishing Market Fee', async () => {
|
||||||
const originalPublishingMarketFee = await datatoken.getPublishingMarketFee(
|
const originalPublishingMarketFee = await datatoken.getPublishingMarketFee(
|
||||||
datatokenAddress,
|
datatokenAddress,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user