From 5ce017ef3d2f0eed1c1a4e89bc8458b796fcc687 Mon Sep 17 00:00:00 2001 From: benedetta davico <46782255+benedettadavico@users.noreply.github.com> Date: Wed, 5 Apr 2023 10:57:45 +0200 Subject: [PATCH] adding vesting tests (#3279) --- clients/validator/src/index.ts | 11 ++++++++++- clients/validator/src/nyxd-querier.ts | 14 +++++++++++++- clients/validator/src/query-client.ts | 10 +++++++++- clients/validator/src/signing-client.ts | 10 +++++++++- 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/clients/validator/src/index.ts b/clients/validator/src/index.ts index a43baaf51d..c143acdd13 100644 --- a/clients/validator/src/index.ts +++ b/clients/validator/src/index.ts @@ -34,10 +34,11 @@ import { StakeSaturationResponse, UnbondedMixnodeResponse, VestingAccountInfo, - ContractState, VestingAccountsCoinPaged, VestingAccountsPaged, DelegationTimes, Delegations, Period, VestingAccountNode + ContractState, VestingAccountsCoinPaged, VestingAccountsPaged, DelegationTimes, Delegations, Period, VestingAccountNode, DelegationBlock } from '@nymproject/types'; import QueryClient from './query-client'; import SigningClient, { ISigningClient } from './signing-client'; +// import { DelegationBlock } from './types/shared'; export interface INymClient { readonly mixnetContract: string; @@ -606,6 +607,14 @@ export default class ValidatorClient implements INymClient { return this.client.getAllDelegations(this.vestingContract); } + public async getDelegation(address: string, mix_id: number): Promise { + return this.client.getDelegation(this.vestingContract, address, mix_id ); + } + + public async getTotalDelegationAmount(address: string, mix_id: number, block_timestamp_sec: number): Promise { + return this.client.getTotalDelegationAmount(this.vestingContract, address, mix_id, block_timestamp_sec); + } + 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 7fe09a4896..1b0d0fed54 100644 --- a/clients/validator/src/nyxd-querier.ts +++ b/clients/validator/src/nyxd-querier.ts @@ -18,7 +18,7 @@ import { PagedMixNodeDetailsResponse, PagedUnbondedMixnodesResponse, LayerDistribution, - ContractState, VestingAccountsCoinPaged, VestingAccountsPaged, DelegationTimes, Delegations, Period, VestingAccountNode + ContractState, VestingAccountsCoinPaged, VestingAccountsPaged, DelegationTimes, Delegations, Period, VestingAccountNode, DelegationBlock } from '@nymproject/types'; import { SmartContractQuery } from './types/shared'; import { Coin } from 'cosmjs-types/cosmos/base/v1beta1/coin'; @@ -317,6 +317,18 @@ export default class NyxdQuerier implements INyxdQuery { }); } + getDelegation(vestingContractAddress: string, address: string, mix_id: number): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + get_all_delegations: {address: address, mix_id: mix_id} + }); + } + + getTotalDelegationAmount(vestingContractAddress: string, address: string, mix_id: number, block_timestamp_sec: number): Promise { + return this.client.queryContractSmart(vestingContractAddress, { + get_all_delegations: {address: address, mix_id: mix_id, block_timestamp_sec: block_timestamp_sec} + }); + } + 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 23fa68be83..c1e958ba9d 100644 --- a/clients/validator/src/query-client.ts +++ b/clients/validator/src/query-client.ts @@ -22,7 +22,7 @@ import { MixNodeRewarding, OriginalVestingResponse, VestingAccountInfo, - ContractState, VestingAccountsCoinPaged, VestingAccountsPaged, DelegationTimes, Delegations, Period, VestingAccountNode + ContractState, VestingAccountsCoinPaged, VestingAccountsPaged, DelegationTimes, Delegations, Period, VestingAccountNode, DelegationBlock } from '@nymproject/types'; import NymApiQuerier, { INymApiQuery } from './nym-api-querier'; import { ICosmWasmQuery } from './types/shared'; @@ -288,6 +288,14 @@ export default class QueryClient extends CosmWasmClient implements IQueryClient return this.nyxdQuerier.getAllDelegations(vestingContractAddress); } + getDelegation(vestingContractAddress: string, vestingAccountAddress: string, mix_id: number): Promise { + return this.nyxdQuerier.getDelegation(vestingContractAddress, vestingAccountAddress, mix_id); + } + + getTotalDelegationAmount(vestingContractAddress: string, vestingAccountAddress: string, mix_id: number, block_timestamp_sec: number): Promise { + return this.nyxdQuerier.getTotalDelegationAmount(vestingContractAddress, vestingAccountAddress, mix_id, block_timestamp_sec); + } + 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 946f848da4..628b31264c 100644 --- a/clients/validator/src/signing-client.ts +++ b/clients/validator/src/signing-client.ts @@ -40,7 +40,7 @@ import { RewardingParams, UnbondedMixnodeResponse, VestingAccountInfo, - ContractState, VestingAccountsCoinPaged, VestingAccountsPaged, DelegationTimes, Delegations, Period, VestingAccountNode + ContractState, VestingAccountsCoinPaged, VestingAccountsPaged, DelegationTimes, Delegations, Period, VestingAccountNode, DelegationBlock } from '@nymproject/types'; import NymApiQuerier from './nym-api-querier'; @@ -597,6 +597,14 @@ export default class SigningClient extends SigningCosmWasmClient implements ISig return this.nyxdQuerier.getAllDelegations(vestingContractAddress); } + getDelegation(vestingContractAddress: string, vestingAccountAddress: string, mix_id: number): Promise { + return this.nyxdQuerier.getDelegation(vestingContractAddress, vestingAccountAddress, mix_id); + } + + getTotalDelegationAmount(vestingContractAddress: string, vestingAccountAddress: string, mix_id: number, block_timestamp_sec: number): Promise { + return this.nyxdQuerier.getTotalDelegationAmount(vestingContractAddress, vestingAccountAddress, mix_id, block_timestamp_sec); + } + getCurrentVestingPeriod(vestingContractAddress: string, address: string): Promise { return this.nyxdQuerier.getCurrentVestingPeriod(vestingContractAddress, address); }