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/Asset.test.ts

81 lines
2.7 KiB
TypeScript
Raw Normal View History

2018-10-18 09:19:10 +02:00
import {assert} from "chai"
2018-10-16 14:56:18 +02:00
import ConfigProvider from "../../src/ConfigProvider"
2018-10-09 15:24:36 +02:00
import ContractHandler from "../../src/keeper/ContractHandler"
import Account from "../../src/ocean/Account"
import Asset from "../../src/ocean/Asset"
2018-10-16 14:56:18 +02:00
import Ocean from "../../src/ocean/Ocean"
2018-10-17 10:12:40 +02:00
import Order from "../../src/ocean/Order"
2018-10-17 18:24:01 +02:00
import ProviderProvider from "../../src/provider/ProviderProvider"
2018-10-16 14:56:18 +02:00
import config from "../config"
2018-10-18 09:19:10 +02:00
import ProviderMock from "../mocks/Provider.Mock"
2018-10-09 15:24:36 +02:00
2018-10-16 14:56:18 +02:00
const testName = "Test Asset 2"
const testDescription = "This asset is pure owange"
const testPrice = 100
2018-10-17 18:24:01 +02:00
const timeout = 100000
const accessToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzM4NCJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE1Mzk3ODcxMDEsImV4cCI6NDcyNjk5NjcwNCwiYXVkIjoiIiwic3ViIjoiIiwic2VydmljZV9lbmRwb2ludCI6Imh0dHA6Ly9hZGFzZCIsInJlc291cmNlX2lkIjoiMTIzNDUifQ.2H3TRC3CAToVE9divSckwHi_HNvgOHKrtJPo8128qrKBHTk7YYb0UNfVCuYqwhGR"
2018-10-09 15:24:36 +02:00
2018-10-16 14:56:18 +02:00
let ocean: Ocean
let testAsset: Asset
let accounts: Account[]
let testPublisher: Account
2018-10-09 15:24:36 +02:00
before(async () => {
2018-10-16 14:56:18 +02:00
ConfigProvider.configure(config)
2018-10-18 09:19:10 +02:00
ProviderProvider.setProvider(ProviderMock)
2018-10-17 18:24:01 +02:00
2018-10-16 14:56:18 +02:00
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)
2018-10-09 15:24:36 +02:00
})
describe("Asset", () => {
2018-10-16 14:56:18 +02:00
describe("#isActive()", () => {
2018-10-09 15:24:36 +02:00
2018-10-16 14:56:18 +02:00
it("should return true on new asset", async () => {
2018-10-09 15:24:36 +02:00
2018-10-16 14:56:18 +02:00
const isAssetActive = await testAsset.isActive()
assert(true === isAssetActive)
})
2018-10-09 15:24:36 +02:00
2018-10-16 14:56:18 +02:00
it("should return false on unknown asset", async () => {
2018-10-09 15:24:36 +02:00
2018-10-16 14:56:18 +02:00
const isAssetActive = await new Asset(testName, testDescription, testPrice, testPublisher)
.isActive()
assert(false === isAssetActive)
2018-10-09 15:24:36 +02:00
})
})
2018-10-16 14:56:18 +02:00
describe("#purchase()", () => {
2018-10-09 15:24:36 +02:00
2018-10-16 14:56:18 +02:00
it("should purchase an asset", async () => {
2018-10-09 15:24:36 +02:00
2018-10-16 14:56:18 +02:00
// todo
2018-10-17 18:24:01 +02:00
const consumerAccount = accounts[5]
const order: Order = await testAsset.purchase(consumerAccount, timeout)
2018-10-17 10:12:40 +02:00
assert(order)
2018-10-09 15:24:36 +02:00
})
2018-10-16 14:56:18 +02:00
})
2018-10-09 15:24:36 +02:00
2018-10-17 18:24:01 +02:00
describe("#consume()", () => {
2018-10-09 15:24:36 +02:00
2018-10-17 18:24:01 +02:00
it("should consume an asset", async () => {
const consumerAccount = accounts[5]
await consumerAccount.requestTokens(testAsset.price)
// place order - consumer
const order: Order = await testAsset.purchase(consumerAccount, timeout)
// commit order - provider
await order.commit(accessToken)
// pay order - consumer
await order.pay(consumerAccount)
const url = await testAsset.consume(order, consumerAccount)
assert(url)
2018-10-09 15:24:36 +02:00
})
})
})