mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
format all the things
This commit is contained in:
parent
537b5a63ad
commit
b61822e30c
@ -1,6 +1,6 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "10"
|
||||
- '10'
|
||||
|
||||
services:
|
||||
- docker
|
||||
@ -42,9 +42,8 @@ notifications:
|
||||
|
||||
deploy:
|
||||
- provider: npm
|
||||
email: "devops@oceanprotocol.com"
|
||||
email: 'devops@oceanprotocol.com'
|
||||
api_key: ${NPM_TOKEN}
|
||||
skip_cleanup: true
|
||||
on:
|
||||
tags: true
|
||||
|
||||
|
@ -138,6 +138,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
||||
|
||||
> 8 April 2019
|
||||
|
||||
* First release
|
||||
|
||||
- Bump version 0.5.1 -> 0.5.2 [`#183`](https://github.com/oceanprotocol/squid-js/pull/183)
|
||||
- Use the new Aquarius response type. [`b8fec2d`](https://github.com/oceanprotocol/squid-js/commit/b8fec2d0844009944f6492aa62049e806a4286a1)
|
||||
- Add a integration test using the consumption of big files. [`6a98fc3`](https://github.com/oceanprotocol/squid-js/commit/6a98fc39cfc8b914c5c59f59242781fd56165856)
|
||||
|
18
README.md
18
README.md
@ -1,6 +1,6 @@
|
||||
[![banner](https://raw.githubusercontent.com/oceanprotocol/art/master/github/repo-banner%402x.png)](https://oceanprotocol.com)
|
||||
|
||||
# squid-js
|
||||
<h1 align="center">Squid-js</h1>
|
||||
|
||||
> 🦑 JavaScript client library for Ocean Protocol
|
||||
> [oceanprotocol.com](https://oceanprotocol.com)
|
||||
@ -9,7 +9,7 @@
|
||||
[![Travis (.com)](https://img.shields.io/travis/com/oceanprotocol/squid-js.svg)](https://travis-ci.com/oceanprotocol/squid-js)
|
||||
[![GitHub contributors](https://img.shields.io/github/contributors/oceanprotocol/squid-js.svg)](https://github.com/oceanprotocol/squid-js/graphs/contributors)
|
||||
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/8508313231b44b0997ec84898cd6f9db)](https://app.codacy.com/app/ocean-protocol/squid-js?utm_source=github.com&utm_medium=referral&utm_content=oceanprotocol/squid-js&utm_campaign=Badge_Grade_Settings)
|
||||
[![js oceanprotocol](https://img.shields.io/badge/js-oceanprotocol-7b1173.svg)](https://github.com/oceanprotocol/eslint-config-oceanprotocol)
|
||||
[![js oceanprotocol](https://img.shields.io/badge/js-oceanprotocol-7b1173.svg)](https://github.com/oceanprotocol/eslint-config-oceanprotocol)
|
||||
[![Greenkeeper badge](https://badges.greenkeeper.io/oceanprotocol/squid-js.svg)](https://greenkeeper.io/)
|
||||
|
||||
---
|
||||
@ -54,17 +54,17 @@ You can then connect to a running [Keeper](https://github.com/oceanprotocol/keep
|
||||
```js
|
||||
const ocean: Ocean = await Ocean.getInstance({
|
||||
// the node of the blockchain to connect to, could also be infura
|
||||
nodeUri: "http://localhost:8545",
|
||||
nodeUri: 'http://localhost:8545',
|
||||
// the uri of aquarius
|
||||
aquariusUri: "http://localhost:5000",
|
||||
aquariusUri: 'http://localhost:5000',
|
||||
// the uri of brizo
|
||||
brizoUri: "http://localhost:8030",
|
||||
brizoUri: 'http://localhost:8030',
|
||||
// address that brizo uses
|
||||
brizoAddress: "0x00bd138abd70e2f00903268f3db08f2d25677c9e"
|
||||
brizoAddress: '0x00bd138abd70e2f00903268f3db08f2d25677c9e'
|
||||
// the uri to the parity node you want to use for encryption and decryption
|
||||
parityUri: "http://localhost:9545",
|
||||
parityUri: 'http://localhost:9545',
|
||||
// the uri of the secret store that holds the keys
|
||||
secretStoreUri: "http://localhost:12001"
|
||||
secretStoreUri: 'http://localhost:12001'
|
||||
})
|
||||
```
|
||||
|
||||
@ -199,4 +199,4 @@ Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
limitations under the License.
|
||||
|
@ -1 +1 @@
|
||||
this document has been moved to [here](https://github.com/oceanprotocol/dev-ocean/blob/master/doc/architecture/squid.md).
|
||||
this document has been moved to [here](https://github.com/oceanprotocol/dev-ocean/blob/master/doc/architecture/squid.md).
|
||||
|
@ -1,32 +1,32 @@
|
||||
import * as HDWalletProvider from "truffle-hdwallet-provider"
|
||||
import { Config } from "../src"
|
||||
import * as HDWalletProvider from 'truffle-hdwallet-provider'
|
||||
import { Config } from '../src'
|
||||
|
||||
const configJson: Config = {
|
||||
nodeUri: "http://localhost:8545",
|
||||
aquariusUri: "http://172.15.0.15:5000",
|
||||
brizoUri: "http://localhost:8030",
|
||||
secretStoreUri: "http://localhost:12001",
|
||||
brizoAddress: "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e",
|
||||
verbose: false,
|
||||
nodeUri: 'http://localhost:8545',
|
||||
aquariusUri: 'http://172.15.0.15:5000',
|
||||
brizoUri: 'http://localhost:8030',
|
||||
secretStoreUri: 'http://localhost:12001',
|
||||
brizoAddress: '0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e',
|
||||
verbose: false
|
||||
}
|
||||
|
||||
if (process.env.NETWORK_NAME === "nile") {
|
||||
if (process.env.NETWORK_NAME === 'nile') {
|
||||
Object.assign(configJson, {
|
||||
nodeUri: "https://nile.dev-ocean.com",
|
||||
aquariusUri: "https://nginx-aquarius.dev-ocean.com",
|
||||
brizoUri: "https://nginx-brizo.dev-ocean.com",
|
||||
secretStoreUri: "https://secret-store.dev-ocean.com",
|
||||
brizoAddress: "0x413c9ba0a05b8a600899b41b0c62dd661e689354",
|
||||
nodeUri: 'https://nile.dev-ocean.com',
|
||||
aquariusUri: 'https://nginx-aquarius.dev-ocean.com',
|
||||
brizoUri: 'https://nginx-brizo.dev-ocean.com',
|
||||
secretStoreUri: 'https://secret-store.dev-ocean.com',
|
||||
brizoAddress: '0x413c9ba0a05b8a600899b41b0c62dd661e689354'
|
||||
})
|
||||
}
|
||||
|
||||
if (process.env.NETWORK_NAME === "duero") {
|
||||
if (process.env.NETWORK_NAME === 'duero') {
|
||||
Object.assign(configJson, {
|
||||
nodeUri: "https://duero.dev-ocean.com",
|
||||
aquariusUri: "https://aquarius.duero.dev-ocean.com",
|
||||
brizoUri: "https://brizo.duero.dev-ocean.com",
|
||||
secretStoreUri: "https://secret-store.duero.dev-ocean.com",
|
||||
brizoAddress: "0x9d4ed58293f71122ad6a733c1603927a150735d0",
|
||||
nodeUri: 'https://duero.dev-ocean.com',
|
||||
aquariusUri: 'https://aquarius.duero.dev-ocean.com',
|
||||
brizoUri: 'https://brizo.duero.dev-ocean.com',
|
||||
secretStoreUri: 'https://secret-store.duero.dev-ocean.com',
|
||||
brizoAddress: '0x9d4ed58293f71122ad6a733c1603927a150735d0'
|
||||
})
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ if (process.env.SEED_WORDS) {
|
||||
seedphrase,
|
||||
configJson.nodeUri,
|
||||
0,
|
||||
5,
|
||||
5
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { assert } from "chai"
|
||||
import { assert } from 'chai'
|
||||
|
||||
import { config } from "../config"
|
||||
import { config } from '../config'
|
||||
|
||||
import { getMetadata } from "../utils"
|
||||
import { getMetadata } from '../utils'
|
||||
|
||||
import { Ocean, Account } from "../../src" // @oceanprotocol/squid
|
||||
import { Ocean, Account } from '../../src' // @oceanprotocol/squid
|
||||
|
||||
describe("Asset Owners", () => {
|
||||
describe('Asset Owners', () => {
|
||||
let ocean: Ocean
|
||||
|
||||
let account1: Account
|
||||
@ -23,7 +23,7 @@ describe("Asset Owners", () => {
|
||||
account2 = accounts[1]
|
||||
})
|
||||
|
||||
it("should be set correctly the owner of a asset", async () => {
|
||||
it('should be set correctly the owner of a asset', async () => {
|
||||
const ddo = await ocean.assets.create(metadata as any, account1)
|
||||
|
||||
const owner = await ocean.assets.owner(ddo.id)
|
||||
@ -31,33 +31,49 @@ describe("Asset Owners", () => {
|
||||
assert.equal(owner, account1.getId())
|
||||
})
|
||||
|
||||
it("should get the assets owned by a user", async () => {
|
||||
const {length: initialLength} = await ocean.assets.ownerAssets(account2.getId())
|
||||
it('should get the assets owned by a user', async () => {
|
||||
const { length: initialLength } = await ocean.assets.ownerAssets(
|
||||
account2.getId()
|
||||
)
|
||||
|
||||
await ocean.assets.create(metadata as any, account1)
|
||||
await ocean.assets.create(metadata as any, account1)
|
||||
|
||||
await ocean.assets.create(metadata as any, account2)
|
||||
|
||||
const {length: finalLength} = await ocean.assets.ownerAssets(account2.getId())
|
||||
const { length: finalLength } = await ocean.assets.ownerAssets(
|
||||
account2.getId()
|
||||
)
|
||||
|
||||
assert.equal(finalLength - initialLength, 1)
|
||||
})
|
||||
|
||||
it("should get the assets that can be consumer by a user", async () => {
|
||||
const {length: initialLength} = await ocean.assets.consumerAssets(account2.getId())
|
||||
it('should get the assets that can be consumer by a user', async () => {
|
||||
const { length: initialLength } = await ocean.assets.consumerAssets(
|
||||
account2.getId()
|
||||
)
|
||||
|
||||
const ddo = await ocean.assets.create(metadata as any, account1)
|
||||
|
||||
const {length: finalLength1} = await ocean.assets.consumerAssets(account2.getId())
|
||||
const { length: finalLength1 } = await ocean.assets.consumerAssets(
|
||||
account2.getId()
|
||||
)
|
||||
assert.equal(finalLength1 - initialLength, 0)
|
||||
|
||||
// Granting access
|
||||
await account2.requestTokens(+metadata.base.price * (10 ** -await ocean.keeper.token.decimals()))
|
||||
await ocean.assets.order(ddo.id, ddo.findServiceByType("Access").serviceDefinitionId, account2)
|
||||
await account2.requestTokens(
|
||||
+metadata.base.price * 10 ** -(await ocean.keeper.token.decimals())
|
||||
)
|
||||
await ocean.assets.order(
|
||||
ddo.id,
|
||||
ddo.findServiceByType('Access').serviceDefinitionId,
|
||||
account2
|
||||
)
|
||||
// Access granted
|
||||
|
||||
const {length: finalLength2} = await ocean.assets.consumerAssets(account2.getId())
|
||||
const { length: finalLength2 } = await ocean.assets.consumerAssets(
|
||||
account2.getId()
|
||||
)
|
||||
assert.equal(finalLength2 - initialLength, 1)
|
||||
})
|
||||
})
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { assert } from "chai"
|
||||
import { assert } from 'chai'
|
||||
|
||||
import { config } from "../config"
|
||||
import { config } from '../config'
|
||||
|
||||
import { Ocean, Account } from "../../src" // @oceanprotocol/squid
|
||||
import { Ocean, Account } from '../../src' // @oceanprotocol/squid
|
||||
|
||||
describe("Authentication Token", () => {
|
||||
describe('Authentication Token', () => {
|
||||
let ocean: Ocean
|
||||
|
||||
let account1: Account
|
||||
@ -13,7 +13,7 @@ describe("Authentication Token", () => {
|
||||
before(async () => {
|
||||
try {
|
||||
localStorage.clear()
|
||||
} catch { }
|
||||
} catch {}
|
||||
|
||||
ocean = await Ocean.getInstance(config)
|
||||
|
||||
@ -23,13 +23,13 @@ describe("Authentication Token", () => {
|
||||
account2 = accounts[1]
|
||||
})
|
||||
|
||||
it("should generate a token", async () => {
|
||||
it('should generate a token', async () => {
|
||||
const token = await ocean.auth.get(account1)
|
||||
|
||||
assert.match(token, /^0x[a-f0-9]{130}-[0-9]{0,14}/i)
|
||||
})
|
||||
|
||||
it("should return the account that signed the token", async () => {
|
||||
it('should return the account that signed the token', async () => {
|
||||
const token = await ocean.auth.get(account1)
|
||||
|
||||
const address = await ocean.auth.check(token)
|
||||
@ -37,7 +37,7 @@ describe("Authentication Token", () => {
|
||||
assert.equal(address, account1.getId())
|
||||
})
|
||||
|
||||
it("should store the token for a user", async () => {
|
||||
it('should store the token for a user', async () => {
|
||||
assert.isUndefined(await account1.getToken())
|
||||
|
||||
await ocean.auth.store(account1)
|
||||
@ -45,19 +45,19 @@ describe("Authentication Token", () => {
|
||||
assert.match(await account1.getToken(), /^0x[a-f0-9]{130}-[0-9]{0,14}/i)
|
||||
})
|
||||
|
||||
it("should restore the token for a user", async () => {
|
||||
it('should restore the token for a user', async () => {
|
||||
const token = await ocean.auth.restore(account1)
|
||||
|
||||
assert.match(token, /^0x[a-f0-9]{130}-[0-9]{0,14}/i)
|
||||
})
|
||||
|
||||
it("should return undefined when is not stored", async () => {
|
||||
it('should return undefined when is not stored', async () => {
|
||||
const token = await ocean.auth.restore(account2)
|
||||
|
||||
assert.isUndefined(token)
|
||||
})
|
||||
|
||||
it("should know if the token is stored", async () => {
|
||||
it('should know if the token is stored', async () => {
|
||||
let acc1Stored
|
||||
let acc2Stored
|
||||
acc1Stored = await ocean.auth.isStored(account1)
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { assert } from "chai"
|
||||
import * as fs from "fs"
|
||||
import { assert } from 'chai'
|
||||
import * as fs from 'fs'
|
||||
|
||||
import { config } from "../config"
|
||||
import { getMetadata } from "../utils"
|
||||
import { config } from '../config'
|
||||
import { getMetadata } from '../utils'
|
||||
|
||||
import { Ocean, DDO, Account, ConditionState } from "../../src" // @oceanprotocol/squid
|
||||
import { Ocean, DDO, Account, ConditionState } from '../../src' // @oceanprotocol/squid
|
||||
|
||||
describe("Consume Asset", () => {
|
||||
describe('Consume Asset', () => {
|
||||
let ocean: Ocean
|
||||
|
||||
let publisher: Account
|
||||
@ -15,7 +15,10 @@ describe("Consume Asset", () => {
|
||||
const metadata = getMetadata()
|
||||
|
||||
let ddo: DDO
|
||||
let serviceAgreementSignatureResult: {agreementId: string, signature: string}
|
||||
let serviceAgreementSignatureResult: {
|
||||
agreementId: string
|
||||
signature: string
|
||||
}
|
||||
|
||||
before(async () => {
|
||||
ocean = await Ocean.getInstance(config)
|
||||
@ -25,35 +28,59 @@ describe("Consume Asset", () => {
|
||||
consumer = (await ocean.accounts.list())[1]
|
||||
})
|
||||
|
||||
it("should regiester a asset", async () => {
|
||||
it('should regiester a asset', async () => {
|
||||
ddo = await ocean.assets.create(metadata as any, publisher)
|
||||
|
||||
assert.isDefined(ddo, "Register has not returned a DDO")
|
||||
assert.match(ddo.id, /^did:op:[a-f0-9]{64}$/, "DDO id is not valid")
|
||||
assert.isAtLeast(ddo.authentication.length, 1, "Default authentication not added")
|
||||
assert.isDefined(ddo.findServiceByType("Access"), "DDO Access service doesn't exist")
|
||||
assert.isDefined(ddo, 'Register has not returned a DDO')
|
||||
assert.match(ddo.id, /^did:op:[a-f0-9]{64}$/, 'DDO id is not valid')
|
||||
assert.isAtLeast(
|
||||
ddo.authentication.length,
|
||||
1,
|
||||
'Default authentication not added'
|
||||
)
|
||||
assert.isDefined(
|
||||
ddo.findServiceByType('Access'),
|
||||
"DDO Access service doesn't exist"
|
||||
)
|
||||
})
|
||||
|
||||
it("should be able to request tokens for consumer", async () => {
|
||||
it('should be able to request tokens for consumer', async () => {
|
||||
const initialBalance = (await consumer.getBalance()).ocn
|
||||
const claimedTokens = +metadata.base.price * (10 ** -await ocean.keeper.token.decimals())
|
||||
const claimedTokens =
|
||||
+metadata.base.price * 10 ** -(await ocean.keeper.token.decimals())
|
||||
await consumer.requestTokens(claimedTokens)
|
||||
|
||||
assert.equal((await consumer.getBalance()).ocn, initialBalance + claimedTokens, "OCN Tokens not delivered")
|
||||
assert.equal(
|
||||
(await consumer.getBalance()).ocn,
|
||||
initialBalance + claimedTokens,
|
||||
'OCN Tokens not delivered'
|
||||
)
|
||||
})
|
||||
|
||||
it("should sign the service agreement", async () => {
|
||||
const accessService = ddo.findServiceByType("Access")
|
||||
it('should sign the service agreement', async () => {
|
||||
const accessService = ddo.findServiceByType('Access')
|
||||
|
||||
serviceAgreementSignatureResult = await ocean.agreements.prepare(ddo.id, accessService.serviceDefinitionId, consumer)
|
||||
serviceAgreementSignatureResult = await ocean.agreements.prepare(
|
||||
ddo.id,
|
||||
accessService.serviceDefinitionId,
|
||||
consumer
|
||||
)
|
||||
|
||||
const {agreementId, signature} = serviceAgreementSignatureResult
|
||||
assert.match(agreementId, /^0x[a-f0-9]{64}$/, "Service agreement ID seems not valid")
|
||||
assert.match(signature, /^0x[a-f0-9]{130}$/, "Service agreement signature seems not valid")
|
||||
const { agreementId, signature } = serviceAgreementSignatureResult
|
||||
assert.match(
|
||||
agreementId,
|
||||
/^0x[a-f0-9]{64}$/,
|
||||
'Service agreement ID seems not valid'
|
||||
)
|
||||
assert.match(
|
||||
signature,
|
||||
/^0x[a-f0-9]{130}$/,
|
||||
'Service agreement signature seems not valid'
|
||||
)
|
||||
})
|
||||
|
||||
it("should execute the service agreement", async () => {
|
||||
const accessService = ddo.findServiceByType("Access")
|
||||
it('should execute the service agreement', async () => {
|
||||
const accessService = ddo.findServiceByType('Access')
|
||||
|
||||
const success = await ocean.agreements.create(
|
||||
ddo.id,
|
||||
@ -61,103 +88,115 @@ describe("Consume Asset", () => {
|
||||
accessService.serviceDefinitionId,
|
||||
serviceAgreementSignatureResult.signature,
|
||||
consumer,
|
||||
publisher,
|
||||
publisher
|
||||
)
|
||||
|
||||
assert.isTrue(success)
|
||||
})
|
||||
|
||||
it("should get the agreement conditions status not fulfilled", async () => {
|
||||
const status = await ocean.agreements.status(serviceAgreementSignatureResult.agreementId)
|
||||
it('should get the agreement conditions status not fulfilled', async () => {
|
||||
const status = await ocean.agreements.status(
|
||||
serviceAgreementSignatureResult.agreementId
|
||||
)
|
||||
|
||||
assert.deepEqual(status, {
|
||||
lockReward: ConditionState.Unfulfilled,
|
||||
accessSecretStore: ConditionState.Unfulfilled,
|
||||
escrowReward: ConditionState.Unfulfilled,
|
||||
escrowReward: ConditionState.Unfulfilled
|
||||
})
|
||||
})
|
||||
|
||||
it("should lock the payment by the consumer", async () => {
|
||||
const paid = await ocean.agreements.conditions
|
||||
.lockReward(
|
||||
serviceAgreementSignatureResult.agreementId,
|
||||
ddo.findServiceByType("Metadata").metadata.base.price,
|
||||
consumer,
|
||||
)
|
||||
it('should lock the payment by the consumer', async () => {
|
||||
const paid = await ocean.agreements.conditions.lockReward(
|
||||
serviceAgreementSignatureResult.agreementId,
|
||||
ddo.findServiceByType('Metadata').metadata.base.price,
|
||||
consumer
|
||||
)
|
||||
|
||||
assert.isTrue(paid, "The asset has not been paid correctly")
|
||||
assert.isTrue(paid, 'The asset has not been paid correctly')
|
||||
})
|
||||
|
||||
// The test will fail because Brizo grants the access faster
|
||||
it("should grant the access by the publisher", async () => {
|
||||
it('should grant the access by the publisher', async () => {
|
||||
try {
|
||||
const granted = await ocean.agreements.conditions
|
||||
.grantAccess(serviceAgreementSignatureResult.agreementId, ddo.id, consumer.getId(), publisher)
|
||||
const granted = await ocean.agreements.conditions.grantAccess(
|
||||
serviceAgreementSignatureResult.agreementId,
|
||||
ddo.id,
|
||||
consumer.getId(),
|
||||
publisher
|
||||
)
|
||||
|
||||
assert.isTrue(granted, "The asset has not been granted correctly")
|
||||
assert.isTrue(granted, 'The asset has not been granted correctly')
|
||||
|
||||
const accessGranted = await ocean.keeper.conditions
|
||||
.accessSecretStoreCondition
|
||||
.checkPermissions(consumer.getId(), ddo.id)
|
||||
const accessGranted = await ocean.keeper.conditions.accessSecretStoreCondition.checkPermissions(
|
||||
consumer.getId(),
|
||||
ddo.id
|
||||
)
|
||||
|
||||
assert.isTrue(accessGranted, "Consumer has been granted.")
|
||||
} catch { }
|
||||
assert.isTrue(accessGranted, 'Consumer has been granted.')
|
||||
} catch {}
|
||||
})
|
||||
|
||||
it("should get the agreement conditions status fulfilled", async () => {
|
||||
const status = await ocean.agreements.status(serviceAgreementSignatureResult.agreementId)
|
||||
it('should get the agreement conditions status fulfilled', async () => {
|
||||
const status = await ocean.agreements.status(
|
||||
serviceAgreementSignatureResult.agreementId
|
||||
)
|
||||
|
||||
assert.deepEqual(status, {
|
||||
lockReward: ConditionState.Fulfilled,
|
||||
accessSecretStore: ConditionState.Fulfilled,
|
||||
escrowReward: ConditionState.Unfulfilled,
|
||||
escrowReward: ConditionState.Unfulfilled
|
||||
})
|
||||
})
|
||||
|
||||
it("should consume and store the assets", async () => {
|
||||
const accessService = ddo.findServiceByType("Access")
|
||||
it('should consume and store the assets', async () => {
|
||||
const accessService = ddo.findServiceByType('Access')
|
||||
|
||||
const folder = "/tmp/ocean/squid-js-1"
|
||||
const folder = '/tmp/ocean/squid-js-1'
|
||||
const path = await ocean.assets.consume(
|
||||
serviceAgreementSignatureResult.agreementId,
|
||||
ddo.id,
|
||||
accessService.serviceDefinitionId,
|
||||
consumer,
|
||||
folder
|
||||
)
|
||||
|
||||
assert.include(path, folder, 'The storage path is not correct.')
|
||||
|
||||
const files = await new Promise<string[]>(resolve => {
|
||||
fs.readdir(path, (err, fileList) => {
|
||||
resolve(fileList)
|
||||
})
|
||||
})
|
||||
|
||||
assert.deepEqual(
|
||||
files,
|
||||
['README.md', 'package.json'],
|
||||
'Stored files are not correct.'
|
||||
)
|
||||
})
|
||||
|
||||
it('should consume and store one assets', async () => {
|
||||
const accessService = ddo.findServiceByType('Access')
|
||||
|
||||
const folder = '/tmp/ocean/squid-js-2'
|
||||
const path = await ocean.assets.consume(
|
||||
serviceAgreementSignatureResult.agreementId,
|
||||
ddo.id,
|
||||
accessService.serviceDefinitionId,
|
||||
consumer,
|
||||
folder,
|
||||
1
|
||||
)
|
||||
|
||||
assert.include(path, folder, "The storage path is not correct.")
|
||||
assert.include(path, folder, 'The storage path is not correct.')
|
||||
|
||||
const files = await new Promise<string[]>((resolve) => {
|
||||
const files = await new Promise<string[]>(resolve => {
|
||||
fs.readdir(path, (err, fileList) => {
|
||||
resolve(fileList)
|
||||
})
|
||||
})
|
||||
|
||||
assert.deepEqual(files, ["README.md", "package.json"], "Stored files are not correct.")
|
||||
})
|
||||
|
||||
it("should consume and store one assets", async () => {
|
||||
const accessService = ddo.findServiceByType("Access")
|
||||
|
||||
const folder = "/tmp/ocean/squid-js-2"
|
||||
const path = await ocean.assets.consume(
|
||||
serviceAgreementSignatureResult.agreementId,
|
||||
ddo.id,
|
||||
accessService.serviceDefinitionId,
|
||||
consumer,
|
||||
folder,
|
||||
1,
|
||||
)
|
||||
|
||||
assert.include(path, folder, "The storage path is not correct.")
|
||||
|
||||
const files = await new Promise<string[]>((resolve) => {
|
||||
fs.readdir(path, (err, fileList) => {
|
||||
resolve(fileList)
|
||||
})
|
||||
})
|
||||
|
||||
assert.deepEqual(files, ["README.md"], "Stored files are not correct.")
|
||||
assert.deepEqual(files, ['README.md'], 'Stored files are not correct.')
|
||||
})
|
||||
})
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { assert } from "chai"
|
||||
import * as fs from "fs"
|
||||
import { assert } from 'chai'
|
||||
import * as fs from 'fs'
|
||||
|
||||
import { config } from "../config"
|
||||
import { getMetadata } from "../utils"
|
||||
import { config } from '../config'
|
||||
import { getMetadata } from '../utils'
|
||||
|
||||
import { Ocean, Account, DDO } from "../../src" // @oceanprotocol/squid
|
||||
import { Ocean, Account, DDO } from '../../src' // @oceanprotocol/squid
|
||||
|
||||
describe("Consume Asset (Brizo)", () => {
|
||||
describe('Consume Asset (Brizo)', () => {
|
||||
let ocean: Ocean
|
||||
|
||||
let publisher: Account
|
||||
@ -28,50 +28,64 @@ describe("Consume Asset (Brizo)", () => {
|
||||
after(() => {
|
||||
try {
|
||||
localStorage.clear()
|
||||
} catch { }
|
||||
} catch {}
|
||||
})
|
||||
|
||||
it("should authenticate the accounts", async () => {
|
||||
it('should authenticate the accounts', async () => {
|
||||
await publisher.authenticate()
|
||||
await consumer.authenticate()
|
||||
})
|
||||
|
||||
it("should regiester an asset", async () => {
|
||||
it('should regiester an asset', async () => {
|
||||
const steps = []
|
||||
ddo = await ocean.assets.create(metadata as any, publisher)
|
||||
.next((step) => steps.push(step))
|
||||
ddo = await ocean.assets
|
||||
.create(metadata as any, publisher)
|
||||
.next(step => steps.push(step))
|
||||
|
||||
assert.instanceOf(ddo, DDO)
|
||||
assert.deepEqual(steps, [0, 1, 2, 3, 4, 5, 6, 7])
|
||||
})
|
||||
|
||||
it("should order the asset", async () => {
|
||||
const accessService = ddo.findServiceByType("Access")
|
||||
it('should order the asset', async () => {
|
||||
const accessService = ddo.findServiceByType('Access')
|
||||
|
||||
await consumer.requestTokens(+metadata.base.price * (10 ** -await ocean.keeper.token.decimals()))
|
||||
await consumer.requestTokens(
|
||||
+metadata.base.price * 10 ** -(await ocean.keeper.token.decimals())
|
||||
)
|
||||
|
||||
const steps = []
|
||||
agreementId = await ocean.assets.order(ddo.id, accessService.serviceDefinitionId, consumer)
|
||||
.next((step) => steps.push(step))
|
||||
agreementId = await ocean.assets
|
||||
.order(ddo.id, accessService.serviceDefinitionId, consumer)
|
||||
.next(step => steps.push(step))
|
||||
|
||||
assert.isDefined(agreementId)
|
||||
assert.deepEqual(steps, [0, 1, 2, 3])
|
||||
})
|
||||
|
||||
it("should consume and store the assets", async () => {
|
||||
const accessService = ddo.findServiceByType("Access")
|
||||
it('should consume and store the assets', async () => {
|
||||
const accessService = ddo.findServiceByType('Access')
|
||||
|
||||
const folder = "/tmp/ocean/squid-js"
|
||||
const path = await ocean.assets.consume(agreementId, ddo.id, accessService.serviceDefinitionId, consumer, folder)
|
||||
const folder = '/tmp/ocean/squid-js'
|
||||
const path = await ocean.assets.consume(
|
||||
agreementId,
|
||||
ddo.id,
|
||||
accessService.serviceDefinitionId,
|
||||
consumer,
|
||||
folder
|
||||
)
|
||||
|
||||
assert.include(path, folder, "The storage path is not correct.")
|
||||
assert.include(path, folder, 'The storage path is not correct.')
|
||||
|
||||
const files = await new Promise<string[]>((resolve) => {
|
||||
const files = await new Promise<string[]>(resolve => {
|
||||
fs.readdir(path, (err, fileList) => {
|
||||
resolve(fileList)
|
||||
})
|
||||
})
|
||||
|
||||
assert.deepEqual(files, ["README.md", "package.json"], "Stored files are not correct.")
|
||||
assert.deepEqual(
|
||||
files,
|
||||
['README.md', 'package.json'],
|
||||
'Stored files are not correct.'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { assert } from "chai"
|
||||
import * as fs from "fs"
|
||||
import { assert } from 'chai'
|
||||
import * as fs from 'fs'
|
||||
|
||||
import { config } from "../config"
|
||||
import { getMetadata } from "../utils"
|
||||
import { config } from '../config'
|
||||
import { getMetadata } from '../utils'
|
||||
|
||||
import { Ocean, Account, DDO } from "../../src" // @oceanprotocol/squid
|
||||
import { Ocean, Account, DDO } from '../../src' // @oceanprotocol/squid
|
||||
|
||||
// Ensure that your network is fast enought and you have some free ram before run it.
|
||||
xdescribe("Consume Asset (Large size)", () => {
|
||||
xdescribe('Consume Asset (Large size)', () => {
|
||||
let ocean: Ocean
|
||||
|
||||
let publisher: Account
|
||||
@ -21,10 +21,12 @@ xdescribe("Consume Asset (Large size)", () => {
|
||||
...baseMetadata,
|
||||
base: {
|
||||
...baseMetadata.base,
|
||||
files: [{
|
||||
url: "https://speed.hetzner.de/1GB.bin",
|
||||
}],
|
||||
},
|
||||
files: [
|
||||
{
|
||||
url: 'https://speed.hetzner.de/1GB.bin'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
before(async () => {
|
||||
@ -35,36 +37,46 @@ xdescribe("Consume Asset (Large size)", () => {
|
||||
consumer = (await ocean.accounts.list())[1]
|
||||
})
|
||||
|
||||
it("should regiester an asset", async () => {
|
||||
it('should regiester an asset', async () => {
|
||||
ddo = await ocean.assets.create(metadata as any, publisher)
|
||||
|
||||
assert.instanceOf(ddo, DDO)
|
||||
})
|
||||
|
||||
it("should order the asset", async () => {
|
||||
const accessService = ddo.findServiceByType("Access")
|
||||
it('should order the asset', async () => {
|
||||
const accessService = ddo.findServiceByType('Access')
|
||||
|
||||
await consumer.requestTokens(metadata.base.price)
|
||||
|
||||
agreementId = await ocean.assets.order(ddo.id, accessService.serviceDefinitionId, consumer)
|
||||
agreementId = await ocean.assets.order(
|
||||
ddo.id,
|
||||
accessService.serviceDefinitionId,
|
||||
consumer
|
||||
)
|
||||
|
||||
assert.isDefined(agreementId)
|
||||
})
|
||||
|
||||
it("should consume and store the assets", async () => {
|
||||
const accessService = ddo.findServiceByType("Access")
|
||||
it('should consume and store the assets', async () => {
|
||||
const accessService = ddo.findServiceByType('Access')
|
||||
|
||||
const folder = "/tmp/ocean/squid-js"
|
||||
const path = await ocean.assets.consume(agreementId, ddo.id, accessService.serviceDefinitionId, consumer, folder)
|
||||
const folder = '/tmp/ocean/squid-js'
|
||||
const path = await ocean.assets.consume(
|
||||
agreementId,
|
||||
ddo.id,
|
||||
accessService.serviceDefinitionId,
|
||||
consumer,
|
||||
folder
|
||||
)
|
||||
|
||||
assert.include(path, folder, "The storage path is not correct.")
|
||||
assert.include(path, folder, 'The storage path is not correct.')
|
||||
|
||||
const files = await new Promise<string[]>((resolve) => {
|
||||
const files = await new Promise<string[]>(resolve => {
|
||||
fs.readdir(path, (err, fileList) => {
|
||||
resolve(fileList)
|
||||
})
|
||||
})
|
||||
|
||||
assert.deepEqual(files, ["1GB.bin"], "Stored files are not correct.")
|
||||
assert.deepEqual(files, ['1GB.bin'], 'Stored files are not correct.')
|
||||
})
|
||||
})
|
||||
|
@ -1,19 +1,23 @@
|
||||
import { assert } from "chai"
|
||||
import { assert } from 'chai'
|
||||
|
||||
import { config } from "../config"
|
||||
import { config } from '../config'
|
||||
|
||||
import { Ocean, templates, conditions, utils, Account, Keeper } from "../../src" // @oceanprotocol/squid
|
||||
import { Ocean, templates, conditions, utils, Account, Keeper } from '../../src' // @oceanprotocol/squid
|
||||
|
||||
const { LockRewardCondition, EscrowReward, AccessSecretStoreCondition } = conditions
|
||||
const {
|
||||
LockRewardCondition,
|
||||
EscrowReward,
|
||||
AccessSecretStoreCondition
|
||||
} = conditions
|
||||
|
||||
describe("Register Escrow Access Secret Store Template", () => {
|
||||
describe('Register Escrow Access Secret Store Template', () => {
|
||||
let ocean: Ocean
|
||||
let keeper: Keeper
|
||||
|
||||
let template: templates.EscrowAccessSecretStoreTemplate
|
||||
|
||||
const url = "https://example.com/did/ocean/test-attr-example.txt"
|
||||
const checksum = "b".repeat(32)
|
||||
const url = 'https://example.com/did/ocean/test-attr-example.txt'
|
||||
const checksum = 'b'.repeat(32)
|
||||
const escrowAmount = 12
|
||||
|
||||
let templateManagerOwner: Account
|
||||
@ -36,26 +40,35 @@ describe("Register Escrow Access Secret Store Template", () => {
|
||||
consumer = (await ocean.accounts.list())[2]
|
||||
|
||||
// Conditions
|
||||
accessSecretStoreCondition = keeper.conditions.accessSecretStoreCondition
|
||||
accessSecretStoreCondition =
|
||||
keeper.conditions.accessSecretStoreCondition
|
||||
lockRewardCondition = keeper.conditions.lockRewardCondition
|
||||
escrowReward = keeper.conditions.escrowReward
|
||||
})
|
||||
|
||||
describe("Propose and approve template", () => {
|
||||
it("should propose the template", async () => {
|
||||
await keeper.templateStoreManager.proposeTemplate(template.getAddress(), consumer.getId(), true)
|
||||
describe('Propose and approve template', () => {
|
||||
it('should propose the template', async () => {
|
||||
await keeper.templateStoreManager.proposeTemplate(
|
||||
template.getAddress(),
|
||||
consumer.getId(),
|
||||
true
|
||||
)
|
||||
// TODO: Use a event to detect template mined
|
||||
await new Promise((_) => setTimeout(_, 2 * 1000))
|
||||
await new Promise(_ => setTimeout(_, 2 * 1000))
|
||||
})
|
||||
|
||||
it("should approve the template", async () => {
|
||||
await keeper.templateStoreManager.approveTemplate(template.getAddress(), templateManagerOwner.getId(), true)
|
||||
it('should approve the template', async () => {
|
||||
await keeper.templateStoreManager.approveTemplate(
|
||||
template.getAddress(),
|
||||
templateManagerOwner.getId(),
|
||||
true
|
||||
)
|
||||
// TODO: Use a event to detect template mined
|
||||
await new Promise((_) => setTimeout(_, 2 * 1000))
|
||||
await new Promise(_ => setTimeout(_, 2 * 1000))
|
||||
})
|
||||
})
|
||||
|
||||
describe("Full flow", () => {
|
||||
describe('Full flow', () => {
|
||||
const agreementId = `0x${utils.generateId()}`
|
||||
const did = `0x${utils.generateId()}`
|
||||
|
||||
@ -63,49 +76,76 @@ describe("Register Escrow Access Secret Store Template", () => {
|
||||
let conditionIdLock: string
|
||||
let conditionIdEscrow: string
|
||||
|
||||
it("should register a DID", async () => {
|
||||
await keeper.didRegistry.registerAttribute(did, checksum, [], url, publisher.getId())
|
||||
it('should register a DID', async () => {
|
||||
await keeper.didRegistry.registerAttribute(
|
||||
did,
|
||||
checksum,
|
||||
[],
|
||||
url,
|
||||
publisher.getId()
|
||||
)
|
||||
})
|
||||
|
||||
it("should generate the condition IDs", async () => {
|
||||
conditionIdAccess = await accessSecretStoreCondition.generateIdHash(agreementId, did, consumer.getId())
|
||||
conditionIdLock = await lockRewardCondition.generateIdHash(agreementId, await escrowReward.getAddress(), escrowAmount)
|
||||
it('should generate the condition IDs', async () => {
|
||||
conditionIdAccess = await accessSecretStoreCondition.generateIdHash(
|
||||
agreementId,
|
||||
did,
|
||||
consumer.getId()
|
||||
)
|
||||
conditionIdLock = await lockRewardCondition.generateIdHash(
|
||||
agreementId,
|
||||
await escrowReward.getAddress(),
|
||||
escrowAmount
|
||||
)
|
||||
conditionIdEscrow = await escrowReward.generateIdHash(
|
||||
agreementId,
|
||||
escrowAmount,
|
||||
publisher.getId(),
|
||||
consumer.getId(),
|
||||
conditionIdLock,
|
||||
conditionIdAccess,
|
||||
conditionIdAccess
|
||||
)
|
||||
})
|
||||
|
||||
it("should have conditions types", async () => {
|
||||
it('should have conditions types', async () => {
|
||||
const conditionTypes = await template.getConditionTypes()
|
||||
|
||||
assert.equal(conditionTypes.length, 3, "Expected 3 conditions.")
|
||||
assert.equal(conditionTypes.length, 3, 'Expected 3 conditions.')
|
||||
assert.deepEqual(
|
||||
[...conditionTypes].sort(),
|
||||
[accessSecretStoreCondition.getAddress(), escrowReward.getAddress(), lockRewardCondition.getAddress()].sort(),
|
||||
"The conditions doesn't match",
|
||||
[
|
||||
accessSecretStoreCondition.getAddress(),
|
||||
escrowReward.getAddress(),
|
||||
lockRewardCondition.getAddress()
|
||||
].sort(),
|
||||
"The conditions doesn't match"
|
||||
)
|
||||
})
|
||||
|
||||
it("should have condition instances asociated", async () => {
|
||||
it('should have condition instances asociated', async () => {
|
||||
const conditionInstances = await template.getConditions()
|
||||
|
||||
assert.equal(conditionInstances.length, 3, "Expected 3 conditions.")
|
||||
assert.equal(conditionInstances.length, 3, 'Expected 3 conditions.')
|
||||
|
||||
const conditionClasses = [AccessSecretStoreCondition, EscrowReward, LockRewardCondition]
|
||||
conditionClasses
|
||||
.forEach((conditionClass) => {
|
||||
if (!conditionInstances.find((condition) => condition instanceof conditionClass)) {
|
||||
throw new Error(`${conditionClass.name} is not part of the conditions.`)
|
||||
}
|
||||
})
|
||||
const conditionClasses = [
|
||||
AccessSecretStoreCondition,
|
||||
EscrowReward,
|
||||
LockRewardCondition
|
||||
]
|
||||
conditionClasses.forEach(conditionClass => {
|
||||
if (
|
||||
!conditionInstances.find(
|
||||
condition => condition instanceof conditionClass
|
||||
)
|
||||
) {
|
||||
throw new Error(
|
||||
`${conditionClass.name} is not part of the conditions.`
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it("should create a new agreement", async () => {
|
||||
it('should create a new agreement', async () => {
|
||||
const agreement = await template.createAgreement(
|
||||
agreementId,
|
||||
did,
|
||||
@ -113,35 +153,52 @@ describe("Register Escrow Access Secret Store Template", () => {
|
||||
[0, 0, 0],
|
||||
[0, 0, 0],
|
||||
consumer.getId(),
|
||||
publisher.getId(),
|
||||
publisher.getId()
|
||||
)
|
||||
|
||||
assert.isTrue(agreement.status)
|
||||
})
|
||||
|
||||
it("should not grant the access to the consumer", async () => {
|
||||
const accessGranted = await accessSecretStoreCondition.checkPermissions(consumer.getId(), did)
|
||||
it('should not grant the access to the consumer', async () => {
|
||||
const accessGranted = await accessSecretStoreCondition.checkPermissions(
|
||||
consumer.getId(),
|
||||
did
|
||||
)
|
||||
|
||||
assert.isFalse(accessGranted, "Consumer has been granted.")
|
||||
assert.isFalse(accessGranted, 'Consumer has been granted.')
|
||||
})
|
||||
|
||||
it("should fulfill LockRewardCondition", async () => {
|
||||
it('should fulfill LockRewardCondition', async () => {
|
||||
await consumer.requestTokens(escrowAmount)
|
||||
|
||||
await keeper.token.approve(lockRewardCondition.getAddress(), escrowAmount, consumer.getId())
|
||||
await keeper.token.approve(
|
||||
lockRewardCondition.getAddress(),
|
||||
escrowAmount,
|
||||
consumer.getId()
|
||||
)
|
||||
|
||||
const fulfill = await lockRewardCondition.fulfill(agreementId, escrowReward.getAddress(), escrowAmount, consumer.getId())
|
||||
const fulfill = await lockRewardCondition.fulfill(
|
||||
agreementId,
|
||||
escrowReward.getAddress(),
|
||||
escrowAmount,
|
||||
consumer.getId()
|
||||
)
|
||||
|
||||
assert.isDefined(fulfill.events.Fulfilled, "Not Fulfilled event.")
|
||||
assert.isDefined(fulfill.events.Fulfilled, 'Not Fulfilled event.')
|
||||
})
|
||||
|
||||
it("should fulfill AccessSecretStoreCondition", async () => {
|
||||
const fulfill = await accessSecretStoreCondition.fulfill(agreementId, did, consumer.getId(), publisher.getId())
|
||||
it('should fulfill AccessSecretStoreCondition', async () => {
|
||||
const fulfill = await accessSecretStoreCondition.fulfill(
|
||||
agreementId,
|
||||
did,
|
||||
consumer.getId(),
|
||||
publisher.getId()
|
||||
)
|
||||
|
||||
assert.isDefined(fulfill.events.Fulfilled, "Not Fulfilled event.")
|
||||
assert.isDefined(fulfill.events.Fulfilled, 'Not Fulfilled event.')
|
||||
})
|
||||
|
||||
it("should fulfill EscrowReward", async () => {
|
||||
it('should fulfill EscrowReward', async () => {
|
||||
const fulfill = await escrowReward.fulfill(
|
||||
agreementId,
|
||||
escrowAmount,
|
||||
@ -149,56 +206,92 @@ describe("Register Escrow Access Secret Store Template", () => {
|
||||
consumer.getId(),
|
||||
conditionIdLock,
|
||||
conditionIdAccess,
|
||||
consumer.getId(),
|
||||
consumer.getId()
|
||||
)
|
||||
|
||||
assert.isDefined(fulfill.events.Fulfilled, "Not Fulfilled event.")
|
||||
assert.isDefined(fulfill.events.Fulfilled, 'Not Fulfilled event.')
|
||||
})
|
||||
|
||||
it("should grant the access to the consumer", async () => {
|
||||
const accessGranted = await accessSecretStoreCondition.checkPermissions(consumer.getId(), did)
|
||||
it('should grant the access to the consumer', async () => {
|
||||
const accessGranted = await accessSecretStoreCondition.checkPermissions(
|
||||
consumer.getId(),
|
||||
did
|
||||
)
|
||||
|
||||
assert.isTrue(accessGranted, "Consumer has not been granted.")
|
||||
assert.isTrue(accessGranted, 'Consumer has not been granted.')
|
||||
})
|
||||
})
|
||||
|
||||
describe("Short flow", () => {
|
||||
describe('Short flow', () => {
|
||||
const did = utils.generateId()
|
||||
|
||||
let agreementId
|
||||
|
||||
it("should register a DID", async () => {
|
||||
it('should register a DID', async () => {
|
||||
// This part is executed inside Ocean.assets.create()
|
||||
await keeper.didRegistry.registerAttribute(did, checksum, [], url, publisher.getId())
|
||||
await keeper.didRegistry.registerAttribute(
|
||||
did,
|
||||
checksum,
|
||||
[],
|
||||
url,
|
||||
publisher.getId()
|
||||
)
|
||||
})
|
||||
|
||||
it("should create a new agreement (short way)", async () => {
|
||||
agreementId = await template.createFullAgreement(did, escrowAmount, consumer.getId(), publisher.getId())
|
||||
it('should create a new agreement (short way)', async () => {
|
||||
agreementId = await template.createFullAgreement(
|
||||
did,
|
||||
escrowAmount,
|
||||
consumer.getId(),
|
||||
publisher.getId()
|
||||
)
|
||||
|
||||
assert.match(agreementId, /^0x[a-f0-9]{64}$/i)
|
||||
})
|
||||
|
||||
it("should not grant the access to the consumer", async () => {
|
||||
const accessGranted = await accessSecretStoreCondition.checkPermissions(consumer.getId(), did)
|
||||
it('should not grant the access to the consumer', async () => {
|
||||
const accessGranted = await accessSecretStoreCondition.checkPermissions(
|
||||
consumer.getId(),
|
||||
did
|
||||
)
|
||||
|
||||
assert.isFalse(accessGranted, "Consumer has been granted.")
|
||||
assert.isFalse(accessGranted, 'Consumer has been granted.')
|
||||
})
|
||||
|
||||
it("should fulfill the conditions from consumer side", async () => {
|
||||
it('should fulfill the conditions from consumer side', async () => {
|
||||
await consumer.requestTokens(escrowAmount)
|
||||
|
||||
await ocean.agreements.conditions.lockReward(agreementId, escrowAmount, consumer)
|
||||
await ocean.agreements.conditions.lockReward(
|
||||
agreementId,
|
||||
escrowAmount,
|
||||
consumer
|
||||
)
|
||||
})
|
||||
|
||||
it("should fulfill the conditions from publisher side", async () => {
|
||||
await ocean.agreements.conditions.grantAccess(agreementId, did, consumer.getId(), publisher)
|
||||
await ocean.agreements.conditions.releaseReward(agreementId, escrowAmount, did, consumer.getId(), publisher.getId(), publisher)
|
||||
it('should fulfill the conditions from publisher side', async () => {
|
||||
await ocean.agreements.conditions.grantAccess(
|
||||
agreementId,
|
||||
did,
|
||||
consumer.getId(),
|
||||
publisher
|
||||
)
|
||||
await ocean.agreements.conditions.releaseReward(
|
||||
agreementId,
|
||||
escrowAmount,
|
||||
did,
|
||||
consumer.getId(),
|
||||
publisher.getId(),
|
||||
publisher
|
||||
)
|
||||
})
|
||||
|
||||
it("should grant the access to the consumer", async () => {
|
||||
const accessGranted = await accessSecretStoreCondition.checkPermissions(consumer.getId(), did)
|
||||
it('should grant the access to the consumer', async () => {
|
||||
const accessGranted = await accessSecretStoreCondition.checkPermissions(
|
||||
consumer.getId(),
|
||||
did
|
||||
)
|
||||
|
||||
assert.isTrue(accessGranted, "Consumer has not been granted.")
|
||||
assert.isTrue(accessGranted, 'Consumer has not been granted.')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -1,18 +1,21 @@
|
||||
import { assert } from "chai"
|
||||
import { assert } from 'chai'
|
||||
|
||||
import { config } from "../config"
|
||||
import { config } from '../config'
|
||||
|
||||
import { generateMetadata } from "../utils"
|
||||
import { generateMetadata } from '../utils'
|
||||
|
||||
import { Ocean, Account, DDO } from "../../src" // @oceanprotocol/squid
|
||||
import { Ocean, Account, DDO } from '../../src' // @oceanprotocol/squid
|
||||
|
||||
describe("Search Asset", () => {
|
||||
describe('Search Asset', () => {
|
||||
let ocean: Ocean
|
||||
|
||||
let publisher: Account
|
||||
|
||||
const testHash = Math.random().toString(36).substr(2)
|
||||
const metadataGenerator = (name: string) => generateMetadata(`${name}${testHash}`)
|
||||
const testHash = Math.random()
|
||||
.toString(36)
|
||||
.substr(2)
|
||||
const metadataGenerator = (name: string) =>
|
||||
generateMetadata(`${name}${testHash}`)
|
||||
|
||||
let test1length
|
||||
let test2length
|
||||
@ -26,56 +29,92 @@ describe("Search Asset", () => {
|
||||
publisher.setPassword(process.env.ACCOUNT_PASSWORD)
|
||||
})
|
||||
|
||||
it("should be able to search the assets", async () => {
|
||||
const {results: ddos} = await ocean.assets.search(`Test1${testHash}`)
|
||||
it('should be able to search the assets', async () => {
|
||||
const { results: ddos } = await ocean.assets.search(`Test1${testHash}`)
|
||||
|
||||
assert.isArray(ddos, "A search should return an array")
|
||||
assert.isArray(ddos, 'A search should return an array')
|
||||
|
||||
test1length = ddos.length
|
||||
test2length = (await ocean.assets.search(`Test2${testHash}`)).results.length
|
||||
test3length = (await ocean.assets.search(`Test3${testHash}`)).results.length
|
||||
test2length = (await ocean.assets.search(`Test2${testHash}`)).results
|
||||
.length
|
||||
test3length = (await ocean.assets.search(`Test3${testHash}`)).results
|
||||
.length
|
||||
})
|
||||
|
||||
it("should regiester some a asset", async () => {
|
||||
assert.instanceOf(await ocean.assets.create(metadataGenerator("Test1") as any, publisher), DDO)
|
||||
assert.instanceOf(await ocean.assets.create(metadataGenerator("Test2") as any, publisher), DDO)
|
||||
assert.instanceOf(await ocean.assets.create(metadataGenerator("Test2") as any, publisher), DDO)
|
||||
assert.instanceOf(await ocean.assets.create(metadataGenerator("Test3") as any, publisher), DDO)
|
||||
it('should regiester some a asset', async () => {
|
||||
assert.instanceOf(
|
||||
await ocean.assets.create(
|
||||
metadataGenerator('Test1') as any,
|
||||
publisher
|
||||
),
|
||||
DDO
|
||||
)
|
||||
assert.instanceOf(
|
||||
await ocean.assets.create(
|
||||
metadataGenerator('Test2') as any,
|
||||
publisher
|
||||
),
|
||||
DDO
|
||||
)
|
||||
assert.instanceOf(
|
||||
await ocean.assets.create(
|
||||
metadataGenerator('Test2') as any,
|
||||
publisher
|
||||
),
|
||||
DDO
|
||||
)
|
||||
assert.instanceOf(
|
||||
await ocean.assets.create(
|
||||
metadataGenerator('Test3') as any,
|
||||
publisher
|
||||
),
|
||||
DDO
|
||||
)
|
||||
})
|
||||
|
||||
it("should search by text and see the increment of DDOs", async () => {
|
||||
it('should search by text and see the increment of DDOs', async () => {
|
||||
assert.equal(
|
||||
(await ocean.assets.search(`Test2${testHash}`)).results.length - test2length,
|
||||
(await ocean.assets.search(`Test2${testHash}`)).results.length -
|
||||
test2length,
|
||||
2,
|
||||
"Something was wrong searching the assets",
|
||||
'Something was wrong searching the assets'
|
||||
)
|
||||
assert.equal(
|
||||
(await ocean.assets.search(`Test3${testHash}`)).results.length - test3length,
|
||||
(await ocean.assets.search(`Test3${testHash}`)).results.length -
|
||||
test3length,
|
||||
1,
|
||||
"Something was wrong searching the assets",
|
||||
'Something was wrong searching the assets'
|
||||
)
|
||||
})
|
||||
|
||||
it("should return a list of DDOs", async () => {
|
||||
const {results: ddos} = await ocean.assets.search(`Test1${testHash}`)
|
||||
it('should return a list of DDOs', async () => {
|
||||
const { results: ddos } = await ocean.assets.search(`Test1${testHash}`)
|
||||
|
||||
assert.equal(ddos.length - test1length, 1, "Something was wrong searching the assets")
|
||||
ddos.map((ddo) => assert.instanceOf(ddo, DDO, "The DDO is not an instance of a DDO"))
|
||||
assert.equal(
|
||||
ddos.length - test1length,
|
||||
1,
|
||||
'Something was wrong searching the assets'
|
||||
)
|
||||
ddos.map(ddo =>
|
||||
assert.instanceOf(ddo, DDO, 'The DDO is not an instance of a DDO')
|
||||
)
|
||||
})
|
||||
|
||||
it("should be able to do a query to get a list of DDOs", async () => {
|
||||
const {results: ddos} = await ocean.assets.query({
|
||||
it('should be able to do a query to get a list of DDOs', async () => {
|
||||
const { results: ddos } = await ocean.assets.query({
|
||||
page: 1,
|
||||
offset: 1,
|
||||
query: {
|
||||
text: [`Test2${testHash}`],
|
||||
text: [`Test2${testHash}`]
|
||||
},
|
||||
sort: {
|
||||
text: 1,
|
||||
},
|
||||
text: 1
|
||||
}
|
||||
})
|
||||
|
||||
assert.equal(ddos.length, 1, "Something was wrong searching the assets")
|
||||
ddos.map((ddo) => assert.instanceOf(ddo, DDO, "The DDO is not an instance of a DDO"))
|
||||
assert.equal(ddos.length, 1, 'Something was wrong searching the assets')
|
||||
ddos.map(ddo =>
|
||||
assert.instanceOf(ddo, DDO, 'The DDO is not an instance of a DDO')
|
||||
)
|
||||
})
|
||||
})
|
||||
|
@ -1,16 +1,16 @@
|
||||
import { assert } from "chai"
|
||||
import { assert } from 'chai'
|
||||
|
||||
import { config } from "../config"
|
||||
import { config } from '../config'
|
||||
|
||||
import { Ocean, Account, DID } from "../../src" // @oceanprotocol/squid
|
||||
import { Ocean, Account, DID } from '../../src' // @oceanprotocol/squid
|
||||
|
||||
describe("Secret Store", () => {
|
||||
describe('Secret Store', () => {
|
||||
let ocean: Ocean
|
||||
|
||||
let account: Account
|
||||
|
||||
const did: DID = DID.generate()
|
||||
const content = {content: "Test 123"}
|
||||
const content = { content: 'Test 123' }
|
||||
let encryptedContent
|
||||
|
||||
before(async () => {
|
||||
@ -20,8 +20,12 @@ describe("Secret Store", () => {
|
||||
account = (await ocean.accounts.list())[0]
|
||||
})
|
||||
|
||||
it("should encrypt a text", async () => {
|
||||
encryptedContent = await ocean.secretStore.encrypt(did.getId(), content, account)
|
||||
it('should encrypt a text', async () => {
|
||||
encryptedContent = await ocean.secretStore.encrypt(
|
||||
did.getId(),
|
||||
content,
|
||||
account
|
||||
)
|
||||
|
||||
assert.isDefined(encryptedContent)
|
||||
assert.match(encryptedContent, /^0x[a-f0-9]{76}$/i)
|
||||
|
@ -1,13 +1,12 @@
|
||||
import { assert } from "chai"
|
||||
import { assert } from 'chai'
|
||||
|
||||
import { config } from "../config"
|
||||
import { config } from '../config'
|
||||
|
||||
import { Ocean, Account, DDO } from "../../src" // @oceanprotocol/squid
|
||||
import { Ocean, Account, DDO } from '../../src' // @oceanprotocol/squid
|
||||
|
||||
// WARN: not integration test. It has been done here because constant values
|
||||
// depends on the first account on spree (only accessible from integration test)
|
||||
describe("Signature", () => {
|
||||
|
||||
describe('Signature', () => {
|
||||
let ocean: Ocean
|