added searchAssets
This commit is contained in:
parent
b06cd5e303
commit
192eecc3ae
|
@ -6,7 +6,7 @@ export default class ConfigProvider {
|
|||
return ConfigProvider.config
|
||||
}
|
||||
|
||||
public static configure(config: Config) {
|
||||
public static setConfig(config: Config) {
|
||||
|
||||
ConfigProvider.config = config
|
||||
}
|
||||
|
|
|
@ -1,8 +1,17 @@
|
|||
import fetch from "node-fetch"
|
||||
import ConfigProvider from "../ConfigProvider"
|
||||
import Logger from "../utils/Logger"
|
||||
|
||||
export default class Aquarius {
|
||||
public static async getAccessUrl(accessToken: any, payload: any): Promise<string> {
|
||||
|
||||
private url: string
|
||||
|
||||
constructor() {
|
||||
|
||||
this.url = ConfigProvider.getConfig().aquariusUri
|
||||
}
|
||||
|
||||
public async getAccessUrl(accessToken: any, payload: any): Promise<string> {
|
||||
|
||||
const accessUrl = await fetch(`${accessToken.service_endpoint}/${accessToken.resource_id}`, {
|
||||
method: "POST",
|
||||
|
@ -27,4 +36,26 @@ export default class Aquarius {
|
|||
|
||||
return accessUrl
|
||||
}
|
||||
|
||||
public async queryMetadata(query): Promise<any[]> {
|
||||
|
||||
const result = await fetch(this.url + "/api/v1/aquarius/assets/metadata/query", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(query),
|
||||
headers: {
|
||||
"Content-type": "application/json",
|
||||
},
|
||||
})
|
||||
.then((response: any) => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
Logger.log("Failed: ", response.status, response.statusText)
|
||||
})
|
||||
.catch((error) => {
|
||||
Logger.error("Error fetching querying metdata: ", error)
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
import Aquarius from "./Aquarius"
|
||||
|
||||
export default class AquariusProvider {
|
||||
|
||||
public static setAquarius(aquarius) {
|
||||
public static setAquarius(aquarius: Aquarius) {
|
||||
|
||||
AquariusProvider.aquarius = aquarius
|
||||
}
|
||||
|
||||
public static getAquarius() {
|
||||
|
||||
if (!AquariusProvider.aquarius) {
|
||||
AquariusProvider.aquarius = new Aquarius()
|
||||
}
|
||||
return AquariusProvider.aquarius
|
||||
}
|
||||
|
||||
private static aquarius
|
||||
private static aquarius: Aquarius = null
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
export default class Config {
|
||||
public providerUri: string
|
||||
public aquariusUri: string
|
||||
public nodeUri: string
|
||||
public web3Provider: any
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import Aquarius from "../aquarius/Aquarius"
|
||||
import AquariusProvider from "../aquarius/AquariusProvider"
|
||||
import ConfigProvider from "../ConfigProvider"
|
||||
import Keeper from "../keeper/Keeper"
|
||||
|
@ -13,8 +12,7 @@ export default class Ocean {
|
|||
public static async getInstance(config) {
|
||||
|
||||
if (!Ocean.instance) {
|
||||
ConfigProvider.configure(config)
|
||||
AquariusProvider.setAquarius(Aquarius)
|
||||
ConfigProvider.setConfig(config)
|
||||
Ocean.instance = new Ocean(await Keeper.getInstance())
|
||||
}
|
||||
|
||||
|
@ -90,4 +88,8 @@ export default class Ocean {
|
|||
|
||||
return orders
|
||||
}
|
||||
|
||||
public async searchAssets(query): Promise<any[]> {
|
||||
return AquariusProvider.getAquarius().queryMetadata(query)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
import * as assert from "assert"
|
||||
import Aquarius from "../../src/aquarius/Aquarius"
|
||||
import ConfigProvider from "../../src/ConfigProvider"
|
||||
import config from "../config"
|
||||
|
||||
describe("Aquarius", () => {
|
||||
|
||||
before(() => {
|
||||
|
||||
ConfigProvider.setConfig(config)
|
||||
})
|
||||
|
||||
describe("#queryMetadata()queryMetadata", async () => {
|
||||
|
||||
const aquarius: Aquarius = new Aquarius()
|
||||
|
||||
const query = {
|
||||
offset: 100,
|
||||
page: 0,
|
||||
query: {
|
||||
value: 1,
|
||||
},
|
||||
sort: {
|
||||
value: 1,
|
||||
},
|
||||
text: "Office",
|
||||
}
|
||||
|
||||
const result: any[] = await aquarius.queryMetadata(query)
|
||||
assert(result)
|
||||
})
|
||||
|
||||
})
|
|
@ -1,5 +1,7 @@
|
|||
import Config from "../src/models/Config"
|
||||
|
||||
export default {
|
||||
aquariusUri: "http://localhost:5000",
|
||||
nodeUri: "http://localhost:8545",
|
||||
web3Provider: null,
|
||||
} as Config
|
||||
|
|
|
@ -5,14 +5,14 @@ import ContractBaseMock from "../mocks/ContractBase.Mock"
|
|||
|
||||
const wrappedContract = new ContractBaseMock("OceanToken")
|
||||
|
||||
before(async () => {
|
||||
ConfigProvider.configure(config)
|
||||
await ContractHandler.deployContracts()
|
||||
wrappedContract.initMock()
|
||||
})
|
||||
|
||||
describe("ContractWrapperBase", () => {
|
||||
|
||||
before(async () => {
|
||||
ConfigProvider.setConfig(config)
|
||||
await ContractHandler.deployContracts()
|
||||
wrappedContract.initMock()
|
||||
})
|
||||
|
||||
describe("#call()", () => {
|
||||
|
||||
it("should fail to call on an unknown contract function", (done) => {
|
||||
|
|
|
@ -3,13 +3,13 @@ import ConfigProvider from "../../src/ConfigProvider"
|
|||
import ContractHandler from "../../src/keeper/ContractHandler"
|
||||
import config from "../config"
|
||||
|
||||
before(async () => {
|
||||
ConfigProvider.configure(config)
|
||||
await ContractHandler.deployContracts()
|
||||
})
|
||||
|
||||
describe("ContractHandler", () => {
|
||||
|
||||
before(async () => {
|
||||
ConfigProvider.setConfig(config)
|
||||
await ContractHandler.deployContracts()
|
||||
})
|
||||
|
||||
describe("#get()", () => {
|
||||
|
||||
it("should load and get OceanToken correctly", async () => {
|
||||
|
|
|
@ -6,14 +6,14 @@ import config from "../config"
|
|||
|
||||
let keeper: Keeper
|
||||
|
||||
before(async () => {
|
||||
ConfigProvider.configure(config)
|
||||
await ContractHandler.deployContracts()
|
||||
keeper = await Keeper.getInstance()
|
||||
})
|
||||
|
||||
describe("Keeper", () => {
|
||||
|
||||
before(async () => {
|
||||
ConfigProvider.setConfig(config)
|
||||
await ContractHandler.deployContracts()
|
||||
keeper = await Keeper.getInstance()
|
||||
})
|
||||
|
||||
describe("public interface", () => {
|
||||
|
||||
it("should have market", () => {
|
||||
|
|
|
@ -2,7 +2,7 @@ import Aquarius from "../../src/aquarius/Aquarius"
|
|||
|
||||
export default class AquariusMock extends Aquarius {
|
||||
|
||||
public static async getAccessUrl(accessToken: any, payload: any): Promise<string> {
|
||||
public async getAccessUrl(accessToken: any, payload: any): Promise<string> {
|
||||
return "http://test/test"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,16 +9,16 @@ import config from "../config"
|
|||
let ocean: Ocean
|
||||
let accounts: Account[]
|
||||
|
||||
before(async () => {
|
||||
ConfigProvider.configure(config)
|
||||
await ContractHandler.deployContracts()
|
||||
ocean = await Ocean.getInstance(config)
|
||||
|
||||
accounts = await ocean.getAccounts()
|
||||
})
|
||||
|
||||
describe("Account", () => {
|
||||
|
||||
before(async () => {
|
||||
ConfigProvider.setConfig(config)
|
||||
await ContractHandler.deployContracts()
|
||||
ocean = await Ocean.getInstance(config)
|
||||
|
||||
accounts = await ocean.getAccounts()
|
||||
})
|
||||
|
||||
describe("#getOceanBalance()", () => {
|
||||
|
||||
it("should get initial ocean balance", async () => {
|
||||
|
|
|
@ -19,21 +19,21 @@ let testAsset: Asset
|
|||
let accounts: Account[]
|
||||
let testPublisher: Account
|
||||
|
||||
before(async () => {
|
||||
ConfigProvider.configure(config)
|
||||
AquariusProvider.setAquarius(AquariusMock)
|
||||
|
||||
await ContractHandler.deployContracts()
|
||||
ocean = await Ocean.getInstance(config)
|
||||
accounts = await ocean.getAccounts()
|
||||
testPublisher = accounts[0]
|
||||
testAsset = new Asset(testName, testDescription, testPrice, testPublisher)
|
||||
|
||||
await ocean.register(testAsset)
|
||||
})
|
||||
|
||||
describe("Asset", () => {
|
||||
|
||||
before(async () => {
|
||||
ConfigProvider.setConfig(config)
|
||||
AquariusProvider.setAquarius(new AquariusMock(config.aquariusUri))
|
||||
|
||||
await ContractHandler.deployContracts()
|
||||
ocean = await Ocean.getInstance(config)
|
||||
accounts = await ocean.getAccounts()
|
||||
testPublisher = accounts[0]
|
||||
testAsset = new Asset(testName, testDescription, testPrice, testPublisher)
|
||||
|
||||
await ocean.register(testAsset)
|
||||
})
|
||||
|
||||
describe("#purchase()", () => {
|
||||
|
||||
it("should purchase an asset", async () => {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import {assert} from "chai"
|
||||
import AquariusProvider from "../../src/aquarius/AquariusProvider"
|
||||
import ConfigProvider from "../../src/ConfigProvider"
|
||||
import ContractHandler from "../../src/keeper/ContractHandler"
|
||||
import Account from "../../src/ocean/Account"
|
||||
|
@ -6,6 +7,7 @@ import Asset from "../../src/ocean/Asset"
|
|||
import Ocean from "../../src/ocean/Ocean"
|
||||
import Order from "../../src/ocean/Order"
|
||||
import config from "../config"
|
||||
import AquariusMock from "../mocks/Aquarius.mock"
|
||||
|
||||
let ocean: Ocean
|
||||
let accounts: Account[]
|
||||
|
@ -17,18 +19,19 @@ const description = "This asset is pure owange"
|
|||
const price = 100
|
||||
const timeout = 100000000
|
||||
|
||||
before(async () => {
|
||||
ConfigProvider.configure(config)
|
||||
await ContractHandler.deployContracts()
|
||||
ocean = await Ocean.getInstance(config)
|
||||
accounts = await ocean.getAccounts()
|
||||
|
||||
testPublisher = accounts[0]
|
||||
testAsset = new Asset(name, description, price, testPublisher)
|
||||
})
|
||||
|
||||
describe("Ocean", () => {
|
||||
|
||||
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 () => {
|
||||
|
@ -84,4 +87,26 @@ describe("Ocean", () => {
|
|||
|
||||
})
|
||||
|
||||
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)
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import {assert} from "chai"
|
||||
import AquariusProvider from "../../src/aquarius/AquariusProvider"
|
||||
import ConfigProvider from "../../src/ConfigProvider"
|
||||
import ContractHandler from "../../src/keeper/ContractHandler"
|
||||
import AccessStatus from "../../src/models/AccessStatus"
|
||||
|
@ -7,6 +8,7 @@ import Asset from "../../src/ocean/Asset"
|
|||
import Ocean from "../../src/ocean/Ocean"
|
||||
import Order from "../../src/ocean/Order"
|
||||
import config from "../config"
|
||||
import AquariusMock from "../mocks/Aquarius.mock"
|
||||
|
||||
const testName = "Order Test Asset"
|
||||
const testDescription = "This asset is pure owange"
|
||||
|
@ -20,20 +22,21 @@ let accounts: Account[]
|
|||
let testPublisher: Account
|
||||
let testConsumer: Account
|
||||
|
||||
before(async () => {
|
||||
ConfigProvider.configure(config)
|
||||
await ContractHandler.deployContracts()
|
||||
ocean = await Ocean.getInstance(config)
|
||||
accounts = await ocean.getAccounts()
|
||||
testPublisher = accounts[0]
|
||||
testConsumer = accounts[1]
|
||||
// register an asset to play around with
|
||||
testAsset = new Asset(testName, testDescription, testPrice, testPublisher)
|
||||
await ocean.register(testAsset)
|
||||
})
|
||||
|
||||
describe("Order", () => {
|
||||
|
||||
before(async () => {
|
||||
ConfigProvider.setConfig(config)
|
||||
AquariusProvider.setAquarius(new AquariusMock())
|
||||
await ContractHandler.deployContracts()
|
||||
ocean = await Ocean.getInstance(config)
|
||||
accounts = await ocean.getAccounts()
|
||||
testPublisher = accounts[0]
|
||||
testConsumer = accounts[1]
|
||||
// register an asset to play around with
|
||||
testAsset = new Asset(testName, testDescription, testPrice, testPublisher)
|
||||
await ocean.register(testAsset)
|
||||
})
|
||||
|
||||
describe("#pay()", async () => {
|
||||
|
||||
it("should pay for an order", async () => {
|
||||
|
|
Loading…
Reference in New Issue