2018-10-05 12:34:18 +02:00
|
|
|
import * as assert from "assert"
|
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-16 14:56:18 +02:00
|
|
|
import Logger from "../../src/utils/Logger"
|
|
|
|
import config from "../config"
|
2018-10-05 12:34:18 +02:00
|
|
|
|
|
|
|
let ocean: Ocean
|
2018-10-16 14:56:18 +02:00
|
|
|
let accounts: Account[]
|
2018-10-05 12:34:18 +02:00
|
|
|
|
|
|
|
before(async () => {
|
2018-10-16 14:56:18 +02:00
|
|
|
ConfigProvider.configure(config)
|
|
|
|
await ContractHandler.deployContracts()
|
2018-10-05 12:34:18 +02:00
|
|
|
ocean = await Ocean.getInstance(config)
|
2018-10-16 14:56:18 +02:00
|
|
|
accounts = await ocean.getAccounts()
|
2018-10-05 12:34:18 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
describe("Ocean", () => {
|
|
|
|
|
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 () => {
|
|
|
|
|
|
|
|
const publisher: Account = accounts[0]
|
2018-10-05 12:34:18 +02:00
|
|
|
|
2018-10-16 14:56:18 +02:00
|
|
|
const name = "Test Asset 3"
|
|
|
|
const description = "This asset is pure owange"
|
|
|
|
const price = 100
|
2018-10-05 12:34:18 +02:00
|
|
|
|
2018-10-16 14:56:18 +02:00
|
|
|
const asset = new Asset(name, description, price, publisher)
|
|
|
|
|
2018-10-17 10:41:56 +02:00
|
|
|
const assetId: string = await ocean.register(asset)
|
2018-10-16 14:56:18 +02:00
|
|
|
|
2018-10-17 10:41:56 +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 () => {
|
|
|
|
|
|
|
|
// todo
|
|
|
|
const orders = await ocean.getOrdersByConsumer(accounts[1])
|
|
|
|
Logger.log(orders)
|
2018-10-05 12:34:18 +02:00
|
|
|
})
|
2018-10-16 14:56:18 +02:00
|
|
|
|
2018-10-05 12:34:18 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
})
|