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

66 lines
2.4 KiB
TypeScript
Raw Normal View History

2018-10-18 09:19:10 +02:00
import {assert} from "chai"
2018-11-05 10:01:58 +01:00
import AquariusConnectorProvider from "../../src/aquarius/AquariusConnectorProvider"
2018-10-25 17:26:26 +02:00
import AquariusProvider from "../../src/aquarius/AquariusProvider"
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-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-11-05 14:56:14 +01:00
import ServiceAgreement from "../../src/ocean/ServiceAgreements/ServiceAgreement"
2018-10-30 08:30:05 +01:00
import SecretStoreProvider from "../../src/secretstore/SecretStoreProvider"
2018-10-16 14:56:18 +02:00
import config from "../config"
2018-10-25 17:26:26 +02:00
import AquariusMock from "../mocks/Aquarius.mock"
2018-11-05 10:01:58 +01:00
import AquariusConnectorMock from "../mocks/AquariusConnector.mock"
2018-10-26 13:53:57 +02:00
import SecretStoreMock from "../mocks/SecretStore.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-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-11-05 10:01:58 +01:00
let ddo: DDO
2018-10-09 15:24:36 +02:00
2018-10-26 10:40:46 +02:00
describe("Asset", () => {
2018-10-17 18:24:01 +02:00
before(async () => {
2018-10-26 10:40:46 +02:00
ConfigProvider.setConfig(config)
2018-10-26 11:57:26 +02:00
AquariusProvider.setAquarius(new AquariusMock(config))
2018-10-26 13:53:57 +02:00
SecretStoreProvider.setSecretStore(new SecretStoreMock(config))
await ContractHandler.deployContracts()
ocean = await Ocean.getInstance(config)
accounts = await ocean.getAccounts()
testPublisher = accounts[0]
testAsset = new Asset(testName, testDescription, testPrice, testPublisher)
2018-10-09 15:24:36 +02:00
2018-11-05 10:01:58 +01:00
ddo = await ocean.register(testAsset)
// @ts-ignore
AquariusConnectorProvider.setConnector(new AquariusConnectorMock(ddo))
})
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-26 12:16:40 +02:00
const consumerAccount = accounts[5]
2018-11-05 10:01:58 +01:00
const serviceAgreement: ServiceAgreement = await testAsset.purchase(consumerAccount)
assert(serviceAgreement)
})
it("should purchase an asset from two different customers", async () => {
const consumerAccount1 = accounts[5]
const serviceAgreement1: ServiceAgreement = await testAsset.purchase(consumerAccount1)
assert(serviceAgreement1)
const consumerAccount2 = accounts[6]
const serviceAgreement2: ServiceAgreement = await testAsset.purchase(consumerAccount2)
assert(serviceAgreement2)
2018-10-26 12:16:40 +02:00
})
2018-10-16 14:56:18 +02:00
})
2018-10-09 15:24:36 +02:00
})