Skip to content

Commit

Permalink
Adding mixnode test
Browse files Browse the repository at this point in the history
  • Loading branch information
benedettadavico committed Nov 20, 2023
1 parent b615f5e commit 6c54574
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 40 deletions.
3 changes: 2 additions & 1 deletion nym-node/tests/functional_test/gateways/gateway.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
51 changes: 26 additions & 25 deletions nym-node/tests/functional_test/mixnodes/mixnode.test.ts
Original file line number Diff line number Diff line change
@@ -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({});
});
});
26 changes: 13 additions & 13 deletions nym-node/tests/src/endpoints/Mixnodes.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 17 additions & 0 deletions nym-node/tests/src/helpers/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
}
2 changes: 1 addition & 1 deletion nym-node/tests/src/types/MixnodeTypes.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
// export interface Mixnodes {}
export interface Mixnodes {}

0 comments on commit 6c54574

Please sign in to comment.