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

Fix tests.

This commit is contained in:
ssallam 2020-01-17 15:35:11 +01:00
parent eac7b172e6
commit 48c4f64599
32 changed files with 2469 additions and 55 deletions

4
.idea/encodings.xml generated Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="TsLint" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>

86
.idea/markdown-navigator.xml generated Normal file
View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MarkdownProjectSettings" wasCopied="false">
<PreviewSettings splitEditorLayout="SPLIT" splitEditorPreview="PREVIEW" useGrayscaleRendering="false" zoomFactor="1.0" maxImageWidth="0" showGitHubPageIfSynced="false" allowBrowsingInPreview="false" synchronizePreviewPosition="true" highlightPreviewType="NONE" highlightFadeOut="5" highlightOnTyping="true" synchronizeSourcePosition="true" verticallyAlignSourceAndPreviewSyncPosition="true" showSearchHighlightsInPreview="false" showSelectionInPreview="true" openRemoteLinks="true" replaceUnicodeEmoji="false" lastLayoutSetsDefault="false">
<PanelProvider>
<provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.panel" providerName="Default - Swing" />
</PanelProvider>
</PreviewSettings>
<ParserSettings gitHubSyntaxChange="false" emojiShortcuts="1" emojiImages="0">
<PegdownExtensions>
<option name="ABBREVIATIONS" value="false" />
<option name="ANCHORLINKS" value="true" />
<option name="ASIDE" value="false" />
<option name="ATXHEADERSPACE" value="true" />
<option name="AUTOLINKS" value="false" />
<option name="DEFINITIONS" value="false" />
<option name="DEFINITION_BREAK_DOUBLE_BLANK_LINE" value="false" />
<option name="FENCED_CODE_BLOCKS" value="true" />
<option name="FOOTNOTES" value="false" />
<option name="HARDWRAPS" value="false" />
<option name="HTML_DEEP_PARSER" value="false" />
<option name="INSERTED" value="false" />
<option name="QUOTES" value="false" />
<option name="RELAXEDHRULES" value="true" />
<option name="SMARTS" value="false" />
<option name="STRIKETHROUGH" value="true" />
<option name="SUBSCRIPT" value="false" />
<option name="SUPERSCRIPT" value="false" />
<option name="SUPPRESS_HTML_BLOCKS" value="false" />
<option name="SUPPRESS_INLINE_HTML" value="false" />
<option name="TABLES" value="true" />
<option name="TASKLISTITEMS" value="true" />
<option name="TOC" value="false" />
<option name="WIKILINKS" value="false" />
</PegdownExtensions>
<ParserOptions>
<option name="ADMONITION_EXT" value="false" />
<option name="ATTRIBUTES_EXT" value="false" />
<option name="COMMONMARK_LISTS" value="true" />
<option name="DUMMY" value="false" />
<option name="EMOJI_SHORTCUTS" value="true" />
<option name="ENUMERATED_REFERENCES_EXT" value="false" />
<option name="FLEXMARK_FRONT_MATTER" value="false" />
<option name="GFM_LOOSE_BLANK_LINE_AFTER_ITEM_PARA" value="false" />
<option name="GFM_TABLE_RENDERING" value="true" />
<option name="GITBOOK_URL_ENCODING" value="false" />
<option name="GITHUB_LISTS" value="false" />
<option name="GITHUB_WIKI_LINKS" value="false" />
<option name="GITLAB_EXT" value="false" />
<option name="GITLAB_MATH_EXT" value="false" />
<option name="GITLAB_MERMAID_EXT" value="false" />
<option name="HEADER_ID_NON_ASCII_TO_LOWERCASE" value="false" />
<option name="HEADER_ID_NO_DUPED_DASHES" value="false" />
<option name="JEKYLL_FRONT_MATTER" value="false" />
<option name="MACROS_EXT" value="false" />
<option name="NO_TEXT_ATTRIBUTES" value="false" />
<option name="PARSE_HTML_ANCHOR_ID" value="false" />
<option name="PLANTUML_FENCED_CODE" value="false" />
<option name="PUML_FENCED_CODE" value="false" />
<option name="SIM_TOC_BLANK_LINE_SPACER" value="true" />
</ParserOptions>
</ParserSettings>
<HtmlSettings headerTopEnabled="false" headerBottomEnabled="false" bodyTopEnabled="false" bodyBottomEnabled="false" embedUrlContent="false" addPageHeader="true" embedImages="false" embedHttpImages="false" imageUriSerials="false" addDocTypeHtml="true" noParaTags="false" plantUmlConversion="0" mathConversion="0">
<GeneratorProvider>
<provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.generator" providerName="Default Swing HTML Generator" />
</GeneratorProvider>
<headerTop />
<headerBottom />
<bodyTop />
<bodyBottom />
</HtmlSettings>
<CssSettings previewScheme="UI_SCHEME" cssUri="" isCssUriEnabled="false" isCssUriSerial="true" isCssTextEnabled="false" isDynamicPageWidth="true">
<StylesheetProvider>
<provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.css" providerName="Default Swing Stylesheet" />
</StylesheetProvider>
<ScriptProviders />
<cssText />
<cssUriHistory />
</CssSettings>
<AnnotatorSettings targetHasSpaces="true" linkCaseMismatch="true" wikiCaseMismatch="true" wikiLinkHasDashes="true" notUnderWikiHome="true" targetNotWikiPageExt="true" notUnderSourceWikiHome="true" targetNameHasAnchor="true" targetPathHasAnchor="true" wikiLinkHasSlash="true" wikiLinkHasSubdir="true" wikiLinkHasOnlyAnchor="true" linkTargetsWikiHasExt="true" linkTargetsWikiHasBadExt="true" notUnderSameRepo="true" targetNotUnderVcs="false" linkNeedsExt="true" linkHasBadExt="true" linkTargetNeedsExt="true" linkTargetHasBadExt="true" wikiLinkNotInWiki="true" imageTargetNotInRaw="true" repoRelativeAcrossVcsRoots="true" multipleWikiTargetsMatch="true" unresolvedLinkReference="true" linkIsIgnored="true" anchorIsIgnored="true" anchorIsUnresolved="true" anchorLineReferenceIsUnresolved="true" anchorLineReferenceFormat="true" anchorHasDuplicates="true" abbreviationDuplicates="true" abbreviationNotUsed="true" attributeIdDuplicateDefinition="true" attributeIdNotUsed="true" footnoteDuplicateDefinition="true" footnoteUnresolved="true" footnoteDuplicates="true" footnoteNotUsed="true" macroDuplicateDefinition="true" macroUnresolved="true" macroDuplicates="true" macroNotUsed="true" referenceDuplicateDefinition="true" referenceUnresolved="true" referenceDuplicates="true" referenceNotUsed="true" referenceUnresolvedNumericId="true" enumRefDuplicateDefinition="true" enumRefUnresolved="true" enumRefDuplicates="true" enumRefNotUsed="true" enumRefLinkUnresolved="true" enumRefLinkDuplicates="true" simTocUpdateNeeded="true" simTocTitleSpaceNeeded="true" />
<HtmlExportSettings updateOnSave="false" parentDir="" targetDir="" cssDir="css" scriptDir="js" plainHtml="false" imageDir="" copyLinkedImages="false" imageUniquifyType="0" targetPathType="2" targetExt="" useTargetExt="false" noCssNoScripts="false" useElementStyleAttribute="false" linkToExportedHtml="true" exportOnSettingsChange="true" regenerateOnProjectOpen="false" linkFormatType="HTTP_ABSOLUTE" />
<LinkMapSettings>
<textMaps />
</LinkMapSettings>
</component>
</project>

View File

@ -0,0 +1,3 @@
<component name="MarkdownNavigator.ProfileManager">
<settings default="" pdf-export="" plain-text-search-scope="Project Files" />
</component>

10
.idea/misc.xml generated Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="MacroExpansionManager">
<option name="directoryName" value="DmznAGbP" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/squid-js.iml" filepath="$PROJECT_DIR$/.idea/squid-js.iml" />
</modules>
</component>
</project>

12
.idea/squid-js.iml generated Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="projectConfiguration" value="Twisted Trial" />
<option name="PROJECT_TEST_RUNNER" value="Twisted Trial" />
</component>
</module>

6
.idea/typescript-compiler.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="TypeScriptCompiler">
<option name="recompileOnChanges" value="true" />
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

59
integration/config.js Normal file
View File

@ -0,0 +1,59 @@
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
exports.__esModule = true;
var hdwallet_provider_1 = __importDefault(require("@truffle/hdwallet-provider"));
var configJson = {
nodeUri: 'http://localhost:8545',
aquariusUri: 'http://aquarius:5000',
brizoUri: 'http://localhost:8030',
secretStoreUri: 'http://localhost:12001',
brizoAddress: '0x068ed00cf0441e4829d9784fcbe7b9e26d4bd8d0',
verbose: false
};
if (process.env.NETWORK_NAME === 'pacific') {
Object.assign(configJson, {
nodeUri: 'https://pacific.oceanprotocol.com',
aquariusUri: 'https://aquarius.commons.oceanprotocol.com',
brizoUri: 'https://brizo.commons.oceanprotocol.com',
secretStoreUri: 'https://secret-store.oceanprotocol.com',
brizoAddress: '0x008c25ed3594e094db4592f4115d5fa74c4f41ea'
});
}
if (process.env.NETWORK_NAME === 'nile') {
Object.assign(configJson, {
nodeUri: 'https://nile.dev-ocean.com',
aquariusUri: 'https://aquarius.nile.dev-ocean.com',
brizoUri: 'https://brizo.nile.dev-ocean.com',
secretStoreUri: 'https://secret-store.nile.dev-ocean.com',
brizoAddress: '0x413c9ba0a05b8a600899b41b0c62dd661e689354'
});
}
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'
});
}
if (process.env.SEED_WORDS) {
var seedphrase = process.env.SEED_WORDS;
// @ts-ignore
configJson.web3Provider = new hdwallet_provider_1["default"](seedphrase, configJson.nodeUri, 0, 5);
}
exports.config = configJson;
exports.config.forceVerbose = __assign(__assign({}, configJson), { verbose: true });

View File

@ -0,0 +1,209 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
exports.__esModule = true;
var chai_1 = require("chai");
var config_1 = require("../config");
var utils_1 = require("../utils");
var src_1 = require("../../src"); // @oceanprotocol/squid
describe('Asset Owners', function () {
var ocean;
var account1;
var account2;
var metadata = utils_1.getMetadata();
before(function () { return __awaiter(void 0, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, src_1.Ocean.getInstance(config_1.config)
// Accounts
];
case 1:
ocean = _b.sent();
return [4 /*yield*/, ocean.accounts.list()];
case 2:
_a = _b.sent(), account1 = _a[0], account2 = _a[1];
if (!ocean.keeper.dispenser) {
metadata = utils_1.getMetadata(0);
}
return [2 /*return*/];
}
});
}); });
it('should set the owner of an asset', function () { return __awaiter(void 0, void 0, void 0, function () {
var ddo, owner;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ocean.assets.create(metadata, account1)];
case 1:
ddo = _a.sent();
return [4 /*yield*/, ocean.assets.owner(ddo.id)];
case 2:
owner = _a.sent();
chai_1.assert.equal(owner, account1.getId());
return [2 /*return*/];
}
});
}); });
it('should set the provider of an asset', function () { return __awaiter(void 0, void 0, void 0, function () {
var ddo, isProvider;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ocean.assets.create(metadata, account1)];
case 1:
ddo = _a.sent();
return [4 /*yield*/, ocean.keeper.didRegistry.isDIDProvider(ddo.id, config_1.config.brizoAddress)];
case 2:
isProvider = _a.sent();
chai_1.assert.isTrue(isProvider);
return [2 /*return*/];
}
});
}); });
it('should be added correctly a permission on an asset', function () { return __awaiter(void 0, void 0, void 0, function () {
var ddo, _a, _b, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0: return [4 /*yield*/, ocean.assets.create(metadata, account1)];
case 1:
ddo = _e.sent();
_b = (_a = chai_1.assert).isFalse;
return [4 /*yield*/, ocean.keeper.didRegistry.getPermission(ddo.id, account2.getId())];
case 2:
_b.apply(_a, [_e.sent()]);
return [4 /*yield*/, ocean.keeper.didRegistry.grantPermission(ddo.id, account2.getId(), account1.getId())];
case 3:
_e.sent();
_d = (_c = chai_1.assert).isTrue;
return [4 /*yield*/, ocean.keeper.didRegistry.getPermission(ddo.id, account2.getId())];
case 4:
_d.apply(_c, [_e.sent()]);
return [2 /*return*/];
}
});
}); });
it('should get the assets owned by a user', function () { return __awaiter(void 0, void 0, void 0, function () {
var initialLength, finalLength;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ocean.assets.ownerAssets(account2.getId())];
case 1:
initialLength = (_a.sent()).length;
return [4 /*yield*/, ocean.assets.create(metadata, account1)];
case 2:
_a.sent();
return [4 /*yield*/, ocean.assets.create(metadata, account1)];
case 3:
_a.sent();
return [4 /*yield*/, ocean.assets.create(metadata, account2)];
case 4:
_a.sent();
return [4 /*yield*/, ocean.assets.ownerAssets(account2.getId())];
case 5:
finalLength = (_a.sent()).length;
chai_1.assert.equal(finalLength - initialLength, 1);
return [2 /*return*/];
}
});
}); });
it('should get the assets that can be consumed by a user', function () { return __awaiter(void 0, void 0, void 0, function () {
var initialLength, ddo, finalLength1, _a, _b, _c, _d, _e, _f, _g, index, finalLength2;
return __generator(this, function (_h) {
switch (_h.label) {
case 0: return [4 /*yield*/, ocean.assets.consumerAssets(account2.getId())];
case 1:
initialLength = (_h.sent()).length;
return [4 /*yield*/, ocean.assets.create(metadata, account1)];
case 2:
ddo = _h.sent();
return [4 /*yield*/, ocean.assets.consumerAssets(account2.getId())];
case 3:
finalLength1 = (_h.sent()).length;
chai_1.assert.equal(finalLength1 - initialLength, 0);
_h.label = 4;
case 4:
_h.trys.push([4, 7, , 8]);
_b = (_a = account2).requestTokens;
_c = +metadata.main.price;
_e = (_d = Math).pow;
_f = [10];
return [4 /*yield*/, ocean.keeper.token.decimals()];
case 5: return [4 /*yield*/, _b.apply(_a, [_c * _e.apply(_d, _f.concat([-(_h.sent())]))])];
case 6:
_h.sent();
return [3 /*break*/, 8];
case 7:
_g = _h.sent();
return [3 /*break*/, 8];
case 8:
index = ddo.findServiceByType('access').index;
return [4 /*yield*/, ocean.assets.order(ddo.id, index, account2)
// Access granted
];
case 9:
_h.sent();
return [4 /*yield*/, ocean.assets.consumerAssets(account2.getId())];
case 10:
finalLength2 = (_h.sent()).length;
chai_1.assert.equal(finalLength2 - initialLength, 1);
return [2 /*return*/];
}
});
}); });
it('should be able to transfer ownership', function () { return __awaiter(void 0, void 0, void 0, function () {
var id, newOwner;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ocean.assets.create(metadata, account1)
// transfer
];
case 1:
id = (_a.sent()).id;
// transfer
return [4 /*yield*/, ocean.assets.transferOwnership(id, account2.getId())];
case 2:
// transfer
_a.sent();
return [4 /*yield*/, ocean.keeper.didRegistry.getDIDOwner(id)];
case 3:
newOwner = _a.sent();
chai_1.assert.equal(newOwner, account2.getId());
return [2 /*return*/];
}
});
}); });
});

View File

@ -0,0 +1,183 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
exports.__esModule = true;
var chai_1 = require("chai");
var config_1 = require("../config");
var src_1 = require("../../src"); // @oceanprotocol/squid
describe('Authentication Token', function () {
var ocean;
var account1;
var account2;
before(function () { return __awaiter(void 0, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
try {
localStorage.clear();
}
catch (_c) { }
return [4 /*yield*/, src_1.Ocean.getInstance(config_1.config)
// Accounts
];
case 1:
ocean = _b.sent();
return [4 /*yield*/, ocean.accounts.list()];
case 2:
_a = _b.sent(), account1 = _a[0], account2 = _a[1];
return [2 /*return*/];
}
});
}); });
after(function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
try {
localStorage.clear();
}
catch (_b) { }
return [2 /*return*/];
});
}); });
it('should generate a token', function () { return __awaiter(void 0, void 0, void 0, function () {
var token;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ocean.auth.get(account1)];
case 1:
token = _a.sent();
chai_1.assert.match(token, /^0x[a-f0-9]{130}-[0-9]{0,14}/i);
return [2 /*return*/];
}
});
}); });
it('should return the account that signed the token', function () { return __awaiter(void 0, void 0, void 0, function () {
var token, address;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ocean.auth.get(account1)];
case 1:
token = _a.sent();
return [4 /*yield*/, ocean.auth.check(token)];
case 2:
address = _a.sent();
chai_1.assert.equal(address, account1.getId());
return [2 /*return*/];
}
});
}); });
it('should store the token for a user', function () { return __awaiter(void 0, void 0, void 0, function () {
var _a, _b, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
_b = (_a = chai_1.assert).isUndefined;
return [4 /*yield*/, account1.getToken()];
case 1:
_b.apply(_a, [_e.sent()]);
return [4 /*yield*/, ocean.auth.store(account1)];
case 2:
_e.sent();
_d = (_c = chai_1.assert).match;
return [4 /*yield*/, account1.getToken()];
case 3:
_d.apply(_c, [_e.sent(), /^0x[a-f0-9]{130}-[0-9]{0,14}/i]);
return [2 /*return*/];
}
});
}); });
it('should restore the token for a user', function () { return __awaiter(void 0, void 0, void 0, function () {
var token;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ocean.auth.restore(account1)];
case 1:
token = _a.sent();
chai_1.assert.match(token, /^0x[a-f0-9]{130}-[0-9]{0,14}/i);
return [2 /*return*/];
}
});
}); });
it('should return undefined when is not stored', function () { return __awaiter(void 0, void 0, void 0, function () {
var token;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ocean.auth.restore(account2)];
case 1:
token = _a.sent();
chai_1.assert.isUndefined(token);
return [2 /*return*/];
}
});
}); });
it('should know if the token is stored', function () { return __awaiter(void 0, void 0, void 0, function () {
var acc1Stored, acc2Stored, _a, _b, _c, _d, _e, _f;
return __generator(this, function (_g) {
switch (_g.label) {
case 0: return [4 /*yield*/, ocean.auth.isStored(account1)];
case 1:
// eslint-disable-next-line
acc1Stored = _g.sent();
return [4 /*yield*/, ocean.auth.isStored(account2)];
case 2:
acc2Stored = _g.sent();
chai_1.assert.isTrue(acc1Stored);
_b = (_a = chai_1.assert).isTrue;
return [4 /*yield*/, account1.isTokenStored()];
case 3:
_b.apply(_a, [_g.sent()]);
chai_1.assert.isFalse(acc2Stored);
_d = (_c = chai_1.assert).isFalse;
return [4 /*yield*/, account2.isTokenStored()];
case 4:
_d.apply(_c, [_g.sent()]);
return [4 /*yield*/, account2.authenticate()];
case 5:
_g.sent();
return [4 /*yield*/, ocean.auth.isStored(account2)];
case 6:
acc2Stored = _g.sent();
chai_1.assert.isTrue(acc2Stored);
_f = (_e = chai_1.assert).isTrue;
return [4 /*yield*/, account2.isTokenStored()];
case 7:
_f.apply(_e, [_g.sent()]);
return [2 /*return*/];
}
});
}); });
});

View File

@ -0,0 +1,268 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
exports.__esModule = true;
var chai_1 = require("chai");
var fs = __importStar(require("fs"));
var config_1 = require("../config");
var utils_1 = require("../utils");
var src_1 = require("../../src"); // @oceanprotocol/squid
describe('Consume Asset', function () {
var ocean;
var publisher;
var consumer;
var metadata = utils_1.getMetadata();
var ddo;
var serviceAgreementSignatureResult;
before(function () { return __awaiter(void 0, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, src_1.Ocean.getInstance(config_1.config)
// Accounts
];
case 1:
ocean = _b.sent();
return [4 /*yield*/, ocean.accounts.list()];
case 2:
_a = _b.sent(), publisher = _a[0], consumer = _a[1];
if (!ocean.keeper.dispenser) {
metadata = utils_1.getMetadata(0);
}
return [2 /*return*/];
}
});
}); });
it('should register an asset', function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ocean.assets.create(metadata, publisher)];
case 1:
ddo = _a.sent();
chai_1.assert.isDefined(ddo, 'Register has not returned a DDO');
chai_1.assert.match(ddo.id, /^did:op:[a-f0-9]{64}$/, 'DDO id is not valid');
chai_1.assert.isAtLeast(ddo.authentication.length, 1, 'Default authentication not added');
chai_1.assert.isDefined(ddo.findServiceByType('access'), "DDO access service doesn't exist");
return [2 /*return*/];
}
});
}); });
it('should be able to request tokens for consumer', function () { return __awaiter(void 0, void 0, void 0, function () {
var initialBalance, claimedTokens, _a, _b, _c, _d, _e, _f, _g;
return __generator(this, function (_h) {
switch (_h.label) {
case 0: return [4 /*yield*/, consumer.getBalance()];
case 1:
initialBalance = (_h.sent()).ocn;
_a = +metadata.main.price;
_c = (_b = Math).pow;
_d = [10];
return [4 /*yield*/, ocean.keeper.token.decimals()];
case 2:
claimedTokens = _a * _c.apply(_b, _d.concat([-(_h.sent())]));
_h.label = 3;
case 3:
_h.trys.push([3, 5, , 6]);
return [4 /*yield*/, consumer.requestTokens(claimedTokens)];
case 4:
_h.sent();
return [3 /*break*/, 6];
case 5:
_e = _h.sent();
return [3 /*break*/, 6];
case 6:
_g = (_f = chai_1.assert).equal;
return [4 /*yield*/, consumer.getBalance()];
case 7:
_g.apply(_f, [(_h.sent()).ocn,
initialBalance + claimedTokens,
'OCN Tokens not delivered']);
return [2 /*return*/];
}
});
}); });
it('should sign the service agreement', function () { return __awaiter(void 0, void 0, void 0, function () {
var accessService, agreementId, signature;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
accessService = ddo.findServiceByType('access');
return [4 /*yield*/, ocean.agreements.prepare(ddo.id, accessService.index, consumer)];
case 1:
serviceAgreementSignatureResult = _a.sent();
agreementId = serviceAgreementSignatureResult.agreementId, signature = serviceAgreementSignatureResult.signature;
chai_1.assert.match(agreementId, /^0x[a-f0-9]{64}$/, 'Service agreement ID seems not valid');
chai_1.assert.match(signature, /^0x[a-f0-9]{130}$/, 'Service agreement signature seems not valid');
return [2 /*return*/];
}
});
}); });
it('should execute the service agreement', function () { return __awaiter(void 0, void 0, void 0, function () {
var accessService, success;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
accessService = ddo.findServiceByType('access');
return [4 /*yield*/, ocean.agreements.create(ddo.id, serviceAgreementSignatureResult.agreementId, accessService.index, serviceAgreementSignatureResult.signature, consumer, publisher)];
case 1:
success = _a.sent();
chai_1.assert.isTrue(success);
return [2 /*return*/];
}
});
}); });
it('should get the agreement conditions status not fulfilled', function () { return __awaiter(void 0, void 0, void 0, function () {
var status;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ocean.agreements.status(serviceAgreementSignatureResult.agreementId)];
case 1:
status = _a.sent();
chai_1.assert.deepEqual(status, {
lockReward: src_1.ConditionState.Unfulfilled,
accessSecretStore: src_1.ConditionState.Unfulfilled,
escrowReward: src_1.ConditionState.Unfulfilled
});
return [2 /*return*/];
}
});
}); });
it('should lock the payment by the consumer', function () { return __awaiter(void 0, void 0, void 0, function () {
var paid;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ocean.agreements.conditions.lockReward(serviceAgreementSignatureResult.agreementId, ddo.findServiceByType('metadata').attributes.main.price, consumer)];
case 1:
paid = _a.sent();
chai_1.assert.isTrue(paid, 'The asset has not been paid correctly');
return [2 /*return*/];
}
});
}); });
// The test will fail because Brizo grants the access faster
it('should grant the access by the publisher', function () { return __awaiter(void 0, void 0, void 0, function () {
var granted, accessGranted, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_b.trys.push([0, 3, , 4]);
return [4 /*yield*/, ocean.agreements.conditions.grantAccess(serviceAgreementSignatureResult.agreementId, ddo.id, consumer.getId(), publisher)];
case 1:
granted = _b.sent();
chai_1.assert.isTrue(granted, 'The asset has not been granted correctly');
return [4 /*yield*/, ocean.keeper.conditions.accessSecretStoreCondition.checkPermissions(consumer.getId(), ddo.id)];
case 2:
accessGranted = _b.sent();
chai_1.assert.isTrue(accessGranted, 'Consumer has been granted.');
return [3 /*break*/, 4];
case 3:
_a = _b.sent();
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
}
});
}); });
it('should get the agreement conditions status fulfilled', function () { return __awaiter(void 0, void 0, void 0, function () {
var status;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ocean.agreements.status(serviceAgreementSignatureResult.agreementId)];
case 1:
status = _a.sent();
chai_1.assert.deepEqual(status, {
lockReward: src_1.ConditionState.Fulfilled,
accessSecretStore: src_1.ConditionState.Fulfilled,
escrowReward: src_1.ConditionState.Unfulfilled
});
return [2 /*return*/];
}
});
}); });
it('should consume and store the assets', function () { return __awaiter(void 0, void 0, void 0, function () {
var accessService, folder, path, files;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
accessService = ddo.findServiceByType('access');
folder = '/tmp/ocean/squid-js-1';
return [4 /*yield*/, ocean.assets.consume(serviceAgreementSignatureResult.agreementId, ddo.id, accessService.index, consumer, folder)];
case 1:
path = _a.sent();
chai_1.assert.include(path, folder, 'The storage path is not correct.');
return [4 /*yield*/, new Promise(function (resolve) {
fs.readdir(path, function (e, fileList) {
resolve(fileList);
});
})];
case 2:
files = _a.sent();
chai_1.assert.deepEqual(files, ['README.md', 'package.json'], 'Stored files are not correct.');
return [2 /*return*/];
}
});
}); });
it('should consume and store one asset', function () { return __awaiter(void 0, void 0, void 0, function () {
var accessService, folder, path, files;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
accessService = ddo.findServiceByType('access');
folder = '/tmp/ocean/squid-js-2';
return [4 /*yield*/, ocean.assets.consume(serviceAgreementSignatureResult.agreementId, ddo.id, accessService.index, consumer, folder, 1)];
case 1:
path = _a.sent();
chai_1.assert.include(path, folder, 'The storage path is not correct.');
return [4 /*yield*/, new Promise(function (resolve) {
fs.readdir(path, function (e, fileList) {
resolve(fileList);
});
})];
case 2:
files = _a.sent();
chai_1.assert.deepEqual(files, ['README.md'], 'Stored files are not correct.');
return [2 /*return*/];
}
});
}); });
});

View File

@ -0,0 +1,170 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
exports.__esModule = true;
var chai_1 = require("chai");
var fs = __importStar(require("fs"));
var config_1 = require("../config");
var utils_1 = require("../utils");
var src_1 = require("../../src"); // @oceanprotocol/squid
describe('Consume Asset (Brizo)', function () {
var ocean;
var publisher;
var consumer;
var ddo;
var agreementId;
var metadata = utils_1.getMetadata();
before(function () { return __awaiter(void 0, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, src_1.Ocean.getInstance(config_1.config)
// Accounts
];
case 1:
ocean = _b.sent();
return [4 /*yield*/, ocean.accounts.list()];
case 2:
_a = _b.sent(), publisher = _a[0], consumer = _a[1];
if (!ocean.keeper.dispenser) {
metadata = utils_1.getMetadata(0);
}
return [2 /*return*/];
}
});
}); });
after(function () {
try {
localStorage.clear();
}
catch (_a) { }
});
it('should authenticate the accounts', function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, publisher.authenticate()];
case 1:
_a.sent();
return [4 /*yield*/, consumer.authenticate()];
case 2:
_a.sent();
return [2 /*return*/];
}
});
}); });
it('should regiester an asset', function () { return __awaiter(void 0, void 0, void 0, function () {
var steps;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
steps = [];
return [4 /*yield*/, ocean.assets
.create(metadata, publisher)
.next(function (step) { return steps.push(step); })];
case 1:
ddo = _a.sent();
chai_1.assert.instanceOf(ddo, src_1.DDO);
chai_1.assert.deepEqual(steps, [0, 1, 2, 3, 4, 5, 6, 7]);
return [2 /*return*/];
}
});
}); });
it('should order the asset', function () { return __awaiter(void 0, void 0, void 0, function () {
var accessService, _a, _b, _c, _d, _e, _f, _g, steps;
return __generator(this, function (_h) {
switch (_h.label) {
case 0:
accessService = ddo.findServiceByType('access');
_h.label = 1;
case 1:
_h.trys.push([1, 4, , 5]);
_b = (_a = consumer).requestTokens;
_c = +metadata.main.price;
_e = (_d = Math).pow;
_f = [10];
return [4 /*yield*/, ocean.keeper.token.decimals()];
case 2: return [4 /*yield*/, _b.apply(_a, [_c * _e.apply(_d, _f.concat([-(_h.sent())]))])];
case 3:
_h.sent();
return [3 /*break*/, 5];
case 4:
_g = _h.sent();
return [3 /*break*/, 5];
case 5:
steps = [];
return [4 /*yield*/, ocean.assets
.order(ddo.id, accessService.index, consumer)
.next(function (step) { return steps.push(step); })];
case 6:
agreementId = _h.sent();
chai_1.assert.isDefined(agreementId);
chai_1.assert.deepEqual(steps, [0, 1, 2, 3]);
return [2 /*return*/];
}
});
}); });
it('should consume and store the assets', function () { return __awaiter(void 0, void 0, void 0, function () {
var accessService, folder, path, files;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
accessService = ddo.findServiceByType('access');
folder = '/tmp/ocean/squid-js';
return [4 /*yield*/, ocean.assets.consume(agreementId, ddo.id, accessService.index, consumer, folder)];
case 1:
path = _a.sent();
chai_1.assert.include(path, folder, 'The storage path is not correct.');
return [4 /*yield*/, new Promise(function (resolve) {
fs.readdir(path, function (e, fileList) {
resolve(fileList);
});
})];
case 2:
files = _a.sent();
chai_1.assert.deepEqual(files, ['README.md', 'package.json'], 'Stored files are not correct.');
return [2 /*return*/];
}
});
}); });
});

View File

@ -0,0 +1,160 @@
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
exports.__esModule = true;
var chai_1 = require("chai");
var fs = __importStar(require("fs"));
var config_1 = require("../config");
var utils_1 = require("../utils");
var src_1 = require("../../src"); // @oceanprotocol/squid
// Ensure that your network is fast enought and you have some free ram before run it.
xdescribe('Consume Asset (Large size)', function () {
var ocean;
var publisher;
var consumer;
var ddo;
var agreementId;
var baseMetadata = utils_1.getMetadata();
var metadata = utils_1.getMetadata();
before(function () { return __awaiter(void 0, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, src_1.Ocean.getInstance(config_1.config)
// Accounts
];
case 1:
ocean = _b.sent();
return [4 /*yield*/, ocean.accounts.list()];
case 2:
_a = _b.sent(), publisher = _a[0], consumer = _a[1];
if (!ocean.keeper.dispenser) {
baseMetadata = utils_1.getMetadata(0);
}
metadata = __assign(__assign({}, baseMetadata), { main: __assign(__assign({}, baseMetadata.main), { files: [
{
index: 0,
contentType: 'hello/hello',
url: 'https://speed.hetzner.de/1GB.bin'
}
] }) });
return [2 /*return*/];
}
});
}); });
it('should regiester an asset', function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ocean.assets.create(metadata, publisher)];
case 1:
ddo = _a.sent();
chai_1.assert.instanceOf(ddo, src_1.DDO);
return [2 /*return*/];
}
});
}); });
it('should order the asset', function () { return __awaiter(void 0, void 0, void 0, function () {
var accessService, _a, _b, _c, _d, _e, _f, _g;
return __generator(this, function (_h) {
switch (_h.label) {
case 0:
accessService = ddo.findServiceByType('access');
_h.label = 1;
case 1:
_h.trys.push([1, 4, , 5]);
_b = (_a = consumer).requestTokens;
_c = +metadata.main.price;
_e = (_d = Math).pow;
_f = [10];
return [4 /*yield*/, ocean.keeper.token.decimals()];
case 2: return [4 /*yield*/, _b.apply(_a, [_c * _e.apply(_d, _f.concat([-(_h.sent())]))])];
case 3:
_h.sent();
return [3 /*break*/, 5];
case 4:
_g = _h.sent();
return [3 /*break*/, 5];
case 5: return [4 /*yield*/, ocean.assets.order(ddo.id, accessService.index, consumer)];
case 6:
agreementId = _h.sent();
chai_1.assert.isDefined(agreementId);
return [2 /*return*/];
}
});
}); });
it('should consume and store the assets', function () { return __awaiter(void 0, void 0, void 0, function () {
var accessService, folder, path, files;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
accessService = ddo.findServiceByType('access');
folder = '/tmp/ocean/squid-js';
return [4 /*yield*/, ocean.assets.consume(agreementId, ddo.id, accessService.index, consumer, folder)];
case 1:
path = _a.sent();
chai_1.assert.include(path, folder, 'The storage path is not correct.');
return [4 /*yield*/, new Promise(function (resolve) {
fs.readdir(path, function (e, fileList) {
resolve(fileList);
});
})];
case 2:
files = _a.sent();
chai_1.assert.deepEqual(files, ['1GB.bin'], 'Stored files are not correct.');
return [2 /*return*/];
}
});
}); });
});

View File

@ -0,0 +1,376 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
exports.__esModule = true;
var chai_1 = require("chai");
var config_1 = require("../config");
var src_1 = require("../../src"); // @oceanprotocol/squid
var LockRewardCondition = src_1.conditions.LockRewardCondition, EscrowReward = src_1.conditions.EscrowReward, AccessSecretStoreCondition = src_1.conditions.AccessSecretStoreCondition;
describe('Register Escrow Access Secret Store Template', function () {
var ocean;
var keeper;
var template;
var url = 'https://example.com/did/ocean/test-attr-example.txt';
var checksum = 'b'.repeat(32);
var escrowAmount = 12;
var templateManagerOwner;
var publisher;
var consumer;
var accessSecretStoreCondition;
var lockRewardCondition;
var escrowReward;
before(function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, src_1.Ocean.getInstance(config_1.config)];
case 1:
ocean = _a.sent();
keeper = ocean.keeper;
template = keeper.templates.escrowAccessSecretStoreTemplate;
return [4 /*yield*/, ocean.accounts.list()];
case 2:
// Accounts
templateManagerOwner = (_a.sent())[0];
return [4 /*yield*/, ocean.accounts.list()];
case 3:
publisher = (_a.sent())[1];
return [4 /*yield*/, ocean.accounts.list()];
case 4:
consumer = (_a.sent())[2];
// Conditions
accessSecretStoreCondition = keeper.conditions.accessSecretStoreCondition;
lockRewardCondition = keeper.conditions.lockRewardCondition;
escrowReward = keeper.conditions.escrowReward;
if (!ocean.keeper.dispenser) {
escrowAmount = 0;
}
return [2 /*return*/];
}
});
}); });
describe('Propose and approve template', function () {
it('should propose the template', function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, keeper.templateStoreManager.proposeTemplate(template.getId(), consumer.getId(), true)
// TODO: Use a event to detect template mined
];
case 1:
_a.sent();
// TODO: Use a event to detect template mined
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 2 * 1000); })];
case 2:
// TODO: Use a event to detect template mined
_a.sent();
return [2 /*return*/];
}
});
}); });
it('should approve the template', function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, keeper.templateStoreManager.approveTemplate(template.getId(), templateManagerOwner.getId(), true)
// TODO: Use a event to detect template mined
];
case 1:
_a.sent();
// TODO: Use a event to detect template mined
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 2 * 1000); })];
case 2:
// TODO: Use a event to detect template mined
_a.sent();
return [2 /*return*/];
}
});
}); });
});
describe('Full flow', function () {
var agreementId = "0x" + src_1.utils.generateId();
var did = "0x" + src_1.utils.generateId();
var conditionIdAccess;
var conditionIdLock;
var conditionIdEscrow;
it('should register a DID', function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, keeper.didRegistry.registerAttribute(did, checksum, [], url, publisher.getId())];
case 1:
_a.sent();
return [2 /*return*/];
}
});
}); });
it('should generate the condition IDs', function () { return __awaiter(void 0, void 0, void 0, function () {
var _a, _b, _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0: return [4 /*yield*/, accessSecretStoreCondition.generateIdHash(agreementId, did, consumer.getId())];
case 1:
conditionIdAccess = _d.sent();
_b = (_a = lockRewardCondition).generateIdHash;
_c = [agreementId];
return [4 /*yield*/, escrowReward.getAddress()];
case 2: return [4 /*yield*/, _b.apply(_a, _c.concat([_d.sent(),
escrowAmount]))];
case 3:
conditionIdLock = _d.sent();
return [4 /*yield*/, escrowReward.generateIdHash(agreementId, escrowAmount, publisher.getId(), consumer.getId(), conditionIdLock, conditionIdAccess)];
case 4:
conditionIdEscrow = _d.sent();
return [2 /*return*/];
}
});
}); });
it('should have conditions types', function () { return __awaiter(void 0, void 0, void 0, function () {
var conditionTypes;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, template.getConditionTypes()];
case 1:
conditionTypes = _a.sent();
chai_1.assert.equal(conditionTypes.length, 3, 'Expected 3 conditions.');
chai_1.assert.deepEqual(__spreadArrays(conditionTypes).sort(), [
accessSecretStoreCondition.getAddress(),
escrowReward.getAddress(),
lockRewardCondition.getAddress()
].sort(), "The conditions doesn't match");
return [2 /*return*/];
}
});
}); });
it('should have condition instances asociated', function () { return __awaiter(void 0, void 0, void 0, function () {
var conditionInstances, conditionClasses;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, template.getConditionTypes()];
case 1:
conditionInstances = (_a.sent()).map(function (address) {
return keeper.getConditionByAddress(address);
});
chai_1.assert.equal(conditionInstances.length, 3, 'Expected 3 conditions.');
conditionClasses = [
AccessSecretStoreCondition,
EscrowReward,
LockRewardCondition
];
conditionClasses.forEach(function (conditionClass) {
if (!conditionInstances.find(function (condition) { return condition instanceof conditionClass; })) {
throw new Error(conditionClass.name + " is not part of the conditions.");
}
});
return [2 /*return*/];
}
});
}); });
it('should create a new agreement', function () { return __awaiter(void 0, void 0, void 0, function () {
var agreement;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, keeper.agreementStoreManager.createAgreement(agreementId, did, template.getId(), [conditionIdLock, conditionIdAccess, conditionIdEscrow], [0, 0, 0], [0, 0, 0], [consumer.getId(), publisher.getId()], publisher.getId())];
case 1:
agreement = _a.sent();
chai_1.assert.isTrue(agreement.status);
return [2 /*return*/];
}
});
}); });
it('should not grant the access to the consumer', function () { return __awaiter(void 0, void 0, void 0, function () {
var accessGranted;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, accessSecretStoreCondition.checkPermissions(consumer.getId(), did)];
case 1:
accessGranted = _a.sent();
chai_1.assert.isFalse(accessGranted, 'Consumer has been granted.');
return [2 /*return*/];
}
});
}); });
it('should fulfill LockRewardCondition', function () { return __awaiter(void 0, void 0, void 0, function () {
var _a, fulfill;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_b.trys.push([0, 2, , 3]);
return [4 /*yield*/, consumer.requestTokens(escrowAmount)];
case 1:
_b.sent();
return [3 /*break*/, 3];
case 2:
_a = _b.sent();
return [3 /*break*/, 3];
case 3: return [4 /*yield*/, keeper.token.approve(lockRewardCondition.getAddress(), escrowAmount, consumer.getId())];
case 4:
_b.sent();
return [4 /*yield*/, lockRewardCondition.fulfill(agreementId, escrowReward.getAddress(), escrowAmount, consumer.getId())];
case 5:
fulfill = _b.sent();
chai_1.assert.isDefined(fulfill.events.Fulfilled, 'Not Fulfilled event.');
return [2 /*return*/];
}
});
}); });
it('should fulfill AccessSecretStoreCondition', function () { return __awaiter(void 0, void 0, void 0, function () {
var fulfill;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, accessSecretStoreCondition.fulfill(agreementId, did, consumer.getId(), publisher.getId())];
case 1:
fulfill = _a.sent();
chai_1.assert.isDefined(fulfill.events.Fulfilled, 'Not Fulfilled event.');
return [2 /*return*/];
}
});
}); });
it('should fulfill EscrowReward', function () { return __awaiter(void 0, void 0, void 0, function () {
var fulfill;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, escrowReward.fulfill(agreementId, escrowAmount, publisher.getId(), consumer.getId(), conditionIdLock, conditionIdAccess, consumer.getId())];
case 1:
fulfill = _a.sent();
chai_1.assert.isDefined(fulfill.events.Fulfilled, 'Not Fulfilled event.');
return [2 /*return*/];
}
});
}); });
it('should grant the access to the consumer', function () { return __awaiter(void 0, void 0, void 0, function () {
var accessGranted;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, accessSecretStoreCondition.checkPermissions(consumer.getId(), did)];
case 1:
accessGranted = _a.sent();
chai_1.assert.isTrue(accessGranted, 'Consumer has not been granted.');
return [2 /*return*/];
}
});
}); });
});
describe('Short flow', function () {
var did = src_1.utils.generateId();
var agreementId;
it('should register a DID', function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
// This part is executed inside Ocean.assets.create()
return [4 /*yield*/, keeper.didRegistry.registerAttribute(did, checksum, [], url, publisher.getId())];
case 1:
// This part is executed inside Ocean.assets.create()
_a.sent();
return [2 /*return*/];
}
});
}); });
it('should create a new agreement (short way)', function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, template.createFullAgreement(did, escrowAmount, consumer.getId(), publisher.getId())];
case 1:
agreementId = _a.sent();
chai_1.assert.match(agreementId, /^0x[a-f0-9]{64}$/i);
return [2 /*return*/];
}
});
}); });
it('should not grant the access to the consumer', function () { return __awaiter(void 0, void 0, void 0, function () {
var accessGranted;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, accessSecretStoreCondition.checkPermissions(consumer.getId(), did)];
case 1:
accessGranted = _a.sent();
chai_1.assert.isFalse(accessGranted, 'Consumer has been granted.');
return [2 /*return*/];
}
});
}); });
it('should fulfill the conditions from consumer side', function () { return __awaiter(void 0, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_b.trys.push([0, 2, , 3]);
return [4 /*yield*/, consumer.requestTokens(escrowAmount)];
case 1:
_b.sent();
return [3 /*break*/, 3];
case 2:
_a = _b.sent();
return [3 /*break*/, 3];
case 3: return [4 /*yield*/, ocean.agreements.conditions.lockReward(agreementId, escrowAmount, consumer)];
case 4:
_b.sent();
return [2 /*return*/];
}
});
}); });
it('should fulfill the conditions from publisher side', function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ocean.agreements.conditions.grantAccess(agreementId, did, consumer.getId(), publisher)];
case 1:
_a.sent();
return [4 /*yield*/, ocean.agreements.conditions.releaseReward(agreementId, escrowAmount, did, consumer.getId(), publisher.getId(), publisher)];
case 2:
_a.sent();
return [2 /*return*/];
}
});
}); });
it('should grant the access to the consumer', function () { return __awaiter(void 0, void 0, void 0, function () {
var accessGranted;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, accessSecretStoreCondition.checkPermissions(consumer.getId(), did)];
case 1:
accessGranted = _a.sent();
chai_1.assert.isTrue(accessGranted, 'Consumer has not been granted.');
return [2 /*return*/];
}
});
}); });
});
});

View File

@ -0,0 +1,374 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
exports.__esModule = true;
var chai_1 = require("chai");
var config_1 = require("../config");
var src_1 = require("../../src"); // @oceanprotocol/squid
var LockRewardCondition = src_1.conditions.LockRewardCondition, EscrowReward = src_1.conditions.EscrowReward, ComputeExecutionCondition = src_1.conditions.ComputeExecutionCondition;
describe('Register Escrow Compute Execution Template', function () {
var ocean;
var keeper;
var template;
var url = 'https://example.com/did/ocean/test-attr-example.txt';
var checksum = 'b'.repeat(32);
var escrowAmount = 12;
var templateManagerOwner;
var publisher;
var consumer;
var computeExecutionCondition;
var lockRewardCondition;
var escrowReward;
before(function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, src_1.Ocean.getInstance(config_1.config)];
case 1:
ocean = _a.sent();
keeper = ocean.keeper;
template = keeper.templates.escrowComputeExecutionTemplate;
return [4 /*yield*/, ocean.accounts.list()];
case 2:
// Accounts
templateManagerOwner = (_a.sent())[0];
return [4 /*yield*/, ocean.accounts.list()];
case 3:
publisher = (_a.sent())[1];
return [4 /*yield*/, ocean.accounts.list()];
case 4:
consumer = (_a.sent())[2];
// Conditions
computeExecutionCondition = keeper.conditions.computeExecutionCondition;
lockRewardCondition = keeper.conditions.lockRewardCondition;
escrowReward = keeper.conditions.escrowReward;
if (!ocean.keeper.dispenser) {
escrowAmount = 0;
}
return [2 /*return*/];
}
});
}); });
describe('Propose and approve template', function () {
it('should propose the template', function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, keeper.templateStoreManager.proposeTemplate(template.getId(), consumer.getId(), true)
// TODO: Use a event to detect template mined
];
case 1:
_a.sent();
// TODO: Use a event to detect template mined
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 2 * 1000); })];
case 2:
// TODO: Use a event to detect template mined
_a.sent();
return [2 /*return*/];
}
});
}); });
it('should approve the template', function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, keeper.templateStoreManager.approveTemplate(template.getId(), templateManagerOwner.getId(), true)
// TODO: Use a event to detect template mined
];
case 1:
_a.sent();
// TODO: Use a event to detect template mined
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 2 * 1000); })];
case 2:
// TODO: Use a event to detect template mined
_a.sent();
return [2 /*return*/];
}
});
}); });
});
describe('Full flow', function () {
var agreementId = "0x" + src_1.utils.generateId();
var did = "0x" + src_1.utils.generateId();
var conditionIdCompute;
var conditionIdLock;
var conditionIdEscrow;
it('should register a DID', function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, keeper.didRegistry.registerAttribute(did, checksum, [], url, publisher.getId())];
case 1:
_a.sent();
return [2 /*return*/];
}
});
}); });
it('should generate the condition IDs', function () { return __awaiter(void 0, void 0, void 0, function () {
var _a, _b, _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0: return [4 /*yield*/, computeExecutionCondition.generateIdHash(agreementId, did, consumer.getId())];
case 1:
conditionIdCompute = _d.sent();
_b = (_a = lockRewardCondition).generateIdHash;
_c = [agreementId];
return [4 /*yield*/, escrowReward.getAddress()];
case 2: return [4 /*yield*/, _b.apply(_a, _c.concat([_d.sent(),
escrowAmount]))];
case 3:
conditionIdLock = _d.sent();
return [4 /*yield*/, escrowReward.generateIdHash(agreementId, escrowAmount, publisher.getId(), consumer.getId(), conditionIdLock, conditionIdCompute)];
case 4:
conditionIdEscrow = _d.sent();
return [2 /*return*/];
}
});
}); });
it('should have conditions types', function () { return __awaiter(void 0, void 0, void 0, function () {
var conditionTypes;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, template.getConditionTypes()];
case 1:
conditionTypes = _a.sent();
chai_1.assert.equal(conditionTypes.length, 3, 'Expected 3 conditions.');
chai_1.assert.deepEqual(__spreadArrays(conditionTypes).sort(), [
computeExecutionCondition.getAddress(),
escrowReward.getAddress(),
lockRewardCondition.getAddress()
].sort(), "The conditions doesn't match");
return [2 /*return*/];
}
});
}); });
it('should have condition instances asociated', function () { return __awaiter(void 0, void 0, void 0, function () {
var conditionInstances, conditionClasses;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, template.getConditions()];
case 1:
conditionInstances = _a.sent();
chai_1.assert.equal(conditionInstances.length, 3, 'Expected 3 conditions.');
conditionClasses = [
ComputeExecutionCondition,
EscrowReward,
LockRewardCondition
];
conditionClasses.forEach(function (conditionClass) {
if (!conditionInstances.find(function (condition) { return condition instanceof conditionClass; })) {
throw new Error(conditionClass.name + " is not part of the conditions.");
}
});
return [2 /*return*/];
}
});
}); });
it('should create a new agreement', function () { return __awaiter(void 0, void 0, void 0, function () {
var agreement;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, keeper.agreementStoreManager.createAgreement(agreementId, did, template.getId(), [conditionIdLock, conditionIdCompute, conditionIdEscrow], [0, 0, 0], [0, 0, 0], [consumer.getId(), publisher.getId()], publisher.getId())];
case 1:
agreement = _a.sent();
chai_1.assert.isTrue(agreement.status);
return [2 /*return*/];
}
});
}); });
it('should not trigger the compute', function () { return __awaiter(void 0, void 0, void 0, function () {
var computeTriggered;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, computeExecutionCondition.wasComputeTriggered(did, consumer.getId())];
case 1:
computeTriggered = _a.sent();
chai_1.assert.isFalse(computeTriggered, 'Compute has been triggered.');
return [2 /*return*/];
}
});
}); });
it('should fulfill LockRewardCondition', function () { return __awaiter(void 0, void 0, void 0, function () {
var _a, fulfill;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_b.trys.push([0, 2, , 3]);
return [4 /*yield*/, consumer.requestTokens(escrowAmount)];
case 1:
_b.sent();
return [3 /*break*/, 3];
case 2:
_a = _b.sent();
return [3 /*break*/, 3];
case 3: return [4 /*yield*/, keeper.token.approve(lockRewardCondition.getAddress(), escrowAmount, consumer.getId())];
case 4:
_b.sent();
return [4 /*yield*/, lockRewardCondition.fulfill(agreementId, escrowReward.getAddress(), escrowAmount, consumer.getId())];
case 5:
fulfill = _b.sent();
chai_1.assert.isDefined(fulfill.events.Fulfilled, 'Not Fulfilled event.');
return [2 /*return*/];
}
});
}); });
it('should fulfill ComputeExecutionCondition', function () { return __awaiter(void 0, void 0, void 0, function () {
var fulfill;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, computeExecutionCondition.fulfill(agreementId, did, consumer.getId(), publisher.getId())];
case 1:
fulfill = _a.sent();
chai_1.assert.isDefined(fulfill.events.Fulfilled, 'Not Fulfilled event.');
return [2 /*return*/];
}
});
}); });
it('should fulfill EscrowReward', function () { return __awaiter(void 0, void 0, void 0, function () {
var fulfill;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, escrowReward.fulfill(agreementId, escrowAmount, publisher.getId(), consumer.getId(), conditionIdLock, conditionIdCompute, consumer.getId())];
case 1:
fulfill = _a.sent();
chai_1.assert.isDefined(fulfill.events.Fulfilled, 'Not Fulfilled event.');
return [2 /*return*/];
}
});
}); });
it('should grant the access to the consumer', function () { return __awaiter(void 0, void 0, void 0, function () {
var computeTriggered;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, computeExecutionCondition.wasComputeTriggered(did, consumer.getId())];
case 1:
computeTriggered = _a.sent();
chai_1.assert.isTrue(computeTriggered, 'Compute has not been triggered.');
return [2 /*return*/];
}
});
}); });
});
describe('Short flow', function () {
var did = src_1.utils.generateId();
var agreementId;
it('should register a DID', function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
// This part is executed inside Ocean.assets.create()
return [4 /*yield*/, keeper.didRegistry.registerAttribute(did, checksum, [], url, publisher.getId())];
case 1:
// This part is executed inside Ocean.assets.create()
_a.sent();
return [2 /*return*/];
}
});
}); });
it('should create a new agreement (short way)', function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, template.createFullAgreement(did, escrowAmount, consumer.getId(), publisher.getId())];
case 1:
agreementId = _a.sent();
chai_1.assert.match(agreementId, /^0x[a-f0-9]{64}$/i);
return [2 /*return*/];
}
});
}); });
it('should not grant the access to the consumer', function () { return __awaiter(void 0, void 0, void 0, function () {
var computeTriggered;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, computeExecutionCondition.wasComputeTriggered(did, consumer.getId())];
case 1:
computeTriggered = _a.sent();
chai_1.assert.isFalse(computeTriggered, 'Compute has been triggered.');
return [2 /*return*/];
}
});
}); });
it('should fulfill the conditions from consumer side', function () { return __awaiter(void 0, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_b.trys.push([0, 2, , 3]);
return [4 /*yield*/, consumer.requestTokens(escrowAmount)];
case 1:
_b.sent();
return [3 /*break*/, 3];
case 2:
_a = _b.sent();
return [3 /*break*/, 3];
case 3: return [4 /*yield*/, ocean.agreements.conditions.lockReward(agreementId, escrowAmount, consumer)];
case 4:
_b.sent();
return [2 /*return*/];
}
});
}); });
it('should fulfill the conditions from computing side', function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ocean.agreements.conditions.grantServiceExecution(agreementId, did, consumer.getId(), publisher)];
case 1:
_a.sent();
return [4 /*yield*/, ocean.agreements.conditions.releaseReward(agreementId, escrowAmount, did, consumer.getId(), publisher.getId(), publisher)];
case 2:
_a.sent();
return [2 /*return*/];
}
});
}); });
it('should grant the access to the consumer', function () { return __awaiter(void 0, void 0, void 0, function () {
var computeTriggered;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, computeExecutionCondition.wasComputeTriggered(did, consumer.getId())];
case 1:
computeTriggered = _a.sent();
chai_1.assert.isTrue(computeTriggered, 'Compute has not been triggered.');
return [2 /*return*/];
}
});
}); });
});
});

View File

@ -149,7 +149,7 @@ describe('Register Escrow Compute Execution Template', () => {
agreementId, agreementId,
did, did,
template.getId(), template.getId(),
[conditionIdCompute, conditionIdLock, conditionIdEscrow], [conditionIdLock, conditionIdCompute, conditionIdEscrow],
[0, 0, 0], [0, 0, 0],
[0, 0, 0], [0, 0, 0],
[consumer.getId(), publisher.getId()], [consumer.getId(), publisher.getId()],

View File

@ -0,0 +1,182 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
exports.__esModule = true;
var chai_1 = require("chai");
var config_1 = require("../config");
var utils_1 = require("../utils");
var src_1 = require("../../src"); // @oceanprotocol/squid
describe('Search Asset', function () {
var ocean;
var publisher;
var testHash = Math.random()
.toString(36)
.substr(2);
var price;
var metadataGenerator = function (name) {
return utils_1.generateMetadata("" + name + testHash, price);
};
var test1length;
var test2length;
var test3length;
before(function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, src_1.Ocean.getInstance(config_1.config)
// Accounts
];
case 1:
ocean = _a.sent();
return [4 /*yield*/, ocean.accounts.list()];
case 2:
publisher = (_a.sent())[0];
return [2 /*return*/];
}
});
}); });
it('should be able to search the assets', function () { return __awaiter(void 0, void 0, void 0, function () {
var ddos;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ocean.assets.search("Test1" + testHash)];
case 1:
ddos = (_a.sent()).results;
chai_1.assert.isArray(ddos, 'A search should return an array');
test1length = ddos.length;
return [4 /*yield*/, ocean.assets.search("Test2" + testHash)];
case 2:
test2length = (_a.sent()).results.length;
return [4 /*yield*/, ocean.assets.search("Test3" + testHash)];
case 3:
test3length = (_a.sent()).results.length;
if (!ocean.keeper.dispenser) {
price = 0;
}
return [2 /*return*/];
}
});
}); });
it('should register an asset', function () { return __awaiter(void 0, void 0, void 0, function () {
var _a, _b, _c, _d, _e, _f, _g, _h;
return __generator(this, function (_j) {
switch (_j.label) {
case 0:
_b = (_a = chai_1.assert).instanceOf;
return [4 /*yield*/, ocean.assets.create(metadataGenerator('Test1'), publisher)];
case 1:
_b.apply(_a, [_j.sent(),
src_1.DDO]);
_d = (_c = chai_1.assert).instanceOf;
return [4 /*yield*/, ocean.assets.create(metadataGenerator('Test2'), publisher)];
case 2:
_d.apply(_c, [_j.sent(),
src_1.DDO]);
_f = (_e = chai_1.assert).instanceOf;
return [4 /*yield*/, ocean.assets.create(metadataGenerator('Test2'), publisher)];
case 3:
_f.apply(_e, [_j.sent(),
src_1.DDO]);
_h = (_g = chai_1.assert).instanceOf;
return [4 /*yield*/, ocean.assets.create(metadataGenerator('Test3'), publisher)];
case 4:
_h.apply(_g, [_j.sent(),
src_1.DDO]);
return [2 /*return*/];
}
});
}); });
it('should search by text and see the increment of DDOs', function () { return __awaiter(void 0, void 0, void 0, function () {
var _a, _b, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
_b = (_a = chai_1.assert).equal;
return [4 /*yield*/, ocean.assets.search("Test2" + testHash)];
case 1:
_b.apply(_a, [(_e.sent()).results.length - test2length,
2,
'Something was wrong searching the assets']);
_d = (_c = chai_1.assert).equal;
return [4 /*yield*/, ocean.assets.search("Test3" + testHash)];
case 2:
_d.apply(_c, [(_e.sent()).results.length - test3length,
1,
'Something was wrong searching the assets']);
return [2 /*return*/];
}
});
}); });
it('should return a list of DDOs', function () { return __awaiter(void 0, void 0, void 0, function () {
var ddos;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ocean.assets.search("Test1" + testHash)];
case 1:
ddos = (_a.sent()).results;
chai_1.assert.equal(ddos.length - test1length, 1, 'Something was wrong searching the assets');
ddos.map(function (ddo) {
return chai_1.assert.instanceOf(ddo, src_1.DDO, 'The DDO is not an instance of a DDO');
});
return [2 /*return*/];
}
});
}); });
it('should be able to do a query to get a list of DDOs', function () { return __awaiter(void 0, void 0, void 0, function () {
var ddos;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ocean.assets.query({
page: 1,
offset: 1,
query: {
text: ["Test2" + testHash]
},
sort: {
text: 1
}
})];
case 1:
ddos = (_a.sent()).results;
chai_1.assert.equal(ddos.length, 1, 'Something was wrong searching the assets');
ddos.map(function (ddo) {
return chai_1.assert.instanceOf(ddo, src_1.DDO, 'The DDO is not an instance of a DDO');
});
return [2 /*return*/];
}
});
}); });
});

View File

@ -0,0 +1,75 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
exports.__esModule = true;
var chai_1 = require("chai");
var config_1 = require("../config");
var src_1 = require("../../src"); // @oceanprotocol/squid
describe('Secret Store', function () {
var ocean;
var account;
var did = src_1.DID.generate();
var content = { content: 'Test 123' };
var encryptedContent;
before(function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, src_1.Ocean.getInstance(config_1.config)
// Accounts
];
case 1:
ocean = _a.sent();
return [4 /*yield*/, ocean.accounts.list()];
case 2:
account = (_a.sent())[0];
return [2 /*return*/];
}
});
}); });
it('should encrypt a text', function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ocean.secretStore.encrypt(did.getId(), content, account)];
case 1:
encryptedContent = _a.sent();
chai_1.assert.isDefined(encryptedContent);
chai_1.assert.match(encryptedContent, /^0x[a-f0-9]{76}$/i);
return [2 /*return*/];
}
});
}); });
});

View File

@ -0,0 +1,115 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
exports.__esModule = true;
var chai_1 = require("chai");
var config_1 = require("../config");
var src_1 = require("../../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', function () {
var ocean;
var consumer;
before(function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, src_1.Ocean.getInstance(config_1.config)
// Accounts
];
case 1:
ocean = _a.sent();
return [4 /*yield*/, ocean.accounts.list()];
case 2:
consumer = (_a.sent())[0];
return [2 /*return*/];
}
});
}); });
it('hashServiceAgreement should generate the correct signature', function () {
var templateId = "0x" + 'f'.repeat(40);
var agreementId = "0x" + 'e'.repeat(64);
var accessId = "0x" + 'a'.repeat(64);
var lockId = "0x" + 'b'.repeat(64);
var escrowId = "0x" + 'c'.repeat(64);
var hash = ocean.utils.agreements.hashServiceAgreement(templateId, agreementId, [lockId, accessId, escrowId], [0, 0, 0], [0, 0, 0]);
chai_1.assert.equal(hash, '0x67901517c18a3d23e05806fff7f04235cc8ae3b1f82345b8bfb3e4b02b5800c7', 'The signature is not correct.');
});
it('signServiceAgreement should generate the correct signature', function () { return __awaiter(void 0, void 0, void 0, function () {
var templates, did, templateId, agreementId, serviceAgreementTemplate, ddo, signature;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
templates = ocean.keeper.templates;
did = "did:op:" + 'c'.repeat(64);
templateId = "0x" + 'f'.repeat(40);
agreementId = "0x" + 'e'.repeat(64);
return [4 /*yield*/, templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplate()];
case 1:
serviceAgreementTemplate = _a.sent();
ddo = new src_1.DDO({
id: did,
service: [
{
type: 'access',
index: 0,
purchaseEndpoint: undefined,
serviceEndpoint: undefined,
templateId: templateId,
attributes: {
serviceAgreementTemplate: serviceAgreementTemplate
}
},
{
type: 'metadata',
index: 1,
attributes: {
main: {
price: 10
}
}
}
]
});
return [4 /*yield*/, ocean.utils.agreements.signServiceAgreement(ddo, 0, agreementId, ["0x" + '1'.repeat(64), "0x" + '2'.repeat(64), "0x" + '3'.repeat(64)], consumer)];
case 2:
signature = _a.sent();
chai_1.assert.equal(signature, '0x3aa8a1c48b8e582d694bbd4ba3a29fde573b78da9720dc48baeb831b2163e1fa6e10e983882ebf8a00f4124de2505136354fd146934053f0d58bba4eced5f8d01b', 'The signature is not correct.');
return [2 /*return*/];
}
});
}); });
});

View File

@ -28,7 +28,7 @@ describe('Signature', () => {
const hash = ocean.utils.agreements.hashServiceAgreement( const hash = ocean.utils.agreements.hashServiceAgreement(
templateId, templateId,
agreementId, agreementId,
[accessId, lockId, escrowId], [lockId, accessId, escrowId],
[0, 0, 0], [0, 0, 0],
[0, 0, 0] [0, 0, 0]
) )

View File

@ -0,0 +1,74 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
exports.__esModule = true;
var chai_1 = require("chai");
var config_1 = require("../config");
var src_1 = require("../../src"); // @oceanprotocol/squid
describe('Versions', function () {
var ocean;
before(function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, src_1.Ocean.getInstance(config_1.config)];
case 1:
ocean = _a.sent();
return [2 /*return*/];
}
});
}); });
// TODO: enable again after new versions of Brizo
xit('should return the versions', function () { return __awaiter(void 0, void 0, void 0, function () {
var versions;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ocean.versions.get()];
case 1:
versions = _a.sent();
chai_1.assert.equal(versions.aquarius.status, src_1.OceanPlatformTechStatus.Working);
chai_1.assert.equal(versions.brizo.status, src_1.OceanPlatformTechStatus.Working);
chai_1.assert.equal(versions.squid.status, src_1.OceanPlatformTechStatus.Working);
chai_1.assert.deepEqual(versions.status, {
ok: true,
contracts: true,
network: true
});
return [2 /*return*/];
}
});
}); });
});

View File

@ -0,0 +1,58 @@
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
exports.__esModule = true;
var metadata = {
main: {
name: undefined,
type: 'dataset',
dateCreated: '2012-10-10T17:00:00Z',
datePublished: '2012-10-10T17:00:00Z',
author: 'Met Office',
license: 'CC-BY',
price: '21' + '0'.repeat(18),
files: [
{
index: 0,
contentType: 'application/json',
url: 'https://raw.githubusercontent.com/oceanprotocol/squid-js/master/package.json'
},
{
index: 1,
contentType: 'text/plain',
url: 'https://raw.githubusercontent.com/oceanprotocol/squid-js/master/README.md'
}
]
},
additionalInformation: {
description: 'Weather information of UK including temperature and humidity',
copyrightHolder: 'Met Office',
workExample: '423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68',
links: [
{
name: 'Sample of Asset Data',
type: 'sample',
url: 'https://foo.com/sample.csv'
},
{
name: 'Data Format Definition',
type: 'format',
url: 'https://foo.com/sample.csv'
}
],
inLanguage: 'en',
categories: ['Economy', 'Data Science'],
tags: ['weather', 'uk', '2011', 'temperature', 'humidity']
}
};
exports.generateMetadata = function (name, price) { return (__assign(__assign({}, metadata), { main: __assign(__assign({}, metadata.main), { name: name, price: (price || 21) + '0'.repeat(18) }), additionalInformation: __assign({}, metadata.additionalInformation) })); };
exports.getMetadata = function (price) { return exports.generateMetadata('TestAsset', price); };

View File

@ -0,0 +1,6 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
exports.__esModule = true;
__export(require("./ddo-metadata-generator"));

View File

@ -93,13 +93,6 @@ export class Keeper extends Instantiable {
accessSecretStoreCondition: keeper.instances.accessSecretStoreCondition, accessSecretStoreCondition: keeper.instances.accessSecretStoreCondition,
computeExecutionCondition: keeper.instances.computeExecutionCondition computeExecutionCondition: keeper.instances.computeExecutionCondition
} }
// Conditions
keeper.templates = {
escrowAccessSecretStoreTemplate:
keeper.instances.escrowAccessSecretStoreTemplate,
escrowComputeExecutionTemplate:
keeper.instances.escrowComputeExecutionTemplate
}
// Templates // Templates
keeper.instances.escrowAccessSecretStoreTemplate = new EscrowAccessSecretStoreTemplate( keeper.instances.escrowAccessSecretStoreTemplate = new EscrowAccessSecretStoreTemplate(
keeper.instances.templateStoreManager, keeper.instances.templateStoreManager,
@ -113,6 +106,13 @@ export class Keeper extends Instantiable {
keeper.instances.didRegistry, keeper.instances.didRegistry,
keeper.instances.conditions keeper.instances.conditions
) )
// Conditions
keeper.templates = {
escrowAccessSecretStoreTemplate:
keeper.instances.escrowAccessSecretStoreTemplate,
escrowComputeExecutionTemplate:
keeper.instances.escrowComputeExecutionTemplate
}
// Utils // Utils
keeper.utils = { keeper.utils = {
eventHandler: new EventHandler(config) eventHandler: new EventHandler(config)

View File

@ -30,9 +30,9 @@ export class TemplateStoreManager extends ContractBase {
} }
public generateId(templateName: string) { public generateId(templateName: string) {
const args: any = [ const args: any = [
{ type: 'string', value: templateName }, { type: 'string', value: templateName },
] ]
return this.web3.utils.soliditySha3(...args) return this.web3.utils.soliditySha3(...args)
} }

View File

@ -77,13 +77,12 @@ export class AgreementTemplateBase {
consumer: string, consumer: string,
from?: string from?: string
) { ) {
const conditionIds = await this.createFullAgreementData( return await this.createFullAgreementData(
agreementId, agreementId,
ddo.shortId(), ddo.shortId(),
ddo.findServiceByType('metadata').attributes.main.price, ddo.findServiceByType('metadata').attributes.main.price,
consumer consumer
) )
return conditionIds
} }
public getId() { public getId() {
@ -94,7 +93,9 @@ export class AgreementTemplateBase {
* Create a agreement using EscrowAccessSecretStoreTemplate using only the most important information. * Create a agreement using EscrowAccessSecretStoreTemplate using only the most important information.
* @param {string} did Asset DID. * @param {string} did Asset DID.
* @param {number} amount Asset price. * @param {number} amount Asset price.
* @param {string} consumer ethereum address of consumer.
* @param {string} from Consumer address. * @param {string} from Consumer address.
* @param {string} agreementId bytes32 agreement id.
* *
* @return {Promise<string>} Agreement ID. * @return {Promise<string>} Agreement ID.
*/ */

View File

@ -2,7 +2,7 @@ import { AgreementTemplateBase } from './AgreementTemplateBase'
import { escrowAccessServiceAgreementTemplate } from './EscrowAccess.serviceAgreementTemplate' import { escrowAccessServiceAgreementTemplate } from './EscrowAccess.serviceAgreementTemplate'
export class EscrowAccessSecretStoreTemplate extends AgreementTemplateBase { export class EscrowAccessSecretStoreTemplate extends AgreementTemplateBase {
public static templateName: 'EscrowAccessSecretStoreTemplate' public templateName: 'EscrowAccessSecretStoreTemplate'
public async getServiceAgreementTemplate() { public async getServiceAgreementTemplate() {
return escrowAccessServiceAgreementTemplate return escrowAccessServiceAgreementTemplate

View File

@ -2,7 +2,7 @@ import { AgreementTemplateBase } from './AgreementTemplateBase'
import { escrowComputeServiceAgreementTemplate } from './EscrowCompute.serviceAgreementTemplate' import { escrowComputeServiceAgreementTemplate } from './EscrowCompute.serviceAgreementTemplate'
export class EscrowComputeExecutionTemplate extends AgreementTemplateBase { export class EscrowComputeExecutionTemplate extends AgreementTemplateBase {
public static templateName: 'EscrowComputeExecutionTemplate' public templateName: 'EscrowComputeExecutionTemplate'
public async getServiceAgreementTemplate() { public async getServiceAgreementTemplate() {
return escrowComputeServiceAgreementTemplate return escrowComputeServiceAgreementTemplate

View File

@ -89,7 +89,7 @@ export default class TestContractHandler extends ContractHandler {
) )
// Conditions // Conditions
const lockRewardCondition = await TestContractHandler.deployContract( await TestContractHandler.deployContract(
'LockRewardCondition', 'LockRewardCondition',
deployerAddress, deployerAddress,
[ [
@ -98,7 +98,7 @@ export default class TestContractHandler extends ContractHandler {
token.options.address token.options.address
] ]
) )
const accessSecretStoreCondition = await TestContractHandler.deployContract( await TestContractHandler.deployContract(
'AccessSecretStoreCondition', 'AccessSecretStoreCondition',
deployerAddress, deployerAddress,
[ [
@ -109,7 +109,7 @@ export default class TestContractHandler extends ContractHandler {
) )
// Conditions rewards // Conditions rewards
const escrowReward = await TestContractHandler.deployContract( await TestContractHandler.deployContract(
'EscrowReward', 'EscrowReward',
deployerAddress, deployerAddress,
[ [
@ -119,19 +119,6 @@ export default class TestContractHandler extends ContractHandler {
] ]
) )
// Templates
await TestContractHandler.deployContract(
'EscrowAccessSecretStoreTemplate',
deployerAddress,
[
deployerAddress,
agreementStoreManager.options.address,
didRegistry.options.address,
accessSecretStoreCondition.options.address,
lockRewardCondition.options.address,
escrowReward.options.address
]
)
} }
private static async deployContract( private static async deployContract(

View File

@ -1,24 +0,0 @@
import { assert } from 'chai'
import { EscrowAccessSecretStoreTemplate } from '../../../src/keeper/contracts/templates'
import config from '../../config'
import TestContractHandler from '../TestContractHandler'
import { Ocean } from '../../../src/ocean/Ocean'
let condition: EscrowAccessSecretStoreTemplate
describe('EscrowAccessSecretStoreTemplate', () => {
before(async () => {
const ocean: Ocean = await Ocean.getInstance(config)
await TestContractHandler.prepareContracts()
condition = ocean.keeper.templates.escrowAccessSecretStoreTemplate
})
// describe("#hashValues()", () => {
// it("should hash the values", async () => {
// const address = `0x${"a".repeat(40)}`
// const hash = await condition.hashValues(address, 15)
// assert.match(hash, /^0x[a-f0-9]{64}$/i)
// })
// })
})