1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

added consumption integration test

This commit is contained in:
Pedro Gutiérrez 2019-02-21 18:07:02 +01:00 committed by Pedro Gutiérrez
parent 6d5be0db75
commit 6b3541bbc5
5 changed files with 373 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{
"nodeUri": "http://localhost:8545",
"aquariusUri": "http://localhost:5000",
"aquariusUri": "http://172.15.0.15:5000",
"brizoUri": "http://localhost:8030",
"parityUri": "http://localhost:9545",
"secretStoreUri": "http://localhost:12001",

View File

@ -109,4 +109,10 @@ describe("Buy Asset", () => {
const paid = await serviceAgreement.payAsset(did.getId(), metadata.base.price, consumer)
assert.isTrue(paid, "The asset has not been paid correctly")
})
xit("should consume the assets", async () => {
const accessService = ddo.findServiceByType("Access")
await ocean.assets.consume(serviceAgreementSignatureResult.agreementId, ddo.id, accessService.serviceDefinitionId, consumer)
})
})

View File

@ -0,0 +1,108 @@
import { assert } from "chai"
import * as Web3 from "web3"
import * as fs from "fs";
import { config } from "../config"
import { Ocean, MetaData, Account, DDO } from "../../src" // @oceanprotocol/squid
describe("Consume Asset", () => {
let ocean: Ocean
let publisher: Account
let consumer: Account
let ddo: DDO
let agreementId: string
const testHash = Math.random().toString(36).substr(2)
let metadata: Partial<MetaData>
let metadataGenerator = (name: string) => ({
...metadata,
base: {
...metadata.base,
name: `${name}${testHash}`,
},
})
before(async () => {
ocean = await Ocean.getInstance({
...config,
web3Provider: new Web3.providers.HttpProvider("http://localhost:8545", 0, "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", "node0"),
})
// Accounts
publisher = new Account("0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e")
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://testocnfiles.blob.core.windows.net/testfiles/testzkp.pdf",
checksum: "085340abffh21495345af97c6b0e761",
contentLength: "12324",
},
{
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);
assert.instanceOf(ddo, DDO)
})
it("should order the asset", async () => {
const accessService = ddo.findServiceByType("Access")
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")
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.")
const files = await new Promise(resolve => {
fs.readdir(path, (err, files) => {
resolve(files)
});
})
assert.deepEqual(files, ["README.md", "testzkp.pdf"], "Stored files are not correct.")
})
})

253
package-lock.json generated
View File

@ -669,6 +669,11 @@
"integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==",
"dev": true
},
"atob-lite": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/atob-lite/-/atob-lite-2.0.0.tgz",
"integrity": "sha1-D+9a1G8b16hQLGVyfwNn1e5D1pY="
},
"aws-sign2": {
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz",
@ -1194,6 +1199,12 @@
"safe-buffer": "^5.0.1"
}
},
"circular-json": {
"version": "0.5.9",
"resolved": "https://registry.npmjs.org/circular-json/-/circular-json-0.5.9.tgz",
"integrity": "sha512-4ivwqHpIFJZBuhN3g/pEcdbnGUywkBblloGbkglyloVjjR3uT6tieI89MVOfbP2tHX5sgb01FuLgAOzebNlJNQ==",
"dev": true
},
"class-utils": {
"version": "0.3.6",
"resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz",
@ -1720,6 +1731,11 @@
"create-hmac": "^1.1.4"
}
},
"dtype": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/dtype/-/dtype-2.0.0.tgz",
"integrity": "sha1-zQUjI84GFETs0uj1dI9popvihDQ="
},
"duplexer3": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.4.tgz",
@ -2234,6 +2250,11 @@
"integrity": "sha512-vNKxJHTEKNThjfrdJwHc7brvM6eVevuO5nTj6ez8ZQ1qbXTvGthucRF7S4vf2cr71QVnT70V34v0S1DyQsti0w==",
"dev": true
},
"file-saver": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.1.tgz",
"integrity": "sha512-dCB3K7/BvAcUmtmh1DzFdv0eXSVJ9IAFt1mw3XZfAexodNRoE29l3xB2EX4wH2q8m/UTzwzEPq/ArYk98kUkBQ=="
},
"file-type": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/file-type/-/file-type-5.2.0.tgz",
@ -2331,6 +2352,14 @@
}
}
},
"flatten-vertex-data": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/flatten-vertex-data/-/flatten-vertex-data-1.0.2.tgz",
"integrity": "sha512-BvCBFK2NZqerFTdMDgqfHBwxYWnxeCkwONsw6PvBMcUXqo8U/KDWwmXhqx1x2kLIg7DqIsJfOaJFOmlua3Lxuw==",
"requires": {
"dtype": "^2.0.0"
}
},
"flush-write-stream": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/flush-write-stream/-/flush-write-stream-1.1.0.tgz",
@ -3423,6 +3452,11 @@
}
}
},
"is-base64": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/is-base64/-/is-base64-0.1.0.tgz",
"integrity": "sha512-WRRyllsGXJM7ZN7gPTCCQ/6wNPTRDwiWdPK66l5sJzcU/oOzcIcRRf0Rux8bkpox/1yjt0F6VJRsQOIG2qz5sg=="
},
"is-binary-path": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-1.0.1.tgz",
@ -3432,6 +3466,11 @@
"binary-extensions": "^1.0.0"
}
},
"is-blob": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-blob/-/is-blob-1.0.0.tgz",
"integrity": "sha1-o9fZb+HD/wZex84nwsIea6ksGDI="
},
"is-buffer": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
@ -4104,6 +4143,149 @@
}
}
},
"mocha-parallel-tests": {
"version": "2.0.6-alpha.3",
"resolved": "https://registry.npmjs.org/mocha-parallel-tests/-/mocha-parallel-tests-2.0.6-alpha.3.tgz",
"integrity": "sha512-yyCObs84loUFbLim3KfeucKeSULudEoDNbOsNuJ/hdwj1vsIVr1bs1Tsk30OAMCpSdi7vUhvU9uIO8nJ3t62FQ==",
"dev": true,
"requires": {
"circular-json": "^0.5.4",
"debug": "3.1.0",
"yargs": "12.0.1"
},
"dependencies": {
"camelcase": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-4.1.0.tgz",
"integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=",
"dev": true
},
"cross-spawn": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz",
"integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=",
"dev": true,
"requires": {
"lru-cache": "^4.0.1",
"shebang-command": "^1.2.0",
"which": "^1.2.9"
}
},
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"dev": true,
"requires": {
"ms": "2.0.0"
}
},
"decamelize": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/decamelize/-/decamelize-2.0.0.tgz",
"integrity": "sha512-Ikpp5scV3MSYxY39ymh45ZLEecsTdv/Xj2CaQfI8RLMuwi7XvjX9H/fhraiSuU+C5w5NTDu4ZU72xNiZnurBPg==",
"dev": true,
"requires": {
"xregexp": "4.0.0"
}
},
"execa": {
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/execa/-/execa-0.7.0.tgz",
"integrity": "sha1-lEvs00zEHuMqY6n68nrVpl/Fl3c=",
"dev": true,
"requires": {
"cross-spawn": "^5.0.1",
"get-stream": "^3.0.0",
"is-stream": "^1.1.0",
"npm-run-path": "^2.0.0",
"p-finally": "^1.0.0",
"signal-exit": "^3.0.0",
"strip-eof": "^1.0.0"
}
},
"invert-kv": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-1.0.0.tgz",
"integrity": "sha1-EEqOSqym09jNFXqO+L+rLXo//bY=",
"dev": true
},
"lcid": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/lcid/-/lcid-1.0.0.tgz",
"integrity": "sha1-MIrMr6C8SDo4Z7S28rlQYlHRuDU=",
"dev": true,
"requires": {
"invert-kv": "^1.0.0"
}
},
"lru-cache": {
"version": "4.1.5",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz",
"integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==",
"dev": true,
"requires": {
"pseudomap": "^1.0.2",
"yallist": "^2.1.2"
}
},
"mem": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/mem/-/mem-1.1.0.tgz",
"integrity": "sha1-Xt1StIXKHZAP5kiVUFOZoN+kX3Y=",
"dev": true,
"requires": {
"mimic-fn": "^1.0.0"
}
},
"os-locale": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/os-locale/-/os-locale-2.1.0.tgz",
"integrity": "sha512-3sslG3zJbEYcaC4YVAvDorjGxc7tv6KVATnLPZONiljsUncvihe9BQoVCEs0RZ1kmf4Hk9OBqlZfJZWI4GanKA==",
"dev": true,
"requires": {
"execa": "^0.7.0",
"lcid": "^1.0.0",
"mem": "^1.1.0"
}
},
"yallist": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz",
"integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=",
"dev": true
},
"yargs": {
"version": "12.0.1",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-12.0.1.tgz",
"integrity": "sha512-B0vRAp1hRX4jgIOWFtjfNjd9OA9RWYZ6tqGA9/I/IrTMsxmKvtWy+ersM+jzpQqbC3YfLzeABPdeTgcJ9eu1qQ==",
"dev": true,
"requires": {
"cliui": "^4.0.0",
"decamelize": "^2.0.0",
"find-up": "^3.0.0",
"get-caller-file": "^1.0.1",
"os-locale": "^2.0.0",
"require-directory": "^2.1.1",
"require-main-filename": "^1.0.1",
"set-blocking": "^2.0.0",
"string-width": "^2.0.0",
"which-module": "^2.0.0",
"y18n": "^3.2.1 || ^4.0.0",
"yargs-parser": "^10.1.0"
}
},
"yargs-parser": {
"version": "10.1.0",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-10.1.0.tgz",
"integrity": "sha512-VCIyR1wJoEBZUqk5PA+oOBF6ypbwh5aNB3I50guxAL/quggdfs4TtNHQrSazFA3fYZ+tEqfs0zIGlv0c/rgjbQ==",
"dev": true,
"requires": {
"camelcase": "^4.1.0"
}
}
}
},
"mock-fs": {
"version": "4.8.0",
"resolved": "https://registry.npmjs.org/mock-fs/-/mock-fs-4.8.0.tgz",
@ -5684,6 +5866,12 @@
"integrity": "sha1-0/wRS6BplaRexok/SEzrHXj19HY=",
"dev": true
},
"pseudomap": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz",
"integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=",
"dev": true
},
"psl": {
"version": "1.1.31",
"resolved": "https://registry.npmjs.org/psl/-/psl-1.1.31.tgz",
@ -6017,6 +6205,26 @@
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"save-file": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/save-file/-/save-file-2.3.0.tgz",
"integrity": "sha512-Tih9uErVBKbKvtdiU2LDw2f5V8b5B3NcrDCcNrFA7qokbcmTXXGFvLfUNMQhVCE4M5t9jvLs2IngnjM2YQuqCA==",
"requires": {
"file-saver": "^2.0.0-rc.4",
"is-blob": "^1.0.0",
"is-buffer": "^2.0.0",
"simple-mime": "^0.1.0",
"to-array-buffer": "^3.2.0",
"write": "^1.0.0"
},
"dependencies": {
"is-buffer": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz",
"integrity": "sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw=="
}
}
},
"schema-utils": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-1.0.0.tgz",
@ -6253,6 +6461,11 @@
"simple-concat": "^1.0.0"
}
},
"simple-mime": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/simple-mime/-/simple-mime-0.1.0.tgz",
"integrity": "sha1-lfUXxPRm18/1YacfydqyWW6p7y4="
},
"snapdragon": {
"version": "0.8.2",
"resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz",
@ -6519,6 +6732,15 @@
"resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz",
"integrity": "sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM="
},
"string-to-arraybuffer": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/string-to-arraybuffer/-/string-to-arraybuffer-1.0.2.tgz",
"integrity": "sha512-DaGZidzi93dwjQen5I2osxR9ERS/R7B1PFyufNMnzhj+fmlDQAc1DSDIJVJhgI8Oq221efIMbABUBdPHDRt43Q==",
"requires": {
"atob-lite": "^2.0.0",
"is-base64": "^0.1.0"
}
},
"string-width": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
@ -6757,6 +6979,23 @@
"setimmediate": "^1.0.4"
}
},
"to-array-buffer": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/to-array-buffer/-/to-array-buffer-3.2.0.tgz",
"integrity": "sha512-zN33mwi0gpL+7xW1ITLfJ48CEj6ZQW0ZAP0MU+2W3kEY0PAIncyuxmD4OqkUVhPAbTP7amq9j/iwvZKYS+lzSQ==",
"requires": {
"flatten-vertex-data": "^1.0.2",
"is-blob": "^2.0.1",
"string-to-arraybuffer": "^1.0.0"
},
"dependencies": {
"is-blob": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/is-blob/-/is-blob-2.0.1.tgz",
"integrity": "sha512-SmqVJYMnAeqrKLcwq6TXu1rpAg3yipVlMZIqR5u510rxoOzJGW9GQY6g+WtWkcc44pjbWAuxzZDCkbgf5e6r0Q=="
}
}
},
"to-arraybuffer": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz",
@ -7850,6 +8089,14 @@
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
},
"write": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/write/-/write-1.0.3.tgz",
"integrity": "sha512-/lg70HAjtkUgWPVZhZcm+T4hkL8Zbtp1nFNOn3lRrxnlv50SRBv7cR7RqR+GMsd3hUXy9hWBo4CHTbFTcOYwig==",
"requires": {
"mkdirp": "^0.5.1"
}
},
"ws": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/ws/-/ws-3.3.3.tgz",
@ -7906,6 +8153,12 @@
"resolved": "https://registry.npmjs.org/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz",
"integrity": "sha1-Z/4HXFwk/vOfnWX197f+dRcZaPw="
},
"xregexp": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/xregexp/-/xregexp-4.0.0.tgz",
"integrity": "sha512-PHyM+sQouu7xspQQwELlGwwd05mXUFqwFYfqPO0cC7x4fxyHnnuetmQr6CjJiafIDoH4MogHb9dOoJzR/Y4rFg==",
"dev": true
},
"xtend": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz",

View File

@ -9,9 +9,10 @@
"test": "mocha",
"test:watch": "mocha -w --watch-extensions js,ts,json",
"test:cover": "nyc --report-dir coverage/unit mocha",
"integration": "mocha --opts integration/mocha.opts",
"@@integration@@": "Using mocha-parallel-tests to ensure independent execution",
"integration": "mocha-parallel-tests --max-parallel 1 --opts integration/mocha.opts",
"integration:watch": "mocha -w --watch-extensions js,ts,json --opts integration/mocha.opts",
"integration:cover": "nyc --report-dir coverage/integration mocha --opts integration/mocha.opts",
"integration:cover": "nyc --report-dir coverage/integration mocha-parallel-tests --max-parallel 1 --opts integration/mocha.opts",
"examples": "./src/examples/fire_lazers.sh",
"clean": "rm -rf ./dist/ ./doc/ ./coverage ./.nyc_output",
"lint": "tslint -c tslint.json 'src/**/*.ts' 'test/**/*.ts'",
@ -65,6 +66,7 @@
"deprecated-decorator": "^0.1.6",
"ethereumjs-util": "^6.0.0",
"node-fetch": "^2.3.0",
"save-file": "^2.3.0",
"uuid": "^3.3.2",
"web3": "1.0.0-beta.37",
"web3-eth-contract": "1.0.0-beta.37",
@ -80,6 +82,7 @@
"chai-spies": "^1.0.0",
"cross-env": "^5.2.0",
"mocha": "^5.2.0",
"mocha-parallel-tests": "^2.0.6-alpha.3",
"nyc": "^13.1.0",
"rollup": "^1.1.0",
"source-map-support": "^0.5.9",