2019-02-06 00:38:54 +01:00
|
|
|
import { assert, spy, use } from "chai"
|
|
|
|
import * as spies from "chai-spies"
|
|
|
|
|
2019-04-01 14:36:44 +02:00
|
|
|
import { SearchQuery } from "../../src/aquarius/Aquarius"
|
2018-10-16 14:56:18 +02:00
|
|
|
import Account from "../../src/ocean/Account"
|
2019-03-19 13:01:28 +01:00
|
|
|
import { Ocean } from "../../src/ocean/Ocean"
|
2018-10-16 14:56:18 +02:00
|
|
|
import config from "../config"
|
2018-11-07 14:33:56 +01:00
|
|
|
import TestContractHandler from "../keeper/TestContractHandler"
|
2018-10-05 12:34:18 +02:00
|
|
|
|
2019-02-06 00:38:54 +01:00
|
|
|
use(spies)
|
|
|
|
|
2018-10-05 12:34:18 +02:00
|
|
|
let ocean: Ocean
|
2018-10-17 18:24:01 +02:00
|
|
|
|
2018-10-05 12:34:18 +02:00
|
|
|
describe("Ocean", () => {
|
|
|
|
|
2019-03-28 12:20:22 +01:00
|
|
|
before(async () => {
|
|
|
|
await TestContractHandler.prepareContracts()
|
|
|
|
ocean = await Ocean.getInstance(config)
|
|
|
|
})
|
2019-02-04 11:46:24 +01:00
|
|
|
|
2019-02-06 00:38:54 +01:00
|
|
|
beforeEach(async () => {
|
2019-03-28 12:20:22 +01:00
|
|
|
spy.on(ocean.utils.signature, "signText", () => `0x${"a".repeat(130)}`)
|
2019-02-06 00:38:54 +01:00
|
|
|
})
|
|
|
|
afterEach(() => {
|
|
|
|
spy.restore()
|
|
|
|
})
|
|
|
|
|
2018-10-18 13:06:52 +02:00
|
|
|
describe("#getInstance()", () => {
|
2018-11-05 10:01:58 +01:00
|
|
|
it("should get an instance of cean", async () => {
|
2018-10-18 13:06:52 +02:00
|
|
|
|
2018-11-05 10:01:58 +01:00
|
|
|
const oceanInstance: Ocean = await Ocean.getInstance(config)
|
2018-10-18 13:06:52 +02:00
|
|
|
|
2018-11-05 10:01:58 +01:00
|
|
|
assert(oceanInstance)
|
2018-10-18 13:06:52 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-10-16 14:56:18 +02:00
|
|
|
describe("#getAccounts()", () => {
|
|
|
|
it("should list accounts", async () => {
|
2018-10-05 12:34:18 +02:00
|
|
|
|
2019-03-21 02:56:58 +01:00
|
|
|
const accs: Account[] = await ocean.accounts.list()
|
2018-10-16 14:56:18 +02:00
|
|
|
|
|
|
|
assert(10 === accs.length)
|
|
|
|
assert(0 === (await accs[5].getBalance()).ocn)
|
|
|
|
assert("string" === typeof accs[0].getId())
|
2018-10-05 12:34:18 +02:00
|
|
|
})
|
2018-10-16 14:56:18 +02:00
|
|
|
})
|
2018-10-05 12:34:18 +02:00
|
|
|
|
2018-10-26 10:40:46 +02:00
|
|
|
describe("#searchAssets()", () => {
|
|
|
|
it("should search for assets", async () => {
|
|
|
|
const query = {
|
|
|
|
offset: 100,
|
2019-04-16 19:01:11 +02:00
|
|
|
page: 1,
|
2018-10-26 10:40:46 +02:00
|
|
|
query: {
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
sort: {
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
text: "Office",
|
2018-11-05 10:01:58 +01:00
|
|
|
} as SearchQuery
|
2018-10-26 10:40:46 +02:00
|
|
|
|
2019-04-05 12:20:42 +02:00
|
|
|
const assets = await ocean.assets.query(query)
|
2018-10-26 10:40:46 +02:00
|
|
|
|
|
|
|
assert(assets)
|
|
|
|
})
|
|
|
|
})
|
2018-11-05 17:50:56 +01:00
|
|
|
|
|
|
|
describe("#searchAssetsByText()", () => {
|
|
|
|
it("should search for assets", async () => {
|
|
|
|
const text = "office"
|
2019-04-05 12:20:42 +02:00
|
|
|
const assets = await ocean.assets.search(text)
|
2018-11-05 17:50:56 +01:00
|
|
|
|
|
|
|
assert(assets)
|
|
|
|
})
|
|
|
|
})
|
2018-10-05 12:34:18 +02:00
|
|
|
})
|