Adding mixnode test

This commit is contained in:
benedettadavico
2023-11-20 07:41:25 +01:00
parent b615f5e75e
commit 6c5457468b
5 changed files with 59 additions and 40 deletions
@@ -13,7 +13,8 @@ describe("Get gateway related info", (): void => {
});
beforeEach(async (): Promise<void> => {
for (let i = 0; i < gatewayHosts.length; i++) {
// Testing only 3 nodes from the list
for (let i = 3; i < gatewayHosts.length; i++) {
console.log("currently trying gateway host", gatewayHosts[i]);
contract = new Gateway(gatewayHosts[i]);
}
@@ -1,28 +1,29 @@
// import Mixnode from "../../src/endpoints/Mixnodes";
// import { getGatewayIPAddresses } from '../../src/helpers/helper';
import Mixnode from "../../src/endpoints/Mixnodes";
import { getMixnodeIPAddresses } 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}`);
// }
// });
describe("Get mixnode related info", (): void => {
let contract: Mixnode;
let mixnodeHosts: string[];
beforeAll(async (): Promise<void> => {
try {
mixnodeHosts = await getMixnodeIPAddresses();
console.log(mixnodeHosts)
} catch (error) {
throw new Error(`Error fetching mixnode 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]);
// }
// });
beforeEach(async (): Promise<void> => {
// Testing only 3 nodes from the list
for (let i = 3; i < mixnodeHosts.length; i++) {
console.log("currently trying mixnode host", mixnodeHosts[i])
contract = new Mixnode(mixnodeHosts[i]);
}
});
// it("Get mixnode details", async (): Promise<void> => {
// const response = await contract.getMixnodeInfo();
// // TODO implement checks here
// });
// });
it("Get mixnode details", async (): Promise<void> => {
const response = await contract.getMixnodeInfo();
// This response is currently just empty {}, amend it when it changes
expect(response).toEqual({});
});
});
+13 -13
View File
@@ -1,15 +1,15 @@
// import { Mixnodes } from "../types/MixnodeTypes";
// import { APIClient } from "./abstracts/APIClient";
import { Mixnodes } from "../types/MixnodeTypes";
import { APIClient } from "./abstracts/APIClient";
// export default class Mixnode extends APIClient {
// constructor(baseUrl: string) {
// super(baseUrl, "/");
// }
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;
// }
// }
public async getMixnodeInfo(): Promise<Mixnodes> {
const response = await this.restClient.sendGet({
route: `mixnode`,
});
return response;
}
}
+17
View File
@@ -27,3 +27,20 @@ export async function getGatewayIPAddresses(): Promise<string[]> {
throw new Error(`Error fetching gateway IP addresses: ${error.message}`);
}
}
export async function getMixnodeIPAddresses(): Promise<string[]> {
helper = new Helper();
try {
const response = await helper.restClient.sendGet({
route: `/mixnodes`,
});
const hosts = response.map((item: { bond_information: { mix_node: { host: string } } } ) => {
const host = item.bond_information.mix_node.host;
const apiUrl = `http://${host}:8000/api/v1`;
return apiUrl;
});
return hosts;
} catch (error) {
throw new Error(`Error fetching mixnode IP addresses: ${error.message}`);
}
}
+1 -1
View File
@@ -1 +1 @@
// export interface Mixnodes {}
export interface Mixnodes {}