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

Merge branch 'v4main' into issue-1347-rewrite-nft-test

This commit is contained in:
Miquel A. Cabot 2022-04-12 09:48:14 +02:00
commit 4b96497089
9 changed files with 1518 additions and 2686 deletions

3891
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -54,7 +54,7 @@
}, },
"homepage": "https://github.com/oceanprotocol/ocean.js#readme", "homepage": "https://github.com/oceanprotocol/ocean.js#readme",
"peerDependencies": { "peerDependencies": {
"web3": "^1.7.1" "web3": "^1.7.3"
}, },
"dependencies": { "dependencies": {
"@oceanprotocol/contracts": "1.0.0-alpha.28", "@oceanprotocol/contracts": "1.0.0-alpha.28",
@ -62,12 +62,12 @@
"cross-fetch": "^3.1.5", "cross-fetch": "^3.1.5",
"crypto-js": "^4.1.1", "crypto-js": "^4.1.1",
"decimal.js": "^10.3.1", "decimal.js": "^10.3.1",
"web3": "^1.7.1", "web3": "^1.7.3",
"web3-core": "^1.7.1", "web3-core": "^1.7.1",
"web3-eth-contract": "^1.7.1" "web3-eth-contract": "^1.7.1"
}, },
"devDependencies": { "devDependencies": {
"@truffle/hdwallet-provider": "^2.0.4", "@truffle/hdwallet-provider": "^2.0.5",
"@types/chai": "^4.2.19", "@types/chai": "^4.2.19",
"@types/chai-spies": "^1.0.3", "@types/chai-spies": "^1.0.3",
"@types/crypto-js": "^4.1.1", "@types/crypto-js": "^4.1.1",
@ -90,12 +90,12 @@
"mock-local-storage": "^1.1.21", "mock-local-storage": "^1.1.21",
"nyc": "^15.1.0", "nyc": "^15.1.0",
"ora": "5.4.1", "ora": "5.4.1",
"prettier": "^2.6.1", "prettier": "^2.6.2",
"release-it": "^14.14.0", "release-it": "^14.14.2",
"source-map-support": "^0.5.19", "source-map-support": "^0.5.19",
"ts-node": "^10.7.0", "ts-node": "^10.7.0",
"ts-node-register": "^1.0.0", "ts-node-register": "^1.0.0",
"typedoc": "0.22.13", "typedoc": "0.22.15",
"typescript": "^4.6.3" "typescript": "^4.6.3"
}, },
"nyc": { "nyc": {

View File

@ -11,7 +11,8 @@ import {
getErcCreationParams, getErcCreationParams,
getPoolCreationParams, getPoolCreationParams,
configHelperNetworks, configHelperNetworks,
setContractDefaults setContractDefaults,
ZERO_ADDRESS
} from '../utils' } from '../utils'
import { Config } from '../models/index.js' import { Config } from '../models/index.js'
import { import {
@ -45,7 +46,6 @@ export interface NftCreateData {
owner: string owner: string
} }
const addressZERO = '0x0000000000000000000000000000000000000000'
/** /**
* Provides an interface for NFT Factory contract * Provides an interface for NFT Factory contract
*/ */
@ -94,8 +94,8 @@ export class NftFactory {
nftData.name, nftData.name,
nftData.symbol, nftData.symbol,
nftData.templateIndex, nftData.templateIndex,
addressZERO, ZERO_ADDRESS,
addressZERO, ZERO_ADDRESS,
nftData.tokenURI, nftData.tokenURI,
nftData.transferable, nftData.transferable,
nftData.owner nftData.owner
@ -139,8 +139,8 @@ export class NftFactory {
nftData.name, nftData.name,
nftData.symbol, nftData.symbol,
nftData.templateIndex, nftData.templateIndex,
addressZERO, ZERO_ADDRESS,
addressZERO, ZERO_ADDRESS,
nftData.tokenURI, nftData.tokenURI,
nftData.transferable, nftData.transferable,
nftData.owner nftData.owner
@ -278,7 +278,7 @@ export class NftFactory {
if ((await this.getOwner()) !== address) { if ((await this.getOwner()) !== address) {
throw new Error(`Caller is not Factory Owner`) throw new Error(`Caller is not Factory Owner`)
} }
if (templateAddress === addressZERO) { if (templateAddress === ZERO_ADDRESS) {
throw new Error(`Template cannot be ZERO address`) throw new Error(`Template cannot be ZERO address`)
} }
@ -445,7 +445,7 @@ export class NftFactory {
if ((await this.getOwner()) !== address) { if ((await this.getOwner()) !== address) {
throw new Error(`Caller is not Factory Owner`) throw new Error(`Caller is not Factory Owner`)
} }
if (templateAddress === addressZERO) { if (templateAddress === ZERO_ADDRESS) {
throw new Error(`Template cannot be address ZERO`) throw new Error(`Template cannot be address ZERO`)
} }

View File

@ -9,7 +9,8 @@ import {
configHelperNetworks, configHelperNetworks,
setContractDefaults, setContractDefaults,
amountToUnits, amountToUnits,
unitsToAmount unitsToAmount,
ZERO_ADDRESS
} from '../../utils' } from '../../utils'
import { Config } from '../../models/index.js' import { Config } from '../../models/index.js'
import { PriceAndFees } from '../..' import { PriceAndFees } from '../..'
@ -164,7 +165,7 @@ export class FixedRateExchange {
exchangeId: string, exchangeId: string,
datatokenAmount: string, datatokenAmount: string,
maxBaseTokenAmount: string, maxBaseTokenAmount: string,
consumeMarketAddress: string = '0x0000000000000000000000000000000000000000', consumeMarketAddress: string = ZERO_ADDRESS,
consumeMarketFee: string = '0' consumeMarketFee: string = '0'
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
const exchange = await this.getExchange(exchangeId) const exchange = await this.getExchange(exchangeId)
@ -260,7 +261,7 @@ export class FixedRateExchange {
exchangeId: string, exchangeId: string,
datatokenAmount: string, datatokenAmount: string,
minBaseTokenAmount: string, minBaseTokenAmount: string,
consumeMarketAddress: string = '0x0000000000000000000000000000000000000000', consumeMarketAddress: string = ZERO_ADDRESS,
consumeMarketFee: string = '0' consumeMarketFee: string = '0'
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
const exchange = await this.getExchange(exchangeId) const exchange = await this.getExchange(exchangeId)

View File

@ -1,3 +1,5 @@
export * from './balancer' export * from './balancer'
export * from './dispenser' export * from './dispenser'
export * from './fixedRate' export * from './fixedRate'
export * from './ssContracts'
export * from './Router'

View File

@ -10,7 +10,8 @@ import {
getFairGasPrice, getFairGasPrice,
setContractDefaults, setContractDefaults,
configHelperNetworks, configHelperNetworks,
getFreOrderParams getFreOrderParams,
ZERO_ADDRESS
} from '../utils' } from '../utils'
import { import {
ConsumeMarketFee, ConsumeMarketFee,
@ -206,8 +207,7 @@ export class Datatoken {
const gasLimitDefault = this.GASLIMIT_DEFAULT const gasLimitDefault = this.GASLIMIT_DEFAULT
if (!fixedRateParams.allowedConsumer) if (!fixedRateParams.allowedConsumer) fixedRateParams.allowedConsumer = ZERO_ADDRESS
fixedRateParams.allowedConsumer = '0x0000000000000000000000000000000000000000'
const withMint = fixedRateParams.withMint ? 1 : 0 const withMint = fixedRateParams.withMint ? 1 : 0
let estGas let estGas
@ -257,8 +257,7 @@ export class Datatoken {
if (!(await this.isERC20Deployer(dtAddress, address))) { if (!(await this.isERC20Deployer(dtAddress, address))) {
throw new Error(`User is not ERC20 Deployer`) throw new Error(`User is not ERC20 Deployer`)
} }
if (!fixedRateParams.allowedConsumer) if (!fixedRateParams.allowedConsumer) fixedRateParams.allowedConsumer = ZERO_ADDRESS
fixedRateParams.allowedConsumer = '0x0000000000000000000000000000000000000000'
const withMint = fixedRateParams.withMint ? 1 : 0 const withMint = fixedRateParams.withMint ? 1 : 0
@ -320,8 +319,7 @@ export class Datatoken {
this.config this.config
) )
if (!dispenserParams.allowedSwapper) if (!dispenserParams.allowedSwapper) dispenserParams.allowedSwapper = ZERO_ADDRESS
dispenserParams.allowedSwapper = '0x0000000000000000000000000000000000000000'
if (!dispenserParams.withMint) dispenserParams.withMint = false if (!dispenserParams.withMint) dispenserParams.withMint = false
@ -367,8 +365,7 @@ export class Datatoken {
this.config this.config
) )
if (!dispenserParams.allowedSwapper) if (!dispenserParams.allowedSwapper) dispenserParams.allowedSwapper = ZERO_ADDRESS
dispenserParams.allowedSwapper = '0x0000000000000000000000000000000000000000'
if (!dispenserParams.withMint) dispenserParams.withMint = false if (!dispenserParams.withMint) dispenserParams.withMint = false
@ -975,8 +972,8 @@ export class Datatoken {
) )
if (!consumeMarketFee) { if (!consumeMarketFee) {
consumeMarketFee = { consumeMarketFee = {
consumeMarketFeeAddress: '0x0000000000000000000000000000000000000000', consumeMarketFeeAddress: ZERO_ADDRESS,
consumeMarketFeeToken: '0x0000000000000000000000000000000000000000', consumeMarketFeeToken: ZERO_ADDRESS,
consumeMarketFeeAmount: '0' consumeMarketFeeAmount: '0'
} }
} }

View File

@ -11,6 +11,7 @@ import {
import { Config } from '../models' import { Config } from '../models'
import { minAbi } from './minAbi' import { minAbi } from './minAbi'
import LoggerInstance from './Logger' import LoggerInstance from './Logger'
import { ZERO_ADDRESS } from './Constants'
export function setContractDefaults(contract: Contract, config: Config): Contract { export function setContractDefaults(contract: Contract, config: Config): Contract {
if (config) { if (config) {
@ -65,8 +66,7 @@ export function getFreOrderParams(freParams: FreOrderParams): any {
} }
export function getFreCreationParams(freParams: FreCreationParams): any { export function getFreCreationParams(freParams: FreCreationParams): any {
if (!freParams.allowedConsumer) if (!freParams.allowedConsumer) freParams.allowedConsumer = ZERO_ADDRESS
freParams.allowedConsumer = '0x0000000000000000000000000000000000000000'
const withMint = freParams.withMint ? 1 : 0 const withMint = freParams.withMint ? 1 : 0
return { return {

View File

@ -1,11 +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 { deployContracts, Addresses } from '../../TestContractHandler' import { deployContracts, Addresses } from '../../TestContractHandler'
import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.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 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, balance, approve, ZERO_ADDRESS } from '../../../src'
import { Router } from '../../../src/pools/Router' import { Router } from '../../../src/pools/Router'
import { Erc20CreateParams, PoolCreationParams, Operation } from '../../../src/@types' import { Erc20CreateParams, PoolCreationParams, Operation } from '../../../src/@types'
@ -13,35 +11,74 @@ const { keccak256 } = require('@ethersproject/keccak256')
describe('Router unit test', () => { describe('Router unit test', () => {
let factoryOwner: string let factoryOwner: string
let nftOwner: string
let user1: string let user1: string
let user2: string let user2: string
let user3: string
let contracts: Addresses let contracts: Addresses
let router: Router let router: Router
let dtAddress: string
let dtAddress2: string const NFT_NAME = '72120Bundle'
let nftAddress: string const NFT_SYMBOL = '72Bundle'
const NFT_TOKEN_URI = 'https://oceanprotocol.com/nft/'
const ERC20_NAME = 'ERC20B1'
const ERC20_SYMBOL = 'ERC20DT1Symbol'
const RATE = '1'
const FEE = '0.001'
const FEE_ZERO = '0'
const DAI_AMOUNT = '2' // 2 DAI
const CAP_AMOUNT = '1000000'
const VESTING_AMOUNT = '10000'
const TOKEN_DECIMALS = 18
const VESTED_BLOCKS = 2500000
const BASE_TOKEN_LIQUIDITY = '2000'
const EXCHANGE_IDS = keccak256('0x00')
const AMOUNTS_IN = web3.utils.toWei('1')
const AMOUNTS_OUT = web3.utils.toWei('0.1')
const MAX_PRICE = web3.utils.toWei('10')
const SWAP_MARKET_FEE = web3.utils.toWei('0.1')
const NFT_DATA: NftCreateData = {
name: NFT_NAME,
symbol: NFT_SYMBOL,
templateIndex: 1,
tokenURI: NFT_TOKEN_URI,
transferable: true,
owner: factoryOwner
}
const ERC_PARAMS: Erc20CreateParams = {
templateIndex: 1,
minter: factoryOwner,
paymentCollector: user2,
mpFeeAddress: factoryOwner,
feeToken: ZERO_ADDRESS,
cap: CAP_AMOUNT,
feeAmount: FEE_ZERO,
name: ERC20_NAME,
symbol: ERC20_SYMBOL
}
before(async () => { before(async () => {
const accounts = await web3.eth.getAccounts() const accounts = await web3.eth.getAccounts()
factoryOwner = accounts[0] factoryOwner = accounts[0]
nftOwner = accounts[1] user1 = accounts[1]
user1 = accounts[2] user2 = accounts[2]
user2 = accounts[3]
user3 = accounts[4] NFT_DATA.owner = factoryOwner
ERC_PARAMS.minter = factoryOwner
ERC_PARAMS.paymentCollector = user2
ERC_PARAMS.mpFeeAddress = factoryOwner
}) })
it('should deploy contracts', async () => { it('should deploy contracts', async () => {
contracts = await deployContracts(web3, factoryOwner) contracts = await deployContracts(web3, factoryOwner)
const daiContract = new web3.eth.Contract( await approve(
MockERC20.abi as AbiItem[], web3,
contracts.daiAddress factoryOwner,
contracts.daiAddress,
contracts.erc721FactoryAddress,
web3.utils.toWei('10000')
) )
await daiContract.methods
.approve(contracts.erc721FactoryAddress, web3.utils.toWei('10000'))
.send({ from: factoryOwner })
}) })
it('should initiate Router instance', async () => { it('should initiate Router instance', async () => {
@ -62,14 +99,17 @@ describe('Router unit test', () => {
expect(await router.isApprovedToken(contracts.oceanAddress)).to.equal(true) expect(await router.isApprovedToken(contracts.oceanAddress)).to.equal(true)
expect(await router.isApprovedToken(contracts.daiAddress)).to.equal(false) expect(await router.isApprovedToken(contracts.daiAddress)).to.equal(false)
}) })
it('#isSideStaking - should return true if in ssContracts list', async () => { it('#isSideStaking - should return true if in ssContracts list', async () => {
expect(await router.isSideStaking(contracts.sideStakingAddress)).to.equal(true) expect(await router.isSideStaking(contracts.sideStakingAddress)).to.equal(true)
expect(await router.isSideStaking(contracts.fixedRateAddress)).to.equal(false) expect(await router.isSideStaking(contracts.fixedRateAddress)).to.equal(false)
}) })
it('#isFixedPrice - should return true if in fixedPrice list', async () => { it('#isFixedPrice - should return true if in fixedPrice list', async () => {
expect(await router.isFixedPrice(contracts.fixedRateAddress)).to.equal(true) expect(await router.isFixedPrice(contracts.fixedRateAddress)).to.equal(true)
expect(await router.isFixedPrice(contracts.daiAddress)).to.equal(false) expect(await router.isFixedPrice(contracts.daiAddress)).to.equal(false)
}) })
it('#isPoolTemplate - should return true if in poolTemplates list', async () => { it('#isPoolTemplate - should return true if in poolTemplates list', async () => {
expect(await router.isPoolTemplate(contracts.poolTemplateAddress)).to.equal(true) expect(await router.isPoolTemplate(contracts.poolTemplateAddress)).to.equal(true)
expect(await router.isPoolTemplate(contracts.fixedRateAddress)).to.equal(false) expect(await router.isPoolTemplate(contracts.fixedRateAddress)).to.equal(false)
@ -83,35 +123,12 @@ describe('Router unit test', () => {
) )
await daiContract.methods await daiContract.methods
.transfer(user2, web3.utils.toWei('2')) .transfer(user1, web3.utils.toWei(DAI_AMOUNT))
.send({ from: factoryOwner }) .send({ from: factoryOwner })
await daiContract.methods
.approve(contracts.routerAddress, web3.utils.toWei('2')) await approve(web3, user1, contracts.daiAddress, contracts.routerAddress, DAI_AMOUNT)
.send({ from: user2 })
// CREATE A FIRST POOL // CREATE A FIRST POOL
// we prepare transaction parameters objects
const nftData: NftCreateData = {
name: '72120Bundle',
symbol: '72Bundle',
templateIndex: 1,
tokenURI: 'https://oceanprotocol.com/nft/',
transferable: true,
owner: factoryOwner
}
const ercParams: Erc20CreateParams = {
templateIndex: 1,
minter: factoryOwner,
paymentCollector: user3,
mpFeeAddress: factoryOwner,
feeToken: '0x0000000000000000000000000000000000000000',
cap: '1000000',
feeAmount: '0',
name: 'ERC20B1',
symbol: 'ERC20DT1Symbol'
}
const poolParams: PoolCreationParams = { const poolParams: PoolCreationParams = {
ssContract: contracts.sideStakingAddress, ssContract: contracts.sideStakingAddress,
baseTokenAddress: contracts.daiAddress, baseTokenAddress: contracts.daiAddress,
@ -119,93 +136,41 @@ describe('Router unit test', () => {
publisherAddress: factoryOwner, publisherAddress: factoryOwner,
marketFeeCollector: factoryOwner, marketFeeCollector: factoryOwner,
poolTemplateAddress: contracts.poolTemplateAddress, poolTemplateAddress: contracts.poolTemplateAddress,
rate: '1', rate: RATE,
baseTokenDecimals: 18, baseTokenDecimals: TOKEN_DECIMALS,
vestingAmount: '10000', vestingAmount: VESTING_AMOUNT,
vestedBlocks: 2500000, vestedBlocks: VESTED_BLOCKS,
initialBaseTokenLiquidity: '2000', initialBaseTokenLiquidity: BASE_TOKEN_LIQUIDITY,
swapFeeLiquidityProvider: '0.001', swapFeeLiquidityProvider: FEE,
swapFeeMarketRunner: '0.001' swapFeeMarketRunner: FEE
} }
const nftFactory = new NftFactory( const nftFactory = new NftFactory(contracts.erc721FactoryAddress, web3)
contracts.erc721FactoryAddress,
web3,
ERC721Factory.abi as AbiItem[]
)
const txReceipt = await nftFactory.createNftErc20WithPool( const txReceipt = await nftFactory.createNftErc20WithPool(
factoryOwner, factoryOwner,
nftData, NFT_DATA,
ercParams, ERC_PARAMS,
poolParams poolParams
) )
const erc20Token = txReceipt.events.TokenCreated.returnValues.newTokenAddress const erc20TokenAddress = txReceipt.events.TokenCreated.returnValues.newTokenAddress
const pool1 = txReceipt.events.NewPool.returnValues.poolAddress const pool1 = txReceipt.events.NewPool.returnValues.poolAddress
// CREATE A SECOND POOL // CREATE A SECOND POOL
const nftData2: NftCreateData = {
name: '72120Bundle2',
symbol: '72Bundle2',
templateIndex: 1,
tokenURI: 'https://oceanprotocol.com/nft2/',
transferable: true,
owner: factoryOwner
}
const ercParams2: Erc20CreateParams = {
templateIndex: 1,
minter: factoryOwner,
paymentCollector: user3,
mpFeeAddress: factoryOwner,
feeToken: '0x0000000000000000000000000000000000000000',
cap: '1000000',
feeAmount: '0',
name: 'ERC20B12',
symbol: 'ERC20DT1Symbol2'
}
const poolParams2: PoolCreationParams = {
ssContract: contracts.sideStakingAddress,
baseTokenAddress: contracts.daiAddress,
baseTokenSender: contracts.erc721FactoryAddress,
publisherAddress: factoryOwner,
marketFeeCollector: factoryOwner,
poolTemplateAddress: contracts.poolTemplateAddress,
rate: '1',
baseTokenDecimals: 18,
vestingAmount: '10000',
vestedBlocks: 2500000,
initialBaseTokenLiquidity: '2000',
swapFeeLiquidityProvider: '0.001',
swapFeeMarketRunner: '0.001'
}
const txReceipt2 = await nftFactory.createNftErc20WithPool( const txReceipt2 = await nftFactory.createNftErc20WithPool(
factoryOwner, factoryOwner,
nftData2, NFT_DATA,
ercParams2, ERC_PARAMS,
poolParams2 poolParams
) )
const erc20Token2 = txReceipt2.events.TokenCreated.returnValues.newTokenAddress const erc20Token2Address = txReceipt2.events.TokenCreated.returnValues.newTokenAddress
const pool2 = txReceipt2.events.NewPool.returnValues.poolAddress const pool2 = txReceipt2.events.NewPool.returnValues.poolAddress
const erc20Contract = new web3.eth.Contract( // user1 has no dt1
ERC20Template.abi as AbiItem[], expect(await balance(web3, erc20TokenAddress, user1)).to.equal('0')
erc20Token // user1 has no dt2
) expect(await balance(web3, erc20Token2Address, user1)).to.equal('0')
// user2 has no dt1
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal('0')
const erc20Contract2 = new web3.eth.Contract(
ERC20Template.abi as AbiItem[],
erc20Token2
)
// user2 has no dt2
expect(await erc20Contract2.methods.balanceOf(user2).call()).to.equal('0')
// we now can prepare the Operations objects // we now can prepare the Operations objects
@ -214,35 +179,35 @@ describe('Router unit test', () => {
// 2 - FixedRateExchange // 2 - FixedRateExchange
// 3 - Dispenser // 3 - Dispenser
const operations1: Operation = { const operations1: Operation = {
exchangeIds: keccak256('0x00'), // used only for FixedRate or Dispenser, but needs to be filled even for pool exchangeIds: EXCHANGE_IDS, // used only for FixedRate or Dispenser, but needs to be filled even for pool
source: pool1, // pool Address source: pool1, // pool Address
operation: 0, // swapExactAmountIn operation: 0, // swapExactAmountIn
tokenIn: contracts.daiAddress, tokenIn: contracts.daiAddress,
amountsIn: web3.utils.toWei('1'), // when swapExactAmountIn is EXACT amount IN amountsIn: AMOUNTS_IN, // when swapExactAmountIn is EXACT amount IN
tokenOut: erc20Token, tokenOut: erc20TokenAddress,
amountsOut: web3.utils.toWei('0.1'), // when swapExactAmountIn is MIN amount OUT amountsOut: AMOUNTS_OUT, // when swapExactAmountIn is MIN amount OUT
maxPrice: web3.utils.toWei('10'), // max price (only for pools), maxPrice: MAX_PRICE, // max price (only for pools),
swapMarketFee: web3.utils.toWei('0.1'), swapMarketFee: SWAP_MARKET_FEE,
marketFeeAddress: factoryOwner marketFeeAddress: factoryOwner
} }
const operations2: Operation = { const operations2: Operation = {
exchangeIds: keccak256('0x00'), // used only for FixedRate or Dispenser, but needs to be filled even for pool exchangeIds: EXCHANGE_IDS, // used only for FixedRate or Dispenser, but needs to be filled even for pool
source: pool2, // pool Address source: pool2, // pool Address
operation: 0, // swapExactAmountIn operation: 0, // swapExactAmountIn
tokenIn: contracts.daiAddress, tokenIn: contracts.daiAddress,
amountsIn: web3.utils.toWei('1'), // when swapExactAmountIn is EXACT amount IN amountsIn: AMOUNTS_IN, // when swapExactAmountIn is EXACT amount IN
tokenOut: erc20Token2, tokenOut: erc20Token2Address,
amountsOut: web3.utils.toWei('0.1'), // when swapExactAmountIn is MIN amount OUT amountsOut: AMOUNTS_OUT, // when swapExactAmountIn is MIN amount OUT
maxPrice: web3.utils.toWei('10'), // max price (only for pools) maxPrice: MAX_PRICE, // max price (only for pools),
swapMarketFee: web3.utils.toWei('0.1'), swapMarketFee: SWAP_MARKET_FEE,
marketFeeAddress: factoryOwner marketFeeAddress: factoryOwner
} }
await router.buyDTBatch(user2, [operations1, operations2]) await router.buyDTBatch(user1, [operations1, operations2])
// user2 got his dts // user1 got his dts
expect(parseInt(await erc20Contract.methods.balanceOf(user2).call())).gt(0) expect(+(await balance(web3, erc20TokenAddress, user1))).gt(0)
expect(parseInt(await erc20Contract2.methods.balanceOf(user2).call())).gt(0) expect(+(await balance(web3, erc20Token2Address, user1))).gt(0)
}) })
}) })

View File

@ -85,7 +85,7 @@ describe('Pool unit test', () => {
contracts.erc721FactoryAddress contracts.erc721FactoryAddress
) )
assert(parseInt(allowCheck) >= 8000) assert(parseInt(allowCheck) >= 2000)
allowCheck = await allowance( allowCheck = await allowance(
web3, web3,
contracts.usdcAddress, contracts.usdcAddress,