Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Adds checkURL function to use provider endpoint. #540

Merged
merged 3 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ before_script:
- export AQUARIUS_URI="http://172.15.0.5:5000"
- export DEPLOY_CONTRACTS="true"
- export CONTRACTS_VERSION=v0.5.7
- export PROVIDER_VERSION=latest
- bash -x start_ocean.sh --no-dashboard 2>&1 > start_ocean.log &
- cd ..
- ./scripts/waitforcontracts.sh
Expand Down
21 changes: 21 additions & 0 deletions src/provider/Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
* @param {String} consumerAddress
* @return {Promise<string>} string
Expand Down Expand Up @@ -281,6 +298,10 @@ export class Provider extends Instantiable {
return `${this.url}${apiPath}/encrypt`
}

public getCheckURLEndpoint(): string {
return `${this.url}${apiPath}/checkURL`
}

public getPublishEndpoint(): string {
return `${this.url}${apiPath}/publish`
}
Expand Down
6 changes: 6 additions & 0 deletions test/integration/Provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ describe('Provider tests', () => {
const valid = await ocean.provider.isValidProvider('http://127.0.0.1:8030')
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')
})
})
10 changes: 5 additions & 5 deletions test/unit/balancer/Balancer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,18 +427,18 @@ describe('Balancer flow', () => {
assert(parseFloat(bobDtBalance) < parseFloat(newbobDtBalance))
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 amounts = await Pool.getTokensRemovedforPoolShares(greatPool, aliceShares)
assert(parseFloat(amounts.dtAmount) > 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)
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 aliceDtBalance = await datatoken.balance(tokenAddress, alice)
const aliceOceanBalance = await datatoken.balance(oceanTokenAddress, alice)
Expand All @@ -450,12 +450,12 @@ describe('Balancer flow', () => {
assert(parseFloat(aliceOceanBalance) < parseFloat(newAliceOceanBalance))
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)
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)
assert(poolLogs.length > 0)
})
Expand Down