2019-04-15 15:30:02 +02:00
|
|
|
import { assert } from "chai"
|
|
|
|
|
|
|
|
import { config } from "../config"
|
|
|
|
|
|
|
|
import { getMetadata } from "../utils"
|
|
|
|
|
|
|
|
import { Ocean, Account } from "../../src" // @oceanprotocol/squid
|
|
|
|
|
2019-04-16 14:03:16 +02:00
|
|
|
describe("Asset Owners", () => {
|
2019-04-15 15:30:02 +02:00
|
|
|
let ocean: Ocean
|
|
|
|
|
2019-04-16 13:27:37 +02:00
|
|
|
let account1: Account
|
|
|
|
let account2: Account
|
2019-04-15 15:30:02 +02:00
|
|
|
|
|
|
|
const metadata = getMetadata()
|
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
ocean = await Ocean.getInstance(config)
|
|
|
|
|
|
|
|
// Accounts
|
2019-04-16 13:27:37 +02:00
|
|
|
const accounts = await ocean.accounts.list()
|
|
|
|
account1 = accounts[0]
|
|
|
|
account2 = accounts[1]
|
2019-04-15 15:30:02 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it("should be set correctly the owner of a asset", async () => {
|
2019-04-16 13:27:37 +02:00
|
|
|
const ddo = await ocean.assets.create(metadata as any, account1)
|
2019-04-15 15:30:02 +02:00
|
|
|
|
|
|
|
const owner = await ocean.assets.owner(ddo.id)
|
|
|
|
|
2019-04-16 13:27:37 +02:00
|
|
|
assert.equal(owner, account1.getId())
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should get the assets owned by a user", async () => {
|
|
|
|
const {length: initialLength} = await ocean.assets.ownerAssets(account2.getId())
|
|
|
|
|
|
|
|
await ocean.assets.create(metadata as any, account1)
|
|
|
|
await ocean.assets.create(metadata as any, account1)
|
|
|
|
|
|
|
|
await ocean.assets.create(metadata as any, account2)
|
|
|
|
|
|
|
|
const {length: finalLength} = await ocean.assets.ownerAssets(account2.getId())
|
|
|
|
|
|
|
|
assert.equal(finalLength - initialLength, 1)
|
2019-04-15 15:30:02 +02:00
|
|
|
})
|
2019-04-16 14:03:16 +02:00
|
|
|
|
|
|
|
it("should get the assets that can be consumer by a user", async () => {
|
|
|
|
const {length: initialLength} = await ocean.assets.consumerAssets(account2.getId())
|
|
|
|
|
|
|
|
const ddo = await ocean.assets.create(metadata as any, account1)
|
|
|
|
|
|
|
|
const {length: finalLength1} = await ocean.assets.consumerAssets(account2.getId())
|
|
|
|
assert.equal(finalLength1 - initialLength, 0)
|
|
|
|
|
|
|
|
// Granting access
|
|
|
|
await account2.requestTokens(metadata.base.price)
|
|
|
|
await ocean.assets.order(ddo.id, ddo.findServiceByType("Access").serviceDefinitionId, account2)
|
|
|
|
// Access granted
|
|
|
|
|
|
|
|
const {length: finalLength2} = await ocean.assets.consumerAssets(account2.getId())
|
|
|
|
assert.equal(finalLength2 - initialLength, 1)
|
|
|
|
})
|
2019-04-15 15:30:02 +02:00
|
|
|
})
|