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

Remove all .js files that were unintentionally committed.

This commit is contained in:
ssallam 2020-01-21 13:20:49 +01:00
parent c7b41724ba
commit 7ccac889ed
14 changed files with 0 additions and 2309 deletions

View File

@ -1,59 +0,0 @@
"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

@ -1,209 +0,0 @@
"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

@ -1,183 +0,0 @@
"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

@ -1,268 +0,0 @@
"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

@ -1,170 +0,0 @@
"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

@ -1,160 +0,0 @@
"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

@ -1,376 +0,0 @@
"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

@ -1,374 +0,0 @@
"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

@ -1,182 +0,0 @@
"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

@ -1,75 +0,0 @@
"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

@ -1,115 +0,0 @@
"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(64);
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, '0x464dac3b79a47f8acad54f67a0f4473249330f025c69687531e58c2e43b36437', '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(64);
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, '0xa04568fccdda7e1594e3e615f8d71b14733705aabe5294af0b7f46f0aedb9d5906a2caa6142ee4de10534a47c5a7083b21b2d3e9a96ac462bc0b9d25070e981e1c', 'The signature is not correct.');
return [2 /*return*/];
}
});
}); });
});

View File

@ -1,74 +0,0 @@
"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

@ -1,58 +0,0 @@
"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

@ -1,6 +0,0 @@
"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"));