mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
convert TestContractHandler class to function
This commit is contained in:
parent
1e12ddd630
commit
a77f1c5862
@ -1,5 +1,4 @@
|
|||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import { Contract } from 'web3-eth-contract'
|
|
||||||
import { AbiItem } from 'web3-utils/types'
|
import { AbiItem } from 'web3-utils/types'
|
||||||
import ERC721Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.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 ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
||||||
@ -11,14 +10,15 @@ import FixedRate from '@oceanprotocol/contracts/artifacts/contracts/pools/fixedR
|
|||||||
import Dispenser from '@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json'
|
import Dispenser from '@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json'
|
||||||
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
|
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
|
||||||
import OPFCommunityFeeCollector from '@oceanprotocol/contracts/artifacts/contracts/communityFee/OPFCommunityFeeCollector.sol/OPFCommunityFeeCollector.json'
|
import OPFCommunityFeeCollector from '@oceanprotocol/contracts/artifacts/contracts/communityFee/OPFCommunityFeeCollector.sol/OPFCommunityFeeCollector.json'
|
||||||
import { getAddresses, GAS_PRICE } from './config'
|
import { web3, getAddresses, GAS_PRICE } from './config'
|
||||||
|
|
||||||
const deployContract = async (
|
const estimateGasAndDeployContract = async (
|
||||||
contract: Contract,
|
abi: AbiItem | AbiItem[],
|
||||||
bytecode: string,
|
bytecode: string,
|
||||||
argumentsArray: any[],
|
argumentsArray: any[],
|
||||||
owner: string
|
owner: string
|
||||||
) => {
|
) => {
|
||||||
|
const contract = new web3.eth.Contract(abi)
|
||||||
// get est gascost
|
// get est gascost
|
||||||
const estimatedGas = await contract
|
const estimatedGas = await contract
|
||||||
.deploy({
|
.deploy({
|
||||||
@ -45,191 +45,177 @@ const deployContract = async (
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TestContractHandler {
|
export interface Addresses {
|
||||||
public ERC721Factory: Contract
|
factory721Address: string
|
||||||
public ERC20Template: Contract
|
template721Address: string
|
||||||
public ERC721Template: Contract
|
template20Address: string
|
||||||
public Router: Contract
|
routerAddress: string
|
||||||
public SideStaking: Contract
|
sideStakingAddress: string
|
||||||
public FixedRate: Contract
|
fixedRateAddress: string
|
||||||
public Dispenser: Contract
|
dispenserAddress: string
|
||||||
public OPFCollector: Contract
|
poolTemplateAddress: string
|
||||||
public PoolTemplate: Contract
|
opfCollectorAddress: string
|
||||||
public MockERC20: Contract
|
oceanAddress: string
|
||||||
public MockOcean: Contract
|
daiAddress: string
|
||||||
|
usdcAddress: string
|
||||||
public factory721Address: string
|
}
|
||||||
public template721Address: string
|
|
||||||
public template20Address: string
|
export const deployContracts = async (owner: string): Promise<Addresses> => {
|
||||||
public routerAddress: string
|
const addresses = getAddresses()
|
||||||
public sideStakingAddress: string
|
|
||||||
public fixedRateAddress: string
|
// DEPLOY OPF Fee Collector
|
||||||
public dispenserAddress: string
|
addresses.opfCollectorAddress =
|
||||||
public poolTemplateAddress: string
|
addresses.OPFCommunityFeeCollector ||
|
||||||
public opfCollectorAddress: string
|
(await estimateGasAndDeployContract(
|
||||||
public oceanAddress: string
|
OPFCommunityFeeCollector.abi as AbiItem[],
|
||||||
public daiAddress: string
|
OPFCommunityFeeCollector.bytecode,
|
||||||
public usdcAddress: string
|
[owner, owner],
|
||||||
public web3: Web3
|
owner
|
||||||
|
))
|
||||||
constructor(web3: Web3) {
|
|
||||||
this.web3 = web3
|
// DEPLOY POOL TEMPLATE
|
||||||
|
addresses.poolTemplateAddress =
|
||||||
this.ERC721Template = new this.web3.eth.Contract(ERC721Template.abi as AbiItem[])
|
addresses.poolTemplate ||
|
||||||
this.ERC20Template = new this.web3.eth.Contract(ERC20Template.abi as AbiItem[])
|
(await estimateGasAndDeployContract(
|
||||||
this.PoolTemplate = new this.web3.eth.Contract(PoolTemplate.abi as AbiItem[])
|
PoolTemplate.abi as AbiItem[],
|
||||||
this.ERC721Factory = new this.web3.eth.Contract(ERC721Factory.abi as AbiItem[])
|
PoolTemplate.bytecode,
|
||||||
this.Router = new this.web3.eth.Contract(Router.abi as AbiItem[])
|
[],
|
||||||
this.SideStaking = new this.web3.eth.Contract(SideStaking.abi as AbiItem[])
|
owner
|
||||||
this.FixedRate = new this.web3.eth.Contract(FixedRate.abi as AbiItem[])
|
))
|
||||||
this.Dispenser = new this.web3.eth.Contract(Dispenser.abi as AbiItem[])
|
|
||||||
this.MockERC20 = new this.web3.eth.Contract(MockERC20.abi as AbiItem[])
|
// DEPLOY ERC20 TEMPLATE
|
||||||
this.OPFCollector = new this.web3.eth.Contract(
|
addresses.template20Address =
|
||||||
OPFCommunityFeeCollector.abi as AbiItem[]
|
addresses.ERC20Template['1'] ||
|
||||||
)
|
(await estimateGasAndDeployContract(
|
||||||
}
|
ERC20Template.abi as AbiItem[],
|
||||||
|
ERC20Template.bytecode,
|
||||||
public async deployContracts(owner: string) {
|
[],
|
||||||
const addresses = getAddresses()
|
owner
|
||||||
|
))
|
||||||
// DEPLOY OPF Fee Collector
|
|
||||||
this.opfCollectorAddress =
|
// DEPLOY ERC721 TEMPLATE
|
||||||
addresses.OPFCommunityFeeCollector ||
|
addresses.template721Address =
|
||||||
(await deployContract(
|
addresses.ERC721Template['1'] ||
|
||||||
this.OPFCollector,
|
(await estimateGasAndDeployContract(
|
||||||
OPFCommunityFeeCollector.bytecode,
|
ERC721Template.abi as AbiItem[],
|
||||||
[owner, owner],
|
ERC721Template.bytecode,
|
||||||
owner
|
[],
|
||||||
))
|
owner
|
||||||
|
))
|
||||||
// DEPLOY POOL TEMPLATE
|
|
||||||
this.poolTemplateAddress =
|
// DEPLOY OCEAN MOCK
|
||||||
addresses.poolTemplate ||
|
addresses.oceanAddress =
|
||||||
(await deployContract(this.PoolTemplate, PoolTemplate.bytecode, [], owner))
|
addresses.Ocean ||
|
||||||
|
(await estimateGasAndDeployContract(
|
||||||
// DEPLOY ERC20 TEMPLATE
|
MockERC20.abi as AbiItem[],
|
||||||
this.template20Address =
|
MockERC20.bytecode,
|
||||||
addresses.ERC20Template['1'] ||
|
['OCEAN', 'OCEAN', 18],
|
||||||
(await deployContract(this.ERC20Template, ERC20Template.bytecode, [], owner))
|
owner
|
||||||
|
))
|
||||||
// DEPLOY ERC721 TEMPLATE
|
|
||||||
this.template721Address =
|
// DEPLOY ROUTER
|
||||||
addresses.ERC721Template['1'] ||
|
addresses.routerAddress =
|
||||||
(await deployContract(this.ERC721Template, ERC721Template.bytecode, [], owner))
|
addresses.Router ||
|
||||||
|
(await estimateGasAndDeployContract(
|
||||||
// DEPLOY OCEAN MOCK
|
Router.abi as AbiItem[],
|
||||||
this.oceanAddress =
|
Router.bytecode,
|
||||||
addresses.Ocean ||
|
[
|
||||||
(await deployContract(
|
owner,
|
||||||
this.MockERC20,
|
addresses.oceanAddress,
|
||||||
MockERC20.bytecode,
|
addresses.poolTemplateAddress,
|
||||||
['OCEAN', 'OCEAN', 18],
|
addresses.opfCollectorAddress,
|
||||||
owner
|
[]
|
||||||
))
|
],
|
||||||
|
owner
|
||||||
// DEPLOY ROUTER
|
))
|
||||||
this.routerAddress =
|
|
||||||
addresses.Router ||
|
// DEPLOY SIDE STAKING
|
||||||
(await deployContract(
|
addresses.sideStakingAddress =
|
||||||
this.Router,
|
addresses.Staking ||
|
||||||
Router.bytecode,
|
(await estimateGasAndDeployContract(
|
||||||
[
|
SideStaking.abi as AbiItem[],
|
||||||
owner,
|
SideStaking.bytecode,
|
||||||
this.oceanAddress,
|
[addresses.routerAddress],
|
||||||
this.poolTemplateAddress,
|
owner
|
||||||
this.opfCollectorAddress,
|
))
|
||||||
[]
|
|
||||||
],
|
// DEPLOY FIXED RATE
|
||||||
owner
|
addresses.fixedRateAddress =
|
||||||
))
|
addresses.FixedPrice ||
|
||||||
|
(await estimateGasAndDeployContract(
|
||||||
// DEPLOY SIDE STAKING
|
FixedRate.abi as AbiItem[],
|
||||||
this.sideStakingAddress =
|
FixedRate.bytecode,
|
||||||
addresses.Staking ||
|
[addresses.routerAddress, addresses.opfCollectorAddress],
|
||||||
(await deployContract(
|
owner
|
||||||
this.SideStaking,
|
))
|
||||||
SideStaking.bytecode,
|
|
||||||
[this.routerAddress],
|
// DEPLOY Dispenser
|
||||||
owner
|
addresses.dispenserAddress =
|
||||||
))
|
addresses.Dispenser ||
|
||||||
|
(await estimateGasAndDeployContract(
|
||||||
// DEPLOY FIXED RATE
|
Dispenser.abi as AbiItem[],
|
||||||
this.fixedRateAddress =
|
Dispenser.bytecode,
|
||||||
addresses.FixedPrice ||
|
[addresses.routerAddress],
|
||||||
(await deployContract(
|
owner
|
||||||
this.FixedRate,
|
))
|
||||||
FixedRate.bytecode,
|
|
||||||
[this.routerAddress, this.opfCollectorAddress],
|
// DEPLOY ERC721 FACTORY
|
||||||
owner
|
addresses.factory721Address =
|
||||||
))
|
addresses.ERC721Factory ||
|
||||||
|
(await estimateGasAndDeployContract(
|
||||||
// DEPLOY Dispenser
|
ERC721Factory.abi as AbiItem[],
|
||||||
this.dispenserAddress =
|
ERC721Factory.bytecode,
|
||||||
addresses.Dispenser ||
|
[
|
||||||
(await deployContract(
|
addresses.template721Address,
|
||||||
this.Dispenser,
|
addresses.template20Address,
|
||||||
Dispenser.bytecode,
|
addresses.opfCollectorAddress,
|
||||||
[this.routerAddress],
|
addresses.routerAddress
|
||||||
owner
|
],
|
||||||
))
|
owner
|
||||||
|
))
|
||||||
// DEPLOY ERC721 FACTORY
|
|
||||||
this.factory721Address =
|
// DEPLOY USDC MOCK
|
||||||
addresses.ERC721Factory ||
|
addresses.usdcAddress =
|
||||||
(await deployContract(
|
addresses.MockUSDC ||
|
||||||
this.ERC721Factory,
|
(await estimateGasAndDeployContract(
|
||||||
ERC721Factory.bytecode,
|
MockERC20.abi as AbiItem[],
|
||||||
[
|
MockERC20.bytecode,
|
||||||
this.template721Address,
|
['USDC', 'USDC', 6],
|
||||||
this.template20Address,
|
owner
|
||||||
this.opfCollectorAddress,
|
))
|
||||||
this.routerAddress
|
|
||||||
],
|
// DEPLOY DAI MOCK
|
||||||
owner
|
addresses.daiAddress =
|
||||||
))
|
addresses.MockDAI ||
|
||||||
|
(await estimateGasAndDeployContract(
|
||||||
// DEPLOY USDC MOCK
|
MockERC20.abi as AbiItem[],
|
||||||
this.usdcAddress =
|
MockERC20.bytecode,
|
||||||
addresses.MockUSDC ||
|
['DAI', 'DAI', 18],
|
||||||
(await deployContract(
|
owner
|
||||||
this.MockERC20,
|
))
|
||||||
MockERC20.bytecode,
|
|
||||||
['USDC', 'USDC', 6],
|
if (!addresses.Router) {
|
||||||
owner
|
const RouterContract = new web3.eth.Contract(
|
||||||
))
|
Router.abi as AbiItem[],
|
||||||
|
addresses.routerAddress
|
||||||
// DEPLOY DAI MOCK
|
)
|
||||||
this.daiAddress =
|
|
||||||
addresses.MockDAI ||
|
await RouterContract.methods
|
||||||
(await deployContract(
|
.addFactory(addresses.factory721Address)
|
||||||
this.MockERC20,
|
.send({ from: owner })
|
||||||
MockERC20.bytecode,
|
await RouterContract.methods
|
||||||
['DAI', 'DAI', 18],
|
.addFixedRateContract(addresses.fixedRateAddress)
|
||||||
owner
|
.send({ from: owner })
|
||||||
))
|
await RouterContract.methods
|
||||||
|
.addDispenserContract(addresses.dispenserAddress)
|
||||||
if (!addresses.Router) {
|
.send({ from: owner })
|
||||||
const RouterContract = new this.web3.eth.Contract(
|
await RouterContract.methods
|
||||||
Router.abi as AbiItem[],
|
.addSSContract(addresses.sideStakingAddress)
|
||||||
this.routerAddress
|
.send({ from: owner })
|
||||||
)
|
// TODO: add OPF deployment
|
||||||
|
// await RouterContract.methods
|
||||||
await RouterContract.methods
|
// .changeRouterOwner(this.opfCollectorAddress)
|
||||||
.addFactory(this.factory721Address)
|
// .send({ from: owner })
|
||||||
.send({ from: owner })
|
}
|
||||||
await RouterContract.methods
|
return addresses
|
||||||
.addFixedRateContract(this.fixedRateAddress)
|
|
||||||
.send({ from: owner })
|
|
||||||
await RouterContract.methods
|
|
||||||
.addDispenserContract(this.dispenserAddress)
|
|
||||||
.send({ from: owner })
|
|
||||||
await RouterContract.methods
|
|
||||||
.addSSContract(this.sideStakingAddress)
|
|
||||||
.send({ from: owner })
|
|
||||||
// TODO: add OPF deployment
|
|
||||||
// await RouterContract.methods
|
|
||||||
// .changeRouterOwner(this.opfCollectorAddress)
|
|
||||||
// .send({ from: owner })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import { assert, expect } from 'chai'
|
import { assert, expect } from 'chai'
|
||||||
import { AbiItem } from 'web3-utils/types'
|
import { AbiItem } from 'web3-utils/types'
|
||||||
import { TestContractHandler } from '../TestContractHandler'
|
import { deployContracts, Addresses } from '../TestContractHandler'
|
||||||
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.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 { web3 } from '../config'
|
import { web3 } from '../config'
|
||||||
import { NftFactory, NftCreateData, TokenOrder, ZERO_ADDRESS, signHash } from '../../src'
|
import { NftFactory, NftCreateData, TokenOrder, ZERO_ADDRESS, signHash } from '../../src'
|
||||||
import {
|
import {
|
||||||
@ -17,7 +18,7 @@ describe('Nft Factory test', () => {
|
|||||||
let user1: string
|
let user1: string
|
||||||
let user2: string
|
let user2: string
|
||||||
let user3: string
|
let user3: string
|
||||||
let contracts: TestContractHandler
|
let contracts: Addresses
|
||||||
let nftFactory: NftFactory
|
let nftFactory: NftFactory
|
||||||
let dtAddress: string
|
let dtAddress: string
|
||||||
let dtAddress2: string
|
let dtAddress2: string
|
||||||
@ -33,11 +34,10 @@ describe('Nft Factory test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contracts = new TestContractHandler(web3)
|
contracts = await deployContracts(factoryOwner)
|
||||||
await contracts.deployContracts(factoryOwner)
|
|
||||||
|
|
||||||
const daiContract = new web3.eth.Contract(
|
const daiContract = new web3.eth.Contract(
|
||||||
contracts.MockERC20.options.jsonInterface,
|
MockERC20.abi as AbiItem[],
|
||||||
contracts.daiAddress
|
contracts.daiAddress
|
||||||
)
|
)
|
||||||
await daiContract.methods
|
await daiContract.methods
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import { assert, expect } from 'chai'
|
import { assert, expect } from 'chai'
|
||||||
import { AbiItem } from 'web3-utils/types'
|
import { AbiItem } from 'web3-utils/types'
|
||||||
import { TestContractHandler } from '../../TestContractHandler'
|
import { deployContracts, Addresses } from '../../TestContractHandler'
|
||||||
import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
|
import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
|
||||||
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.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 { web3 } from '../../config'
|
import { web3 } from '../../config'
|
||||||
import { NftFactory, NftCreateData } from '../../../src'
|
import { NftFactory, NftCreateData } from '../../../src'
|
||||||
import { Router } from '../../../src/pools/Router'
|
import { Router } from '../../../src/pools/Router'
|
||||||
@ -16,7 +17,7 @@ describe('Router unit test', () => {
|
|||||||
let user1: string
|
let user1: string
|
||||||
let user2: string
|
let user2: string
|
||||||
let user3: string
|
let user3: string
|
||||||
let contracts: TestContractHandler
|
let contracts: Addresses
|
||||||
let router: Router
|
let router: Router
|
||||||
let dtAddress: string
|
let dtAddress: string
|
||||||
let dtAddress2: string
|
let dtAddress2: string
|
||||||
@ -32,11 +33,10 @@ describe('Router unit test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contracts = new TestContractHandler(web3)
|
contracts = await deployContracts(factoryOwner)
|
||||||
await contracts.deployContracts(factoryOwner)
|
|
||||||
|
|
||||||
const daiContract = new web3.eth.Contract(
|
const daiContract = new web3.eth.Contract(
|
||||||
contracts.MockERC20.options.jsonInterface,
|
MockERC20.abi as AbiItem[],
|
||||||
contracts.daiAddress
|
contracts.daiAddress
|
||||||
)
|
)
|
||||||
await daiContract.methods
|
await daiContract.methods
|
||||||
@ -78,7 +78,7 @@ describe('Router unit test', () => {
|
|||||||
it('#buyDTBatch - should buy multiple DT in one call', async () => {
|
it('#buyDTBatch - should buy multiple DT in one call', async () => {
|
||||||
// APPROVE DAI
|
// APPROVE DAI
|
||||||
const daiContract = new web3.eth.Contract(
|
const daiContract = new web3.eth.Contract(
|
||||||
contracts.MockERC20.options.jsonInterface,
|
MockERC20.abi as AbiItem[],
|
||||||
contracts.daiAddress
|
contracts.daiAddress
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -4,7 +4,8 @@ import { Contract } from 'web3-eth-contract'
|
|||||||
import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
|
import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
|
||||||
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.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 { TestContractHandler } from '../../../TestContractHandler'
|
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
|
||||||
|
import { deployContracts, Addresses } from '../../../TestContractHandler'
|
||||||
import { web3 } from '../../../config'
|
import { web3 } from '../../../config'
|
||||||
import {
|
import {
|
||||||
allowance,
|
allowance,
|
||||||
@ -30,7 +31,7 @@ describe('Pool unit test', () => {
|
|||||||
let user1: string
|
let user1: string
|
||||||
let user2: string
|
let user2: string
|
||||||
let user3: string
|
let user3: string
|
||||||
let contracts: TestContractHandler
|
let contracts: Addresses
|
||||||
let pool: Pool
|
let pool: Pool
|
||||||
let dtAddress: string
|
let dtAddress: string
|
||||||
let dtAddress2: string
|
let dtAddress2: string
|
||||||
@ -50,20 +51,16 @@ describe('Pool unit test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contracts = new TestContractHandler(web3)
|
contracts = await deployContracts(factoryOwner)
|
||||||
await contracts.deployContracts(factoryOwner)
|
|
||||||
|
|
||||||
// initialize Pool instance
|
// initialize Pool instance
|
||||||
pool = new Pool(web3, PoolTemplate.abi as AbiItem[])
|
pool = new Pool(web3, PoolTemplate.abi as AbiItem[])
|
||||||
assert(pool != null)
|
assert(pool != null)
|
||||||
|
|
||||||
daiContract = new web3.eth.Contract(
|
daiContract = new web3.eth.Contract(MockERC20.abi as AbiItem[], contracts.daiAddress)
|
||||||
contracts.MockERC20.options.jsonInterface,
|
|
||||||
contracts.daiAddress
|
|
||||||
)
|
|
||||||
|
|
||||||
usdcContract = new web3.eth.Contract(
|
usdcContract = new web3.eth.Contract(
|
||||||
contracts.MockERC20.options.jsonInterface,
|
MockERC20.abi as AbiItem[],
|
||||||
contracts.usdcAddress
|
contracts.usdcAddress
|
||||||
)
|
)
|
||||||
await approve(
|
await approve(
|
||||||
|
@ -2,7 +2,7 @@ import { AbiItem } from 'web3-utils'
|
|||||||
import { assert, expect } from 'chai'
|
import { assert, expect } from 'chai'
|
||||||
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
||||||
import DispenserTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json'
|
import DispenserTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json'
|
||||||
import { TestContractHandler } from '../../../TestContractHandler'
|
import { deployContracts, Addresses } from '../../../TestContractHandler'
|
||||||
import { web3 } from '../../../config'
|
import { web3 } from '../../../config'
|
||||||
import {
|
import {
|
||||||
NftFactory,
|
NftFactory,
|
||||||
@ -19,7 +19,7 @@ describe('Dispenser flow', () => {
|
|||||||
let user1: string
|
let user1: string
|
||||||
let user2: string
|
let user2: string
|
||||||
let user3: string
|
let user3: string
|
||||||
let contracts: TestContractHandler
|
let contracts: Addresses
|
||||||
let DispenserAddress: string
|
let DispenserAddress: string
|
||||||
let DispenserClass: Dispenser
|
let DispenserClass: Dispenser
|
||||||
let nftFactory: NftFactory
|
let nftFactory: NftFactory
|
||||||
@ -37,8 +37,7 @@ describe('Dispenser flow', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contracts = new TestContractHandler(web3)
|
contracts = await deployContracts(factoryOwner)
|
||||||
await contracts.deployContracts(factoryOwner)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should initialize Dispenser class', async () => {
|
it('should initialize Dispenser class', async () => {
|
||||||
|
@ -4,7 +4,8 @@ import { Contract } from 'web3-eth-contract'
|
|||||||
import BN from 'bn.js'
|
import BN from 'bn.js'
|
||||||
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
||||||
import FixedRate from '@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json'
|
import FixedRate from '@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json'
|
||||||
import { TestContractHandler } from '../../../TestContractHandler'
|
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
|
||||||
|
import { deployContracts, Addresses } from '../../../TestContractHandler'
|
||||||
import { web3 } from '../../../config'
|
import { web3 } from '../../../config'
|
||||||
import { NftFactory, NftCreateData, FixedRateExchange } from '../../../../src'
|
import { NftFactory, NftCreateData, FixedRateExchange } from '../../../../src'
|
||||||
import { FreCreationParams, Erc20CreateParams } from '../../../../src/@types'
|
import { FreCreationParams, Erc20CreateParams } from '../../../../src/@types'
|
||||||
@ -22,7 +23,7 @@ describe('Fixed Rate unit test', () => {
|
|||||||
let daiAddress: string
|
let daiAddress: string
|
||||||
let usdcAddress: string
|
let usdcAddress: string
|
||||||
let exchangeId: string
|
let exchangeId: string
|
||||||
let contracts: TestContractHandler
|
let contracts: Addresses
|
||||||
let fixedRate: FixedRateExchange
|
let fixedRate: FixedRateExchange
|
||||||
let dtAddress: string
|
let dtAddress: string
|
||||||
let dtAddress2: string
|
let dtAddress2: string
|
||||||
@ -44,19 +45,15 @@ describe('Fixed Rate unit test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contracts = new TestContractHandler(web3)
|
contracts = await deployContracts(factoryOwner)
|
||||||
await contracts.deployContracts(factoryOwner)
|
|
||||||
|
|
||||||
// initialize fixed rate
|
// initialize fixed rate
|
||||||
//
|
//
|
||||||
|
|
||||||
daiContract = new web3.eth.Contract(
|
daiContract = new web3.eth.Contract(MockERC20.abi as AbiItem[], contracts.daiAddress)
|
||||||
contracts.MockERC20.options.jsonInterface,
|
|
||||||
contracts.daiAddress
|
|
||||||
)
|
|
||||||
|
|
||||||
usdcContract = new web3.eth.Contract(
|
usdcContract = new web3.eth.Contract(
|
||||||
contracts.MockERC20.options.jsonInterface,
|
MockERC20.abi as AbiItem[],
|
||||||
contracts.usdcAddress
|
contracts.usdcAddress
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -4,7 +4,8 @@ import { Contract } from 'web3-eth-contract'
|
|||||||
import SSContract from '@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json'
|
import SSContract from '@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json'
|
||||||
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.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 { TestContractHandler } from '../../../TestContractHandler'
|
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
|
||||||
|
import { deployContracts, Addresses } from '../../../TestContractHandler'
|
||||||
import { web3 } from '../../../config'
|
import { web3 } from '../../../config'
|
||||||
import {
|
import {
|
||||||
allowance,
|
allowance,
|
||||||
@ -32,7 +33,7 @@ describe('SideStaking unit test', () => {
|
|||||||
let user3: string
|
let user3: string
|
||||||
let initialBlock: number
|
let initialBlock: number
|
||||||
let sideStakingAddress: string
|
let sideStakingAddress: string
|
||||||
let contracts: TestContractHandler
|
let contracts: Addresses
|
||||||
let pool: Pool
|
let pool: Pool
|
||||||
let sideStaking: SideStaking
|
let sideStaking: SideStaking
|
||||||
let dtAddress: string
|
let dtAddress: string
|
||||||
@ -54,9 +55,8 @@ describe('SideStaking unit test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contracts = new TestContractHandler(web3)
|
|
||||||
sideStakingAddress = contracts.sideStakingAddress
|
sideStakingAddress = contracts.sideStakingAddress
|
||||||
await contracts.deployContracts(factoryOwner)
|
contracts = await deployContracts(factoryOwner)
|
||||||
|
|
||||||
// initialize Pool instance
|
// initialize Pool instance
|
||||||
pool = new Pool(web3, PoolTemplate.abi as AbiItem[])
|
pool = new Pool(web3, PoolTemplate.abi as AbiItem[])
|
||||||
@ -65,13 +65,10 @@ describe('SideStaking unit test', () => {
|
|||||||
sideStaking = new SideStaking(web3, SSContract.abi as AbiItem[])
|
sideStaking = new SideStaking(web3, SSContract.abi as AbiItem[])
|
||||||
assert(sideStaking != null)
|
assert(sideStaking != null)
|
||||||
|
|
||||||
daiContract = new web3.eth.Contract(
|
daiContract = new web3.eth.Contract(MockERC20.abi as AbiItem[], contracts.daiAddress)
|
||||||
contracts.MockERC20.options.jsonInterface,
|
|
||||||
contracts.daiAddress
|
|
||||||
)
|
|
||||||
|
|
||||||
usdcContract = new web3.eth.Contract(
|
usdcContract = new web3.eth.Contract(
|
||||||
contracts.MockERC20.options.jsonInterface,
|
MockERC20.abi as AbiItem[],
|
||||||
contracts.usdcAddress
|
contracts.usdcAddress
|
||||||
)
|
)
|
||||||
await approve(
|
await approve(
|
||||||
|
@ -3,7 +3,8 @@ import ERC20TemplateEnterprise from '@oceanprotocol/contracts/artifacts/contract
|
|||||||
import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.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 ERC721Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json'
|
||||||
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
||||||
import { TestContractHandler } from '../../TestContractHandler'
|
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
|
||||||
|
import { deployContracts, Addresses } from '../../TestContractHandler'
|
||||||
import { AbiItem } from 'web3-utils'
|
import { AbiItem } from 'web3-utils'
|
||||||
import { web3 } from '../../config'
|
import { web3 } from '../../config'
|
||||||
import {
|
import {
|
||||||
@ -23,7 +24,7 @@ describe('Datatoken', () => {
|
|||||||
let user1: string
|
let user1: string
|
||||||
let user2: string
|
let user2: string
|
||||||
let user3: string
|
let user3: string
|
||||||
let contractHandler: TestContractHandler
|
let contracts: Addresses
|
||||||
let nftDatatoken: Nft
|
let nftDatatoken: Nft
|
||||||
let datatoken: Datatoken
|
let datatoken: Datatoken
|
||||||
let nftFactory: NftFactory
|
let nftFactory: NftFactory
|
||||||
@ -44,21 +45,20 @@ describe('Datatoken', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contractHandler = new TestContractHandler(web3)
|
contracts = await deployContracts(nftOwner)
|
||||||
await contractHandler.deployContracts(nftOwner)
|
|
||||||
|
|
||||||
const daiContract = new web3.eth.Contract(
|
const daiContract = new web3.eth.Contract(
|
||||||
contractHandler.MockERC20.options.jsonInterface,
|
MockERC20.abi as AbiItem[],
|
||||||
contractHandler.daiAddress
|
contracts.daiAddress
|
||||||
)
|
)
|
||||||
await daiContract.methods
|
await daiContract.methods
|
||||||
.approve(contractHandler.factory721Address, web3.utils.toWei('10000'))
|
.approve(contracts.factory721Address, web3.utils.toWei('10000'))
|
||||||
.send({ from: nftOwner })
|
.send({ from: nftOwner })
|
||||||
})
|
})
|
||||||
|
|
||||||
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,
|
contracts.factory721Address,
|
||||||
web3,
|
web3,
|
||||||
ERC721Factory.abi as AbiItem[]
|
ERC721Factory.abi as AbiItem[]
|
||||||
)
|
)
|
||||||
@ -139,8 +139,8 @@ 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 = {
|
const freParams: FreCreationParams = {
|
||||||
fixedRateAddress: contractHandler.fixedRateAddress,
|
fixedRateAddress: contracts.fixedRateAddress,
|
||||||
baseTokenAddress: contractHandler.daiAddress,
|
baseTokenAddress: contracts.daiAddress,
|
||||||
owner: nftOwner,
|
owner: nftOwner,
|
||||||
marketFeeCollector: nftOwner,
|
marketFeeCollector: nftOwner,
|
||||||
baseTokenDecimals: 18,
|
baseTokenDecimals: 18,
|
||||||
@ -157,8 +157,8 @@ 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 = {
|
const freParams: FreCreationParams = {
|
||||||
fixedRateAddress: contractHandler.fixedRateAddress,
|
fixedRateAddress: contracts.fixedRateAddress,
|
||||||
baseTokenAddress: contractHandler.daiAddress,
|
baseTokenAddress: contracts.daiAddress,
|
||||||
owner: nftOwner,
|
owner: nftOwner,
|
||||||
marketFeeCollector: nftOwner,
|
marketFeeCollector: nftOwner,
|
||||||
baseTokenDecimals: 18,
|
baseTokenDecimals: 18,
|
||||||
@ -182,7 +182,7 @@ describe('Datatoken', () => {
|
|||||||
const dispenser = await datatoken.createDispenser(
|
const dispenser = await datatoken.createDispenser(
|
||||||
datatokenAddress,
|
datatokenAddress,
|
||||||
nftOwner,
|
nftOwner,
|
||||||
contractHandler.dispenserAddress,
|
contracts.dispenserAddress,
|
||||||
dispenserParams
|
dispenserParams
|
||||||
)
|
)
|
||||||
assert(dispenser !== null)
|
assert(dispenser !== null)
|
||||||
@ -198,7 +198,7 @@ describe('Datatoken', () => {
|
|||||||
await datatoken.createDispenser(
|
await datatoken.createDispenser(
|
||||||
datatokenAddress,
|
datatokenAddress,
|
||||||
user2,
|
user2,
|
||||||
contractHandler.dispenserAddress,
|
contracts.dispenserAddress,
|
||||||
dispenserParams
|
dispenserParams
|
||||||
)
|
)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -403,7 +403,7 @@ describe('Datatoken', () => {
|
|||||||
datatokenAddress,
|
datatokenAddress,
|
||||||
nftOwner,
|
nftOwner,
|
||||||
order,
|
order,
|
||||||
contractHandler.dispenserAddress
|
contracts.dispenserAddress
|
||||||
)
|
)
|
||||||
assert(buyFromDispenseTx !== null)
|
assert(buyFromDispenseTx !== null)
|
||||||
})
|
})
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { assert } from 'chai'
|
import { assert } from 'chai'
|
||||||
import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.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 ERC721Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json'
|
||||||
import { TestContractHandler } from '../../TestContractHandler'
|
import { deployContracts, Addresses } from '../../TestContractHandler'
|
||||||
import { AbiItem } from 'web3-utils'
|
import { AbiItem } from 'web3-utils'
|
||||||
import sha256 from 'crypto-js/sha256'
|
import sha256 from 'crypto-js/sha256'
|
||||||
import { web3 } from '../../config'
|
import { web3 } from '../../config'
|
||||||
@ -13,7 +13,7 @@ describe('NFT', () => {
|
|||||||
let user1: string
|
let user1: string
|
||||||
let user2: string
|
let user2: string
|
||||||
let user3: string
|
let user3: string
|
||||||
let contractHandler: TestContractHandler
|
let contracts: Addresses
|
||||||
let nftDatatoken: Nft
|
let nftDatatoken: Nft
|
||||||
let nftFactory: NftFactory
|
let nftFactory: NftFactory
|
||||||
let nftAddress: string
|
let nftAddress: string
|
||||||
@ -32,13 +32,12 @@ describe('NFT', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contractHandler = new TestContractHandler(web3)
|
contracts = await deployContracts(nftOwner)
|
||||||
await contractHandler.deployContracts(nftOwner)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
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,
|
contracts.factory721Address,
|
||||||
web3,
|
web3,
|
||||||
ERC721Factory.abi as AbiItem[]
|
ERC721Factory.abi as AbiItem[]
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user