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

69 lines
2.1 KiB
TypeScript
Raw Normal View History

import { assert } from "chai"
2019-03-14 21:28:51 +01:00
import * as Web3 from "web3"
import * as fs from "fs"
import { config } from "../config"
2019-03-15 15:23:28 +01:00
import { getMetadata } from "../utils"
2019-03-15 15:23:28 +01:00
import { Ocean, Account, DDO } from "../../src" // @oceanprotocol/squid
describe("Consume Asset (Brizo)", () => {
let ocean: Ocean
let publisher: Account
let consumer: Account
let ddo: DDO
let agreementId: string
2019-03-15 15:23:28 +01:00
const metadata = getMetadata()
before(async () => {
ocean = await Ocean.getInstance({
...config,
2019-03-14 21:28:51 +01:00
web3Provider: new Web3.providers
.HttpProvider("http://localhost:8545", 0, "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", "node0"),
})
// Accounts
2019-03-21 03:17:36 +01:00
const instanceConfig = (ocean as any).instanceConfig
publisher = new Account("0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", instanceConfig)
publisher.setPassword("node0")
consumer = new Account("0x068Ed00cF0441e4829D9784fCBe7b9e26D4BD8d0", instanceConfig)
consumer.setPassword("secret")
})
it("should regiester an asset", async () => {
2019-03-15 15:23:28 +01:00
ddo = await ocean.assets.create(metadata as any, publisher)
assert.instanceOf(ddo, DDO)
})
it("should order the asset", async () => {
const accessService = ddo.findServiceByType("Access")
await consumer.requestTokens(metadata.base.price)
agreementId = await ocean.assets.order(ddo.id, accessService.serviceDefinitionId, consumer)
assert.isDefined(agreementId)
})
it("should consume and store the assets", async () => {
const accessService = ddo.findServiceByType("Access")
const folder = "/tmp/ocean/squid-js"
const path = await ocean.assets.consume(agreementId, ddo.id, accessService.serviceDefinitionId, consumer, folder)
assert.include(path, folder, "The storage path is not correct.")
2019-03-14 22:54:04 +01:00
const files = await new Promise<string[]>((resolve) => {
2019-03-14 21:28:51 +01:00
fs.readdir(path, (err, fileList) => {
resolve(fileList)
})
})
2019-03-14 22:54:04 +01:00
assert.deepEqual(files, ["README.md", "package.json"], "Stored files are not correct.")
})
})