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

add bob consumes

This commit is contained in:
arsenyjin 2020-06-17 12:18:02 +02:00
parent a6bccad3f1
commit 653dcf5dda
2 changed files with 19 additions and 23 deletions

View File

@ -176,34 +176,24 @@ export class Assets extends Instantiable {
public async download(
dtAddress: string,
serviceEndpoint: string,
account: Account,
files: File[],
destination: string,
index: number = -1
account: string
): Promise<string> {
// const signature = await this.createSignature(account, agreementId)
const filesPromises = files
.filter((_, i) => index === -1 || i === index)
.map(async ({ index: i }) => {
let consumeUrl = serviceEndpoint
consumeUrl += `?index=${i}`
consumeUrl += `&serviceAgreementId=${dtAddress}`
// consumeUrl += `&consumerAddress=${account.getId()}`
// consumeUrl += `&signature=${signature}`
let consumeUrl = serviceEndpoint
consumeUrl += `&consumerAddress=${account}`
consumeUrl += `&serviceAgreementId=${dtAddress}`
let serviceConnector = new WebServiceConnector(this.logger)
let serviceConnector = new WebServiceConnector(this.logger)
try {
// TODO: change to WebServiceConnector.ts
await serviceConnector.downloadFile(consumeUrl, destination, i)
try {
await serviceConnector.downloadFile(consumeUrl)
} catch (e) {
this.logger.error('Error consuming assets')
this.logger.error(e)
throw e
}
})
await Promise.all(filesPromises)
return destination
}
return serviceEndpoint
}
}

View File

@ -1,6 +1,9 @@
import { assert } from 'chai'
import { TestContractHandler } from '../TestContractHandler'
import { DataTokens } from '../../src/datatokens/Datatokens'
import { Ocean } from '../../src/ocean/Ocean'
import { Config } from '../../src/models/Config'
const Web3 = require('web3')
const web3 = new Web3("http://127.0.0.1:8545")
@ -20,7 +23,7 @@ describe('Simple flow', () => {
let tokenAmount = 100
let transferAmount = 1
let blob = 'localhost:8030/api/v1/services'
let blob = 'https://localhost:8030/api/v1/services'
describe('#test', () => {
it('Initialize Ocean contracts v3', async () => {
@ -52,7 +55,10 @@ describe('Simple flow', () => {
})
it('Bob consumes dataset', async () => {
datatoken.transfer(tokenAddress, bob, tokenAmount, alice)
const config = new Config()
let ocean = await Ocean.getInstance(config)
ocean.assets.download(tokenAddress, blob, bob)
})
})
})