adding a test for SP endpoint

This commit is contained in:
benedettadavico
2023-04-27 15:37:59 +02:00
parent 3f4f76859b
commit 6872d7bf77
4 changed files with 63 additions and 4 deletions
@@ -0,0 +1,28 @@
import ContractCache from "../../src/endpoints/ContractCache";
import ConfigHandler from "../../src/config/configHandler";
let contract: ContractCache;
let config: ConfigHandler;
describe("Get service provider info", (): void => {
beforeAll(async (): Promise<void> => {
contract = new ContractCache();
config = ConfigHandler.getInstance();
});
it("Get service providers", async (): Promise<void> => {
const response = await contract.getServiceProviders();
if ("[service_id]" in response) {
response.services.forEach((x) => {
expect(typeof x.service.nym_address.address).toBe("string");
expect(typeof x.service.service_type).toBe("string");
expect(typeof x.service.block_height).toBe("number");
expect(typeof x.service.announcer).toBe("string");
expect(typeof x.service.deposit.amount).toBe("string");
expect(typeof x.service.deposit.denom).toBe("string");
});
} else if ("[ ]" in response) {
return;
}
});
});
@@ -4,6 +4,7 @@ import {
AllMixnodes,
EpochRewardParams,
CurrentEpoch,
ServiceProviders,
} from "../types/ContractCacheTypes";
import { APIClient } from "./abstracts/APIClient";
@@ -89,4 +90,11 @@ export default class ContractCache extends APIClient {
});
return response.data;
}
public async getServiceProviders(): Promise<ServiceProviders> {
const response = await this.restClient.sendGet({
route: `services`,
});
return response.data;
}
}
@@ -123,3 +123,26 @@ export interface EpochLength {
secs: number;
nanos: number;
}
export interface ServiceProviders {
services: (Services)[];
}
export interface Services {
service_id: number;
service: Service;
}
export interface Service {
nym_address: NymAddress;
service_type: string;
announcer: string;
block_height: number;
deposit: Deposit;
}
export interface NymAddress {
address: string;
}
export interface Deposit {
denom: string;
amount: string;
}
+4 -4
View File
@@ -2457,10 +2457,10 @@ prettier-linter-helpers@^1.0.0:
dependencies:
fast-diff "^1.1.2"
prettier@2.7.1:
version "2.7.1"
resolved "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz"
integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==
prettier@^2.8.7:
version "2.8.8"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==
pretty-format@^28.0.0, pretty-format@^28.1.3:
version "28.1.3"