From 77a7c7fe26bb51bd2281ccbb6772689f82b8a504 Mon Sep 17 00:00:00 2001 From: benedettadavico Date: Thu, 2 Mar 2023 09:31:08 +0100 Subject: [PATCH] starting to add vesting tests & merging develop --- clients/validator/src/index.ts | 74 +++++++++++++-- clients/validator/src/nyxd-querier.ts | 84 ++++++++++++++++- clients/validator/src/query-client.ts | 61 ++++++++++++- clients/validator/src/signing-client.ts | 61 ++++++++++++- .../validator/src/tests/expectedResponses.ts | 80 +++++++++++++++- .../src/tests/query/vestingQueries.test.ts | 91 ++++++++++++++++++- ts-packages/types/src/types/global.ts | 52 +++++++++++ 7 files changed, 486 insertions(+), 17 deletions(-) diff --git a/clients/validator/src/index.ts b/clients/validator/src/index.ts index e11d24525f..977010da06 100644 --- a/clients/validator/src/index.ts +++ b/clients/validator/src/index.ts @@ -16,12 +16,14 @@ import { GatewayOwnershipResponse, LayerDistribution, MixnetContractVersion, + Mixnode, MixNode, MixNodeBond, MixNodeCostParams, MixNodeDetails, MixNodeRewarding, MixOwnershipResponse, + OriginalVestingResponse, PagedAllDelegationsResponse, PagedDelegatorDelegationsResponse, PagedGatewayResponse, @@ -32,10 +34,11 @@ import { RewardingParams, StakeSaturationResponse, UnbondedMixnodeResponse, + VestingAccountInfo, + ContractState, VestingAccountsCoinPaged, VestingAccountsPaged, DelegationTimes, Delegations } from '@nymproject/types'; import QueryClient from './query-client'; import SigningClient, { ISigningClient } from './signing-client'; -import { ContractState } from './types/shared'; export interface INymClient { readonly mixnetContract: string; @@ -204,7 +207,7 @@ export default class ValidatorClient implements INymClient { let mixNodes: UnbondedMixnodeResponse[] = []; const limit = 50; let startAfter; - for (;;) { + for (; ;) { // eslint-disable-next-line no-await-in-loop const pagedResponse: PagedUnbondedMixnodesResponse = await this.client.getUnbondedMixNodes( this.mixnetContract, @@ -227,7 +230,7 @@ export default class ValidatorClient implements INymClient { let mixNodes: MixNodeBond[] = []; const limit = 50; let startAfter; - for (;;) { + for (; ;) { // eslint-disable-next-line no-await-in-loop const pagedResponse: PagedMixNodeBondResponse = await this.client.getMixNodeBonds( this.mixnetContract, @@ -249,7 +252,7 @@ export default class ValidatorClient implements INymClient { let mixNodes: MixNodeDetails[] = []; const limit = 50; let startAfter; - for (;;) { + for (; ;) { // eslint-disable-next-line no-await-in-loop const pagedResponse: PagedMixNodeDetailsResponse = await this.client.getMixNodesDetailed( this.mixnetContract, @@ -281,7 +284,7 @@ export default class ValidatorClient implements INymClient { let delegations: Delegation[] = []; const limit = 250; let startAfter; - for (;;) { + for (; ;) { // eslint-disable-next-line no-await-in-loop const pagedResponse: PagedMixDelegationsResponse = await this.client.getMixNodeDelegationsPaged( this.mixnetContract, @@ -304,7 +307,7 @@ export default class ValidatorClient implements INymClient { let delegations: Delegation[] = []; const limit = 250; let startAfter; - for (;;) { + for (; ;) { // eslint-disable-next-line no-await-in-loop const pagedResponse: PagedDelegatorDelegationsResponse = await this.client.getDelegatorDelegationsPaged( this.mixnetContract, @@ -327,7 +330,7 @@ export default class ValidatorClient implements INymClient { let delegations: Delegation[] = []; const limit = 250; let startAfter; - for (;;) { + for (; ;) { // eslint-disable-next-line no-await-in-loop const pagedResponse: PagedAllDelegationsResponse = await this.client.getAllDelegationsPaged( this.mixnetContract, @@ -514,4 +517,61 @@ export default class ValidatorClient implements INymClient { this.assertSigning(); return (this.client as ISigningClient).updateContractStateParams(this.mixnetContract, newParams, fee, memo); } + + + // VESTING + // TODO - MOVE TO A DIFFERENT FILE + + + public async getVestingAccountsPaged(): Promise { + return this.client.getVestingAccountsPaged(this.vestingContract); + } + + public async getVestingAmountsAccountsPaged(): Promise { + return this.client.getVestingAmountsAccountsPaged(this.vestingContract); + } + + public async getLockedTokens(vestingAccountAddress: string): Promise { + return this.client.getLockedTokens(this.vestingContract, vestingAccountAddress); + } + + public async getSpendableTokens(vestingAccountAddress: string): Promise { + return this.client.getSpendableTokens(this.vestingContract, vestingAccountAddress); + } + + public async getVestedTokens(vestingAccountAddress: string): Promise { + return this.client.getVestedTokens(this.vestingContract, vestingAccountAddress); + } + + public async getVestingTokens(vestingAccountAddress: string): Promise { + return this.client.getVestingTokens(this.vestingContract, vestingAccountAddress); + } + + public async getStartTime(vestingAccountAddress: string): Promise { + return this.client.getStartTime(this.vestingContract, vestingAccountAddress); + } + + public async getOriginalVestingDetails(vestingAccountAddress: string): Promise { + return this.client.getOriginalVestingDetails(this.vestingContract, vestingAccountAddress); + } + + public async getHistoricStakingRewards(vestingAccountAddress: string): Promise { + return this.client.getHistoricStakingRewards(this.vestingContract, vestingAccountAddress); + } + + public async getAccountDetails(address: string): Promise { + return this.client.getAccountDetails(this.vestingContract, address); + } + + public async getMixnode(address: string): Promise { + return this.client.getMixnode(this.vestingContract, address); + } + + public async getDelegationTimes(mix_id: number, delegatorAddress: string): Promise { + return this.client.getDelegationTimes(this.vestingContract, mix_id, delegatorAddress); + } + + public async getAllDelegations(): Promise { + return this.client.getAllDelegations(this.vestingContract); + } } diff --git a/clients/validator/src/nyxd-querier.ts b/clients/validator/src/nyxd-querier.ts index 0e34493c2e..40408029fd 100644 --- a/clients/validator/src/nyxd-querier.ts +++ b/clients/validator/src/nyxd-querier.ts @@ -4,8 +4,8 @@ */ // eslint-disable-next-line import/no-cycle import { INyxdQuery } from './query-client'; -import { Delegation, RewardingParams, StakeSaturationResponse } from '@nymproject/types'; import { + Delegation, Mixnode, OriginalVestingResponse, RewardingParams, StakeSaturationResponse, VestingAccountInfo, UnbondedMixnodeResponse, GatewayOwnershipResponse, MixnetContractVersion, @@ -18,8 +18,10 @@ import { PagedMixNodeDetailsResponse, PagedUnbondedMixnodesResponse, LayerDistribution, + ContractState, VestingAccountsCoinPaged, VestingAccountsPaged, DelegationTimes, Delegations } from '@nymproject/types'; -import { ContractState, SmartContractQuery } from './types/shared'; +import { SmartContractQuery } from './types/shared'; +import { Coin } from 'cosmjs-types/cosmos/base/v1beta1/coin'; export default class NyxdQuerier implements INyxdQuery { client: SmartContractQuery; @@ -188,4 +190,82 @@ export default class NyxdQuerier implements INyxdQuery { vesting_account_address: vestingAccountAddress, }); } + + getVestingAccountsPaged(vestingContractAddress: string): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + get_accounts_paged: {} + }); + } + + getVestingAmountsAccountsPaged(vestingContractAddress: string): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + get_accounts_vesting_coins_paged: {} + }); + } + + getLockedTokens(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + locked_coins: { vesting_account_address: vestingAccountAddress } + }); + } + + getSpendableTokens(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + spendable_coins: { vesting_account_address: vestingAccountAddress } + }); + } + + getVestedTokens(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + get_vested_coins: { vesting_account_address: vestingAccountAddress } + }); + } + + getVestingTokens(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + get_vesting_coins: { vesting_account_address: vestingAccountAddress } + }); + } + + getStartTime(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + get_start_time: { vesting_account_address: vestingAccountAddress } + }); + } + + getOriginalVestingDetails(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + get_original_vesting: { vesting_account_address: vestingAccountAddress } + }); + } + + getHistoricStakingRewards(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + get_historical_vesting_staking_reward: { vesting_account_address: vestingAccountAddress } + }); + } + + getAccountDetails(vestingContractAddress: string, address: string): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + get_account: { address: address } + }); + } + + getMixnode(vestingContractAddress: string, address: string): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + get_mixnode: { address: address } + }); + } + + getDelegationTimes(vestingContractAddress: string, mix_id: number, address: string): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + get_delegation_times: { mix_id: mix_id, address: address } + }); + } + + getAllDelegations(vestingContractAddress: string): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + get_all_delegations: {} + }); + } } diff --git a/clients/validator/src/query-client.ts b/clients/validator/src/query-client.ts index 319c46f80e..9217f099ed 100644 --- a/clients/validator/src/query-client.ts +++ b/clients/validator/src/query-client.ts @@ -20,11 +20,16 @@ import { UnbondedMixnodeResponse, MixNodeBond, MixNodeRewarding, + OriginalVestingResponse, + VestingAccountInfo, + Mixnode, + ContractState, VestingAccountsCoinPaged, VestingAccountsPaged, DelegationTimes, Delegations } from '@nymproject/types'; import NymApiQuerier, { INymApiQuery } from './nym-api-querier'; -import { ContractState, ICosmWasmQuery } from './types/shared'; +import { ICosmWasmQuery } from './types/shared'; import { RewardingParams } from '@nymproject/types'; import { Tendermint34Client } from '@cosmjs/tendermint-rpc'; +import { Coin } from 'cosmjs-types/cosmos/base/v1beta1/coin'; export interface INyxdQuery { // nym-specific implemented inside NymQuerier @@ -68,7 +73,7 @@ export interface INyxdQuery { getMixnodeRewardingDetails(mixnetContractAddress: string, mixId: number): Promise; } -export interface IQueryClient extends ICosmWasmQuery, INyxdQuery, INymApiQuery {} +export interface IQueryClient extends ICosmWasmQuery, INyxdQuery, INymApiQuery { } export default class QueryClient extends CosmWasmClient implements IQueryClient { private nyxdQuerier: NyxdQuerier; @@ -199,4 +204,56 @@ export default class QueryClient extends CosmWasmClient implements IQueryClient getSpendableCoins(vestingContractAddress: string, vestingAccountAddress: string): Promise { return this.nyxdQuerier.getSpendableCoins(vestingContractAddress, vestingAccountAddress); } + + getVestingAccountsPaged(vestingContractAddress: string): Promise { + return this.nyxdQuerier.getVestingAccountsPaged(vestingContractAddress); + } + + getVestingAmountsAccountsPaged(vestingContractAddress: string): Promise { + return this.nyxdQuerier.getVestingAmountsAccountsPaged(vestingContractAddress); + } + + getLockedTokens(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getLockedTokens(vestingContractAddress, vestingAccountAddress); + } + + getSpendableTokens(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getSpendableTokens(vestingContractAddress, vestingAccountAddress); + } + + getVestedTokens(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getVestedTokens(vestingContractAddress, vestingAccountAddress); + } + + getVestingTokens(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getVestingTokens(vestingContractAddress, vestingAccountAddress); + } + + getStartTime(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getStartTime(vestingContractAddress, vestingAccountAddress); + } + + getOriginalVestingDetails(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getOriginalVestingDetails(vestingContractAddress, vestingAccountAddress); + } + + getHistoricStakingRewards(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getHistoricStakingRewards(vestingContractAddress, vestingAccountAddress); + } + + getAccountDetails(vestingContractAddress: string, address: string): Promise { + return this.nyxdQuerier.getAccountDetails(vestingContractAddress, address); + } + + getMixnode(vestingContractAddress: string, address: string): Promise { + return this.nyxdQuerier.getMixnode(vestingContractAddress, address); + } + + getDelegationTimes(vestingContractAddress: string, mix_id: number, delegatorAddress: string): Promise { + return this.nyxdQuerier.getDelegationTimes(vestingContractAddress, mix_id, delegatorAddress); + } + + getAllDelegations(vestingContractAddress: string): Promise { + return this.nyxdQuerier.getAllDelegations(vestingContractAddress); + } } diff --git a/clients/validator/src/signing-client.ts b/clients/validator/src/signing-client.ts index d750eefcd2..95c316c99a 100644 --- a/clients/validator/src/signing-client.ts +++ b/clients/validator/src/signing-client.ts @@ -23,12 +23,14 @@ import { GatewayOwnershipResponse, LayerDistribution, MixnetContractVersion, + Mixnode, MixNode, MixNodeBond, MixNodeCostParams, MixNodeDetails, MixNodeRewarding, MixOwnershipResponse, + OriginalVestingResponse, PagedAllDelegationsResponse, PagedDelegatorDelegationsResponse, PagedGatewayResponse, @@ -38,9 +40,10 @@ import { PagedUnbondedMixnodesResponse, RewardingParams, UnbondedMixnodeResponse, + VestingAccountInfo, + ContractState, VestingAccountsCoinPaged, VestingAccountsPaged, DelegationTimes, Delegations } from '@nymproject/types'; import NymApiQuerier from './nym-api-querier'; -import { ContractState } from './types/shared'; // methods exposed by `SigningCosmWasmClient` export interface ICosmWasmSigning { @@ -243,7 +246,7 @@ export default class SigningClient extends SigningCosmWasmClient implements ISig // query related: getContractVersion(mixnetContractAddress: string): Promise { - return this.getContractVersion(mixnetContractAddress); + return this.nyxdQuerier.getContractVersion(mixnetContractAddress); } getMixNodeBonds( @@ -508,4 +511,58 @@ export default class SigningClient extends SigningCosmWasmClient implements ISig memo, ); } + + // vesting related + + getVestingAccountsPaged(vestingContractAddress: string): Promise { + return this.nyxdQuerier.getVestingAccountsPaged(vestingContractAddress); + }; + + getVestingAmountsAccountsPaged(vestingContractAddress: string): Promise { + return this.nyxdQuerier.getVestingAmountsAccountsPaged(vestingContractAddress); + } + + getLockedTokens(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getLockedTokens(vestingContractAddress, vestingAccountAddress); + } + + getSpendableTokens(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getSpendableTokens(vestingContractAddress, vestingAccountAddress); + } + + getVestedTokens(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getVestedTokens(vestingContractAddress, vestingAccountAddress); + } + + getVestingTokens(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getVestingTokens(vestingContractAddress, vestingAccountAddress); + } + + getStartTime(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getStartTime(vestingContractAddress, vestingAccountAddress); + } + + getOriginalVestingDetails(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getOriginalVestingDetails(vestingContractAddress, vestingAccountAddress); + } + + getHistoricStakingRewards(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getHistoricStakingRewards(vestingContractAddress, vestingAccountAddress); + } + + getAccountDetails(vestingContractAddress: string, address: string): Promise { + return this.nyxdQuerier.getAccountDetails(vestingContractAddress, address); + } + + getMixnode(vestingContractAddress: string, address: string): Promise { + return this.nyxdQuerier.getMixnode(vestingContractAddress, address); + } + + getDelegationTimes(vestingContractAddress: string, mix_id: number, delegatorAddress: string): Promise { + return this.nyxdQuerier.getDelegationTimes(vestingContractAddress, mix_id, delegatorAddress); + } + + getAllDelegations(vestingContractAddress: string): Promise { + return this.nyxdQuerier.getAllDelegations(vestingContractAddress); + } } diff --git a/clients/validator/src/tests/expectedResponses.ts b/clients/validator/src/tests/expectedResponses.ts index 876f61e866..fee632690e 100644 --- a/clients/validator/src/tests/expectedResponses.ts +++ b/clients/validator/src/tests/expectedResponses.ts @@ -1,8 +1,9 @@ +import { Coin } from 'cosmjs-types/cosmos/base/v1beta1/coin'; import expect from 'expect'; export const amountDemon = { - amount: expect.any(String), - denom: expect.any(String) + denom: expect.any(String), + amount: expect.any(String) } export const delegation = { @@ -176,3 +177,78 @@ export const rewardingParams = { rewarded_set_size: expect.any(Number), active_set_size: expect.any(Number) } + +export const VestAccounts = [{ + account_id: expect.any(String), + owner: expect.any(String) +}] + +export const VestAccountCoin = [{ + account_id: expect.any(String), + owner: expect.any(String), + still_vesting: Coin +}] + +export const vestingAccountsPaged = { + accounts: VestAccounts, + start_next_after: expect.any(String) +} + +export const VestingCoinAccounts = { + accounts: VestAccountCoin, + start_next_after: expect.any(String) +} + +export const startTime = { +} + +export const OriginalVestingDetails = { + amount: Coin, + number_of_periods: expect.any(Number), + period_duration: expect.any(Number) +} + +export const PledgeCap = { + percent: expect.any(String), +}; + +export const Periods = [{ + period_seconds: expect.any(Number), + start_time: expect.any(Number), +}] + +export const VestingAccountDetails = { + coin: Coin, + owner_address: expect.any(String), + periods: Periods, + pledge_cap: PledgeCap, + staking_address: expect.any(String) || null, + start_time: expect.any(String), + storage_key: expect.any(Number) +} + +export const Mixnode = { + amount: Coin, + block_time: expect.any(String) +} + +export const DelegationTimestamps = [{}] + +export const DelegatorTimes = { + account_id: expect.any(Number), + delegation_timestamps: DelegationTimestamps, + mix_id: expect.any(Number), + owner: expect.any(String), +} + +export const DelegationBlock = [{ + account_id: expect.any(Number), + amount: expect.any(String), + block_timestamp: expect.any(Number), + mix_id: expect.any(Number) +}] + +export const Delegations = { + delegations: DelegationBlock, + start_next_after: expect.any(String) || null +} \ No newline at end of file diff --git a/clients/validator/src/tests/query/vestingQueries.test.ts b/clients/validator/src/tests/query/vestingQueries.test.ts index 2cbe4f5088..a86d808f48 100644 --- a/clients/validator/src/tests/query/vestingQueries.test.ts +++ b/clients/validator/src/tests/query/vestingQueries.test.ts @@ -1,11 +1,12 @@ import expect from 'expect'; import ValidatorClient from '../../index'; +import { amountDemon, Delegations, DelegatorTimes, Mixnode, OriginalVestingDetails, startTime, VestingAccountDetails, vestingAccountsPaged, VestingCoinAccounts } from '../expectedResponses'; const dotenv = require('dotenv'); dotenv.config(); -describe('Vesting queries', () => { +describe.only('Vesting queries', () => { let client: ValidatorClient; beforeEach(async () => { @@ -24,5 +25,91 @@ describe('Vesting queries', () => { expect(contract).toBeTruthy(); }); - it('can get the balance on the account', () => {}); + // TODO see if we can use AccountEntry type here instead + it('can get all accounts paged', async () => { + const accounts = await client.getVestingAccountsPaged(); + expect(Object.keys(accounts)).toEqual(Object.keys(vestingAccountsPaged)); + expect(accounts).toBeTruthy(); + }); + + it('can get coins for all accounts paged', async () => { + const accounts = await client.getVestingAmountsAccountsPaged(); + expect(Object.keys(accounts)).toEqual(Object.keys(VestingCoinAccounts)); + expect(accounts).toBeTruthy(); + }); + + it('can get locked tokens for an account', async () => { + const locked = await client.getLockedTokens("n14juvj7llvx8eppypnqj6xlrgwss9wfrcuy0nkv"); + expect(Object.keys(locked)).toEqual(Object.keys(amountDemon)); + expect(locked).toBeTruthy(); + }); + + it('can get spendable tokens for an account', async () => { + const spendable = await client.getSpendableTokens("n14juvj7llvx8eppypnqj6xlrgwss9wfrcuy0nkv"); + expect(Object.keys(spendable)).toEqual(Object.keys(amountDemon)); + expect(spendable).toBeTruthy(); + }); + + it('can get vested tokens for an account', async () => { + const vested = await client.getVestedTokens("n14juvj7llvx8eppypnqj6xlrgwss9wfrcuy0nkv"); + expect(Object.keys(vested)).toEqual(Object.keys(amountDemon)); + expect(vested).toBeTruthy(); + }); + + it('can get vesting tokens for an account', async () => { + const vesting = await client.getVestingTokens("n14juvj7llvx8eppypnqj6xlrgwss9wfrcuy0nkv"); + expect(Object.keys(vesting)).toEqual(Object.keys(amountDemon)); + expect(vesting).toBeTruthy(); + }); + + // TODO fix this + it.skip('can get start time of an account', async () => { + const time = await client.getStartTime("n14juvj7llvx8eppypnqj6xlrgwss9wfrcuy0nkv"); + console.log("----------------") + console.log(time) + expect(Object.keys(time)).toEqual(Object.keys(startTime)); + expect(time).toBeTruthy(); + }); + + it('can get account original vesting details', async () => { + const original = await client.getOriginalVestingDetails("n14juvj7llvx8eppypnqj6xlrgwss9wfrcuy0nkv"); + expect(Object.keys(original)).toEqual(Object.keys(OriginalVestingDetails)); + expect(original).toBeTruthy(); + }); + + it('can get historic vesting staking rewards', async () => { + const rewards = await client.getHistoricStakingRewards("n14juvj7llvx8eppypnqj6xlrgwss9wfrcuy0nkv"); + expect(Object.keys(rewards)).toEqual(Object.keys(amountDemon)); + expect(rewards).toBeTruthy(); + }); + + // TODO VestingAccountInfo autogenerated file needs to be edited/fixed as it's wrong + it.skip('can get account details', async () => { + const account = await client.getAccountDetails("n14juvj7llvx8eppypnqj6xlrgwss9wfrcuy0nkv"); + expect(Object.keys(account)).toEqual(Object.keys(VestingAccountDetails)); + expect(account).toBeTruthy(); + }); + + // TODO add option for if account has no mixnode and expected is null + it('can get mixnode', async () => { + const mixnode = await client.getMixnode("n1z93z44vf8ssvdhujjvxcj4rd5e3lz0l60wdk70"); + expect(Object.keys(mixnode)).toEqual(Object.keys(Mixnode)); + expect(mixnode).toBeTruthy(); + }); + + // TODO nyxd query returns value in different order to this test, understand why + it('can get delegations times', async () => { + const delegation = await client.getDelegationTimes(79, "n1z93z44vf8ssvdhujjvxcj4rd5e3lz0l60wdk70"); + console.log("---") + console.log(delegation) + console.log("---") + expect(Object.keys(delegation)).toEqual(Object.keys(DelegatorTimes)); + expect(delegation).toBeTruthy(); + }); + + it.only('can get all delegations', async () => { + const delegation = await client.getAllDelegations(); + expect(Object.keys(delegation)).toEqual(Object.keys(Delegations)); + expect(delegation).toBeTruthy(); + }); }); diff --git a/ts-packages/types/src/types/global.ts b/ts-packages/types/src/types/global.ts index c949456494..100daba854 100644 --- a/ts-packages/types/src/types/global.ts +++ b/ts-packages/types/src/types/global.ts @@ -150,3 +150,55 @@ export type LayerDistribution = { layer2: number; layer3: number; }; + +export interface ContractState { + owner: string; + rewarding_validator_address: string; + vesting_contract_address: string; + rewarding_denom: string; + params: ContractStateParams; +}; + +export type Mixnode = { + amount: Coin; + block_time: string; +}; + +export interface VestAccounts { + account_id: string; + owner: string; +}; + +export interface VestingAccountsPaged { + accounts: VestAccounts[]; + start_next_after: string; +}; + +export interface VestingAccountsCoinPaged { + account_id: string; + owner: string; + still_vesting: Coin; +}; + +export interface DelegationTimestamps { +}; + +export interface DelegationTimes { + account_id: number; + delegation_timestamps: DelegationTimestamps[]; + mix_id: number; + owner: string; +}; + +export interface DelegationBlock { + account_id: number; + amount: string; + block_timestamp: number; + mix_id: number; +} + +export interface Delegations { + delegations: DelegationBlock[]; + start_next_after: string | null; + +} \ No newline at end of file