1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00
squid-js/test/integration/ocean/ConsumeBigAsset.test.ts

84 lines
2.3 KiB
TypeScript
Raw Normal View History

2019-06-20 00:20:09 +02:00
import { assert } from 'chai'
import * as fs from 'fs'
2019-06-20 00:20:09 +02:00
import { config } from '../config'
import { getMetadata } from '../utils'
2020-01-31 00:15:55 +01:00
import { Ocean, Account, DDO } from '../../../src' // @oceanprotocol/squid
// 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)', () => {
let ocean: Ocean
let publisher: Account
let consumer: Account
let ddo: DDO
let agreementId: string
let baseMetadata = getMetadata()
let metadata = getMetadata()
before(async () => {
ocean = await Ocean.getInstance(config)
// Accounts
2019-06-24 13:06:38 +02:00
;[publisher, consumer] = await ocean.accounts.list()
if (!ocean.keeper.dispenser) {
baseMetadata = getMetadata(0)
}
metadata = {
...baseMetadata,
2019-08-15 13:23:56 +02:00
main: {
...baseMetadata.main,
2019-11-15 00:00:10 +01:00
files: [
{
index: 0,
contentType: 'hello/hello',
url: 'https://speed.hetzner.de/1GB.bin'
}
]
}
}
})
it('should register an asset', async () => {
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 () => {
try {
2019-11-15 00:00:10 +01:00
await consumer.requestTokens(
parseInt(
(
+metadata.main.price *
10 ** -(await ocean.keeper.token.decimals())
).toString()
)
2019-11-15 00:00:10 +01:00
)
} catch {}
agreementId = await ocean.assets.order(ddo.id, consumer)
assert.isDefined(agreementId)
})
2019-06-20 00:20:09 +02:00
it('should consume and store the assets', async () => {
const folder = '/tmp/ocean/squid-js'
const path = await ocean.assets.consume(agreementId, ddo.id, consumer, folder)
2019-06-20 00:20:09 +02:00
assert.include(path, folder, 'The storage path is not correct.')
const files = await new Promise<string[]>((resolve) => {
2019-06-24 13:06:38 +02:00
fs.readdir(path, (e, fileList) => {
resolve(fileList)
})
})
2019-06-20 00:20:09 +02:00
assert.deepEqual(files, ['1GB.bin'], 'Stored files are not correct.')
})
})