Merge pull request #4018 from nymtech/feature/nym-node-api-tests
Initial step to adding nym-node functional tests
This commit is contained in:
@@ -17,6 +17,9 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: install yarn in root
|
||||
run: cd ../.. yarn install
|
||||
|
||||
- name: Install npm
|
||||
run: npm install
|
||||
|
||||
|
||||
@@ -15,4 +15,4 @@ prod:
|
||||
mixnode_identity: 3pMCJswCyA19MGYWGDWT5fBk2M8ybSZGXttyAoNY5gBB
|
||||
gateway_identity: 2BuMSfMW3zpeAjKXyKLhmY4QW1DXurrtSPEJ6CjX3SEh
|
||||
log_level: error
|
||||
time_zone: utc
|
||||
time_zone: utc
|
||||
+19
-4
@@ -1,4 +1,6 @@
|
||||
import { dir } from "console";
|
||||
import { readFileSync } from "fs";
|
||||
import { dirname } from "path";
|
||||
import { TLogLevelName } from "tslog";
|
||||
|
||||
import YAML from "yaml";
|
||||
@@ -10,9 +12,11 @@ class ConfigHandler {
|
||||
|
||||
public commonConfig: { request_headers: object };
|
||||
|
||||
private currentEnvironment: string;
|
||||
|
||||
public environment: string;
|
||||
|
||||
public environmnetConfig: {
|
||||
public environmentConfig: {
|
||||
log_level: TLogLevelName;
|
||||
time_zone: string;
|
||||
api_base_url: string;
|
||||
@@ -35,8 +39,9 @@ class ConfigHandler {
|
||||
|
||||
private setCommonConfig(): void {
|
||||
try {
|
||||
const baseWorkingDirectory = __dirname;
|
||||
this.commonConfig = YAML.parse(
|
||||
readFileSync("src/config/config.yaml", "utf8")
|
||||
readFileSync(baseWorkingDirectory + "/config.yaml", "utf8"),
|
||||
).common;
|
||||
} catch (error) {
|
||||
throw Error(`Error reading common config: (${error})`);
|
||||
@@ -46,14 +51,24 @@ class ConfigHandler {
|
||||
private setEnvironmentConfig(environment: string): void {
|
||||
this.ensureEnvironmentIsValid(environment);
|
||||
try {
|
||||
this.environmnetConfig = YAML.parse(
|
||||
readFileSync("src/config/config.yaml", "utf8")
|
||||
const baseWorkingDirectory = __dirname;
|
||||
this.environmentConfig = YAML.parse(
|
||||
readFileSync(baseWorkingDirectory + "/config.yaml", "utf8"),
|
||||
)[environment];
|
||||
} catch (error) {
|
||||
console.log("fadsfasdfasdfsdfsa")
|
||||
throw Error(`Error reading environment config: (${error})`);
|
||||
}
|
||||
}
|
||||
|
||||
public getEnvironmentConfig(environment: string): any {
|
||||
const baseWorkingDirectory = __dirname;
|
||||
return (
|
||||
this.environmentConfig ||
|
||||
YAML.parse(readFileSync(baseWorkingDirectory + "/config.yaml", "utf8"))[environment]
|
||||
);
|
||||
}
|
||||
|
||||
private ensureEnvironmentIsValid(environment: string): void {
|
||||
if (this.validEnvironments.indexOf(environment) === -1) {
|
||||
throw Error(`Config environment is not valid: "${environment}"`);
|
||||
@@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
ConfigHandler: require('./config/configHandler.ts'),
|
||||
RestClient: require('./restClient/RestClient.ts')
|
||||
};
|
||||
+5
-5
@@ -13,9 +13,9 @@ import ConfigHandler from "../config/configHandler";
|
||||
|
||||
const config = ConfigHandler.getInstance();
|
||||
const log = new Logger({
|
||||
minLevel: config.environmnetConfig.log_level,
|
||||
minLevel: config.environmentConfig.log_level,
|
||||
dateTimeTimezone:
|
||||
config.environmnetConfig.time_zone ||
|
||||
config.environmentConfig.time_zone ||
|
||||
Intl.DateTimeFormat().resolvedOptions().timeZone,
|
||||
});
|
||||
|
||||
@@ -24,7 +24,7 @@ function isSet(property): boolean {
|
||||
}
|
||||
|
||||
export class RestClient {
|
||||
private static authToken: string;
|
||||
public static authToken: string;
|
||||
|
||||
private axiosInstance: AxiosInstance;
|
||||
|
||||
@@ -83,7 +83,7 @@ export class RestClient {
|
||||
data,
|
||||
additionalConfigs,
|
||||
params,
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
await this.axiosInstance
|
||||
@@ -214,7 +214,7 @@ export class RestClient {
|
||||
|
||||
if (isSet(additionalConfigs)) {
|
||||
logRecord = `${logRecord}\nAdditional Configuration: ${stringify(
|
||||
additionalConfigs
|
||||
additionalConfigs,
|
||||
)}`;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import ContractCache from "../../../src/endpoints/ContractCache";
|
||||
import ConfigHandler from "../../../src/config/configHandler";
|
||||
import ConfigHandler from "../../../../../common/api-test-utils/config/configHandler"
|
||||
|
||||
let contract: ContractCache;
|
||||
let config: ConfigHandler;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Status from "../../src/endpoints/Status";
|
||||
import ConfigHandler from "../../src/config/configHandler";
|
||||
import ConfigHandler from "../../../../common/api-test-utils/config/configHandler"
|
||||
|
||||
let status: Status;
|
||||
let config: ConfigHandler;
|
||||
@@ -29,7 +29,7 @@ describe("Get gateway data", (): void => {
|
||||
});
|
||||
|
||||
it("Get a gateway history", async (): Promise<void> => {
|
||||
const identity_key = config.environmnetConfig.gateway_identity;
|
||||
const identity_key = config.environmentConfig.gateway_identity;
|
||||
const response = await status.getGatewayHistory(identity_key);
|
||||
|
||||
if ("identity" in response) {
|
||||
@@ -47,14 +47,14 @@ describe("Get gateway data", (): void => {
|
||||
});
|
||||
|
||||
it("Get gateway core status count", async (): Promise<void> => {
|
||||
const identity_key = config.environmnetConfig.gateway_identity;
|
||||
const identity_key = config.environmentConfig.gateway_identity;
|
||||
const response = await status.getGatewayCoreCount(identity_key);
|
||||
expect(identity_key).toStrictEqual(response.identity);
|
||||
expect(typeof response.count).toBe("number");
|
||||
});
|
||||
|
||||
it("Get gateway average uptime", async (): Promise<void> => {
|
||||
const identity_key = config.environmnetConfig.gateway_identity;
|
||||
const identity_key = config.environmentConfig.gateway_identity;
|
||||
const response = await status.getGatewayAverageUptime(identity_key);
|
||||
if ("identity" in response) {
|
||||
expect(identity_key).toStrictEqual(response.identity);
|
||||
@@ -65,7 +65,7 @@ describe("Get gateway data", (): void => {
|
||||
});
|
||||
|
||||
it("Get a gateway status report", async (): Promise<void> => {
|
||||
const identity_key = config.environmnetConfig.gateway_identity;
|
||||
const identity_key = config.environmentConfig.gateway_identity;
|
||||
const response = await status.getGatewayStatusReport(identity_key);
|
||||
if ("identity" in response) {
|
||||
expect(identity_key).toStrictEqual(response.identity);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Status from "../../src/endpoints/Status";
|
||||
import ConfigHandler from "../../src/config/configHandler";
|
||||
import ConfigHandler from "../../../../common/api-test-utils/config/configHandler"
|
||||
|
||||
let status: Status;
|
||||
let config: ConfigHandler;
|
||||
@@ -11,7 +11,7 @@ describe("Get mixnode data", (): void => {
|
||||
});
|
||||
|
||||
it("Get a mixnode report", async (): Promise<void> => {
|
||||
const identity_key = config.environmnetConfig.mix_id;
|
||||
const identity_key = config.environmentConfig.mix_id;
|
||||
const response = await status.getMixnodeStatusReport(identity_key);
|
||||
if ("mix_id" in response) {
|
||||
expect(typeof response.last_day).toBe("number");
|
||||
@@ -22,7 +22,7 @@ describe("Get mixnode data", (): void => {
|
||||
});
|
||||
|
||||
it("Get a mixnode stake saturation", async (): Promise<void> => {
|
||||
const identity_key = config.environmnetConfig.mix_id;
|
||||
const identity_key = config.environmentConfig.mix_id;
|
||||
const response = await status.getMixnodeStakeSaturation(identity_key);
|
||||
if ("saturation" in response) {
|
||||
expect(typeof response.as_at).toBe("number");
|
||||
@@ -34,7 +34,7 @@ describe("Get mixnode data", (): void => {
|
||||
});
|
||||
|
||||
it("Get a mixnode average uptime", async (): Promise<void> => {
|
||||
const identity_key = config.environmnetConfig.mix_id;
|
||||
const identity_key = config.environmentConfig.mix_id;
|
||||
const response = await status.getMixnodeAverageUptime(identity_key);
|
||||
if ("mix_id" in response) {
|
||||
expect(identity_key).toStrictEqual(response.mix_id);
|
||||
@@ -45,7 +45,7 @@ describe("Get mixnode data", (): void => {
|
||||
});
|
||||
|
||||
it("Get a mixnode history", async (): Promise<void> => {
|
||||
const identity_key = config.environmnetConfig.mix_id;
|
||||
const identity_key = config.environmentConfig.mix_id;
|
||||
const response = await status.getMixnodeHistory(identity_key);
|
||||
if ("mix_id" in response) {
|
||||
response.history.forEach((x) => {
|
||||
@@ -62,14 +62,14 @@ describe("Get mixnode data", (): void => {
|
||||
});
|
||||
|
||||
it("Get a mixnode core count", async (): Promise<void> => {
|
||||
const identity_key = config.environmnetConfig.mix_id;
|
||||
const identity_key = config.environmentConfig.mix_id;
|
||||
const response = await status.getMixnodeCoreCount(identity_key);
|
||||
expect(identity_key).toStrictEqual(response.mix_id);
|
||||
expect(typeof response.count).toBe("number");
|
||||
});
|
||||
|
||||
it("Get a mixnode reward estimation", async (): Promise<void> => {
|
||||
const identity_key = config.environmnetConfig.mix_id;
|
||||
const identity_key = config.environmentConfig.mix_id;
|
||||
const response = await status.getMixnodeRewardComputation(identity_key);
|
||||
if ("estimation" in response) {
|
||||
expect(response.reward_params.interval.sybil_resistance).toStrictEqual(
|
||||
@@ -83,7 +83,7 @@ describe("Get mixnode data", (): void => {
|
||||
});
|
||||
|
||||
it("Get a mixnode inclusion probability", async (): Promise<void> => {
|
||||
const identity_key = config.environmnetConfig.mix_id;
|
||||
const identity_key = config.environmentConfig.mix_id;
|
||||
const response = await status.getMixnodeInclusionProbability(identity_key);
|
||||
if ("mix_id" in response) {
|
||||
expect(typeof response.in_active).toBe("string");
|
||||
@@ -119,7 +119,7 @@ describe("Get mixnode data", (): void => {
|
||||
});
|
||||
|
||||
it("Get a mixnode status", async (): Promise<void> => {
|
||||
const identity_key = config.environmnetConfig.mix_id;
|
||||
const identity_key = config.environmentConfig.mix_id;
|
||||
const response = await status.getMixnodeStatus(identity_key);
|
||||
const unfiltered_mixnodes_response = await status.getUnfilteredMixnodes();
|
||||
const mixnode = unfiltered_mixnodes_response.find(
|
||||
@@ -155,7 +155,7 @@ describe("Get mixnode data", (): void => {
|
||||
});
|
||||
|
||||
it("with correct data", async (): Promise<void> => {
|
||||
const mix_id = config.environmnetConfig.mix_id;
|
||||
const mix_id = config.environmentConfig.mix_id;
|
||||
const response = await status.sendMixnodeRewardEstimatedComputation(
|
||||
mix_id
|
||||
);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Logger } from "tslog";
|
||||
import ConfigHandler from "../../config/configHandler";
|
||||
import { RestClient } from "../../restClient/RestClient";
|
||||
import ConfigHandler from "../../../../../common/api-test-utils/config/configHandler";
|
||||
import { RestClient } from "../../../../../common/api-test-utils/restClient/RestClient";
|
||||
|
||||
export abstract class APIClient {
|
||||
protected constructor(serviceUrl: string) {
|
||||
const baseUrl: string = this.config.environmnetConfig.api_base_url;
|
||||
const baseUrl: string = this.config.environmentConfig.api_base_url;
|
||||
this.url = baseUrl + serviceUrl;
|
||||
this.restClient = new RestClient(this.url);
|
||||
this.serviceName = this.constructor.toString().match(/\w+/g)[1];
|
||||
@@ -16,9 +16,9 @@ export abstract class APIClient {
|
||||
protected config = ConfigHandler.getInstance();
|
||||
|
||||
protected log: Logger = new Logger({
|
||||
minLevel: this.config.environmnetConfig.log_level,
|
||||
minLevel: this.config.environmentConfig.log_level,
|
||||
dateTimeTimezone:
|
||||
this.config.environmnetConfig.time_zone ||
|
||||
this.config.environmentConfig.time_zone ||
|
||||
Intl.DateTimeFormat().resolvedOptions().timeZone,
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"root": true,
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:prettier/recommended"
|
||||
],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"rules": {
|
||||
"import/extensions": "off",
|
||||
"no-console": ["warn", { "allow": ["warn", "error"] }],
|
||||
"import/prefer-default-export": "off",
|
||||
"prettier/prettier": ["error"]
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["**/*.ts", "**/*.tsx"],
|
||||
"rules": {
|
||||
"@typescript-eslint/explicit-function-return-type": "off",
|
||||
"@typescript-eslint/explicit-module-boundary-types": "off",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"no-shadow": "off",
|
||||
"@typescript-eslint/no-shadow": ["error"]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
node_modules
|
||||
dist
|
||||
coverage/
|
||||
.DS_Store
|
||||
.idea/
|
||||
junit.xml
|
||||
@@ -0,0 +1,67 @@
|
||||
import Gateway from "../../src/endpoints/Gateways";
|
||||
import { getGatewayIPAddresses } from "../../src/helpers/helper";
|
||||
|
||||
describe("Get gateway related info", (): void => {
|
||||
let contract: Gateway;
|
||||
let gatewayHosts: string[];
|
||||
beforeAll(async (): Promise<void> => {
|
||||
try {
|
||||
gatewayHosts = await getGatewayIPAddresses();
|
||||
console.log(gatewayHosts);
|
||||
} catch (error) {
|
||||
throw new Error(`Error fetching gateway IP addresses: ${error.message}`);
|
||||
}
|
||||
});
|
||||
|
||||
beforeEach(async (): Promise<void> => {
|
||||
for (let i = 0; i < gatewayHosts.length; i++) {
|
||||
// console.log("currently trying gateway host", gatewayHosts[i]);
|
||||
contract = new Gateway(gatewayHosts[i]);
|
||||
}
|
||||
});
|
||||
|
||||
// TODO this test is failing, it's incorrectly entering the else statement
|
||||
it("Get root gateway information", async (): Promise<void> => {
|
||||
const response = await contract.getGatewayInformation();
|
||||
console.log(response)
|
||||
console.log(response.wireguard)
|
||||
if (response.wireguard === null) {
|
||||
console.log("This is the code I should be entering............")
|
||||
expect(response.wireguard).toBeNull();
|
||||
expect(typeof response.mixnet_websockets.ws_port).toBe("number");
|
||||
expect(typeof response.mixnet_websockets.wss_port).toBe("number");
|
||||
return;
|
||||
} else {
|
||||
console.log("This is wrong, I shouldn't be in the else statement.........")
|
||||
console.log(response.wireguard);
|
||||
expect(typeof response.wireguard.port).toBe("number");
|
||||
expect(typeof response.wireguard.public_key).toBe("string");
|
||||
expect(typeof response.mixnet_websockets.ws_port).toBe("number");
|
||||
expect(typeof response.mixnet_websockets.wss_port).toBe("number");
|
||||
}
|
||||
});
|
||||
|
||||
it("Get client interfaces supported by gateway", async (): Promise<void> => {
|
||||
const response = await contract.getGatewayClientInterfaces();
|
||||
if (response.wireguard === null) {
|
||||
expect(response.wireguard).toBeNull();
|
||||
} else {
|
||||
expect(typeof response.wireguard.port).toBe("number");
|
||||
expect(typeof response.wireguard.public_key).toBe("string");
|
||||
expect(typeof response.mixnet_websockets.ws_port).toBe("number");
|
||||
expect(typeof response.mixnet_websockets.wss_port).toBe("number");
|
||||
}
|
||||
});
|
||||
|
||||
it("Get mixnet websocket info", async (): Promise<void> => {
|
||||
const response = await contract.getMixnetWebsocketInfo();
|
||||
expect(typeof response.ws_port).toBe("number");
|
||||
expect(typeof response.wss_port === ("number") || response.wss_port === null).toBe(true);
|
||||
});
|
||||
|
||||
// it("Get wireguard info", async (): Promise<void> => {
|
||||
// const response = await contract.getWireguardInfo();
|
||||
// expect(typeof response.port).toBe("number");
|
||||
// expect(typeof response.public_key).toBe("string");
|
||||
// });
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
// import Mixnode from "../../src/endpoints/Mixnodes";
|
||||
// import { getGatewayIPAddresses } from '../../src/helpers/helper';
|
||||
|
||||
// describe("Get mixnode related info", (): void => {
|
||||
// let contract: Mixnode;
|
||||
// let gatewayHosts: string[];
|
||||
// beforeAll(async (): Promise<void> => {
|
||||
// try {
|
||||
// gatewayHosts = await getGatewayIPAddresses();
|
||||
// console.log(gatewayHosts)
|
||||
// } catch (error) {
|
||||
// throw new Error(`Error fetching gateway IP addresses: ${error.message}`);
|
||||
// }
|
||||
// });
|
||||
|
||||
// beforeEach(async (): Promise<void> => {
|
||||
// for (let i = 0; i < gatewayHosts.length; i++) {
|
||||
// console.log("currently trying gateway host", gatewayHosts[i])
|
||||
// contract = new Mixnode(gatewayHosts[i]);
|
||||
// }
|
||||
// });
|
||||
|
||||
// it("Get mixnode details", async (): Promise<void> => {
|
||||
// const response = await contract.getMixnodeInfo();
|
||||
// // TODO implement checks here
|
||||
// });
|
||||
|
||||
// });
|
||||
@@ -0,0 +1,54 @@
|
||||
import Nodes from "../../src/endpoints/Node";
|
||||
import { getGatewayIPAddresses } from "../../src/helpers/helper";
|
||||
|
||||
describe("Get Node information", (): void => {
|
||||
let contract: Nodes;
|
||||
let gatewayHosts: string[];
|
||||
beforeAll(async (): Promise<void> => {
|
||||
try {
|
||||
gatewayHosts = await getGatewayIPAddresses();
|
||||
// console.log(gatewayHosts);
|
||||
} catch (error) {
|
||||
throw new Error(`Error fetching gateway IP addresses: ${error.message}`);
|
||||
}
|
||||
});
|
||||
|
||||
beforeEach(async (): Promise<void> => {
|
||||
for (let i = 0; i < gatewayHosts.length; i++) {
|
||||
// console.log("currently trying gateway host", gatewayHosts[i]);
|
||||
contract = new Nodes(gatewayHosts[i]);
|
||||
}
|
||||
});
|
||||
|
||||
it("Get build data for the binary running the API", async (): Promise<void> => {
|
||||
const response = await contract.getBuildInformation();
|
||||
expect(typeof response.binary_name).toBe("string");
|
||||
expect(typeof response.build_timestamp).toBe("string");
|
||||
expect(typeof response.build_version).toBe("string");
|
||||
expect(typeof response.cargo_profile).toBe("string");
|
||||
expect(typeof response.commit_branch).toBe("string");
|
||||
expect(typeof response.commit_sha).toBe("string");
|
||||
expect(typeof response.commit_timestamp).toBe("string");
|
||||
expect(typeof response.rustc_channel).toBe("string");
|
||||
expect(typeof response.rustc_version).toBe("string");
|
||||
});
|
||||
|
||||
it("Get host information for the node", async (): Promise<void> => {
|
||||
const response = await contract.getHostInformation();
|
||||
response.data.ip_address.forEach((x) => {
|
||||
expect(typeof x).toBe("string");
|
||||
});
|
||||
// expect(typeof response.data.hostname).toBe("string" || "null");
|
||||
expect(typeof response.data.hostname === "string" || response.data.hostname === null).toBe(true);
|
||||
expect(typeof response.data.keys.ed25519).toBe("string");
|
||||
expect(typeof response.data.keys.x25519).toBe("string");
|
||||
expect(typeof response.signature).toBe("string");
|
||||
});
|
||||
|
||||
it("Get roles supported by the node", async (): Promise<void> => {
|
||||
const response = await contract.getSupportedRoles();
|
||||
expect(typeof response.gateway_enabled).toBe("boolean");
|
||||
expect(typeof response.mixnode_enabled).toBe("boolean");
|
||||
expect(typeof response.network_requester_enabled).toBe("boolean");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
preset: "ts-jest",
|
||||
testEnvironment: "node",
|
||||
reporters: ["default", "jest-junit"],
|
||||
collectCoverageFrom: ["src/**/*.ts"],
|
||||
};
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "nym-node-test-suite",
|
||||
"version": "1.0.0",
|
||||
"description": "a basic nym-node-api suite to test the nym-node-api",
|
||||
"main": "dist/index.js",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"scripts": {
|
||||
"test:sandbox": "TEST_ENV=sandbox jest --forceExit --detectOpenHandles --passWithNoTests",
|
||||
"test:prod": "TEST_ENV=prod jest --forceExit --detectOpenHandles --passWithNoTests",
|
||||
"build": "tsc",
|
||||
"lint": "eslint --fix --ext .js,.ts,.tsx .",
|
||||
"cleanup": "rm -rf node_modules; rm -rf dist; yarn install"
|
||||
},
|
||||
"author": "Nymtech",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"engines": {
|
||||
"node": "18.1.0",
|
||||
"npm": "8.x"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.27.2",
|
||||
"eslint": "^8.51.0",
|
||||
"form-data": "4.0.0",
|
||||
"json-stringify-safe": "5.0.1",
|
||||
"tslog": "../../../../../node_modules/tslog",
|
||||
"uuid": "8.3.2",
|
||||
"yaml": "^2.2.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.5.5",
|
||||
"@types/node": "^20.8.4",
|
||||
"@typescript-eslint/eslint-plugin": "^5.12.1",
|
||||
"@typescript-eslint/parser": "^5.33.0",
|
||||
"axios-mock-adapter": "^1.20.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-plugin-prettier": "^5.0.1",
|
||||
"jest": "^28.1.3",
|
||||
"jest-junit": "^14.0.0",
|
||||
"prettier": "^3.0.3",
|
||||
"process": "0.11.10",
|
||||
"ts-jest": "28.0.7",
|
||||
"typescript": "^4.7.4",
|
||||
"uuidv4": "^6.2.12"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import {
|
||||
ClientInterfaces,
|
||||
MixnetWebsockets,
|
||||
Wireguard,
|
||||
} from "../types/GatewayTypes";
|
||||
import { APIClient } from "./abstracts/APIClient";
|
||||
|
||||
export default class Gateway extends APIClient {
|
||||
constructor(baseUrl: string) {
|
||||
super(baseUrl, "/");
|
||||
}
|
||||
|
||||
public async getGatewayInformation(): Promise<ClientInterfaces> {
|
||||
const response = await this.restClient.sendGet({
|
||||
route: `gateway`,
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
|
||||
public async getGatewayClientInterfaces(): Promise<ClientInterfaces> {
|
||||
const response = await this.restClient.sendGet({
|
||||
route: `gateway/client-interfaces`,
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
|
||||
public async getMixnetWebsocketInfo(): Promise<MixnetWebsockets> {
|
||||
const response = await this.restClient.sendGet({
|
||||
route: `gateway/client-interfaces/mixnet-websockets`,
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
|
||||
public async getWireguardInfo(): Promise<Wireguard> {
|
||||
const response = await this.restClient.sendGet({
|
||||
route: `gateway/client-interfaces/wireguard`,
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// import { Mixnodes } from "../types/MixnodeTypes";
|
||||
// import { APIClient } from "./abstracts/APIClient";
|
||||
|
||||
// export default class Mixnode extends APIClient {
|
||||
// constructor(baseUrl: string) {
|
||||
// super(baseUrl, "/");
|
||||
// }
|
||||
|
||||
// public async getMixnodeInfo(): Promise<Mixnodes> {
|
||||
// const response = await this.restClient.sendGet({
|
||||
// route: `mixnode`,
|
||||
// });
|
||||
// return response.data;
|
||||
// }
|
||||
// }
|
||||
@@ -0,0 +1,29 @@
|
||||
import { BuildInformation, HostInformation, Roles } from "../types/NodeTypes";
|
||||
import { APIClient } from "./abstracts/APIClient";
|
||||
|
||||
export default class Nodes extends APIClient {
|
||||
constructor(baseUrl: string) {
|
||||
super(baseUrl, "/");
|
||||
}
|
||||
|
||||
public async getBuildInformation(): Promise<BuildInformation> {
|
||||
const response = await this.restClient.sendGet({
|
||||
route: `build-information`,
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
|
||||
public async getHostInformation(): Promise<HostInformation> {
|
||||
const response = await this.restClient.sendGet({
|
||||
route: `host-information`,
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
|
||||
public async getSupportedRoles(): Promise<Roles> {
|
||||
const response = await this.restClient.sendGet({
|
||||
route: `roles`,
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { Logger } from "tslog";
|
||||
import ConfigHandler from "../../../../../common/api-test-utils/config/configHandler";
|
||||
import { RestClient } from "../../../../../common/api-test-utils/restClient/RestClient";
|
||||
// import { ConfigHandler, RestClient } from '../../../../../common/api-test-utils';
|
||||
|
||||
|
||||
export abstract class APIClient {
|
||||
protected constructor(baseUrl: string, serviceUrl: string) {
|
||||
this.url = baseUrl + serviceUrl;
|
||||
this.restClient = new RestClient(this.url);
|
||||
this.serviceName = this.constructor.toString().match(/\w+/g)[1];
|
||||
this.log.info(`The Service URL for ${this.serviceName} is ${this.url}`);
|
||||
}
|
||||
|
||||
public createdItemIds: Set<string> = new Set();
|
||||
|
||||
protected config = ConfigHandler.getInstance();
|
||||
|
||||
protected log: Logger = new Logger({
|
||||
minLevel: this.config.environmentConfig.log_level,
|
||||
dateTimeTimezone:
|
||||
this.config.environmentConfig.time_zone ||
|
||||
Intl.DateTimeFormat().resolvedOptions().timeZone,
|
||||
});
|
||||
|
||||
protected url: string;
|
||||
|
||||
public restClient: RestClient;
|
||||
|
||||
protected serviceName: string;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import axios from "axios";
|
||||
import ConfigHandler from "../../../../common/api-test-utils/config/configHandler"
|
||||
|
||||
// Get the current env from configHandler
|
||||
const configHandler = ConfigHandler.getInstance();
|
||||
const currentEnvironment = process.env.TEST_ENV || "sandbox" || "prod";
|
||||
const apiBaseUrl =
|
||||
configHandler.getEnvironmentConfig(currentEnvironment).api_base_url;
|
||||
|
||||
// get the gateway ip addresses
|
||||
export async function getGatewayIPAddresses(): Promise<string[]> {
|
||||
try {
|
||||
const response = await axios.get(`${apiBaseUrl}/gateways`);
|
||||
if (response.status === 200) {
|
||||
const hosts = response.data.map((item: { gateway: { host: string } }) => {
|
||||
const host = item.gateway.host;
|
||||
const apiUrl = `http://${host}:8080/api/v1`;
|
||||
// console.log(`API URL for host ${host}: ${apiUrl}`);
|
||||
return apiUrl;
|
||||
});
|
||||
return hosts;
|
||||
} else {
|
||||
throw new Error("Failed to fetch gateway hosts.");
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(`Error fetching gateway IP addresses: ${error.message}`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
export interface ClientInterfaces {
|
||||
mixnet_websockets: MixnetWebsockets;
|
||||
wireguard: Wireguard;
|
||||
}
|
||||
|
||||
export interface MixnetWebsockets {
|
||||
ws_port: number | null;
|
||||
wss_port: number | null;
|
||||
}
|
||||
|
||||
export interface Wireguard {
|
||||
port: number | null;
|
||||
public_key: string;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
// export interface Mixnodes {}
|
||||
@@ -0,0 +1,33 @@
|
||||
export interface BuildInformation {
|
||||
binary_name: string;
|
||||
build_timestamp: string;
|
||||
build_version: string;
|
||||
cargo_profile: string;
|
||||
commit_branch: string;
|
||||
commit_sha: string;
|
||||
commit_timestamp: string;
|
||||
rustc_channel: string;
|
||||
rustc_version: string;
|
||||
}
|
||||
|
||||
export interface HostInformation {
|
||||
data: Data;
|
||||
signature: string;
|
||||
}
|
||||
|
||||
export interface Data {
|
||||
hostname: string | null;
|
||||
ip_address: string[];
|
||||
keys: Keys;
|
||||
}
|
||||
|
||||
export interface Keys {
|
||||
ed25519: string;
|
||||
x25519: string;
|
||||
}
|
||||
|
||||
export interface Roles {
|
||||
gateway_enabled: boolean;
|
||||
mixnode_enabled: boolean;
|
||||
network_requester_enabled: boolean;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"removeComments": true,
|
||||
"allowJs": true,
|
||||
"preserveConstEnums": true,
|
||||
"module": "commonjs",
|
||||
"target": "ES2019",
|
||||
"declaration": true,
|
||||
"esModuleInterop": true,
|
||||
"sourceMap": true,
|
||||
"lib": ["esnext"],
|
||||
"outDir": "dist",
|
||||
"resolveJsonModule": true,
|
||||
"moduleResolution": "node",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"paths": {
|
||||
"*": ["types/*"],
|
||||
"common/api-test-utils": ["../../common/api-test-utils/index.ts"]
|
||||
},
|
||||
"baseUrl": "./",
|
||||
"typeRoots": ["node_modules/@types"],
|
||||
"alwaysStrict": true
|
||||
},
|
||||
"include": ["src/**/*", "tests/functional_test/*/*"],
|
||||
"exclude": ["unit_test/**/*"]
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
+2
-1
@@ -51,6 +51,7 @@
|
||||
"lerna": "^7.3.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"@npmcli/node-gyp": "^3.0.0",
|
||||
"node-gyp": "^9.3.1"
|
||||
"node-gyp": "^9.3.1",
|
||||
"tslog": "3.3.3"
|
||||
}
|
||||
}
|
||||
@@ -18660,6 +18660,13 @@ tslib@^2.0.0, tslib@^2.0.1, tslib@^2.0.3, tslib@^2.1.0, tslib@^2.3.0, tslib@^2.4
|
||||
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae"
|
||||
integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==
|
||||
|
||||
tslog@3.3.3:
|
||||
version "3.3.3"
|
||||
resolved "https://registry.yarnpkg.com/tslog/-/tslog-3.3.3.tgz#751a469e0d36841bd7e03676c27e53e7ffe9bc3d"
|
||||
integrity sha512-lGrkndwpAohZ9ntQpT+xtUw5k9YFV1DjsksiWQlBSf82TTqsSAWBARPRD9juI730r8o3Awpkjp2aXy9k+6vr+g==
|
||||
dependencies:
|
||||
source-map-support "^0.5.21"
|
||||
|
||||
tsutils@^3.21.0:
|
||||
version "3.21.0"
|
||||
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.21.0.tgz#b48717d394cea6c1e096983eed58e9d61715b623"
|
||||
|
||||
Reference in New Issue
Block a user