Adding missing tests and cleaning up Types files
This commit is contained in:
+14
@@ -21,4 +21,18 @@ describe("Get service provider info", (): void => {
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
it("Get Nym address names", async (): Promise<void> => {
|
||||
const response = await contract.getNymAddressNames();
|
||||
if ("[id]" in response) {
|
||||
response.names.forEach((x) => {
|
||||
expect(typeof x.name.name).toBe("string");
|
||||
expect(typeof x.name.address.gateway_id).toBe("string");
|
||||
expect(typeof x.id).toBe("number");
|
||||
|
||||
});
|
||||
} else if ("[ ]" in response) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,47 @@
|
||||
import NetworkTypes from "../../src/endpoints/Network";
|
||||
let contract: NetworkTypes;
|
||||
|
||||
describe("Get network and contract details", (): void => {
|
||||
beforeAll(async (): Promise<void> => {
|
||||
contract = new NetworkTypes();
|
||||
});
|
||||
|
||||
it("Get network details", async (): Promise<void> => {
|
||||
const response = await contract.getNetworkDetails();
|
||||
expect(typeof response.network.network_name).toBe("string");
|
||||
});
|
||||
|
||||
it("Get nym contract info", async (): Promise<void> => {
|
||||
const response = await contract.getNymContractInfo();
|
||||
for (const key in response) {
|
||||
if (response.hasOwnProperty(key)) {
|
||||
const additionalProp = response[key];
|
||||
expect(typeof additionalProp.address).toBe("string");
|
||||
if ("build_timestamp" in response) {
|
||||
expect(typeof additionalProp.details.contract).toBe("string");
|
||||
expect(typeof additionalProp.details.version).toBe("string");
|
||||
}
|
||||
else if (additionalProp.details === null) {
|
||||
expect(additionalProp.details).toBeNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("Get nym contract info detailed", async (): Promise<void> => {
|
||||
const response = await contract.getNymContractDetailedInfo();
|
||||
for (const key in response) {
|
||||
if (response.hasOwnProperty(key)) {
|
||||
const additionalProp = response[key];
|
||||
expect(typeof additionalProp.address).toBe("string");
|
||||
if ("build_timestamp" in response) {
|
||||
expect(typeof additionalProp.details.build_timestamp).toBe("string");
|
||||
expect(typeof additionalProp.details.rustc_version).toBe("string");
|
||||
}
|
||||
else if (additionalProp.details === null) {
|
||||
expect(additionalProp.details).toBeNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
EpochRewardParams,
|
||||
CurrentEpoch,
|
||||
ServiceProviders,
|
||||
NymAddressNames,
|
||||
} from "../types/ContractCacheTypes";
|
||||
import { APIClient } from "./abstracts/APIClient";
|
||||
|
||||
@@ -97,4 +98,11 @@ export default class ContractCache extends APIClient {
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
|
||||
public async getNymAddressNames(): Promise<NymAddressNames> {
|
||||
const response = await this.restClient.sendGet({
|
||||
route: `names`,
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { NetworkDetails, NymContracts, NymContractsDetailed } from "../types/NetworkTypes";
|
||||
import { APIClient } from "./abstracts/APIClient";
|
||||
|
||||
export default class NetworkTypes extends APIClient {
|
||||
constructor() {
|
||||
super("/");
|
||||
}
|
||||
|
||||
public async getNetworkDetails(): Promise<NetworkDetails> {
|
||||
const response = await this.restClient.sendGet({
|
||||
route: `network/details`,
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
|
||||
public async getNymContractInfo(): Promise<NymContracts> {
|
||||
const response = await this.restClient.sendGet({
|
||||
route: `network/nym-contracts`,
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
|
||||
public async getNymContractDetailedInfo(): Promise<NymContractsDetailed> {
|
||||
const response = await this.restClient.sendGet({
|
||||
route: `network/nym-contracts-detailed`,
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ export interface AllMixnodes {
|
||||
export interface BondInformation {
|
||||
mix_id: number;
|
||||
owner: string;
|
||||
original_pledge: OriginalPledge;
|
||||
original_pledge: DenominationAndAmount;
|
||||
layer: number;
|
||||
mix_node: Mixnode;
|
||||
proxy: string;
|
||||
@@ -26,24 +26,13 @@ export interface RewardingDetails {
|
||||
|
||||
export interface CostParams {
|
||||
profit_margin_percent: string;
|
||||
interval_operating_cost: IntervalOperatingCost;
|
||||
interval_operating_cost: DenominationAndAmount;
|
||||
}
|
||||
|
||||
export interface IntervalOperatingCost {
|
||||
export interface DenominationAndAmount {
|
||||
denom: string;
|
||||
amount: string;
|
||||
}
|
||||
|
||||
export interface OriginalPledge {
|
||||
denom: string;
|
||||
amount: string;
|
||||
}
|
||||
|
||||
export interface TotalDelegation {
|
||||
denom: string;
|
||||
amount: string;
|
||||
}
|
||||
|
||||
export interface Mixnode {
|
||||
host: string;
|
||||
mix_port: number;
|
||||
@@ -55,8 +44,8 @@ export interface Mixnode {
|
||||
}
|
||||
|
||||
export interface MixnodeBond {
|
||||
pledge_amount: OriginalPledge;
|
||||
total_delegation: TotalDelegation;
|
||||
pledge_amount: DenominationAndAmount;
|
||||
total_delegation: DenominationAndAmount;
|
||||
owner: string;
|
||||
layer: string;
|
||||
block_height: string;
|
||||
@@ -86,7 +75,7 @@ export interface Gateway {
|
||||
}
|
||||
|
||||
export interface AllGateways {
|
||||
pledge_amount: OriginalPledge;
|
||||
pledge_amount: DenominationAndAmount;
|
||||
owner: string;
|
||||
block_height: number;
|
||||
gateway: Gateway;
|
||||
@@ -136,12 +125,30 @@ export interface Service {
|
||||
service_type: string;
|
||||
announcer: string;
|
||||
block_height: number;
|
||||
deposit: Deposit;
|
||||
deposit: DenominationAndAmount;
|
||||
}
|
||||
export interface NymAddress {
|
||||
address: string;
|
||||
}
|
||||
export interface Deposit {
|
||||
denom: string;
|
||||
amount: string;
|
||||
|
||||
export interface NymAddressNames {
|
||||
names: Names[];
|
||||
}
|
||||
export interface Names {
|
||||
id: number;
|
||||
name: Name;
|
||||
owner: string;
|
||||
block_height: number;
|
||||
deposit: DenominationAndAmount;
|
||||
}
|
||||
export interface Name {
|
||||
name: string;
|
||||
address: NameAddress;
|
||||
identity_key: string;
|
||||
}
|
||||
|
||||
export interface NameAddress {
|
||||
client_id: string;
|
||||
client_enc: string;
|
||||
gateway_id: string;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
export interface NetworkDetails {
|
||||
connected_nyxd: string;
|
||||
network: Network;
|
||||
}
|
||||
|
||||
export interface Network {
|
||||
network_name: string;
|
||||
chain_details: ChainDetails;
|
||||
endpoints: Endpoint[];
|
||||
contracts: Contracts;
|
||||
explorer_api: string;
|
||||
}
|
||||
|
||||
export interface ChainDetails {
|
||||
bech32_account_prefix: string;
|
||||
mix_denom: Denom;
|
||||
stake_denom: Denom;
|
||||
}
|
||||
|
||||
export interface Denom {
|
||||
base: string;
|
||||
display: string;
|
||||
display_exponent: number;
|
||||
}
|
||||
|
||||
export interface Contracts {
|
||||
mixnet_contract_address: string;
|
||||
vesting_contract_address: string;
|
||||
coconut_bandwidth_contract_address: string;
|
||||
group_contract_address: string;
|
||||
multisig_contract_address: string;
|
||||
coconut_dkg_contract_address: string;
|
||||
ephemera_contract_address: string;
|
||||
service_provider_directory_contract_address: string;
|
||||
name_service_contract_address: string;
|
||||
}
|
||||
|
||||
export interface Endpoint {
|
||||
nyxd_url: string;
|
||||
api_url: string;
|
||||
}
|
||||
|
||||
|
||||
export interface NymContracts {
|
||||
[additionalProp: string]: AdditionalProp;
|
||||
}
|
||||
|
||||
export interface AdditionalProp {
|
||||
address: string;
|
||||
details: Info;
|
||||
}
|
||||
|
||||
export interface Info {
|
||||
contract: string;
|
||||
version: string;
|
||||
}
|
||||
|
||||
|
||||
export interface NymContractsDetailed {
|
||||
[additionalProp: string]: AdditionalPropDetailed;
|
||||
}
|
||||
|
||||
export interface AdditionalPropDetailed {
|
||||
address: string;
|
||||
details: InfoDetailed;
|
||||
}
|
||||
|
||||
export interface InfoDetailed {
|
||||
build_timestamp: string;
|
||||
build_version: string;
|
||||
commit_sha: string;
|
||||
commit_timestamp: string;
|
||||
commit_branch: string;
|
||||
rustc_version: string;
|
||||
}
|
||||
@@ -52,11 +52,11 @@ export interface ComputeRewardEstimation {
|
||||
active_in_rewarded_set: boolean;
|
||||
pledge_amount: number;
|
||||
total_delegation: number;
|
||||
interval_operating_cost: IntervalOperatingCost;
|
||||
interval_operating_cost: DenominationAndAmount;
|
||||
profit_margin_percent: string;
|
||||
}
|
||||
|
||||
export interface IntervalOperatingCost {
|
||||
export interface DenominationAndAmount {
|
||||
denom: string;
|
||||
amount: string;
|
||||
}
|
||||
@@ -138,11 +138,6 @@ export interface ActiveStatus {
|
||||
status: string;
|
||||
}
|
||||
|
||||
export interface PledgeAmount {
|
||||
denom: string;
|
||||
amount: string;
|
||||
}
|
||||
|
||||
export interface Gateway {
|
||||
host: string;
|
||||
mix_port: number;
|
||||
@@ -154,7 +149,7 @@ export interface Gateway {
|
||||
}
|
||||
|
||||
export interface GatewayBond {
|
||||
pledge_amount: PledgeAmount;
|
||||
pledge_amount: DenominationAndAmount;
|
||||
owner: string;
|
||||
block_height: number;
|
||||
gateway: Gateway;
|
||||
@@ -179,11 +174,6 @@ export interface DetailedGateway {
|
||||
node_performance: nodePerformance;
|
||||
}
|
||||
|
||||
export interface OriginalPledge {
|
||||
denom: string;
|
||||
amount: string;
|
||||
}
|
||||
|
||||
export interface MixNode {
|
||||
host: string;
|
||||
mix_port: number;
|
||||
@@ -197,7 +187,7 @@ export interface MixNode {
|
||||
export interface BondInformation {
|
||||
mix_id: number;
|
||||
owner: string;
|
||||
original_pledge: OriginalPledge;
|
||||
original_pledge: DenominationAndAmount;
|
||||
layer: string;
|
||||
mix_node: MixNode;
|
||||
proxy: string;
|
||||
@@ -205,14 +195,9 @@ export interface BondInformation {
|
||||
is_unbonding: boolean;
|
||||
}
|
||||
|
||||
export interface IntervalOperatingCost {
|
||||
denom: string;
|
||||
amount: string;
|
||||
}
|
||||
|
||||
export interface CostParams {
|
||||
profit_margin_percent: string;
|
||||
interval_operating_cost: IntervalOperatingCost;
|
||||
interval_operating_cost: DenominationAndAmount;
|
||||
}
|
||||
|
||||
export interface RewardingDetails {
|
||||
|
||||
Reference in New Issue
Block a user