mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
added tests and code cleanup
This commit is contained in:
parent
919e182bc8
commit
b5e90fa790
@ -179,7 +179,7 @@ export class Datatoken {
|
||||
marketFeeCollector: string,
|
||||
baseTokenDecimals: number,
|
||||
dataTokenDecimals: number,
|
||||
fixedRate: number,
|
||||
fixedRate: String,
|
||||
marketFee: number,
|
||||
withMint: number,
|
||||
contractInstance?: Contract
|
||||
@ -226,7 +226,7 @@ export class Datatoken {
|
||||
marketFeeCollector: string,
|
||||
baseTokenDecimals: number,
|
||||
dataTokenDecimals: number,
|
||||
fixedRate: number,
|
||||
fixedRate: String,
|
||||
marketFee: number,
|
||||
withMint: number
|
||||
): Promise<TransactionReceipt> {
|
||||
@ -252,7 +252,12 @@ export class Datatoken {
|
||||
const trxReceipt = await dtContract.methods
|
||||
.createFixedRate(
|
||||
fixedPriceAddress,
|
||||
[baseTokenAddress, address, marketFeeCollector],
|
||||
[
|
||||
baseTokenAddress,
|
||||
address,
|
||||
marketFeeCollector,
|
||||
'0x0000000000000000000000000000000000000000'
|
||||
],
|
||||
[baseTokenDecimals, dataTokenDecimals, fixedRate, marketFee, withMint]
|
||||
)
|
||||
.send({
|
||||
|
@ -996,7 +996,7 @@ export class NFTDatatoken {
|
||||
*/
|
||||
public async getNFTPermissions(nftAddress: string, address: string): Promise<Roles> {
|
||||
const nftContract = new this.web3.eth.Contract(this.nftDatatokenABI, nftAddress)
|
||||
const roles = await nftContract.methods.permissions(address).call()
|
||||
const roles = await nftContract.methods.getPermissions(address).call()
|
||||
return roles
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import Router from '@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRo
|
||||
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 OPFCollector from '@oceanprotocol/contracts/artifacts/contracts/communityFee/OPFCommunityFeeCollector.sol/OPFCommunityFeeCollector.json'
|
||||
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
|
||||
|
||||
import { TestContractHandler } from '../TestContractHandler'
|
||||
@ -30,6 +31,8 @@ describe('Datatoken', () => {
|
||||
let nftFactory: NFTFactory
|
||||
let nftAddress: string
|
||||
let datatokenAddress: string
|
||||
let fixedRateAddress: string
|
||||
let exchangeId: string
|
||||
|
||||
const nftName = 'NFTName'
|
||||
const nftSymbol = 'NFTSymbol'
|
||||
@ -45,6 +48,7 @@ describe('Datatoken', () => {
|
||||
SideStaking.abi as AbiItem[],
|
||||
FixedRate.abi as AbiItem[],
|
||||
Dispenser.abi as AbiItem[],
|
||||
OPFCollector.abi as AbiItem[],
|
||||
|
||||
ERC721Template.bytecode,
|
||||
ERC20Template.bytecode,
|
||||
@ -53,7 +57,8 @@ describe('Datatoken', () => {
|
||||
Router.bytecode,
|
||||
SideStaking.bytecode,
|
||||
FixedRate.bytecode,
|
||||
Dispenser.bytecode
|
||||
Dispenser.bytecode,
|
||||
OPFCollector.bytecode
|
||||
)
|
||||
await contractHandler.getAccounts()
|
||||
nftOwner = contractHandler.accounts[0]
|
||||
@ -61,6 +66,14 @@ describe('Datatoken', () => {
|
||||
user2 = contractHandler.accounts[2]
|
||||
user3 = contractHandler.accounts[3]
|
||||
await contractHandler.deployContracts(nftOwner, Router.abi as AbiItem[])
|
||||
|
||||
const daiContract = new web3.eth.Contract(
|
||||
contractHandler.MockERC20.options.jsonInterface,
|
||||
contractHandler.daiAddress
|
||||
)
|
||||
await daiContract.methods
|
||||
.approve(contractHandler.factory721Address, web3.utils.toWei('10000'))
|
||||
.send({ from: contractHandler.accounts[0] })
|
||||
})
|
||||
|
||||
it('should initialize NFTFactory instance and create a new NFT', async () => {
|
||||
@ -131,6 +144,40 @@ describe('Datatoken', () => {
|
||||
assert((await datatoken.balance(datatokenAddress, user1)) === '10')
|
||||
})
|
||||
|
||||
it('#createFixedRate - should create FRE for the erc20 dt', async () => {
|
||||
const fre = await datatoken.createFixedRate(
|
||||
datatokenAddress,
|
||||
nftOwner,
|
||||
contractHandler.fixedRateAddress,
|
||||
contractHandler.daiAddress,
|
||||
nftOwner,
|
||||
18,
|
||||
18,
|
||||
web3.utils.toWei('1'),
|
||||
1e15,
|
||||
1
|
||||
)
|
||||
assert(fre !== null)
|
||||
fixedRateAddress = fre.events.NewFixedRate.address
|
||||
exchangeId = fre.events.NewFixedRate.returnValues[0]
|
||||
})
|
||||
|
||||
it('#createDispenser - Enterprise method', async () => {
|
||||
// console.log('dispenser address', contractHandler.dispenserAddress)
|
||||
// // create dispenser
|
||||
// const dispenser = await datatoken.createDispenser(
|
||||
// datatokenAddress,
|
||||
// nftOwner,
|
||||
// contractHandler.dispenserAddress,
|
||||
// '10',
|
||||
// '100',
|
||||
// true,
|
||||
// user1
|
||||
// )
|
||||
// console.log('dispenser', dispenser)
|
||||
// // assert(dispenser !== null)
|
||||
})
|
||||
|
||||
it('#removeMinter - should remove user1 as minter, if nftDatatoken has ERC20Deployer permission', async () => {
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === true)
|
||||
assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === true)
|
||||
@ -190,6 +237,92 @@ describe('Datatoken', () => {
|
||||
assert((await datatoken.getFeeCollector(datatokenAddress)) === user3)
|
||||
})
|
||||
|
||||
it('#startOrder- user2 should create an order for DT ', async () => {
|
||||
assert(
|
||||
(await datatoken.balance(datatokenAddress, user1)) === '10',
|
||||
'User1 does not hold 10 datatokens'
|
||||
)
|
||||
assert(
|
||||
(await datatoken.balance(datatokenAddress, user2)) === '0',
|
||||
'User2 does not hold 0 datatokens'
|
||||
)
|
||||
|
||||
const order = await datatoken.startOrder(
|
||||
datatokenAddress,
|
||||
user1,
|
||||
user2,
|
||||
'1',
|
||||
1,
|
||||
user3,
|
||||
'0x0000000000000000000000000000000000000000',
|
||||
'0'
|
||||
)
|
||||
assert(order !== null)
|
||||
|
||||
assert(
|
||||
(await datatoken.balance(datatokenAddress, user1)) === '9',
|
||||
'Invalid user balance, DT was not substracted'
|
||||
)
|
||||
assert(
|
||||
(await datatoken.balance(
|
||||
datatokenAddress,
|
||||
await datatoken.getFeeCollector(datatokenAddress)
|
||||
)) === '1',
|
||||
'Invalid publisher reward, we should have 1 DT'
|
||||
)
|
||||
})
|
||||
|
||||
it('#buyFromDispenserAndOrder- Enterprise method', async () => {
|
||||
// await nftDatatoken.addERC20Deployer(nftAddress, nftOwner, user1)
|
||||
// // create dt
|
||||
// const erc20Dt = await nftDatatoken.createERC20(
|
||||
// nftAddress,
|
||||
// nftOwner,
|
||||
// nftOwner,
|
||||
// user1,
|
||||
// user2,
|
||||
// '0x0000000000000000000000000000000000000000',
|
||||
// '0',
|
||||
// '10000',
|
||||
// nftName,
|
||||
// nftSymbol,
|
||||
// 1
|
||||
// )
|
||||
// assert(erc20Dt !== null)
|
||||
// console.log('dispenser address', contractHandler.dispenserAddress)
|
||||
// // create dispenser
|
||||
// const dispenser = await datatoken.createDispenser(
|
||||
// erc20Dt,
|
||||
// user1,
|
||||
// contractHandler.dispenserAddress,
|
||||
// '10',
|
||||
// '100',
|
||||
// true,
|
||||
// user1
|
||||
// )
|
||||
// console.log('dispenser', dispenser)
|
||||
// assert(dispenser !== null)
|
||||
})
|
||||
|
||||
it('#buyFromFreAndOrder - Enterprise method ', async () => {
|
||||
const order: OrderParams = {
|
||||
consumer: user1,
|
||||
amount: '1',
|
||||
serviceId: 1,
|
||||
consumeFeeAddress: user1,
|
||||
consumeFeeToken: '0x0000000000000000000000000000000000000000',
|
||||
consumeFeeAmount: '0'
|
||||
}
|
||||
const fre: FreParams = {
|
||||
exchangeContract: fixedRateAddress,
|
||||
exchangeId: exchangeId,
|
||||
maxBaseTokenAmount: '1'
|
||||
}
|
||||
|
||||
const buyTx = await datatoken.buyFromFreAndOrder(datatokenAddress, user1, order, fre)
|
||||
assert(buyTx !== null)
|
||||
})
|
||||
|
||||
it('#cleanPermissions - should clean permissions at ERC20 level', async () => {
|
||||
assert((await datatoken.getDTPermissions(datatokenAddress, nftOwner)).minter === true)
|
||||
|
||||
@ -222,43 +355,4 @@ describe('Datatoken', () => {
|
||||
const key = web3.utils.keccak256(datatokenAddress)
|
||||
assert((await nftDatatoken.getData(nftAddress, key)) === data)
|
||||
})
|
||||
|
||||
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'))
|
||||
// assert((await erc20Token.balanceOf(user2.address)) == web3.utils.toWei('10'))
|
||||
// const consumer = user2.address // could be different user
|
||||
// const dtAmount = web3.utils.toWei('1')
|
||||
// const serviceId = 1 // dummy index
|
||||
// const consumeFeeAddress = user3.address // marketplace fee Collector
|
||||
// const consumeFeeAmount = 1 // fee to be collected on top, requires approval
|
||||
// const consumeFeeToken = addressZero // token address for the feeAmount, in this case DAI
|
||||
// await erc20Token
|
||||
// .connect(user2)
|
||||
// .startOrder(
|
||||
// consumer,
|
||||
// dtAmount,
|
||||
// serviceId,
|
||||
// consumeFeeAddress,
|
||||
// consumeFeeToken,
|
||||
// consumeFeeAmount
|
||||
// )
|
||||
// assert(
|
||||
// (await erc20Token.balanceOf(user2.address)) == web3.utils.toWei('9'),
|
||||
// 'Invalid user balance, DT was not substracted'
|
||||
// )
|
||||
// assert(
|
||||
// (await erc20Token.balanceOf(opfCollector.address)) == web3.utils.toWei('0'),
|
||||
// 'Invalid OPF balance, we should not get any DTs'
|
||||
// )
|
||||
// assert(
|
||||
// (await erc20Token.balanceOf(user3.address)) == web3.utils.toWei('0'),
|
||||
// 'Invalid consumeFee, we should have DT as fee'
|
||||
// )
|
||||
// assert(
|
||||
// (await erc20Token.balanceOf(await erc20Token.getFeeCollector())) ==
|
||||
// web3.utils.toWei('1'),
|
||||
// 'Invalid publisher reward, we should have 1 DT'
|
||||
// )
|
||||
})
|
||||
})
|
||||
|
@ -9,6 +9,7 @@ import Router from '@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRo
|
||||
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 OPFCollector from '@oceanprotocol/contracts/artifacts/contracts/communityFee/OPFCommunityFeeCollector.sol/OPFCommunityFeeCollector.json'
|
||||
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
|
||||
|
||||
import { TestContractHandler } from '../TestContractHandler'
|
||||
@ -45,6 +46,7 @@ describe('NFTDatatoken', () => {
|
||||
SideStaking.abi as AbiItem[],
|
||||
FixedRate.abi as AbiItem[],
|
||||
Dispenser.abi as AbiItem[],
|
||||
OPFCollector.abi as AbiItem[],
|
||||
|
||||
ERC721Template.bytecode,
|
||||
ERC20Template.bytecode,
|
||||
@ -53,7 +55,8 @@ describe('NFTDatatoken', () => {
|
||||
Router.bytecode,
|
||||
SideStaking.bytecode,
|
||||
FixedRate.bytecode,
|
||||
Dispenser.bytecode
|
||||
Dispenser.bytecode,
|
||||
OPFCollector.bytecode
|
||||
)
|
||||
await contractHandler.getAccounts()
|
||||
nftOwner = contractHandler.accounts[0]
|
||||
@ -99,11 +102,11 @@ describe('NFTDatatoken', () => {
|
||||
|
||||
// Manager
|
||||
it('#addManager - should add a new Manager', async () => {
|
||||
// assert((await nftDatatoken.getNFTPermissions(nftAddress, user1)).manager === false)
|
||||
assert((await nftDatatoken.getNFTPermissions(nftAddress, user1)).manager === false)
|
||||
|
||||
await nftDatatoken.addManager(nftAddress, nftOwner, user1)
|
||||
|
||||
// assert((await nftDatatoken.getNFTPermissions(nftAddress, user1)).manager === true)
|
||||
assert((await nftDatatoken.getNFTPermissions(nftAddress, user1)).manager === true)
|
||||
})
|
||||
|
||||
it('#addManager - should fail to add a new Manager, if NOT NFT Owner', async () => {
|
||||
@ -115,11 +118,11 @@ describe('NFTDatatoken', () => {
|
||||
})
|
||||
|
||||
it('#removeManager - should remove a Manager', async () => {
|
||||
// assert((await nftDatatoken.getNFTPermissions(nftAddress, user1)).manager === true)
|
||||
assert((await nftDatatoken.getNFTPermissions(nftAddress, user1)).manager === true)
|
||||
|
||||
await nftDatatoken.removeManager(nftAddress, nftOwner, user1)
|
||||
|
||||
// assert((await nftDatatoken.getNFTPermissions(nftAddress, user1)).manager === false)
|
||||
assert((await nftDatatoken.getNFTPermissions(nftAddress, user1)).manager === false)
|
||||
})
|
||||
|
||||
it('#removeManager - should fail to remove a new Manager, if NOT NFT Owner', async () => {
|
||||
@ -171,15 +174,15 @@ describe('NFTDatatoken', () => {
|
||||
|
||||
// MetadataUpdate
|
||||
it('#addMetadataUpdate - should add to remove Metadata Updater if Manager', async () => {
|
||||
// assert(
|
||||
// (await nftDatatoken.getNFTPermissions(nftAddress, user1)).updateMetadata === false
|
||||
// )
|
||||
assert(
|
||||
(await nftDatatoken.getNFTPermissions(nftAddress, user1)).updateMetadata === false
|
||||
)
|
||||
|
||||
await nftDatatoken.addMetadataUpdater(nftAddress, nftOwner, user1)
|
||||
|
||||
// assert(
|
||||
// (await nftDatatoken.getNFTPermissions(nftAddress, user1)).updateMetadata === true
|
||||
// )
|
||||
assert(
|
||||
(await nftDatatoken.getNFTPermissions(nftAddress, user1)).updateMetadata === true
|
||||
)
|
||||
})
|
||||
|
||||
it('#addMetadataUpdate - should fail to add Metadata Updater if NOT Manager', async () => {
|
||||
@ -194,15 +197,15 @@ describe('NFTDatatoken', () => {
|
||||
})
|
||||
|
||||
it('#removeMetadataUpdate - remove Metadata Updater if Manager', async () => {
|
||||
// assert(
|
||||
// (await nftDatatoken.getNFTPermissions(nftAddress, user1)).updateMetadata === false
|
||||
// )
|
||||
assert(
|
||||
(await nftDatatoken.getNFTPermissions(nftAddress, user1)).updateMetadata === true
|
||||
)
|
||||
|
||||
await nftDatatoken.removeMetadataUpdater(nftAddress, nftOwner, user1)
|
||||
|
||||
// assert(
|
||||
// (await nftDatatoken.getNFTPermissions(nftAddress, user1)).updateMetadata === true
|
||||
// )
|
||||
assert(
|
||||
(await nftDatatoken.getNFTPermissions(nftAddress, user1)).updateMetadata === false
|
||||
)
|
||||
})
|
||||
|
||||
it('#removeMetadataUpdate - should fail to remove Metadata Updater if NOT Manager', async () => {
|
||||
@ -218,11 +221,11 @@ describe('NFTDatatoken', () => {
|
||||
|
||||
// StoreUpdater
|
||||
it('#addStoreUpdater - should add to remove Store Updater if Manager', async () => {
|
||||
// assert((await nftDatatoken.getNFTPermissions(nftAddress, user1)).store === false)
|
||||
assert((await nftDatatoken.getNFTPermissions(nftAddress, user1)).store === false)
|
||||
|
||||
await nftDatatoken.addStoreUpdater(nftAddress, nftOwner, user1)
|
||||
|
||||
// assert((await nftDatatoken.getNFTPermissions(nftAddress, user1)).store === true)
|
||||
assert((await nftDatatoken.getNFTPermissions(nftAddress, user1)).store === true)
|
||||
})
|
||||
|
||||
it('#addStoreUpdater - should fail to add Store Updater if NOT Manager', async () => {
|
||||
@ -237,11 +240,11 @@ describe('NFTDatatoken', () => {
|
||||
})
|
||||
|
||||
it('#removeStoreUpdater - remove Metadata Updater if Manager', async () => {
|
||||
// assert((await nftDatatoken.getNFTPermissions(nftAddress, user1)).store === false)
|
||||
assert((await nftDatatoken.getNFTPermissions(nftAddress, user1)).store === true)
|
||||
|
||||
await nftDatatoken.removeStoreUpdater(nftAddress, nftOwner, user1)
|
||||
|
||||
// assert((await nftDatatoken.getNFTPermissions(nftAddress, user1)).store === true)
|
||||
assert((await nftDatatoken.getNFTPermissions(nftAddress, user1)).store === false)
|
||||
})
|
||||
|
||||
it('#removeStoreUpdater - should fail to remove Metadata Updater if NOT Manager', async () => {
|
||||
@ -296,6 +299,6 @@ describe('NFTDatatoken', () => {
|
||||
await nftDatatoken.cleanPermissions(nftAddress, user1)
|
||||
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, user2)) === false)
|
||||
// assert((await nftDatatoken.getNFTPermissions(nftAddress, nftOwner)).manager === false)
|
||||
assert((await nftDatatoken.getNFTPermissions(nftAddress, nftOwner)).manager === false)
|
||||
})
|
||||
})
|
||||
|
@ -10,6 +10,7 @@ import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/template
|
||||
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 OPFCollector from '@oceanprotocol/contracts/artifacts/contracts/communityFee/OPFCommunityFeeCollector.sol/OPFCommunityFeeCollector.json'
|
||||
import PoolTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/balancer/BPool.sol/BPool.json'
|
||||
import { LoggerInstance } from '../../src/utils'
|
||||
// import { NFTDataToken } from '../../../src/datatokens/NFTDatatoken'
|
||||
@ -40,6 +41,7 @@ describe('NFT Factory test', () => {
|
||||
SideStaking.abi as AbiItem[],
|
||||
FixedRate.abi as AbiItem[],
|
||||
Dispenser.abi as AbiItem[],
|
||||
OPFCollector.abi as AbiItem[],
|
||||
|
||||
ERC721Template.bytecode,
|
||||
ERC20Template.bytecode,
|
||||
@ -48,7 +50,8 @@ describe('NFT Factory test', () => {
|
||||
Router.bytecode,
|
||||
SideStaking.bytecode,
|
||||
FixedRate.bytecode,
|
||||
Dispenser.bytecode
|
||||
Dispenser.bytecode,
|
||||
OPFCollector.bytecode
|
||||
)
|
||||
await contracts.getAccounts()
|
||||
factoryOwner = contracts.accounts[0]
|
||||
|
@ -9,6 +9,7 @@ import FactoryRouter from '@oceanprotocol/contracts/artifacts/contracts/pools/Fa
|
||||
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 OPFCollector from '@oceanprotocol/contracts/artifacts/contracts/communityFee/OPFCommunityFeeCollector.sol/OPFCommunityFeeCollector.json'
|
||||
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
|
||||
import PoolTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/balancer/BPool.sol/BPool.json'
|
||||
import { LoggerInstance } from '../../../src/utils'
|
||||
@ -41,6 +42,7 @@ describe('Router unit test', () => {
|
||||
SideStaking.abi as AbiItem[],
|
||||
FixedRate.abi as AbiItem[],
|
||||
Dispenser.abi as AbiItem[],
|
||||
OPFCollector.abi as AbiItem[],
|
||||
|
||||
ERC721Template.bytecode,
|
||||
ERC20Template.bytecode,
|
||||
@ -49,7 +51,8 @@ describe('Router unit test', () => {
|
||||
FactoryRouter.bytecode,
|
||||
SideStaking.bytecode,
|
||||
FixedRate.bytecode,
|
||||
Dispenser.bytecode
|
||||
Dispenser.bytecode,
|
||||
OPFCollector.bytecode
|
||||
)
|
||||
await contracts.getAccounts()
|
||||
factoryOwner = contracts.accounts[0]
|
||||
|
Loading…
x
Reference in New Issue
Block a user