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

fix error messages

This commit is contained in:
Ahmed Ali 2020-10-20 11:45:06 +02:00
parent b01908a7bd
commit ca733f2a06
3 changed files with 14 additions and 11 deletions

View File

@ -1,9 +1,9 @@
import { Logger } from '../utils'
import defaultFixedRateExchangeABI from '@oceanprotocol/contracts/artifacts/FixedRateExchange.json'
import BigNumber from 'bignumber.js'
import { TransactionReceipt } from 'web3-core'
import { Contract, EventData } from 'web3-eth-contract'
import { AbiItem } from 'web3-utils/types'
import { Logger } from '../utils'
import Web3 from 'web3'
export interface FixedPriceExchange {
@ -42,10 +42,10 @@ export class OceanFixedRateExchange {
*/
constructor(
web3: Web3,
logger: Logger,
fixedRateExchangeAddress: string = null,
fixedRateExchangeABI: AbiItem | AbiItem[] = null,
oceanAddress: string = null,
logger: Logger
oceanAddress: string = null
) {
this.web3 = web3
this.fixedRateExchangeAddress = fixedRateExchangeAddress
@ -182,7 +182,7 @@ export class OceanFixedRateExchange {
.setRate(exchangeId, this.web3.utils.toWei(String(newRate)))
.estimateGas(function (err, estGas) {
if (err) {
this.logger.error(`ERROR: FixedPriceExchange: ${err.message}`)
console.error(`ERROR: FixedPriceExchange: ${err.message}`)
return DEFAULT_GAS_LIMIT
}
return estGas
@ -218,12 +218,13 @@ export class OceanFixedRateExchange {
.toggleExchangeState(exchangeId)
.estimateGas(function (err, estGas) {
if (err) {
this.logger.error(`ERROR: FixedPriceExchange: ${err.message}`)
console.error(`ERROR: FixedPriceExchange: ${err.message}`)
estGas = DEFAULT_GAS_LIMIT
}
return estGas
})
} catch (e) {
this.logger.error(`ERROR: FixedPriceExchange: ${e.message}`)
estGas = DEFAULT_GAS_LIMIT
}
const trxReceipt = await this.contract.methods.toggleExchangeState(exchangeId).send({
@ -252,12 +253,13 @@ export class OceanFixedRateExchange {
.toggleExchangeState(exchangeId)
.estimateGas(function (err, estGas) {
if (err) {
this.logger.error(`ERROR: FixedPriceExchange: ${err.message}`)
console.error(`ERROR: FixedPriceExchange: ${err.message}`)
estGas = DEFAULT_GAS_LIMIT
}
return estGas
})
} catch (e) {
this.logger.error(`ERROR: FixedPriceExchange: ${e.message}`)
estGas = DEFAULT_GAS_LIMIT
}
const trxReceipt = await this.contract.methods.toggleExchangeState(exchangeId).send({

View File

@ -61,10 +61,10 @@ export class Ocean extends Instantiable {
)
instance.fixedRateExchange = new OceanFixedRateExchange(
instanceConfig.config.web3Provider,
instanceConfig.logger,
instanceConfig.config.fixedRateExchangeAddress,
instanceConfig.config.fixedRateExchangeAddressABI,
instanceConfig.config.oceanTokenAddress,
instanceConfig.logger
instanceConfig.config.oceanTokenAddress
)
instance.OnChainMetadataCache = new OnChainMetadataCache(
instanceConfig.config.web3Provider,

View File

@ -4,7 +4,7 @@ import { TestContractHandler } from '../../TestContractHandler'
import { FixedPricedContractHandler } from '../../FixedPriceContractHandler'
import { DataTokens } from '../../../src/datatokens/Datatokens'
import { OceanFixedRateExchange } from '../../../src/exchange/FixedRateExchange'
import { Logger } from '../../../src/utils'
import { LoggerInstance } from '../../../src/utils'
import Web3 from 'web3'
import factory from '@oceanprotocol/contracts/artifacts/DTFactory.json'
import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json'
@ -105,10 +105,10 @@ describe('FixedRateExchange flow', () => {
it('should initialize FixedExchangeRate class', async () => {
FixedRateClass = new OceanFixedRateExchange(
web3,
LoggerInstance,
FixedRateExchangeAddress,
FixedRateExchangeContract.abi as AbiItem[],
oceanTokenAddress,
new Logger()
oceanTokenAddress
)
assert(FixedRateClass !== null)
})
@ -208,6 +208,7 @@ describe('FixedRateExchange flow', () => {
if (consoleDebug) console.log('Bob ocean balance:' + balance)
})
it('Alice should update the rate', async () => {
// console.log(await FixedRateClass.getLogger())
const tx = await FixedRateClass.setRate(aliceExchangeId, updatedPriceRate, alice)
assert(tx !== null)
})