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

113 lines
2.8 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-10-16 14:56:18 +02:00
import ConfigProvider from "../../src/ConfigProvider"
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-17 18:24:01 +02:00
import Order from "../../src/ocean/Order"
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-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 testAsset: Asset
let testPublisher: Account
const name = "Test Asset 3"
const description = "This asset is pure owange"
const price = 100
const timeout = 100000000
2018-10-05 12:34:18 +02:00
describe("Ocean", () => {
2018-10-26 10:40:46 +02:00
before(async () => {
ConfigProvider.setConfig(config)
AquariusProvider.setAquarius(new AquariusMock())
await ContractHandler.deployContracts()
ocean = await Ocean.getInstance(config)
accounts = await ocean.getAccounts()
testPublisher = accounts[0]
testAsset = new Asset(name, description, price, testPublisher)
})
describe("#getInstance()", () => {
it("should list accounts", async () => {
const ocn = Ocean.getInstance(config)
assert(ocn)
})
})
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-10-17 18:24:01 +02:00
const assetId: string = await ocean.register(testAsset)
2018-10-16 14:56:18 +02:00
assert(assetId.length === 66)
assert(assetId.startsWith("0x"))
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("#getOrdersByConsumer()", () => {
2018-10-05 12:34:18 +02:00
2018-10-16 14:56:18 +02:00
it("should list orders", async () => {
2018-10-17 18:24:01 +02:00
const testConsumer = accounts[1]
const asset: Asset = new Asset("getOrdersByConsumer test", description, price, testPublisher)
await ocean.register(asset)
const order: Order = await asset.purchase(testConsumer, timeout)
const orders = await ocean.getOrdersByAccount(testConsumer)
2018-10-17 18:24:01 +02:00
assert(orders.length === 1)
assert(orders[0].getId() === order.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",
}
const assets: any[] = await ocean.searchAssets(query)
assert(assets)
})
})
2018-10-05 12:34:18 +02:00
})