2019-06-20 00:20:09 +02:00
|
|
|
import { assert } from 'chai'
|
|
|
|
import * as fs from 'fs'
|
2019-04-05 16:12:39 +02:00
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
import { config } from '../config'
|
|
|
|
import { getMetadata } from '../utils'
|
2019-04-05 16:12:39 +02:00
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
import { Ocean, Account, DDO } from '../../src' // @oceanprotocol/squid
|
2019-04-05 16:12:39 +02:00
|
|
|
|
|
|
|
// Ensure that your network is fast enought and you have some free ram before run it.
|
2019-06-20 00:20:09 +02:00
|
|
|
xdescribe('Consume Asset (Large size)', () => {
|
2019-04-05 16:12:39 +02:00
|
|
|
let ocean: Ocean
|
|
|
|
|
|
|
|
let publisher: Account
|
|
|
|
let consumer: Account
|
|
|
|
|
|
|
|
let ddo: DDO
|
|
|
|
let agreementId: string
|
|
|
|
|
2019-06-26 20:57:50 +02:00
|
|
|
let baseMetadata = getMetadata()
|
|
|
|
let metadata = getMetadata()
|
2019-04-05 16:12:39 +02:00
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
ocean = await Ocean.getInstance(config)
|
|
|
|
|
|
|
|
// Accounts
|
2019-06-24 13:06:38 +02:00
|
|
|
;[publisher, consumer] = await ocean.accounts.list()
|
2019-06-26 20:57:50 +02:00
|
|
|
|
|
|
|
if (!ocean.keeper.dispenser) {
|
|
|
|
baseMetadata = getMetadata(0)
|
|
|
|
}
|
|
|
|
metadata = {
|
|
|
|
...baseMetadata,
|
2019-08-15 13:23:56 +02:00
|
|
|
main: {
|
|
|
|
...baseMetadata.main,
|
2019-06-26 20:57:50 +02:00
|
|
|
files: [
|
|
|
|
{
|
|
|
|
url: 'https://speed.hetzner.de/1GB.bin'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2019-04-05 16:12:39 +02:00
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
it('should regiester an asset', async () => {
|
2019-04-05 16:12:39 +02:00
|
|
|
ddo = await ocean.assets.create(metadata as any, publisher)
|
|
|
|
|
|
|
|
assert.instanceOf(ddo, DDO)
|
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
it('should order the asset', async () => {
|
2019-08-16 14:12:31 +02:00
|
|
|
const accessService = ddo.findServiceByType('access')
|
2019-04-05 16:12:39 +02:00
|
|
|
|
2019-06-26 20:57:50 +02:00
|
|
|
try {
|
2019-09-09 12:18:54 +02:00
|
|
|
await consumer.requestTokens(+metadata.main.price * 10 ** -(await ocean.keeper.token.decimals()))
|
2019-06-26 20:57:50 +02:00
|
|
|
} catch {}
|
2019-04-05 16:12:39 +02:00
|
|
|
|
2019-09-09 12:18:54 +02:00
|
|
|
agreementId = await ocean.assets.order(ddo.id, accessService.index, consumer)
|
2019-04-05 16:12:39 +02:00
|
|
|
|
|
|
|
assert.isDefined(agreementId)
|
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
it('should consume and store the assets', async () => {
|
2019-08-16 14:12:31 +02:00
|
|
|
const accessService = ddo.findServiceByType('access')
|
2019-04-05 16:12:39 +02:00
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
const folder = '/tmp/ocean/squid-js'
|
2019-09-09 12:18:54 +02:00
|
|
|
const path = await ocean.assets.consume(agreementId, ddo.id, accessService.index, consumer, folder)
|
2019-04-05 16:12:39 +02:00
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
assert.include(path, folder, 'The storage path is not correct.')
|
2019-04-05 16:12:39 +02:00
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
const files = await new Promise<string[]>(resolve => {
|
2019-06-24 13:06:38 +02:00
|
|
|
fs.readdir(path, (e, fileList) => {
|
2019-04-05 16:12:39 +02:00
|
|
|
resolve(fileList)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
assert.deepEqual(files, ['1GB.bin'], 'Stored files are not correct.')
|
2019-04-05 16:12:39 +02:00
|
|
|
})
|
|
|
|
})
|