diff --git a/src/factories/NFTFactory.ts b/src/factories/NFTFactory.ts index 7fd43f54..dbf376a3 100644 --- a/src/factories/NFTFactory.ts +++ b/src/factories/NFTFactory.ts @@ -162,7 +162,7 @@ export class NFTFactory { address: string, templateAddress: string ): Promise { - if ((await this.getOwner()) != address) { + if ((await this.getOwner()) !== address) { throw new Error(`Caller is not Factory Owner`) } @@ -198,7 +198,7 @@ export class NFTFactory { address: string, templateIndex: number ): Promise { - if ((await this.getOwner()) != address) { + if ((await this.getOwner()) !== address) { throw new Error(`Caller is not Factory Owner`) } @@ -234,7 +234,7 @@ export class NFTFactory { address: string, templateIndex: number ): Promise { - if ((await this.getOwner()) != address) { + if ((await this.getOwner()) !== address) { throw new Error(`Caller is not Factory Owner`) } @@ -270,7 +270,7 @@ export class NFTFactory { address: string, templateAddress: string ): Promise { - if ((await this.getOwner()) != address) { + if ((await this.getOwner()) !== address) { throw new Error(`Caller is not Factory Owner`) } @@ -306,7 +306,7 @@ export class NFTFactory { address: string, templateIndex: number ): Promise { - if ((await this.getOwner()) != address) { + if ((await this.getOwner()) !== address) { throw new Error(`Caller is not Factory Owner`) } @@ -342,7 +342,7 @@ export class NFTFactory { address: string, templateIndex: number ): Promise { - if ((await this.getOwner()) != address) { + if ((await this.getOwner()) !== address) { throw new Error(`Caller is not Factory Owner`) } diff --git a/src/pools/balancer/PoolFactory.ts b/src/pools/balancer/PoolFactory.ts index e9bb7198..1b74b57c 100644 --- a/src/pools/balancer/PoolFactory.ts +++ b/src/pools/balancer/PoolFactory.ts @@ -37,7 +37,7 @@ export class PoolFactory { public async deployPool( account: string, tokens: string[], - weights: string[], + weightsInWei: string[], swapFeePercentage: number, swapMarketFee: number, owner: string @@ -53,5 +53,6 @@ export class PoolFactory { this.logger.log(e) estGas = gasLimitDefault } + return estGas } } diff --git a/src/pools/index.ts b/src/pools/index.ts index 986f661d..2da36a1d 100644 --- a/src/pools/index.ts +++ b/src/pools/index.ts @@ -1,3 +1,3 @@ export * from './balancer' -export * from './dispencer' +export * from './dispenser' export * from './fixedRate' diff --git a/test/TestContractHandler.ts b/test/TestContractHandler.ts index 8db521ac..28f766b7 100644 --- a/test/TestContractHandler.ts +++ b/test/TestContractHandler.ts @@ -2,6 +2,7 @@ import Web3 from 'web3' import { Contract } from 'web3-eth-contract' import { AbiItem } from 'web3-utils/types' +// TODO: add OPF deployment const communityCollector = '0xeE9300b7961e0a01d9f0adb863C7A227A07AaD75' const oceanAddress = '0x967da4048cd07ab37855c090aaf366e4ce1b9f48' export class TestContractHandler { @@ -25,18 +26,16 @@ export class TestContractHandler { public DispenserBytecode: string public PoolTemplateBytecode: string public OPFCollectorBytecode: string - public factory721Address: string public template721Address: string public template20Address: string - public routerAddress:string + public routerAddress: string public sideStakingAddress: string - public fixedRateAddress:string + public fixedRateAddress: string public dispenserAddress: string public poolTemplateAddress: string public opfCollectorAddress: string - public web3: Web3 @@ -50,26 +49,25 @@ export class TestContractHandler { SideStakingABI?: AbiItem | AbiItem[], FixedRateABI?: AbiItem | AbiItem[], DispenserABI?: AbiItem | AbiItem[], - + template721Bytecode?: string, template20Bytecode?: string, poolTemplateBytecode?: string, factory721Bytecode?: string, routerBytecode?: string, sideStakingBytecode?: string, - fixedRateBytecode?:string, - dispenserBytecode?: string, + fixedRateBytecode?: string, + dispenserBytecode?: string ) { this.web3 = web3 this.ERC721Template = new this.web3.eth.Contract(ERC721TemplateABI) this.ERC20Template = new this.web3.eth.Contract(ERC20TemplateABI) this.PoolTemplate = new this.web3.eth.Contract(PoolTemplateABI) this.ERC721Factory = new this.web3.eth.Contract(ERC721FactoryABI) - this.Router=new this.web3.eth.Contract(RouterABI) + this.Router = new this.web3.eth.Contract(RouterABI) this.SideStaking = new this.web3.eth.Contract(SideStakingABI) - this.FixedRate= new this.web3.eth.Contract(FixedRateABI) + this.FixedRate = new this.web3.eth.Contract(FixedRateABI) this.Dispenser = new this.web3.eth.Contract(DispenserABI) - this.ERC721FactoryBytecode = factory721Bytecode this.ERC20TemplateBytecode = template20Bytecode @@ -86,37 +84,34 @@ export class TestContractHandler { return this.accounts } - public async deployContracts(owner: string) { + public async deployContracts(owner: string, routerABI?: AbiItem | AbiItem[]) { let estGas - // console.log(this.ERC721TemplateBytecode) - // console.log(this.ERC20TemplateBytecode) - // DEPLOY POOL TEMPLATE - // get est gascost - estGas = await this.PoolTemplate.deploy({ - data: this.PoolTemplateBytecode, - arguments: [] - }).estimateGas(function (err, estGas) { - if (err) console.log('DeployContracts: ' + err) - return estGas - }) - // deploy the contract and get it's address - this.poolTemplateAddress = await this.PoolTemplate.deploy({ - data: this.PoolTemplateBytecode, - arguments: [] - }) - .send({ - from: owner, - gas: estGas + 1, - gasPrice: '3000000000' + // DEPLOY POOL TEMPLATE + // get est gascost + estGas = await this.PoolTemplate.deploy({ + data: this.PoolTemplateBytecode, + arguments: [] + }).estimateGas(function (err, estGas) { + if (err) console.log('DeployContracts: ' + err) + return estGas }) - .then(function (contract) { - return contract.options.address + // deploy the contract and get it's address + this.poolTemplateAddress = await this.PoolTemplate.deploy({ + data: this.PoolTemplateBytecode, + arguments: [] }) + .send({ + from: owner, + gas: estGas + 1, + gasPrice: '3000000000' + }) + .then(function (contract) { + return contract.options.address + }) - - // DEPLOY ERC20 TEMPLATE - // get est gascost + // DEPLOY ERC20 TEMPLATE + // get est gascost estGas = await this.ERC20Template.deploy({ data: this.ERC20TemplateBytecode, arguments: [] @@ -138,10 +133,7 @@ export class TestContractHandler { return contract.options.address }) - - - - // DEPLOY ERC721 TEMPLATE + // DEPLOY ERC721 TEMPLATE // get est gascost estGas = await this.ERC721Template.deploy({ data: this.ERC721TemplateBytecode, @@ -167,7 +159,7 @@ export class TestContractHandler { // DEPLOY ROUTER estGas = await this.Router.deploy({ data: this.RouterBytecode, - arguments: [owner,oceanAddress,this.poolTemplateAddress,communityCollector,[]] + arguments: [owner, oceanAddress, this.poolTemplateAddress, communityCollector, []] }).estimateGas(function (err, estGas) { if (err) console.log('DeployContracts: ' + err) return estGas @@ -175,7 +167,7 @@ export class TestContractHandler { // deploy the contract and get it's address this.routerAddress = await this.Router.deploy({ data: this.RouterBytecode, - arguments: [owner,oceanAddress,this.poolTemplateAddress,communityCollector,[]] + arguments: [owner, oceanAddress, this.poolTemplateAddress, communityCollector, []] }) .send({ from: owner, @@ -186,8 +178,7 @@ export class TestContractHandler { return contract.options.address }) - - // DEPLOY SIDE STAKING + // DEPLOY SIDE STAKING estGas = await this.SideStaking.deploy({ data: this.SideStakingBytecode, arguments: [this.routerAddress] @@ -208,8 +199,8 @@ export class TestContractHandler { .then(function (contract) { return contract.options.address }) - - // DEPLOY FIXED RATE + + // DEPLOY FIXED RATE estGas = await this.FixedRate.deploy({ data: this.FixedRateBytecode, arguments: [this.routerAddress, communityCollector] @@ -231,7 +222,7 @@ export class TestContractHandler { return contract.options.address }) - // DEPLOY Dispenser + // DEPLOY Dispenser estGas = await this.Dispenser.deploy({ data: this.DispenserBytecode, arguments: [this.routerAddress] @@ -253,10 +244,15 @@ export class TestContractHandler { return contract.options.address }) - // DEPLOY ERC721 FACTORY + // DEPLOY ERC721 FACTORY estGas = await this.ERC721Factory.deploy({ data: this.ERC721FactoryBytecode, - arguments: [this.template721Address, this.template20Address, communityCollector,this.routerAddress] + arguments: [ + this.template721Address, + this.template20Address, + communityCollector, + this.routerAddress + ] }).estimateGas(function (err, estGas) { if (err) console.log('DeployContracts: ' + err) return estGas @@ -264,7 +260,12 @@ export class TestContractHandler { // deploy the contract and get it's address this.factory721Address = await this.ERC721Factory.deploy({ data: this.ERC721FactoryBytecode, - arguments: [this.template721Address, this.template20Address, communityCollector,this.routerAddress] + arguments: [ + this.template721Address, + this.template20Address, + communityCollector, + this.routerAddress + ] }) .send({ from: owner, @@ -275,7 +276,21 @@ export class TestContractHandler { return contract.options.address }) - // // TODO: SET ERC721 Factory address in ERC20 Factory - + const RouterContract = new this.web3.eth.Contract(routerABI, this.routerAddress) + + await RouterContract.methods.addFactory(this.factory721Address).send({ from: owner }) + await RouterContract.methods + .addFixedRateContract(this.fixedRateAddress) + .send({ from: owner }) + await RouterContract.methods + .addFixedRateContract(this.dispenserAddress) + .send({ from: owner }) + await RouterContract.methods + .addSSContract(this.sideStakingAddress) + .send({ from: owner }) + // TODO: add OPF deployment and update argument + await RouterContract.methods + .changeRouterOwner(communityCollector) + .send({ from: owner }) } -} \ No newline at end of file +} diff --git a/test/unit/NFTFactory.test.ts b/test/unit/NFTFactory.test.ts index cc8a359e..ab193c72 100644 --- a/test/unit/NFTFactory.test.ts +++ b/test/unit/NFTFactory.test.ts @@ -10,8 +10,9 @@ 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 PoolTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/balancer/BPool.sol/BPool.json' +import { LoggerInstance } from '../../src/utils' // import { NFTDataToken } from '../../../src/datatokens/NFTDatatoken' -// import { NFTFactory } from '../../../src/factories/NFTFactory' +import { NFTFactory } from '../../src/factories/NFTFactory' // import { DT20Factory } from '../../../src/factories/DT20Factory' const web3 = new Web3('http://127.0.0.1:8545') @@ -22,12 +23,7 @@ describe('NFT Factory test', () => { let user1: string let user2: string let contracts: TestContractHandler -// let nftDatatoken: NFTDataToken -// let nftFactory: NFTFactory -// let erc20Factory: DT20Factory -// let nftAddress: string -// let newNFTAddress: string -// let newNFTDatatoken: NFTDataToken + let nftFactory: NFTFactory const nftName = 'NFT' const nftSymbol = 'NFTSymbol' @@ -40,16 +36,16 @@ describe('NFT Factory test', () => { // TODO: complete unit test it('should deploy contracts', async () => { contracts = new TestContractHandler( - web3, + web3, ERC721Template.abi as AbiItem[], ERC20Template.abi as AbiItem[], - PoolTemplate.abi as AbiItem[], + PoolTemplate.abi as AbiItem[], ERC721Factory.abi as AbiItem[], Router.abi as AbiItem[], - SideStaking.abi as AbiItem[], - FixedRate.abi as AbiItem[], - Dispenser.abi as AbiItem[], - + SideStaking.abi as AbiItem[], + FixedRate.abi as AbiItem[], + Dispenser.abi as AbiItem[], + ERC721Template.bytecode, ERC20Template.bytecode, PoolTemplate.bytecode, @@ -57,52 +53,22 @@ describe('NFT Factory test', () => { Router.bytecode, SideStaking.bytecode, FixedRate.bytecode, - Dispenser.bytecode, - - + Dispenser.bytecode ) await contracts.getAccounts() factoryOwner = contracts.accounts[0] nftOwner = contracts.accounts[1] user1 = contracts.accounts[2] console.log(factoryOwner) - await contracts.deployContracts(factoryOwner) + await contracts.deployContracts(factoryOwner, Router.abi as AbiItem[]) + console.log('BOOM') }) - -// it('should set ERC721Factory on ERC20Factory', async () => { -// erc20Factory = new DT20Factory( -// contracts.factory20Address, -// //ERC20Factory.abi as AbiItem[], -// web3, -// LoggerInstance -// ) + it('should initiate NFTFactory instance', async () => { + nftFactory = new NFTFactory(contracts.factory721Address, web3, LoggerInstance) -// await erc20Factory.setERC721Factory(factoryOwner, contracts.factory721Address) -// }) - -// it('should initialize NFTFactory instance, create a new NFT and initializing a NFT dt class', async () => { -// nftFactory = new NFTFactory( -// contracts.factory721Address, -// web3, -// LoggerInstance -// // ERC721Factory.abi as AbiItem[], -// ) - -// nftAddress = await nftFactory.createNFT( -// nftOwner, -// data, -// flags, -// nftName, -// nftSymbol, -// nftTemplateIndex -// ) -// //console.log(newNFTAddress) - -// nftDatatoken = new NFTDataToken( -// web3, -// LoggerInstance -// // ERC721Template.abi as AbiItem[], -// ) -}) \ No newline at end of file + const nftCount = await nftFactory.getCurrentNFTCount() + assert(nftCount == 0) + }) +})