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

fix lint, complete deployment script, add initial instance test

This commit is contained in:
lacoop6tu 2021-10-20 15:29:04 -05:00
parent 3e247d46bf
commit 3c638ab597
5 changed files with 95 additions and 113 deletions

View File

@ -162,7 +162,7 @@ export class NFTFactory {
address: string,
templateAddress: string
): Promise<TransactionReceipt> {
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<TransactionReceipt> {
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<TransactionReceipt> {
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<TransactionReceipt> {
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<TransactionReceipt> {
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<TransactionReceipt> {
if ((await this.getOwner()) != address) {
if ((await this.getOwner()) !== address) {
throw new Error(`Caller is not Factory Owner`)
}

View File

@ -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
}
}

View File

@ -1,3 +1,3 @@
export * from './balancer'
export * from './dispencer'
export * from './dispenser'
export * from './fixedRate'

View File

@ -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 {
@ -26,7 +27,6 @@ export class TestContractHandler {
public PoolTemplateBytecode: string
public OPFCollectorBytecode: string
public factory721Address: string
public template721Address: string
public template20Address: string
@ -37,7 +37,6 @@ export class TestContractHandler {
public poolTemplateAddress: string
public opfCollectorAddress: string
public web3: Web3
constructor(
@ -58,7 +57,7 @@ export class TestContractHandler {
routerBytecode?: string,
sideStakingBytecode?: string,
fixedRateBytecode?: string,
dispenserBytecode?: string,
dispenserBytecode?: string
) {
this.web3 = web3
this.ERC721Template = new this.web3.eth.Contract(ERC721TemplateABI)
@ -70,7 +69,6 @@ export class TestContractHandler {
this.FixedRate = new this.web3.eth.Contract(FixedRateABI)
this.Dispenser = new this.web3.eth.Contract(DispenserABI)
this.ERC721FactoryBytecode = factory721Bytecode
this.ERC20TemplateBytecode = template20Bytecode
this.PoolTemplateBytecode = poolTemplateBytecode
@ -86,10 +84,8 @@ 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
@ -114,7 +110,6 @@ export class TestContractHandler {
return contract.options.address
})
// DEPLOY ERC20 TEMPLATE
// get est gascost
estGas = await this.ERC20Template.deploy({
@ -138,9 +133,6 @@ export class TestContractHandler {
return contract.options.address
})
// DEPLOY ERC721 TEMPLATE
// get est gascost
estGas = await this.ERC721Template.deploy({
@ -186,7 +178,6 @@ export class TestContractHandler {
return contract.options.address
})
// DEPLOY SIDE STAKING
estGas = await this.SideStaking.deploy({
data: this.SideStakingBytecode,
@ -256,7 +247,12 @@ export class TestContractHandler {
// 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 })
}
}

View File

@ -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'
@ -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 initiate NFTFactory instance', async () => {
nftFactory = new NFTFactory(contracts.factory721Address, web3, LoggerInstance)
// it('should set ERC721Factory on ERC20Factory', async () => {
// erc20Factory = new DT20Factory(
// contracts.factory20Address,
// //ERC20Factory.abi as AbiItem[],
// 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[],
// )
const nftCount = await nftFactory.getCurrentNFTCount()
assert(nftCount == 0)
})
})