From 43dee2fca7fca7f63b3ff7d2d7cc276f5adfdf88 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Fri, 25 Sep 2020 00:49:19 -0700 Subject: [PATCH] fix tests --- src/balancer/OceanPool.ts | 11 +++-- src/exchange/FixedRateExchange.ts | 44 +++++++++++++------ .../unit/exchanges/FixedPriceExchange.test.ts | 4 +- 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/balancer/OceanPool.ts b/src/balancer/OceanPool.ts index f6935d73..3a9ffb30 100644 --- a/src/balancer/OceanPool.ts +++ b/src/balancer/OceanPool.ts @@ -382,9 +382,7 @@ export class OceanPool extends Pool { */ public async getPoolsbyCreator(account?: string): Promise { const result: PoolDetails[] = [] - const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress, { - from: account - }) + const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress) let myFilter if (account) { myFilter = { registeredBy: account } @@ -405,9 +403,14 @@ export class OceanPool extends Pool { } return result } + /** + * Get pool details + * @param {String} poolAddress Pool address + * @return {PoolDetails[]} + */ public async getPoolDetails(poolAddress: string): Promise { - const details: PoolDetails = null + const details: PoolDetails = { poolAddress: null, tokens: null } details.poolAddress = poolAddress details.tokens = await super.getFinalTokens(poolAddress) return details diff --git a/src/exchange/FixedRateExchange.ts b/src/exchange/FixedRateExchange.ts index bee7ebc9..00c1481e 100644 --- a/src/exchange/FixedRateExchange.ts +++ b/src/exchange/FixedRateExchange.ts @@ -15,6 +15,12 @@ export interface FixedPricedExchange { supply: string } +export interface FixedPricedSwap { + exchangeID: string + caller: string + baseTokenAmount: string + dataTokenAmount: string +} const DEFAULT_GAS_LIMIT = 300000 export class OceanFixedRateExchange { @@ -363,9 +369,7 @@ export class OceanFixedRateExchange { * @param {String} account * @return {Promise} */ - public async searchExchangesbyCreator( - account?: string - ): Promise { + public async getExchangesbyCreator(account?: string): Promise { const result: FixedPricedExchange[] = [] const events = await this.contract.getPastEvents('ExchangeCreated', { filter: {}, @@ -385,10 +389,13 @@ export class OceanFixedRateExchange { * Get all swaps for an exchange, filtered by account(if any) * @param {String} exchangeId * @param {String} account - * @return {Promise} + * @return {Promise} */ - public async searchExchangesSwaps(exchangeId: string, account?: string): Promise { - const result: FixedPricedExchange[] = [] + public async getExchangeSwaps( + exchangeId: string, + account?: string + ): Promise { + const result: FixedPricedSwap[] = [] const events = await this.contract.getPastEvents('Swapped', { filter: { exchangeId: exchangeId }, fromBlock: 0, @@ -406,23 +413,34 @@ export class OceanFixedRateExchange { /** * Get all swaps for an account * @param {String} account - * @return {Promise} + * @return {Promise} */ - public async searchAllExchangesSwaps(account: string): Promise { - const result = [] + public async getAllExchangesSwaps(account: string): Promise { + const result: FixedPricedSwap[] = [] const events = await this.contract.getPastEvents('ExchangeCreated', { filter: {}, fromBlock: 0, toBlock: 'latest' }) for (let i = 0; i < events.length; i++) { - result.push(await this.searchExchangesSwaps(events[i].returnValues[0], account)) - } + const swaps: FixedPricedSwap[] = await this.getExchangeSwaps( + events[i].returnValues[0], + account + ) + swaps.forEach((swap) => { + result.push(swap) + }) + } return result } - private getEventData(data: any) { - const result = Object() + private getEventData(data: any): FixedPricedSwap { + const result: FixedPricedSwap = { + exchangeID: null, + caller: null, + baseTokenAmount: null, + dataTokenAmount: null + } result.exchangeID = data.returnValues[0] result.caller = data.returnValues[1] result.baseTokenAmount = data.returnValues[2] diff --git a/test/unit/exchanges/FixedPriceExchange.test.ts b/test/unit/exchanges/FixedPriceExchange.test.ts index 00f1e795..ea4cc205 100644 --- a/test/unit/exchanges/FixedPriceExchange.test.ts +++ b/test/unit/exchanges/FixedPriceExchange.test.ts @@ -227,11 +227,11 @@ describe('FixedRateExchange flow', () => { assert(exchangeDetails.length === 0) }) it('Bob should find all the exchanges created by Alice', async () => { - const exchangeDetails = await FixedRateClass.searchExchangesbyCreator(alice) + const exchangeDetails = await FixedRateClass.getExchangesbyCreator(alice) assert(exchangeDetails.length > 0) }) it('Bob should find all his swaps', async () => { - const exchangeDetails = await FixedRateClass.searchAllExchangesSwaps(bob) + const exchangeDetails = await FixedRateClass.getAllExchangesSwaps(bob) assert(exchangeDetails.length > 0) }) })