mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
Fix all ignored tests.
This commit is contained in:
parent
19cba1dc57
commit
cf99c9ff64
@ -1,8 +1,10 @@
|
||||
import { assert } from "chai"
|
||||
import * as fs from "fs"
|
||||
|
||||
import { config } from "../config"
|
||||
import { getMetadata } from "../utils"
|
||||
|
||||
import { Ocean, MetaData, DDO, DID, Account/*, ServiceAgreement*/ } from "../../src" // @oceanprotocol/squid
|
||||
import { Ocean, DDO, Account } from "../../src" // @oceanprotocol/squid
|
||||
|
||||
describe("Consume Asset", () => {
|
||||
let ocean: Ocean
|
||||
@ -10,7 +12,7 @@ describe("Consume Asset", () => {
|
||||
let publisher: Account
|
||||
let consumer: Account
|
||||
|
||||
let metadata: Partial<MetaData>
|
||||
const metadata = getMetadata()
|
||||
|
||||
let ddo: DDO
|
||||
let serviceAgreementSignatureResult: {agreementId: string, signature: string}
|
||||
@ -22,43 +24,6 @@ describe("Consume Asset", () => {
|
||||
publisher = (await ocean.accounts.list())[0]
|
||||
publisher.setPassword(process.env.ACCOUNT_PASSWORD)
|
||||
consumer = (await ocean.accounts.list())[1]
|
||||
|
||||
// Data
|
||||
metadata = {
|
||||
base: {
|
||||
name: "Office Humidity",
|
||||
type: "dataset",
|
||||
description: "Weather information of UK including temperature and humidity",
|
||||
size: "3.1gb",
|
||||
dateCreated: "2012-02-01T10:55:11+00:00",
|
||||
author: "Met Office",
|
||||
license: "CC-BY",
|
||||
copyrightHolder: "Met Office",
|
||||
encoding: "UTF-8",
|
||||
compression: "zip",
|
||||
contentType: "text/csv",
|
||||
// tslint:disable-next-line
|
||||
workExample: "stationId,latitude,longitude,datetime,temperature,humidity423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68",
|
||||
files: [
|
||||
{
|
||||
url: "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip",
|
||||
checksum: "085340abffh21495345af97c6b0e761",
|
||||
contentLength: "12324",
|
||||
},
|
||||
{
|
||||
url: "https://testocnfiles.blob.core.windows.net/testfiles/testzkp2.zip",
|
||||
},
|
||||
],
|
||||
links: [
|
||||
{sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/"},
|
||||
{sample2: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-averages-25km/"},
|
||||
{fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/"},
|
||||
],
|
||||
inLanguage: "en",
|
||||
tags: "weather, uk, 2011, temperature, humidity",
|
||||
price: 10,
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
it("should regiester a asset", async () => {
|
||||
@ -102,27 +67,44 @@ describe("Consume Asset", () => {
|
||||
assert.isTrue(success)
|
||||
})
|
||||
|
||||
xit("should lock the payment", async () => {
|
||||
it("should lock the payment", async () => {
|
||||
const paid = await ocean.agreements.conditions
|
||||
.lockReward(
|
||||
serviceAgreementSignatureResult.agreementId,
|
||||
ddo.findServiceByType("Metadata").metadata.base.price,
|
||||
publisher,
|
||||
consumer,
|
||||
)
|
||||
|
||||
assert.isTrue(paid, "The asset has not been paid correctly")
|
||||
})
|
||||
|
||||
xit("should grant the access", async () => {
|
||||
it("should grant the access", async () => {
|
||||
const granted = await ocean.agreements.conditions
|
||||
.grantAccess(serviceAgreementSignatureResult.agreementId, ddo.id, consumer.getId(), publisher)
|
||||
|
||||
assert.isTrue(granted, "The asset has not been granted correctly")
|
||||
})
|
||||
|
||||
xit("should consume the assets", async () => {
|
||||
it("should consume and store the assets", async () => {
|
||||
const accessService = ddo.findServiceByType("Access")
|
||||
|
||||
await ocean.assets.consume(serviceAgreementSignatureResult.agreementId, ddo.id, accessService.serviceDefinitionId, consumer)
|
||||
const folder = "/tmp/ocean/squid-js"
|
||||
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.")
|
||||
})
|
||||
})
|
||||
|
@ -3,8 +3,9 @@ import * as Web3 from "web3"
|
||||
import * as fs from "fs"
|
||||
|
||||
import { config } from "../config"
|
||||
import { getMetadata } from "../utils"
|
||||
|
||||
import { Ocean, MetaData, Account, DDO } from "../../src" // @oceanprotocol/squid
|
||||
import { Ocean, Account, DDO } from "../../src" // @oceanprotocol/squid
|
||||
|
||||
describe("Consume Asset (Brizo)", () => {
|
||||
let ocean: Ocean
|
||||
@ -15,15 +16,7 @@ describe("Consume Asset (Brizo)", () => {
|
||||
let ddo: DDO
|
||||
let agreementId: string
|
||||
|
||||
const testHash = Math.random().toString(36).substr(2)
|
||||
let metadata: Partial<MetaData>
|
||||
const metadataGenerator = (name: string) => ({
|
||||
...metadata,
|
||||
base: {
|
||||
...metadata.base,
|
||||
name: `${name}${testHash}`,
|
||||
},
|
||||
})
|
||||
const metadata = getMetadata()
|
||||
|
||||
before(async () => {
|
||||
ocean = await Ocean.getInstance({
|
||||
@ -37,45 +30,10 @@ describe("Consume Asset (Brizo)", () => {
|
||||
publisher.setPassword("node0")
|
||||
consumer = new Account("0x068Ed00cF0441e4829D9784fCBe7b9e26D4BD8d0")
|
||||
consumer.setPassword("secret")
|
||||
|
||||
// Data
|
||||
metadata = {
|
||||
base: {
|
||||
name: undefined,
|
||||
type: "dataset",
|
||||
description: "Weather information of UK including temperature and humidity",
|
||||
size: "3.1gb",
|
||||
dateCreated: "2012-02-01T10:55:11+00:00",
|
||||
author: "Met Office",
|
||||
license: "CC-BY",
|
||||
copyrightHolder: "Met Office",
|
||||
encoding: "UTF-8",
|
||||
compression: "zip",
|
||||
contentType: "text/csv",
|
||||
// tslint:disable-next-line
|
||||
workExample: "stationId,latitude,longitude,datetime,temperature,humidity423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68",
|
||||
files: [
|
||||
{
|
||||
url: "https://raw.githubusercontent.com/oceanprotocol/squid-js/develop/package.json",
|
||||
},
|
||||
{
|
||||
url: "https://raw.githubusercontent.com/oceanprotocol/squid-js/develop/README.md",
|
||||
},
|
||||
],
|
||||
links: [
|
||||
{sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/"},
|
||||
{sample2: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-averages-25km/"},
|
||||
{fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/"},
|
||||
],
|
||||
inLanguage: "en",
|
||||
tags: "weather, uk, 2011, temperature, humidity",
|
||||
price: 10,
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
it("should regiester an asset", async () => {
|
||||
ddo = await ocean.assets.create(metadataGenerator("ToBeConsumed") as any, publisher)
|
||||
ddo = await ocean.assets.create(metadata as any, publisher)
|
||||
|
||||
assert.instanceOf(ddo, DDO)
|
||||
})
|
||||
|
@ -163,8 +163,7 @@ describe("Register Escrow Access Secret Store Template", () => {
|
||||
})
|
||||
})
|
||||
|
||||
// Not consisten flow on `condition.grantAccess`
|
||||
xdescribe("Short flow", () => {
|
||||
describe("Short flow", () => {
|
||||
const did = utils.generateId()
|
||||
|
||||
let agreementId
|
||||
|
@ -2,7 +2,9 @@ import { assert } from "chai"
|
||||
|
||||
import { config } from "../config"
|
||||
|
||||
import { Ocean, MetaData, Account, DDO } from "../../src" // @oceanprotocol/squid
|
||||
import { generateMetadata } from "../utils"
|
||||
|
||||
import { Ocean, Account, DDO } from "../../src" // @oceanprotocol/squid
|
||||
|
||||
describe("Search Asset", () => {
|
||||
let ocean: Ocean
|
||||
@ -10,14 +12,7 @@ describe("Search Asset", () => {
|
||||
let publisher: Account
|
||||
|
||||
const testHash = Math.random().toString(36).substr(2)
|
||||
let metadata: Partial<MetaData>
|
||||
const metadataGenerator = (name: string) => ({
|
||||
...metadata,
|
||||
base: {
|
||||
...metadata.base,
|
||||
name: `${name}${testHash}`,
|
||||
},
|
||||
})
|
||||
const metadataGenerator = (name: string) => generateMetadata(`${name}${testHash}`)
|
||||
|
||||
let test1length
|
||||
let test2length
|
||||
@ -29,44 +24,6 @@ describe("Search Asset", () => {
|
||||
// Accounts
|
||||
publisher = (await ocean.accounts.list())[0]
|
||||
publisher.setPassword(process.env.ACCOUNT_PASSWORD)
|
||||
|
||||
// Data
|
||||
metadata = {
|
||||
base: {
|
||||
name: undefined,
|
||||
type: "dataset",
|
||||
description: "Weather information of UK including temperature and humidity",
|
||||
size: "3.1gb",
|
||||
dateCreated: "2012-02-01T10:55:11+00:00",
|
||||
author: "Met Office",
|
||||
license: "CC-BY",
|
||||
copyrightHolder: "Met Office",
|
||||
encoding: "UTF-8",
|
||||
compression: "zip",
|
||||
contentType: "text/csv",
|
||||
// tslint:disable-next-line
|
||||
workExample: "stationId,latitude,longitude,datetime,temperature,humidity423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68",
|
||||
files: [
|
||||
{
|
||||
url: "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip",
|
||||
checksum: "085340abffh21495345af97c6b0e761",
|
||||
contentLength: "12324",
|
||||
},
|
||||
{
|
||||
url: "https://testocnfiles.blob.core.windows.net/testfiles/testzkp2.zip",
|
||||
},
|
||||
],
|
||||
links: [
|
||||
{sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/"},
|
||||
{sample2: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-averages-25km/"},
|
||||
{fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/"},
|
||||
],
|
||||
inLanguage: "en",
|
||||
tags: "weather, uk, 2011, temperature, humidity",
|
||||
price: 10,
|
||||
},
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
it("should be able to search the assets", async () => {
|
||||
|
45
integration/utils/ddo-metadata-generator.ts
Normal file
45
integration/utils/ddo-metadata-generator.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import { MetaData } from "../../src" // @oceanprotocol/squid
|
||||
|
||||
const metadata: Partial<MetaData> = {
|
||||
base: {
|
||||
name: undefined,
|
||||
type: "dataset",
|
||||
description: "Weather information of UK including temperature and humidity",
|
||||
size: "3.1gb",
|
||||
dateCreated: "2012-02-01T10:55:11+00:00",
|
||||
author: "Met Office",
|
||||
license: "CC-BY",
|
||||
copyrightHolder: "Met Office",
|
||||
encoding: "UTF-8",
|
||||
compression: "zip",
|
||||
contentType: "text/csv",
|
||||
// tslint:disable-next-line
|
||||
workExample: "stationId,latitude,longitude,datetime,temperature,humidity423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68",
|
||||
files: [
|
||||
{
|
||||
url: "https://raw.githubusercontent.com/oceanprotocol/squid-js/develop/package.json",
|
||||
},
|
||||
{
|
||||
url: "https://raw.githubusercontent.com/oceanprotocol/squid-js/develop/README.md",
|
||||
},
|
||||
],
|
||||
links: [
|
||||
{sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/"},
|
||||
{sample2: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-averages-25km/"},
|
||||
{fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/"},
|
||||
],
|
||||
inLanguage: "en",
|
||||
tags: "weather, uk, 2011, temperature, humidity",
|
||||
price: 10,
|
||||
},
|
||||
}
|
||||
|
||||
export const generateMetadata = (name: string): Partial<MetaData> => ({
|
||||
...metadata,
|
||||
base: {
|
||||
...metadata.base,
|
||||
name,
|
||||
},
|
||||
})
|
||||
|
||||
export const getMetadata = () => generateMetadata("TestAsset")
|
1
integration/utils/index.ts
Normal file
1
integration/utils/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from "./ddo-metadata-generator"
|
@ -59,7 +59,7 @@ export class EscrowAccessSecretStoreTemplate extends AgreementTemplate {
|
||||
|
||||
public async getAgreementIdsFromDDO(agreementId: string, ddo: DDO, consumer: string, from?: string) {
|
||||
const {accessSecretStoreConditionId, lockRewardConditionId, escrowRewardId} =
|
||||
await this.createFullAgreementData(agreementId, ddo.shortId(), ddo.findServiceByType("Metadata").metadata.base.price, from)
|
||||
await this.createFullAgreementData(agreementId, ddo.shortId(), ddo.findServiceByType("Metadata").metadata.base.price, consumer)
|
||||
return [accessSecretStoreConditionId, lockRewardConditionId, escrowRewardId]
|
||||
}
|
||||
|
||||
@ -71,9 +71,9 @@ export class EscrowAccessSecretStoreTemplate extends AgreementTemplate {
|
||||
* @return {Promise<string>} Agreement ID.
|
||||
*/
|
||||
public async createFullAgreement(did: string, amount: number, consumer: string, from?: string, agreementId?: string): Promise<string> {
|
||||
agreementId = agreementId || zeroX(generateId())
|
||||
agreementId = agreementId || generateId()
|
||||
const {accessSecretStoreConditionId, lockRewardConditionId, escrowRewardId} =
|
||||
await this.createFullAgreementData(agreementId, did, amount, from)
|
||||
await this.createFullAgreementData(agreementId, did, amount, consumer)
|
||||
|
||||
await this.createAgreement(
|
||||
agreementId,
|
||||
@ -85,12 +85,10 @@ export class EscrowAccessSecretStoreTemplate extends AgreementTemplate {
|
||||
from,
|
||||
)
|
||||
|
||||
return agreementId
|
||||
return zeroX(agreementId)
|
||||
}
|
||||
|
||||
private async createFullAgreementData(agreementId: string, did: string, amount: number, from?: string) {
|
||||
from = await this.getFromAddress(from)
|
||||
|
||||
private async createFullAgreementData(agreementId: string, did: string, amount: number, consumer: string) {
|
||||
const didRegistry = await DIDRegistry.getInstance()
|
||||
|
||||
const accessSecretStoreCondition = await AccessSecretStoreCondition.getInstance()
|
||||
@ -100,12 +98,12 @@ export class EscrowAccessSecretStoreTemplate extends AgreementTemplate {
|
||||
const publisher = await didRegistry.getDIDOwner(did)
|
||||
|
||||
const lockRewardConditionId = await lockRewardCondition.generateIdHash(agreementId, await escrowReward.getAddress(), amount)
|
||||
const accessSecretStoreConditionId = await accessSecretStoreCondition.generateIdHash(agreementId, did, from)
|
||||
const accessSecretStoreConditionId = await accessSecretStoreCondition.generateIdHash(agreementId, did, consumer)
|
||||
const escrowRewardId = await escrowReward.generateIdHash(
|
||||
agreementId,
|
||||
amount,
|
||||
publisher,
|
||||
from,
|
||||
consumer,
|
||||
lockRewardConditionId,
|
||||
accessSecretStoreConditionId,
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user