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

93 lines
2.6 KiB
TypeScript
Raw Normal View History

2018-10-18 09:19:10 +02:00
import {assert} from "chai"
2018-10-26 10:40:46 +02:00
import AquariusProvider from "../../src/aquarius/AquariusProvider"
2018-11-05 10:01:58 +01:00
import SearchQuery from "../../src/aquarius/query/SearchQuery"
2018-10-16 14:56:18 +02:00
import ConfigProvider from "../../src/ConfigProvider"
2018-11-05 10:01:58 +01:00
import DDO from "../../src/ddo/DDO"
2018-10-05 12:34:18 +02:00
import ContractHandler from "../../src/keeper/ContractHandler"
2018-10-16 14:56:18 +02:00
import Account from "../../src/ocean/Account"
import Asset from "../../src/ocean/Asset"
2018-10-05 12:34:18 +02:00
import Ocean from "../../src/ocean/Ocean"
2018-10-26 13:37:09 +02:00
import SecretStoreProvider from "../../src/secretstore/SecretStoreProvider"
2018-10-16 14:56:18 +02:00
import config from "../config"
2018-10-26 10:40:46 +02:00
import AquariusMock from "../mocks/Aquarius.mock"
2018-10-26 13:37:09 +02:00
import SecretStoreMock from "../mocks/SecretStore.mock"
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-11-05 10:01:58 +01:00
const name = "Test Asset 3" + Math.random().toString()
2018-10-17 18:24:01 +02:00
const description = "This asset is pure owange"
const price = 100
2018-10-05 12:34:18 +02:00
describe("Ocean", () => {
2018-10-26 10:40:46 +02:00
before(async () => {
ConfigProvider.setConfig(config)
2018-10-26 11:57:26 +02:00
AquariusProvider.setAquarius(new AquariusMock(config))
2018-10-26 13:37:09 +02:00
SecretStoreProvider.setSecretStore(new SecretStoreMock(config))
2018-10-26 10:40:46 +02:00
await ContractHandler.deployContracts()
ocean = await Ocean.getInstance(config)
accounts = await ocean.getAccounts()
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()", () => {
2018-10-05 12:34:18 +02:00
2018-10-16 14:56:18 +02:00
it("should list accounts", async () => {
2018-10-05 12:34:18 +02:00
2018-10-16 14:56:18 +02:00
const accs: Account[] = await ocean.getAccounts()
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-16 14:56:18 +02:00
describe("#register()", () => {
it("should register an asset", async () => {
2018-11-05 10:01:58 +01:00
const asset: Asset = new Asset(name, description, price, testPublisher)
const ddo: DDO = await ocean.register(asset)
2018-10-16 14:56:18 +02:00
2018-11-05 10:01:58 +01:00
assert(ddo.id.startsWith("did:op:"))
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.searchAssets(query)
assert(assets)
})
})
2018-10-05 12:34:18 +02:00
})