Skip to content

Commit

Permalink
ZKWAS-253: changes for pressure test script (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
qozymandias authored Apr 18, 2024
1 parent 135bcda commit 0a8a80a
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 82 deletions.
3 changes: 2 additions & 1 deletion dist/cjs/helper/endpoint.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ export declare class ZkWasmServiceEndpoint {
endpoint: string;
username: string;
useraddress: string;
constructor(endpoint: string, username: string, useraddress: string);
enable_logs: boolean;
constructor(endpoint: string, username: string, useraddress: string, enable_logs?: boolean);
prepareRequest(method: "GET" | "POST", url: string, body: JSON | FormData | null, headers?: {
[key: string]: string;
}): Promise<any>;
Expand Down
19 changes: 14 additions & 5 deletions dist/cjs/helper/endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.ZkWasmServiceEndpoint = void 0;
const axios_1 = __importDefault(require("axios"));
class ZkWasmServiceEndpoint {
constructor(endpoint, username, useraddress) {
constructor(endpoint, username, useraddress, enable_logs = true) {
this.endpoint = endpoint;
this.username = username;
this.useraddress = useraddress;
this.enable_logs = enable_logs;
}
prepareRequest(method, url, body, headers) {
return __awaiter(this, void 0, void 0, function* () {
if (method === "GET") {
console.log(this.endpoint + url);
if (this.enable_logs) {
console.log(this.endpoint + url);
}
try {
let response = yield axios_1.default.get(this.endpoint + url, body ? { params: body, headers: Object.assign({}, headers) } : {});
return response.data;
}
catch (e) {
console.error(e);
if (this.enable_logs) {
console.error(e);
}
return {
success: false,
error: e.response ? {
Expand All @@ -50,7 +55,9 @@ class ZkWasmServiceEndpoint {
return response.data;
}
catch (e) {
console.log(e);
if (this.enable_logs) {
console.log(e);
}
return {
success: false,
error: e.response ? {
Expand All @@ -68,7 +75,9 @@ class ZkWasmServiceEndpoint {
getJSONResponse(json) {
return __awaiter(this, void 0, void 0, function* () {
if (json["success"] !== true) {
console.error(json);
if (this.enable_logs) {
console.error(json);
}
throw new Error(json["error"].message);
}
return json["result"];
Expand Down
2 changes: 1 addition & 1 deletion dist/cjs/helper/task.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { QueryParams, ProvingParams, DeployParams, Statistics, AddImageParams, W
import { ZkWasmServiceEndpoint } from "./endpoint.js";
export declare class ZkWasmServiceHelper {
endpoint: ZkWasmServiceEndpoint;
constructor(endpoint: string, username: string, useraddress: string);
constructor(endpoint: string, username: string, useraddress: string, enable_logs?: boolean);
queryImage(md5: string): Promise<Image>;
queryImageBinary(md5: string): Promise<number[]>;
queryUser(user_query: UserQueryParams): Promise<User>;
Expand Down
78 changes: 57 additions & 21 deletions dist/cjs/helper/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ const util_js_1 = require("./util.js");
const endpoint_js_1 = require("./endpoint.js");
const ethers_1 = require("ethers");
class ZkWasmServiceHelper {
constructor(endpoint, username, useraddress) {
this.endpoint = new endpoint_js_1.ZkWasmServiceEndpoint(endpoint, username, useraddress);
constructor(endpoint, username, useraddress, enable_logs = true) {
this.endpoint = new endpoint_js_1.ZkWasmServiceEndpoint(endpoint, username, useraddress, enable_logs);
}
queryImage(md5) {
return __awaiter(this, void 0, void 0, function* () {
let req = JSON.parse("{}");
req["md5"] = md5;
const images = yield this.endpoint.invokeRequest("GET", "/image", req);
console.log("get queryImage response.");
if (this.endpoint.enable_logs) {
console.log("get queryImage response.");
}
return images[0];
});
}
Expand All @@ -46,7 +48,9 @@ class ZkWasmServiceHelper {
let req = JSON.parse("{}");
req["md5"] = md5;
const image = yield this.endpoint.invokeRequest("GET", "/imagebinary", req);
console.log("get queryImageBinary response.");
if (this.endpoint.enable_logs) {
console.log("get queryImageBinary response.");
}
return image;
});
}
Expand All @@ -55,7 +59,9 @@ class ZkWasmServiceHelper {
let req = JSON.parse("{}");
req["user_address"] = user_query.user_address;
const user = yield this.endpoint.invokeRequest("GET", "/user", req);
console.log("get queryUser response.");
if (this.endpoint.enable_logs) {
console.log("get queryUser response.");
}
return user;
});
}
Expand All @@ -64,7 +70,9 @@ class ZkWasmServiceHelper {
let req = JSON.parse("{}");
req["user_address"] = user_query.user_address;
const user = yield this.endpoint.invokeRequest("GET", "/user_subscription", req);
console.log("get queryUserSubscription response.");
if (this.endpoint.enable_logs) {
console.log("get queryUserSubscription response.");
}
return user;
});
}
Expand All @@ -73,7 +81,9 @@ class ZkWasmServiceHelper {
let req = JSON.parse("{}");
req["user_address"] = history_query.user_address;
const txs = yield this.endpoint.invokeRequest("GET", "/transactions", req);
console.log("get queryTxHistory response.");
if (this.endpoint.enable_logs) {
console.log("get queryTxHistory response.");
}
return txs;
});
}
Expand All @@ -82,14 +92,18 @@ class ZkWasmServiceHelper {
let req = JSON.parse("{}");
req["user_address"] = history_query.user_address;
const txs = yield this.endpoint.invokeRequest("GET", "/deposits", req);
console.log("get queryDepositHistory response.");
if (this.endpoint.enable_logs) {
console.log("get queryDepositHistory response.");
}
return txs;
});
}
queryConfig() {
return __awaiter(this, void 0, void 0, function* () {
const config = yield this.endpoint.invokeRequest("GET", "/config", JSON.parse("{}"));
console.log("get queryConfig response.");
if (this.endpoint.enable_logs) {
console.log("get queryConfig response.");
}
return config;
});
}
Expand All @@ -98,7 +112,9 @@ class ZkWasmServiceHelper {
let headers = { "Content-Type": "application/json" };
let queryJson = JSON.parse("{}");
let st = yield this.endpoint.invokeRequest("GET", `/statistics`, queryJson);
console.log("loading task board!");
if (this.endpoint.enable_logs) {
console.log("loading task board!");
}
return {
totalImages: st.total_images,
totalProofs: st.total_proofs,
Expand Down Expand Up @@ -142,66 +158,86 @@ class ZkWasmServiceHelper {
if (query[key] != "" && query[key] != null)
queryJson[key] = query[key];
});
console.log("params:", query);
console.log("json", queryJson);
if (this.endpoint.enable_logs) {
console.log("params:", query);
console.log("json", queryJson);
}
let tasks = yield this.endpoint.invokeRequest("GET", `/tasks`, queryJson);
console.log("loading task board!");
if (this.endpoint.enable_logs) {
console.log("loading task board!");
}
return tasks;
});
}
queryLogs(query) {
return __awaiter(this, void 0, void 0, function* () {
let logs = yield this.sendRequestWithSignature("GET", TaskEndpoint.LOGS, query);
console.log("loading logs!");
if (this.endpoint.enable_logs) {
console.log("loading logs!");
}
return logs;
});
}
addPayment(payRequest) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.endpoint.invokeRequest("POST", TaskEndpoint.PAY, JSON.parse(JSON.stringify(payRequest)));
console.log("get addPayment response:", response.toString());
if (this.endpoint.enable_logs) {
console.log("get addPayment response:", response.toString());
}
return response;
});
}
addSubscription(subscription) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.endpoint.invokeRequest("POST", TaskEndpoint.SUBSCRIBE, JSON.parse(JSON.stringify(subscription)));
console.log("get addSubscription response:", response.toString());
if (this.endpoint.enable_logs) {
console.log("get addSubscription response:", response.toString());
}
return response;
});
}
addNewWasmImage(task) {
return __awaiter(this, void 0, void 0, function* () {
let response = yield this.sendRequestWithSignature("POST", TaskEndpoint.SETUP, task, true);
console.log("get addNewWasmImage response:", response.toString());
if (this.endpoint.enable_logs) {
console.log("get addNewWasmImage response:", response.toString());
}
return response;
});
}
addProvingTask(task) {
return __awaiter(this, void 0, void 0, function* () {
let response = yield this.sendRequestWithSignature("POST", TaskEndpoint.PROVE, task, true);
console.log("get addProvingTask response:", response.toString());
if (this.endpoint.enable_logs) {
console.log("get addProvingTask response:", response.toString());
}
return response;
});
}
addDeployTask(task) {
return __awaiter(this, void 0, void 0, function* () {
let response = yield this.sendRequestWithSignature("POST", TaskEndpoint.DEPLOY, task);
console.log("get addDeployTask response:", response.toString());
if (this.endpoint.enable_logs) {
console.log("get addDeployTask response:", response.toString());
}
return response;
});
}
addResetTask(task) {
return __awaiter(this, void 0, void 0, function* () {
let response = yield this.sendRequestWithSignature("POST", TaskEndpoint.RESET, task, true);
console.log("get addResetTask response:", response.toString());
if (this.endpoint.enable_logs) {
console.log("get addResetTask response:", response.toString());
}
return response;
});
}
modifyImage(data) {
return __awaiter(this, void 0, void 0, function* () {
let response = yield this.sendRequestWithSignature("POST", TaskEndpoint.MODIFY, data);
console.log("get modifyImage response:", response.toString());
if (this.endpoint.enable_logs) {
console.log("get modifyImage response:", response.toString());
}
return response;
});
}
Expand Down
3 changes: 2 additions & 1 deletion dist/mjs/helper/endpoint.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ export declare class ZkWasmServiceEndpoint {
endpoint: string;
username: string;
useraddress: string;
constructor(endpoint: string, username: string, useraddress: string);
enable_logs: boolean;
constructor(endpoint: string, username: string, useraddress: string, enable_logs?: boolean);
prepareRequest(method: "GET" | "POST", url: string, body: JSON | FormData | null, headers?: {
[key: string]: string;
}): Promise<any>;
Expand Down
20 changes: 15 additions & 5 deletions dist/mjs/helper/endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@ export class ZkWasmServiceEndpoint {
endpoint;
username;
useraddress;
constructor(endpoint, username, useraddress) {
enable_logs;
constructor(endpoint, username, useraddress, enable_logs = true) {
this.endpoint = endpoint;
this.username = username;
this.useraddress = useraddress;
this.enable_logs = enable_logs;
}
async prepareRequest(method, url, body, headers) {
if (method === "GET") {
console.log(this.endpoint + url);
if (this.enable_logs) {
console.log(this.endpoint + url);
}
try {
let response = await axios.get(this.endpoint + url, body ? { params: body, headers: { ...headers } } : {});
return response.data;
}
catch (e) {
console.error(e);
if (this.enable_logs) {
console.error(e);
}
return {
success: false,
error: e.response ? {
Expand All @@ -39,7 +45,9 @@ export class ZkWasmServiceEndpoint {
return response.data;
}
catch (e) {
console.log(e);
if (this.enable_logs) {
console.log(e);
}
return {
success: false,
error: e.response ? {
Expand All @@ -55,7 +63,9 @@ export class ZkWasmServiceEndpoint {
}
async getJSONResponse(json) {
if (json["success"] !== true) {
console.error(json);
if (this.enable_logs) {
console.error(json);
}
throw new Error(json["error"].message);
}
return json["result"];
Expand Down
2 changes: 1 addition & 1 deletion dist/mjs/helper/task.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { QueryParams, ProvingParams, DeployParams, Statistics, AddImageParams, W
import { ZkWasmServiceEndpoint } from "./endpoint.js";
export declare class ZkWasmServiceHelper {
endpoint: ZkWasmServiceEndpoint;
constructor(endpoint: string, username: string, useraddress: string);
constructor(endpoint: string, username: string, useraddress: string, enable_logs?: boolean);
queryImage(md5: string): Promise<Image>;
queryImageBinary(md5: string): Promise<number[]>;
queryUser(user_query: UserQueryParams): Promise<User>;
Expand Down
Loading

0 comments on commit 0a8a80a

Please sign in to comment.