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:
parent
ffdd8f561a
commit
43dee2fca7
@ -382,9 +382,7 @@ export class OceanPool extends Pool {
|
||||
*/
|
||||
public async getPoolsbyCreator(account?: string): Promise<PoolDetails[]> {
|
||||
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<PoolDetails> {
|
||||
const details: PoolDetails = null
|
||||
const details: PoolDetails = { poolAddress: null, tokens: null }
|
||||
details.poolAddress = poolAddress
|
||||
details.tokens = await super.getFinalTokens(poolAddress)
|
||||
return details
|
||||
|
@ -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<FixedPricedExchange[]>}
|
||||
*/
|
||||
public async searchExchangesbyCreator(
|
||||
account?: string
|
||||
): Promise<FixedPricedExchange[]> {
|
||||
public async getExchangesbyCreator(account?: string): Promise<FixedPricedExchange[]> {
|
||||
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<any>}
|
||||
* @return {Promise<FixedPricedSwap[]>}
|
||||
*/
|
||||
public async searchExchangesSwaps(exchangeId: string, account?: string): Promise<any> {
|
||||
const result: FixedPricedExchange[] = []
|
||||
public async getExchangeSwaps(
|
||||
exchangeId: string,
|
||||
account?: string
|
||||
): Promise<FixedPricedSwap[]> {
|
||||
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<any>}
|
||||
* @return {Promise<FixedPricedSwap[]>}
|
||||
*/
|
||||
public async searchAllExchangesSwaps(account: string): Promise<any> {
|
||||
const result = []
|
||||
public async getAllExchangesSwaps(account: string): Promise<FixedPricedSwap[]> {
|
||||
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]
|
||||
|
@ -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)
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user