From 246b6c0e406e6e0a68178b5a35568e8e913a4945 Mon Sep 17 00:00:00 2001 From: benedettadavico Date: Thu, 2 Mar 2023 09:31:08 +0100 Subject: [PATCH 1/3] starting to add vesting tests --- Cargo.lock | 20 ++-- 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 +++++++++++ 8 files changed, 496 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4f0fab00f8..9f2d2f7a14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -677,7 +677,7 @@ dependencies = [ [[package]] name = "client-core" -version = "1.1.10" +version = "1.1.11" dependencies = [ "async-trait", "dashmap 5.4.0", @@ -1802,7 +1802,7 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" [[package]] name = "explorer-api" -version = "1.1.10" +version = "1.1.11" dependencies = [ "chrono", "clap 4.1.4", @@ -3281,7 +3281,7 @@ dependencies = [ [[package]] name = "nym-api" -version = "1.1.11" +version = "1.1.12" dependencies = [ "anyhow", "async-trait", @@ -3391,7 +3391,7 @@ dependencies = [ [[package]] name = "nym-cli" -version = "1.1.10" +version = "1.1.11" dependencies = [ "anyhow", "base64 0.13.1", @@ -3449,7 +3449,7 @@ dependencies = [ [[package]] name = "nym-client" -version = "1.1.10" +version = "1.1.11" dependencies = [ "clap 4.1.4", "client-core", @@ -3543,7 +3543,7 @@ dependencies = [ [[package]] name = "nym-gateway" -version = "1.1.10" +version = "1.1.11" dependencies = [ "anyhow", "async-trait", @@ -3620,7 +3620,7 @@ dependencies = [ [[package]] name = "nym-mixnode" -version = "1.1.11" +version = "1.1.12" dependencies = [ "anyhow", "atty", @@ -3675,7 +3675,7 @@ dependencies = [ [[package]] name = "nym-network-requester" -version = "1.1.10" +version = "1.1.11" dependencies = [ "async-trait", "clap 4.1.4", @@ -3713,7 +3713,7 @@ dependencies = [ [[package]] name = "nym-network-statistics" -version = "1.1.10" +version = "1.1.11" dependencies = [ "dirs", "log", @@ -3788,7 +3788,7 @@ dependencies = [ [[package]] name = "nym-socks5-client" -version = "1.1.10" +version = "1.1.11" dependencies = [ "clap 4.1.4", "client-core", 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 From 277373fb59092967d23d6e48fd7611d32faa99f4 Mon Sep 17 00:00:00 2001 From: benedettadavico Date: Mon, 6 Mar 2023 11:28:18 +0100 Subject: [PATCH 2/3] adding more vesting client tests --- clients/validator/src/index.ts | 41 ++++++- clients/validator/src/nyxd-querier.ts | 60 ++++++++++- clients/validator/src/query-client.ts | 41 ++++++- clients/validator/src/signing-client.ts | 41 ++++++- .../validator/src/tests/expectedResponses.ts | 30 +++--- .../src/tests/query/vestingQueries.test.ts | 101 +++++++++++++----- ts-packages/types/src/types/global.ts | 12 +-- 7 files changed, 267 insertions(+), 59 deletions(-) diff --git a/clients/validator/src/index.ts b/clients/validator/src/index.ts index 977010da06..a43baaf51d 100644 --- a/clients/validator/src/index.ts +++ b/clients/validator/src/index.ts @@ -16,7 +16,6 @@ import { GatewayOwnershipResponse, LayerDistribution, MixnetContractVersion, - Mixnode, MixNode, MixNodeBond, MixNodeCostParams, @@ -35,7 +34,7 @@ import { StakeSaturationResponse, UnbondedMixnodeResponse, VestingAccountInfo, - ContractState, VestingAccountsCoinPaged, VestingAccountsPaged, DelegationTimes, Delegations + ContractState, VestingAccountsCoinPaged, VestingAccountsPaged, DelegationTimes, Delegations, Period, VestingAccountNode } from '@nymproject/types'; import QueryClient from './query-client'; import SigningClient, { ISigningClient } from './signing-client'; @@ -547,10 +546,38 @@ export default class ValidatorClient implements INymClient { return this.client.getVestingTokens(this.vestingContract, vestingAccountAddress); } + public async getSpendableVestedTokens(vestingAccountAddress: string): Promise { + return this.client.getSpendableVestedTokens(this.vestingContract, vestingAccountAddress); + } + + public async getSpendableRewards(vestingAccountAddress: string): Promise { + return this.client.getSpendableRewards(this.vestingContract, vestingAccountAddress); + } + + public async getDelegatedCoins(vestingAccountAddress: string): Promise { + return this.client.getDelegatedCoins(this.vestingContract, vestingAccountAddress); + } + + public async getPledgedCoins(vestingAccountAddress: string): Promise { + return this.client.getPledgedCoins(this.vestingContract, vestingAccountAddress); + } + + public async getStakedCoins(vestingAccountAddress: string): Promise { + return this.client.getStakedCoins(this.vestingContract, vestingAccountAddress); + } + + public async getWithdrawnCoins(vestingAccountAddress: string): Promise { + return this.client.getWithdrawnCoins(this.vestingContract, vestingAccountAddress); + } + public async getStartTime(vestingAccountAddress: string): Promise { return this.client.getStartTime(this.vestingContract, vestingAccountAddress); } + public async getEndTime(vestingAccountAddress: string): Promise { + return this.client.getEndTime(this.vestingContract, vestingAccountAddress); + } + public async getOriginalVestingDetails(vestingAccountAddress: string): Promise { return this.client.getOriginalVestingDetails(this.vestingContract, vestingAccountAddress); } @@ -563,10 +590,14 @@ export default class ValidatorClient implements INymClient { return this.client.getAccountDetails(this.vestingContract, address); } - public async getMixnode(address: string): Promise { + public async getMixnode(address: string): Promise { return this.client.getMixnode(this.vestingContract, address); } + public async getGateway(address: string): Promise { + return this.client.getGateway(this.vestingContract, address); + } + public async getDelegationTimes(mix_id: number, delegatorAddress: string): Promise { return this.client.getDelegationTimes(this.vestingContract, mix_id, delegatorAddress); } @@ -574,4 +605,8 @@ export default class ValidatorClient implements INymClient { public async getAllDelegations(): Promise { return this.client.getAllDelegations(this.vestingContract); } + + public async getCurrentVestingPeriod(address: string): Promise { + return this.client.getCurrentVestingPeriod(this.vestingContract, address); + } } diff --git a/clients/validator/src/nyxd-querier.ts b/clients/validator/src/nyxd-querier.ts index 40408029fd..7fe09a4896 100644 --- a/clients/validator/src/nyxd-querier.ts +++ b/clients/validator/src/nyxd-querier.ts @@ -5,7 +5,7 @@ // eslint-disable-next-line import/no-cycle import { INyxdQuery } from './query-client'; import { - Delegation, Mixnode, OriginalVestingResponse, RewardingParams, StakeSaturationResponse, VestingAccountInfo, + Delegation, OriginalVestingResponse, RewardingParams, StakeSaturationResponse, VestingAccountInfo, UnbondedMixnodeResponse, GatewayOwnershipResponse, MixnetContractVersion, @@ -18,7 +18,7 @@ import { PagedMixNodeDetailsResponse, PagedUnbondedMixnodesResponse, LayerDistribution, - ContractState, VestingAccountsCoinPaged, VestingAccountsPaged, DelegationTimes, Delegations + ContractState, VestingAccountsCoinPaged, VestingAccountsPaged, DelegationTimes, Delegations, Period, VestingAccountNode } from '@nymproject/types'; import { SmartContractQuery } from './types/shared'; import { Coin } from 'cosmjs-types/cosmos/base/v1beta1/coin'; @@ -227,12 +227,54 @@ export default class NyxdQuerier implements INyxdQuery { }); } + getSpendableVestedTokens(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + get_spendable_vested_coins: { vesting_account_address: vestingAccountAddress } + }); + } + + getSpendableRewards(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + get_spendable_reward_coins: { vesting_account_address: vestingAccountAddress } + }); + } + + getDelegatedCoins(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + get_delegated_coins: { vesting_account_address: vestingAccountAddress } + }); + } + + getPledgedCoins(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + get_pledged_coins: { vesting_account_address: vestingAccountAddress } + }); + } + + getStakedCoins(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + get_staked_coins: { vesting_account_address: vestingAccountAddress } + }); + } + + getWithdrawnCoins(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + get_withdrawn_coins: { vesting_account_address: vestingAccountAddress } + }); + } + getStartTime(vestingContractAddress: string, vestingAccountAddress: string): Promise { return this.client.queryContractSmart(vestingContractAddress, { get_start_time: { vesting_account_address: vestingAccountAddress } }); } + getEndTime(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + get_end_time: { vesting_account_address: vestingAccountAddress } + }); + } + getOriginalVestingDetails(vestingContractAddress: string, vestingAccountAddress: string): Promise { return this.client.queryContractSmart(vestingContractAddress, { get_original_vesting: { vesting_account_address: vestingAccountAddress } @@ -251,12 +293,18 @@ export default class NyxdQuerier implements INyxdQuery { }); } - getMixnode(vestingContractAddress: string, address: string): Promise { + getMixnode(vestingContractAddress: string, address: string): Promise { return this.client.queryContractSmart(vestingContractAddress, { get_mixnode: { address: address } }); } + getGateway(vestingContractAddress: string, address: string): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + get_gateway: { 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 } @@ -268,4 +316,10 @@ export default class NyxdQuerier implements INyxdQuery { get_all_delegations: {} }); } + + getCurrentVestingPeriod(vestingContractAddress: string, address: string): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + get_current_vesting_period: { address: address } + }); + } } diff --git a/clients/validator/src/query-client.ts b/clients/validator/src/query-client.ts index 9217f099ed..23fa68be83 100644 --- a/clients/validator/src/query-client.ts +++ b/clients/validator/src/query-client.ts @@ -22,8 +22,7 @@ import { MixNodeRewarding, OriginalVestingResponse, VestingAccountInfo, - Mixnode, - ContractState, VestingAccountsCoinPaged, VestingAccountsPaged, DelegationTimes, Delegations + ContractState, VestingAccountsCoinPaged, VestingAccountsPaged, DelegationTimes, Delegations, Period, VestingAccountNode } from '@nymproject/types'; import NymApiQuerier, { INymApiQuery } from './nym-api-querier'; import { ICosmWasmQuery } from './types/shared'; @@ -229,10 +228,38 @@ export default class QueryClient extends CosmWasmClient implements IQueryClient return this.nyxdQuerier.getVestingTokens(vestingContractAddress, vestingAccountAddress); } + getSpendableVestedTokens(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getSpendableVestedTokens(vestingContractAddress, vestingAccountAddress); + } + + getSpendableRewards(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getSpendableRewards(vestingContractAddress, vestingAccountAddress); + } + + getDelegatedCoins(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getDelegatedCoins(vestingContractAddress, vestingAccountAddress); + } + + getPledgedCoins(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getPledgedCoins(vestingContractAddress, vestingAccountAddress); + } + + getStakedCoins(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getStakedCoins(vestingContractAddress, vestingAccountAddress); + } + + getWithdrawnCoins(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getWithdrawnCoins(vestingContractAddress, vestingAccountAddress); + } + getStartTime(vestingContractAddress: string, vestingAccountAddress: string): Promise { return this.nyxdQuerier.getStartTime(vestingContractAddress, vestingAccountAddress); } + getEndTime(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getEndTime(vestingContractAddress, vestingAccountAddress); + } + getOriginalVestingDetails(vestingContractAddress: string, vestingAccountAddress: string): Promise { return this.nyxdQuerier.getOriginalVestingDetails(vestingContractAddress, vestingAccountAddress); } @@ -245,10 +272,14 @@ export default class QueryClient extends CosmWasmClient implements IQueryClient return this.nyxdQuerier.getAccountDetails(vestingContractAddress, address); } - getMixnode(vestingContractAddress: string, address: string): Promise { + getMixnode(vestingContractAddress: string, address: string): Promise { return this.nyxdQuerier.getMixnode(vestingContractAddress, address); } + getGateway(vestingContractAddress: string, address: string): Promise { + return this.nyxdQuerier.getGateway(vestingContractAddress, address); + } + getDelegationTimes(vestingContractAddress: string, mix_id: number, delegatorAddress: string): Promise { return this.nyxdQuerier.getDelegationTimes(vestingContractAddress, mix_id, delegatorAddress); } @@ -256,4 +287,8 @@ export default class QueryClient extends CosmWasmClient implements IQueryClient getAllDelegations(vestingContractAddress: string): Promise { return this.nyxdQuerier.getAllDelegations(vestingContractAddress); } + + getCurrentVestingPeriod(vestingContractAddress: string, address: string): Promise { + return this.nyxdQuerier.getCurrentVestingPeriod(vestingContractAddress, address); + } } diff --git a/clients/validator/src/signing-client.ts b/clients/validator/src/signing-client.ts index 95c316c99a..946f848da4 100644 --- a/clients/validator/src/signing-client.ts +++ b/clients/validator/src/signing-client.ts @@ -23,7 +23,6 @@ import { GatewayOwnershipResponse, LayerDistribution, MixnetContractVersion, - Mixnode, MixNode, MixNodeBond, MixNodeCostParams, @@ -41,7 +40,7 @@ import { RewardingParams, UnbondedMixnodeResponse, VestingAccountInfo, - ContractState, VestingAccountsCoinPaged, VestingAccountsPaged, DelegationTimes, Delegations + ContractState, VestingAccountsCoinPaged, VestingAccountsPaged, DelegationTimes, Delegations, Period, VestingAccountNode } from '@nymproject/types'; import NymApiQuerier from './nym-api-querier'; @@ -538,10 +537,38 @@ export default class SigningClient extends SigningCosmWasmClient implements ISig return this.nyxdQuerier.getVestingTokens(vestingContractAddress, vestingAccountAddress); } + getSpendableVestedTokens(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getSpendableVestedTokens(vestingContractAddress, vestingAccountAddress); + } + + getSpendableRewards(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getSpendableRewards(vestingContractAddress, vestingAccountAddress); + } + + getDelegatedCoins(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getDelegatedCoins(vestingContractAddress, vestingAccountAddress); + } + + getPledgedCoins(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getPledgedCoins(vestingContractAddress, vestingAccountAddress); + } + + getStakedCoins(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getStakedCoins(vestingContractAddress, vestingAccountAddress); + } + + getWithdrawnCoins(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getWithdrawnCoins(vestingContractAddress, vestingAccountAddress); + } + getStartTime(vestingContractAddress: string, vestingAccountAddress: string): Promise { return this.nyxdQuerier.getStartTime(vestingContractAddress, vestingAccountAddress); } + getEndTime(vestingContractAddress: string, vestingAccountAddress: string): Promise { + return this.nyxdQuerier.getEndTime(vestingContractAddress, vestingAccountAddress); + } + getOriginalVestingDetails(vestingContractAddress: string, vestingAccountAddress: string): Promise { return this.nyxdQuerier.getOriginalVestingDetails(vestingContractAddress, vestingAccountAddress); } @@ -554,10 +581,14 @@ export default class SigningClient extends SigningCosmWasmClient implements ISig return this.nyxdQuerier.getAccountDetails(vestingContractAddress, address); } - getMixnode(vestingContractAddress: string, address: string): Promise { + getMixnode(vestingContractAddress: string, address: string): Promise { return this.nyxdQuerier.getMixnode(vestingContractAddress, address); } + getGateway(vestingContractAddress: string, address: string): Promise { + return this.nyxdQuerier.getGateway(vestingContractAddress, address); + } + getDelegationTimes(vestingContractAddress: string, mix_id: number, delegatorAddress: string): Promise { return this.nyxdQuerier.getDelegationTimes(vestingContractAddress, mix_id, delegatorAddress); } @@ -565,4 +596,8 @@ export default class SigningClient extends SigningCosmWasmClient implements ISig getAllDelegations(vestingContractAddress: string): Promise { return this.nyxdQuerier.getAllDelegations(vestingContractAddress); } + + getCurrentVestingPeriod(vestingContractAddress: string, address: string): Promise { + return this.nyxdQuerier.getCurrentVestingPeriod(vestingContractAddress, address); + } } diff --git a/clients/validator/src/tests/expectedResponses.ts b/clients/validator/src/tests/expectedResponses.ts index fee632690e..74b7d02b4a 100644 --- a/clients/validator/src/tests/expectedResponses.ts +++ b/clients/validator/src/tests/expectedResponses.ts @@ -160,7 +160,6 @@ export const layerDistribution = { layer3: expect.any(Number) } - export const intervalRewardParams = { reward_pool: expect.any(Number), staking_supply: expect.any(Number), @@ -199,9 +198,6 @@ export const VestingCoinAccounts = { start_next_after: expect.any(String) } -export const startTime = { -} - export const OriginalVestingDetails = { amount: Coin, number_of_periods: expect.any(Number), @@ -209,7 +205,7 @@ export const OriginalVestingDetails = { } export const PledgeCap = { - percent: expect.any(String), + percent: expect.any(String) || null, }; export const Periods = [{ @@ -218,27 +214,31 @@ export const Periods = [{ }] 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) + periods: Periods, + coin: Coin, + storage_key: expect.any(Number), + pledge_cap: PledgeCap } -export const Mixnode = { +export const Node = { amount: Coin, block_time: expect.any(String) } -export const DelegationTimestamps = [{}] +export type VestingPeriod = 'Before' | { In: number } | 'After'; + +export const DelegationTimestamps = [ + expect.any(Number) +] export const DelegatorTimes = { - account_id: expect.any(Number), - delegation_timestamps: DelegationTimestamps, - mix_id: expect.any(Number), owner: expect.any(String), + account_id: expect.any(Number), + mix_id: expect.any(Number), + delegation_timestamps: DelegationTimestamps } export const DelegationBlock = [{ @@ -251,4 +251,4 @@ export const DelegationBlock = [{ 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 a86d808f48..8b8098f8f1 100644 --- a/clients/validator/src/tests/query/vestingQueries.test.ts +++ b/clients/validator/src/tests/query/vestingQueries.test.ts @@ -1,6 +1,6 @@ import expect from 'expect'; import ValidatorClient from '../../index'; -import { amountDemon, Delegations, DelegatorTimes, Mixnode, OriginalVestingDetails, startTime, VestingAccountDetails, vestingAccountsPaged, VestingCoinAccounts } from '../expectedResponses'; +import { amountDemon, Delegations, DelegatorTimes, Node, OriginalVestingDetails, VestingAccountDetails, vestingAccountsPaged, VestingCoinAccounts, VestingPeriod } from '../expectedResponses'; const dotenv = require('dotenv'); @@ -20,6 +20,11 @@ describe.only('Vesting queries', () => { ); }); + const vesting_account_address = 'n14juvj7llvx8eppypnqj6xlrgwss9wfrcuy0nkv'; + const mixnodeowner = 'n1z93z44vf8ssvdhujjvxcj4rd5e3lz0l60wdk70'; + const gatewayowner = 'n1un9cuvw9e3xqratmde4j55ucksev0dkeruq800'; + const mix_id = 79; + it('can query for contract version', async () => { const contract = await client.getVestingContractVersion(); expect(contract).toBeTruthy(); @@ -39,77 +44,125 @@ describe.only('Vesting queries', () => { }); it('can get locked tokens for an account', async () => { - const locked = await client.getLockedTokens("n14juvj7llvx8eppypnqj6xlrgwss9wfrcuy0nkv"); + const locked = await client.getLockedTokens(vesting_account_address); 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"); + const spendable = await client.getSpendableTokens(vesting_account_address); 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"); + const vested = await client.getVestedTokens(vesting_account_address); 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"); + const vesting = await client.getVestingTokens(vesting_account_address); 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)); + it('can get spendable vested tokens for an account', async () => { + const spendable = await client.getSpendableVestedTokens(vesting_account_address); + expect(Object.keys(spendable)).toEqual(Object.keys(amountDemon)); + expect(spendable).toBeTruthy(); + }); + + it('can get spendable rewards for an account', async () => { + const rewards = await client.getSpendableRewards(vesting_account_address); + expect(Object.keys(rewards)).toEqual(Object.keys(amountDemon)); + expect(rewards).toBeTruthy(); + }); + + it('can get delegated coins', async () => { + const delegated = await client.getDelegatedCoins(vesting_account_address); + expect(Object.keys(delegated)).toEqual(Object.keys(amountDemon)); + expect(delegated).toBeTruthy(); + }); + + it('can get pledged coins', async () => { + const pledged = await client.getPledgedCoins(vesting_account_address); + expect(Object.keys(pledged)).toEqual(Object.keys(amountDemon)); + expect(pledged).toBeTruthy(); + }); + + it('can get staked coins', async () => { + const staked = await client.getStakedCoins(vesting_account_address); + expect(Object.keys(staked)).toEqual(Object.keys(amountDemon)); + expect(staked).toBeTruthy(); + }); + + it('can get withdrawn coins', async () => { + const withdrawn = await client.getWithdrawnCoins(vesting_account_address); + expect(Object.keys(withdrawn)).toEqual(Object.keys(amountDemon)); + expect(withdrawn).toBeTruthy(); + }); + + it('can get start time of an account', async () => { + const time = await client.getStartTime(vesting_account_address); + expect(typeof time).toBe("string"); + expect(time).toBeTruthy(); + }); + + it('can get end time of an account', async () => { + const time = await client.getEndTime(vesting_account_address); + expect(typeof time).toBe("string"); expect(time).toBeTruthy(); }); it('can get account original vesting details', async () => { - const original = await client.getOriginalVestingDetails("n14juvj7llvx8eppypnqj6xlrgwss9wfrcuy0nkv"); + const original = await client.getOriginalVestingDetails(vesting_account_address); 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"); + const rewards = await client.getHistoricStakingRewards(vesting_account_address); 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"); + // TODO see if we can use "VestingAccountInfo" type here instead + it('can get account details', async () => { + const account = await client.getAccountDetails(vesting_account_address); 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)); + const mixnode = await client.getMixnode(mixnodeowner); + expect(Object.keys(mixnode)).toEqual(Object.keys(Node)); expect(mixnode).toBeTruthy(); }); - // TODO nyxd query returns value in different order to this test, understand why + // TODO add option for if account has no gateway and expected is null + it('can get gateway', async () => { + const gateway = await client.getGateway(gatewayowner); + expect(Object.keys(gateway)).toEqual(Object.keys(Node)); + expect(gateway).toBeTruthy(); + }); + it('can get delegations times', async () => { - const delegation = await client.getDelegationTimes(79, "n1z93z44vf8ssvdhujjvxcj4rd5e3lz0l60wdk70"); - console.log("---") - console.log(delegation) - console.log("---") + const delegation = await client.getDelegationTimes(mix_id, mixnodeowner); expect(Object.keys(delegation)).toEqual(Object.keys(DelegatorTimes)); expect(delegation).toBeTruthy(); }); - it.only('can get all delegations', async () => { + it('can get all delegations', async () => { const delegation = await client.getAllDelegations(); expect(Object.keys(delegation)).toEqual(Object.keys(Delegations)); expect(delegation).toBeTruthy(); }); + + it('can get current vesting period', async () => { + const period = await client.getCurrentVestingPeriod(gatewayowner); + expect(period).toEqual(expect.anything() as unknown as VestingPeriod); + expect(period).toBeTruthy(); + }); }); diff --git a/ts-packages/types/src/types/global.ts b/ts-packages/types/src/types/global.ts index 100daba854..b095628f1f 100644 --- a/ts-packages/types/src/types/global.ts +++ b/ts-packages/types/src/types/global.ts @@ -159,7 +159,7 @@ export interface ContractState { params: ContractStateParams; }; -export type Mixnode = { +export type VestingAccountNode = { amount: Coin; block_time: string; }; @@ -180,12 +180,9 @@ export interface VestingAccountsCoinPaged { still_vesting: Coin; }; -export interface DelegationTimestamps { -}; - export interface DelegationTimes { account_id: number; - delegation_timestamps: DelegationTimestamps[]; + delegation_timestamps: []; mix_id: number; owner: string; }; @@ -195,10 +192,9 @@ export interface DelegationBlock { amount: string; block_timestamp: number; mix_id: number; -} +}; export interface Delegations { delegations: DelegationBlock[]; start_next_after: string | null; - -} \ No newline at end of file +}; From a31135697b0853fe30633d8f98b4b8072bf5fe32 Mon Sep 17 00:00:00 2001 From: fmtabbara Date: Wed, 8 Mar 2023 09:27:18 +0000 Subject: [PATCH 3/3] fix linting --- ts-packages/types/src/types/global.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ts-packages/types/src/types/global.ts b/ts-packages/types/src/types/global.ts index b095628f1f..bcd08f738a 100644 --- a/ts-packages/types/src/types/global.ts +++ b/ts-packages/types/src/types/global.ts @@ -157,7 +157,7 @@ export interface ContractState { vesting_contract_address: string; rewarding_denom: string; params: ContractStateParams; -}; +} export type VestingAccountNode = { amount: Coin; @@ -167,34 +167,34 @@ export type VestingAccountNode = { 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 DelegationTimes { account_id: number; delegation_timestamps: []; 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; -}; +}