mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
[WIP] Adds checkURL function to use provider endpoint. (#540)
* Adds checkURL function to use provider endpoint. * Change Provider version in Travis. * Update checkURL function to return full result instead of boolean. Co-authored-by: Calina Cenan <calina.tutunaru@algotech.solutions>
This commit is contained in:
parent
7accf0fb60
commit
34f8b4a9e0
@ -29,6 +29,7 @@ before_script:
|
|||||||
- export AQUARIUS_URI="http://172.15.0.5:5000"
|
- export AQUARIUS_URI="http://172.15.0.5:5000"
|
||||||
- export DEPLOY_CONTRACTS="true"
|
- export DEPLOY_CONTRACTS="true"
|
||||||
- export CONTRACTS_VERSION=v0.5.7
|
- export CONTRACTS_VERSION=v0.5.7
|
||||||
|
- export PROVIDER_VERSION=latest
|
||||||
- bash -x start_ocean.sh --no-dashboard 2>&1 > start_ocean.log &
|
- bash -x start_ocean.sh --no-dashboard 2>&1 > start_ocean.log &
|
||||||
- cd ..
|
- cd ..
|
||||||
- ./scripts/waitforcontracts.sh
|
- ./scripts/waitforcontracts.sh
|
||||||
|
@ -73,6 +73,23 @@ export class Provider extends Instantiable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async checkURL(url: string): Promise<Record<string, string>> {
|
||||||
|
const args = { url }
|
||||||
|
try {
|
||||||
|
const response = await this.ocean.utils.fetch.post(
|
||||||
|
this.getCheckURLEndpoint(),
|
||||||
|
decodeURI(JSON.stringify(args))
|
||||||
|
)
|
||||||
|
|
||||||
|
const result = await response.json()
|
||||||
|
|
||||||
|
return result.result
|
||||||
|
} catch (e) {
|
||||||
|
this.logger.error(e)
|
||||||
|
throw new Error('HTTP request failed')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Get nonce from provider
|
/** Get nonce from provider
|
||||||
* @param {String} consumerAddress
|
* @param {String} consumerAddress
|
||||||
* @return {Promise<string>} string
|
* @return {Promise<string>} string
|
||||||
@ -281,6 +298,10 @@ export class Provider extends Instantiable {
|
|||||||
return `${this.url}${apiPath}/encrypt`
|
return `${this.url}${apiPath}/encrypt`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getCheckURLEndpoint(): string {
|
||||||
|
return `${this.url}${apiPath}/checkURL`
|
||||||
|
}
|
||||||
|
|
||||||
public getPublishEndpoint(): string {
|
public getPublishEndpoint(): string {
|
||||||
return `${this.url}${apiPath}/publish`
|
return `${this.url}${apiPath}/publish`
|
||||||
}
|
}
|
||||||
|
@ -16,4 +16,10 @@ describe('Provider tests', () => {
|
|||||||
const valid = await ocean.provider.isValidProvider('http://127.0.0.1:8030')
|
const valid = await ocean.provider.isValidProvider('http://127.0.0.1:8030')
|
||||||
assert(valid === true)
|
assert(valid === true)
|
||||||
})
|
})
|
||||||
|
it('Check a valid URL', async () => {
|
||||||
|
const url = 'https://s3.amazonaws.com/testfiles.oceanprotocol.com/info.0.json'
|
||||||
|
const response = await ocean.provider.checkURL(url)
|
||||||
|
assert(response.contentLength === '1161')
|
||||||
|
assert(response.contentType === 'application/json')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -427,18 +427,18 @@ describe('Balancer flow', () => {
|
|||||||
assert(parseFloat(bobDtBalance) < parseFloat(newbobDtBalance))
|
assert(parseFloat(bobDtBalance) < parseFloat(newbobDtBalance))
|
||||||
assert(parseFloat(poolShares) > parseFloat(newpoolShares))
|
assert(parseFloat(poolShares) > parseFloat(newpoolShares))
|
||||||
})
|
})
|
||||||
it('ALice should know how many tokens she will get for removing all liquidity', async () => {
|
it('Alice should know how many tokens she will get for removing all liquidity', async () => {
|
||||||
const aliceShares = await Pool.sharesBalance(alice, greatPool)
|
const aliceShares = await Pool.sharesBalance(alice, greatPool)
|
||||||
const amounts = await Pool.getTokensRemovedforPoolShares(greatPool, aliceShares)
|
const amounts = await Pool.getTokensRemovedforPoolShares(greatPool, aliceShares)
|
||||||
assert(parseFloat(amounts.dtAmount) > 0)
|
assert(parseFloat(amounts.dtAmount) > 0)
|
||||||
assert(parseFloat(amounts.oceanAmount) > 0)
|
assert(parseFloat(amounts.oceanAmount) > 0)
|
||||||
})
|
})
|
||||||
it('ALice should get all her shares for all the pools', async () => {
|
it('Alice should get all her shares for all the pools', async () => {
|
||||||
const aliceShares = await Pool.getPoolSharesByAddress(alice)
|
const aliceShares = await Pool.getPoolSharesByAddress(alice)
|
||||||
assert(aliceShares.length > 0)
|
assert(aliceShares.length > 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('ALice should remove all liquidity', async () => {
|
it('Alice should remove all liquidity', async () => {
|
||||||
const aliceShares = await Pool.sharesBalance(alice, greatPool)
|
const aliceShares = await Pool.sharesBalance(alice, greatPool)
|
||||||
const aliceDtBalance = await datatoken.balance(tokenAddress, alice)
|
const aliceDtBalance = await datatoken.balance(tokenAddress, alice)
|
||||||
const aliceOceanBalance = await datatoken.balance(oceanTokenAddress, alice)
|
const aliceOceanBalance = await datatoken.balance(oceanTokenAddress, alice)
|
||||||
@ -450,12 +450,12 @@ describe('Balancer flow', () => {
|
|||||||
assert(parseFloat(aliceOceanBalance) < parseFloat(newAliceOceanBalance))
|
assert(parseFloat(aliceOceanBalance) < parseFloat(newAliceOceanBalance))
|
||||||
assert(parseFloat(aliceShares) > parseFloat(newAliceShares))
|
assert(parseFloat(aliceShares) > parseFloat(newAliceShares))
|
||||||
})
|
})
|
||||||
it('ALice should get all the pools that she created', async () => {
|
it('Alice should get all the pools that she created', async () => {
|
||||||
const alicePools = await Pool.getPoolsbyCreator(alice)
|
const alicePools = await Pool.getPoolsbyCreator(alice)
|
||||||
assert(alicePools.length > 0)
|
assert(alicePools.length > 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('ALice should get the logs for her pool', async () => {
|
it('Alice should get the logs for her pool', async () => {
|
||||||
const poolLogs = await Pool.getPoolLogs(greatPool, null)
|
const poolLogs = await Pool.getPoolLogs(greatPool, null)
|
||||||
assert(poolLogs.length > 0)
|
assert(poolLogs.length > 0)
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user