From 6c5457468b9fe4e6d69aee611a647ce9337a23e5 Mon Sep 17 00:00:00 2001 From: benedettadavico Date: Mon, 20 Nov 2023 07:41:25 +0100 Subject: [PATCH] Adding mixnode test --- .../functional_test/gateways/gateway.test.ts | 3 +- .../functional_test/mixnodes/mixnode.test.ts | 51 ++++++++++--------- nym-node/tests/src/endpoints/Mixnodes.ts | 26 +++++----- nym-node/tests/src/helpers/helper.ts | 17 +++++++ nym-node/tests/src/types/MixnodeTypes.ts | 2 +- 5 files changed, 59 insertions(+), 40 deletions(-) diff --git a/nym-node/tests/functional_test/gateways/gateway.test.ts b/nym-node/tests/functional_test/gateways/gateway.test.ts index 5156defc5ab..183c1e7b1e2 100644 --- a/nym-node/tests/functional_test/gateways/gateway.test.ts +++ b/nym-node/tests/functional_test/gateways/gateway.test.ts @@ -13,7 +13,8 @@ describe("Get gateway related info", (): void => { }); beforeEach(async (): Promise => { - 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]); } diff --git a/nym-node/tests/functional_test/mixnodes/mixnode.test.ts b/nym-node/tests/functional_test/mixnodes/mixnode.test.ts index 86f8e1f3194..126e99f38da 100644 --- a/nym-node/tests/functional_test/mixnodes/mixnode.test.ts +++ b/nym-node/tests/functional_test/mixnodes/mixnode.test.ts @@ -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 => { -// 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 => { + try { + mixnodeHosts = await getMixnodeIPAddresses(); + console.log(mixnodeHosts) + } catch (error) { + throw new Error(`Error fetching mixnode IP addresses: ${error.message}`); + } + }); -// beforeEach(async (): Promise => { -// for (let i = 0; i < gatewayHosts.length; i++) { -// console.log("currently trying gateway host", gatewayHosts[i]) -// contract = new Mixnode(gatewayHosts[i]); -// } -// }); + beforeEach(async (): Promise => { + // 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 => { -// const response = await contract.getMixnodeInfo(); -// // TODO implement checks here -// }); - -// }); + it("Get mixnode details", async (): Promise => { + const response = await contract.getMixnodeInfo(); + // This response is currently just empty {}, amend it when it changes + expect(response).toEqual({}); + }); +}); diff --git a/nym-node/tests/src/endpoints/Mixnodes.ts b/nym-node/tests/src/endpoints/Mixnodes.ts index 2d5217a73cd..77d42e2f1d8 100644 --- a/nym-node/tests/src/endpoints/Mixnodes.ts +++ b/nym-node/tests/src/endpoints/Mixnodes.ts @@ -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 { -// const response = await this.restClient.sendGet({ -// route: `mixnode`, -// }); -// return response; -// } -// } + public async getMixnodeInfo(): Promise { + const response = await this.restClient.sendGet({ + route: `mixnode`, + }); + return response; + } +} diff --git a/nym-node/tests/src/helpers/helper.ts b/nym-node/tests/src/helpers/helper.ts index ee626ce26df..5d80b63cc4a 100644 --- a/nym-node/tests/src/helpers/helper.ts +++ b/nym-node/tests/src/helpers/helper.ts @@ -27,3 +27,20 @@ export async function getGatewayIPAddresses(): Promise { throw new Error(`Error fetching gateway IP addresses: ${error.message}`); } } + +export async function getMixnodeIPAddresses(): Promise { + 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}`); + } +} diff --git a/nym-node/tests/src/types/MixnodeTypes.ts b/nym-node/tests/src/types/MixnodeTypes.ts index 787cdbc581c..48260f70649 100644 --- a/nym-node/tests/src/types/MixnodeTypes.ts +++ b/nym-node/tests/src/types/MixnodeTypes.ts @@ -1 +1 @@ -// export interface Mixnodes {} +export interface Mixnodes {}