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

fix tests

This commit is contained in:
alexcos20 2020-09-25 00:49:19 -07:00
parent ffdd8f561a
commit 43dee2fca7
3 changed files with 40 additions and 19 deletions

View File

@ -382,9 +382,7 @@ export class OceanPool extends Pool {
*/ */
public async getPoolsbyCreator(account?: string): Promise<PoolDetails[]> { public async getPoolsbyCreator(account?: string): Promise<PoolDetails[]> {
const result: PoolDetails[] = [] const result: PoolDetails[] = []
const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress, { const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress)
from: account
})
let myFilter let myFilter
if (account) { if (account) {
myFilter = { registeredBy: account } myFilter = { registeredBy: account }
@ -405,9 +403,14 @@ export class OceanPool extends Pool {
} }
return result return result
} }
/**
* Get pool details
* @param {String} poolAddress Pool address
* @return {PoolDetails[]}
*/
public async getPoolDetails(poolAddress: string): Promise<PoolDetails> { public async getPoolDetails(poolAddress: string): Promise<PoolDetails> {
const details: PoolDetails = null const details: PoolDetails = { poolAddress: null, tokens: null }
details.poolAddress = poolAddress details.poolAddress = poolAddress
details.tokens = await super.getFinalTokens(poolAddress) details.tokens = await super.getFinalTokens(poolAddress)
return details return details

View File

@ -15,6 +15,12 @@ export interface FixedPricedExchange {
supply: string supply: string
} }
export interface FixedPricedSwap {
exchangeID: string
caller: string
baseTokenAmount: string
dataTokenAmount: string
}
const DEFAULT_GAS_LIMIT = 300000 const DEFAULT_GAS_LIMIT = 300000
export class OceanFixedRateExchange { export class OceanFixedRateExchange {
@ -363,9 +369,7 @@ export class OceanFixedRateExchange {
* @param {String} account * @param {String} account
* @return {Promise<FixedPricedExchange[]>} * @return {Promise<FixedPricedExchange[]>}
*/ */
public async searchExchangesbyCreator( public async getExchangesbyCreator(account?: string): Promise<FixedPricedExchange[]> {
account?: string
): Promise<FixedPricedExchange[]> {
const result: FixedPricedExchange[] = [] const result: FixedPricedExchange[] = []
const events = await this.contract.getPastEvents('ExchangeCreated', { const events = await this.contract.getPastEvents('ExchangeCreated', {
filter: {}, filter: {},
@ -385,10 +389,13 @@ export class OceanFixedRateExchange {
* Get all swaps for an exchange, filtered by account(if any) * Get all swaps for an exchange, filtered by account(if any)
* @param {String} exchangeId * @param {String} exchangeId
* @param {String} account * @param {String} account
* @return {Promise<any>} * @return {Promise<FixedPricedSwap[]>}
*/ */
public async searchExchangesSwaps(exchangeId: string, account?: string): Promise<any> { public async getExchangeSwaps(
const result: FixedPricedExchange[] = [] exchangeId: string,
account?: string
): Promise<FixedPricedSwap[]> {
const result: FixedPricedSwap[] = []
const events = await this.contract.getPastEvents('Swapped', { const events = await this.contract.getPastEvents('Swapped', {
filter: { exchangeId: exchangeId }, filter: { exchangeId: exchangeId },
fromBlock: 0, fromBlock: 0,
@ -406,23 +413,34 @@ export class OceanFixedRateExchange {
/** /**
* Get all swaps for an account * Get all swaps for an account
* @param {String} account * @param {String} account
* @return {Promise<any>} * @return {Promise<FixedPricedSwap[]>}
*/ */
public async searchAllExchangesSwaps(account: string): Promise<any> { public async getAllExchangesSwaps(account: string): Promise<FixedPricedSwap[]> {
const result = [] const result: FixedPricedSwap[] = []
const events = await this.contract.getPastEvents('ExchangeCreated', { const events = await this.contract.getPastEvents('ExchangeCreated', {
filter: {}, filter: {},
fromBlock: 0, fromBlock: 0,
toBlock: 'latest' toBlock: 'latest'
}) })
for (let i = 0; i < events.length; i++) { 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 return result
} }
private getEventData(data: any) { private getEventData(data: any): FixedPricedSwap {
const result = Object() const result: FixedPricedSwap = {
exchangeID: null,
caller: null,
baseTokenAmount: null,
dataTokenAmount: null
}
result.exchangeID = data.returnValues[0] result.exchangeID = data.returnValues[0]
result.caller = data.returnValues[1] result.caller = data.returnValues[1]
result.baseTokenAmount = data.returnValues[2] result.baseTokenAmount = data.returnValues[2]

View File

@ -227,11 +227,11 @@ describe('FixedRateExchange flow', () => {
assert(exchangeDetails.length === 0) assert(exchangeDetails.length === 0)
}) })
it('Bob should find all the exchanges created by Alice', async () => { 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) assert(exchangeDetails.length > 0)
}) })
it('Bob should find all his swaps', async () => { it('Bob should find all his swaps', async () => {
const exchangeDetails = await FixedRateClass.searchAllExchangesSwaps(bob) const exchangeDetails = await FixedRateClass.getAllExchangesSwaps(bob)
assert(exchangeDetails.length > 0) assert(exchangeDetails.length > 0)
}) })
}) })