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

87 lines
2.3 KiB
TypeScript
Raw Normal View History

2019-02-06 00:38:54 +01:00
import { assert, spy, use } from "chai"
import * as spies from "chai-spies"
2019-02-12 15:07:10 +01:00
import { SearchQuery } from "../../src/aquarius/query/SearchQuery"
import { DDO } from "../../src/ddo/DDO"
2018-10-16 14:56:18 +02:00
import Account from "../../src/ocean/Account"
import { Ocean } from "../../src/ocean/Ocean"
2019-02-06 00:38:54 +01:00
import * as signatureHelpers from "../../src/utils/SignatureHelpers"
2018-10-16 14:56:18 +02:00
import config from "../config"
import TestContractHandler from "../keeper/TestContractHandler"
import { metadataMock } from "../testdata/MetaData"
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-16 14:56:18 +02:00
let accounts: Account[]
2018-10-17 18:24:01 +02:00
let testPublisher: Account
2018-10-05 12:34:18 +02:00
describe("Ocean", () => {
const metadata = metadataMock
2019-02-06 00:38:54 +01:00
beforeEach(async () => {
spy.on(signatureHelpers, "signText", () => `0x${"a".repeat(130)}`)
})
afterEach(() => {
spy.restore()
})
2018-10-26 10:40:46 +02:00
before(async () => {
await TestContractHandler.prepareContracts()
2018-10-26 10:40:46 +02:00
ocean = await Ocean.getInstance(config)
accounts = await ocean.accounts.list()
2018-10-26 10:40:46 +02:00
testPublisher = accounts[0]
})
2018-10-26 11:57:26 +02:00
describe("#getInstance()", () => {
2018-11-05 10:01:58 +01:00
it("should get an instance of cean", async () => {
2018-11-05 10:01:58 +01:00
const oceanInstance: Ocean = await Ocean.getInstance(config)
2018-11-05 10:01:58 +01:00
assert(oceanInstance)
})
})
2018-10-16 14:56:18 +02:00
describe("#getAccounts()", () => {
it("should list accounts", async () => {
2018-10-05 12:34:18 +02: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,
page: 0,
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
const assets: any[] = await ocean.assets.query(query)
2018-10-26 10:40:46 +02:00
assert(assets)
})
})
describe("#searchAssetsByText()", () => {
it("should search for assets", async () => {
const text = "office"
const assets: any[] = await ocean.assets.search(text)
assert(assets)
})
})
2018-10-05 12:34:18 +02:00
})