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

fixeded unit tests

This commit is contained in:
Bogdan Fazakas 2021-12-07 20:12:44 +02:00
parent 7092803c55
commit 35c59f0b7b
5 changed files with 77 additions and 23 deletions

View File

@ -0,0 +1,59 @@
export interface Operation {
/**
* used only for FixedRate or Dispenser, but needs to be filled even for pool
* @type {string}
*/
exchangeIds: string
/**
* pool Address
* @type {string}
*/
source: string
/**
* operation:
* 0 - swapExactAmountIn
* 1 - swapExactAmountOut
* 2 - FixedRateExchange
* 3 - Dispenser
* @type {number}
*/
operation: number
/**
* token in address
* @type {string}
*/
tokenIn: string
/**
* when swapExactAmountIn is EXACT amount IN
* expressed in Wei
* @type {string | number}
*/
amountsIn: string | number
/**
* token out address
* @type {string}
*/
tokenOut: string
/**
* when swapExactAmountIn is MIN amount OUT
* expressed in Wei
* @type {string | number}
*/
amountsOut: string | number
/**
* max price (only for pools)
* expressed in Wei
* @type {string | number}
*/
maxPrice: string | number
/**
* swap fee amount
* @type {string}
*/
swapMarketFee: string
/**
* market fee address to receive fees
* @type {string}
*/
marketFeeAddress: string
}

View File

@ -2,3 +2,4 @@ export * from './FixedRateInterface'
export * from './PoolInterface'
export * from './Erc20Interface'
export * from './DispenserInterface'
export * from './RouterInterface'

View File

@ -3,18 +3,8 @@ import Web3 from 'web3'
import { TransactionReceipt } from 'web3-core'
import { AbiItem } from 'web3-utils'
import defaultRouter from '@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json'
import { LoggerInstance, getFairGasPrice } from '../utils'
interface Operations {
exchangeIds: string
source: string
operation: number
tokenIn: string
amountsIn: string | number
tokenOut: string
amountsOut: string | number
maxPrice: string | number
}
import { getFairGasPrice } from '../utils'
import { Operation } from '../interfaces/RouterInterface'
/**
* Provides an interface for FactoryRouter contract
@ -49,10 +39,10 @@ export class Router {
/**
* Estimate gas cost for buyDTBatch method
* @param {String} address
* @param {Operations} operations Operations objects array
* @param {Operation} operations Operations objects array
* @return {Promise<TransactionReceipt>} Transaction receipt
*/
public async estGasBuyDTBatch(address: string, operations: Operations[]): Promise<any> {
public async estGasBuyDTBatch(address: string, operations: Operation[]): Promise<any> {
const gasLimitDefault = this.GASLIMIT_DEFAULT
let estGas
try {
@ -68,12 +58,12 @@ export class Router {
/**
* BuyDTBatch
* @param {String} address
* @param {Operations} operations Operations objects array
* @param {Operation} operations Operations objects array
* @return {Promise<TransactionReceipt>} Transaction receipt
*/
public async buyDTBatch(
address: string,
operations: Operations[]
operations: Operation[]
): Promise<TransactionReceipt> {
const estGas = await this.estGasBuyDTBatch(address, operations)

View File

@ -353,7 +353,7 @@ export class Pool {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
let result = null
try {
result = await pool.methods._marketCollector().call()
result = await pool.methods._publishMarketCollector().call()
} catch (e) {
this.logger.error(`ERROR: Failed to get marketFeeCollector address: ${e.message}`)
}
@ -509,7 +509,7 @@ export class Pool {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
let weight = null
try {
const result = await pool.methods.publishMarketFee(token).call()
const result = await pool.methods.publishMarketFees(token).call()
weight = await this.unitsToAmount(token, result)
} catch (e) {
this.logger.error(`ERROR: Failed to get market fees for a token: ${e.message}`)

View File

@ -16,7 +16,7 @@ import { LoggerInstance } from '../../../src/utils'
import { NFTFactory, NFTCreateData } from '../../../src/factories/NFTFactory'
import { Router } from '../../../src/pools/Router'
import { BigNumber } from 'bignumber.js'
import { Erc20CreateParams, PoolCreationParams } from '../../../src/interfaces'
import { Erc20CreateParams, PoolCreationParams, Operation } from '../../../src/interfaces'
const { keccak256 } = require('@ethersproject/keccak256')
const web3 = new Web3('http://127.0.0.1:8545')
const communityCollector = '0xeE9300b7961e0a01d9f0adb863C7A227A07AaD75'
@ -292,7 +292,7 @@ describe('Router unit test', () => {
// 1 - swapExactAmountOut
// 2 - FixedRateExchange
// 3 - Dispenser
const operations1 = {
const operations1: Operation = {
exchangeIds: keccak256('0x00'), // used only for FixedRate or Dispenser, but needs to be filled even for pool
source: pool1, // pool Address
operation: 0, // swapExactAmountIn
@ -300,10 +300,12 @@ describe('Router unit test', () => {
amountsIn: web3.utils.toWei('1'), // when swapExactAmountIn is EXACT amount IN
tokenOut: erc20Token,
amountsOut: web3.utils.toWei('0.1'), // when swapExactAmountIn is MIN amount OUT
maxPrice: web3.utils.toWei('10') // max price (only for pools)
maxPrice: web3.utils.toWei('10'), // max price (only for pools),
swapMarketFee: web3.utils.toWei('0.1'),
marketFeeAddress: contracts.accounts[0]
}
const operations2 = {
const operations2: Operation = {
exchangeIds: keccak256('0x00'), // used only for FixedRate or Dispenser, but needs to be filled even for pool
source: pool2, // pool Address
operation: 0, // swapExactAmountIn
@ -311,7 +313,9 @@ describe('Router unit test', () => {
amountsIn: web3.utils.toWei('1'), // when swapExactAmountIn is EXACT amount IN
tokenOut: erc20Token2,
amountsOut: web3.utils.toWei('0.1'), // when swapExactAmountIn is MIN amount OUT
maxPrice: web3.utils.toWei('10') // max price (only for pools)
maxPrice: web3.utils.toWei('10'), // max price (only for pools)
swapMarketFee: web3.utils.toWei('0.1'),
marketFeeAddress: contracts.accounts[0]
}
await router.buyDTBatch(user2, [operations1, operations2])