diff --git a/src/exchange/FixedRateExchange.ts b/src/exchange/FixedRateExchange.ts index 84c91c3c..5c7f9f2a 100644 --- a/src/exchange/FixedRateExchange.ts +++ b/src/exchange/FixedRateExchange.ts @@ -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({ diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index 0ff9b0a5..28df3a11 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -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, diff --git a/test/unit/exchanges/FixedPriceExchange.test.ts b/test/unit/exchanges/FixedPriceExchange.test.ts index 1908f505..1b6fd336 100644 --- a/test/unit/exchanges/FixedPriceExchange.test.ts +++ b/test/unit/exchanges/FixedPriceExchange.test.ts @@ -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) })