Merge pull request #641 from cosmos/629-stargate-query-extension-tests
Fill out Stargate query extension tests
This commit is contained in:
commit
a34998b476
@ -2,7 +2,7 @@
|
||||
import { coin, coins } from "@cosmjs/launchpad";
|
||||
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
|
||||
import { adaptor34, Client as TendermintClient } from "@cosmjs/tendermint-rpc";
|
||||
import { assertDefinedAndNotNull, sleep } from "@cosmjs/utils";
|
||||
import { sleep } from "@cosmjs/utils";
|
||||
|
||||
import { cosmos } from "../codec";
|
||||
import { SigningStargateClient } from "../signingstargateclient";
|
||||
@ -55,11 +55,124 @@ describe("DistributionExtension", () => {
|
||||
const [client, tmClient] = await makeClientWithDistribution(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.distribution.unverified.communityPool();
|
||||
assertDefinedAndNotNull(response.pool);
|
||||
expect(response.pool.length).toBeGreaterThanOrEqual(1);
|
||||
expect(response.pool).toBeDefined();
|
||||
expect(response.pool).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("delegationRewards", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithDistribution(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.distribution.unverified.delegationRewards(
|
||||
faucet.address0,
|
||||
validator.validatorAddress,
|
||||
);
|
||||
expect(response.rewards).toBeDefined();
|
||||
expect(response.rewards).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("delegationTotalRewards", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithDistribution(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.distribution.unverified.delegationTotalRewards(faucet.address0);
|
||||
expect(response.rewards).toBeDefined();
|
||||
expect(response.rewards).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("delegatorValidators", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithDistribution(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.distribution.unverified.delegatorValidators(faucet.address0);
|
||||
expect(response.validators).toBeDefined();
|
||||
expect(response.validators).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("delegatorWithdrawAddress", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithDistribution(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.distribution.unverified.delegatorWithdrawAddress(faucet.address0);
|
||||
expect(response.withdrawAddress).toBeDefined();
|
||||
expect(response.withdrawAddress).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("params", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithDistribution(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.distribution.unverified.params();
|
||||
expect(response.params).toBeDefined();
|
||||
expect(response.params).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("validatorCommission", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithDistribution(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.distribution.unverified.validatorCommission(validator.validatorAddress);
|
||||
expect(response.commission).toBeDefined();
|
||||
expect(response.commission).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("validatorOutstandingRewards", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithDistribution(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.distribution.unverified.validatorOutstandingRewards(
|
||||
validator.validatorAddress,
|
||||
);
|
||||
expect(response.rewards).toBeDefined();
|
||||
expect(response.rewards).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("validatorSlashes", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithDistribution(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.distribution.unverified.validatorSlashes(
|
||||
validator.validatorAddress,
|
||||
1,
|
||||
5,
|
||||
);
|
||||
expect(response.slashes).toBeDefined();
|
||||
expect(response.slashes).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -2,19 +2,12 @@
|
||||
import { coin, coins } from "@cosmjs/launchpad";
|
||||
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
|
||||
import { adaptor34, Client as TendermintClient } from "@cosmjs/tendermint-rpc";
|
||||
import { assertDefinedAndNotNull, sleep } from "@cosmjs/utils";
|
||||
import { sleep } from "@cosmjs/utils";
|
||||
|
||||
import { cosmos } from "../codec";
|
||||
import { SigningStargateClient } from "../signingstargateclient";
|
||||
import { assertIsBroadcastTxSuccess } from "../stargateclient";
|
||||
import {
|
||||
faucet,
|
||||
nonNegativeIntegerMatcher,
|
||||
pendingWithoutSimapp,
|
||||
simapp,
|
||||
simappEnabled,
|
||||
validator,
|
||||
} from "../testutils.spec";
|
||||
import { faucet, pendingWithoutSimapp, simapp, simappEnabled, validator } from "../testutils.spec";
|
||||
import { QueryClient } from "./queryclient";
|
||||
import { setupStakingExtension, StakingExtension } from "./staking";
|
||||
|
||||
@ -82,18 +75,190 @@ describe("StakingExtension", () => {
|
||||
faucet.address0,
|
||||
validator.validatorAddress,
|
||||
);
|
||||
assertDefinedAndNotNull(response.delegationResponse);
|
||||
assertDefinedAndNotNull(response.delegationResponse.delegation);
|
||||
assertDefinedAndNotNull(response.delegationResponse.balance);
|
||||
expect({ ...response.delegationResponse.delegation }).toEqual({
|
||||
delegatorAddress: faucet.address0,
|
||||
validatorAddress: validator.validatorAddress,
|
||||
shares: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
});
|
||||
expect({ ...response.delegationResponse.balance }).toEqual({
|
||||
denom: "ustake",
|
||||
amount: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
});
|
||||
expect(response.delegationResponse).toBeDefined();
|
||||
expect(response.delegationResponse).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("delegatorDelegations", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.staking.unverified.delegatorDelegations(faucet.address0);
|
||||
expect(response.delegationResponses).toBeDefined();
|
||||
expect(response.delegationResponses).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("delegatorUnbondingDelegations", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.staking.unverified.delegatorUnbondingDelegations(faucet.address0);
|
||||
expect(response.unbondingResponses).toBeDefined();
|
||||
expect(response.unbondingResponses).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("delegatorValidator", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.staking.unverified.delegatorValidator(
|
||||
faucet.address0,
|
||||
validator.validatorAddress,
|
||||
);
|
||||
expect(response.validator).toBeDefined();
|
||||
expect(response.validator).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("delegatorValidators", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.staking.unverified.delegatorValidators(faucet.address0);
|
||||
expect(response.validators).toBeDefined();
|
||||
expect(response.validators).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("historicalInfo", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.staking.unverified.historicalInfo(5);
|
||||
expect(response.hist).toBeDefined();
|
||||
expect(response.hist).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("params", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.staking.unverified.params();
|
||||
expect(response.params).toBeDefined();
|
||||
expect(response.params).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("pool", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.staking.unverified.pool();
|
||||
expect(response.pool).toBeDefined();
|
||||
expect(response.pool).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("redelegations", () => {
|
||||
it("works", async () => {
|
||||
// TODO: Set up a result for this test
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl);
|
||||
|
||||
await expectAsync(
|
||||
client.staking.unverified.redelegations(
|
||||
faucet.address0,
|
||||
validator.validatorAddress,
|
||||
validator.validatorAddress,
|
||||
),
|
||||
).toBeRejectedWithError(/redelegation not found/i);
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("unbondingDelegation", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.staking.unverified.unbondingDelegation(
|
||||
faucet.address0,
|
||||
validator.validatorAddress,
|
||||
);
|
||||
expect(response.unbond).toBeDefined();
|
||||
expect(response.unbond).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("validator", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.staking.unverified.validator(validator.validatorAddress);
|
||||
expect(response.validator).toBeDefined();
|
||||
expect(response.validator).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("validatorDelegations", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.staking.unverified.validatorDelegations(validator.validatorAddress);
|
||||
expect(response.delegationResponses).toBeDefined();
|
||||
expect(response.delegationResponses).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("validators", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.staking.unverified.validators("BOND_STATUS_BONDED");
|
||||
expect(response.validators).toBeDefined();
|
||||
expect(response.validators).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("validatorUnbondingDelegations", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.staking.unverified.validatorUnbondingDelegations(
|
||||
validator.validatorAddress,
|
||||
);
|
||||
expect(response.unbondingResponses).toBeDefined();
|
||||
expect(response.unbondingResponses).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
|
||||
@ -20,8 +20,12 @@ type IQueryValidatorDelegationsResponse = cosmos.staking.v1beta1.IQueryValidator
|
||||
type IQueryValidatorsResponse = cosmos.staking.v1beta1.IQueryValidatorsResponse;
|
||||
type IQueryValidatorUnbondingDelegationsResponse = cosmos.staking.v1beta1.IQueryValidatorUnbondingDelegationsResponse;
|
||||
|
||||
// This needs to be exported otherwise TS won’t let you export BondStatusString
|
||||
export const { BondStatus } = cosmos.staking.v1beta1;
|
||||
const { Query } = cosmos.staking.v1beta1;
|
||||
|
||||
export type BondStatusString = Exclude<keyof typeof BondStatus, "BOND_STATUS_UNSPECIFIED">;
|
||||
|
||||
export interface StakingExtension {
|
||||
readonly staking: {
|
||||
readonly unverified: {
|
||||
@ -60,7 +64,7 @@ export interface StakingExtension {
|
||||
validatorAddress: string,
|
||||
paginationKey?: Uint8Array,
|
||||
) => Promise<IQueryValidatorDelegationsResponse>;
|
||||
validators: (status: string, paginationKey?: Uint8Array) => Promise<IQueryValidatorsResponse>;
|
||||
validators: (status: BondStatusString, paginationKey?: Uint8Array) => Promise<IQueryValidatorsResponse>;
|
||||
validatorUnbondingDelegations: (
|
||||
validatorAddress: string,
|
||||
paginationKey?: Uint8Array,
|
||||
@ -165,7 +169,7 @@ export function setupStakingExtension(base: QueryClient): StakingExtension {
|
||||
});
|
||||
return toObject(response);
|
||||
},
|
||||
validators: async (status: string, paginationKey?: Uint8Array) => {
|
||||
validators: async (status: BondStatusString, paginationKey?: Uint8Array) => {
|
||||
const response = await queryService.validators({
|
||||
status: status,
|
||||
pagination: paginationKey ? { key: paginationKey } : undefined,
|
||||
|
||||
4
packages/stargate/types/queries/staking.d.ts
vendored
4
packages/stargate/types/queries/staking.d.ts
vendored
@ -14,6 +14,8 @@ declare type IQueryValidatorResponse = cosmos.staking.v1beta1.IQueryValidatorRes
|
||||
declare type IQueryValidatorDelegationsResponse = cosmos.staking.v1beta1.IQueryValidatorDelegationsResponse;
|
||||
declare type IQueryValidatorsResponse = cosmos.staking.v1beta1.IQueryValidatorsResponse;
|
||||
declare type IQueryValidatorUnbondingDelegationsResponse = cosmos.staking.v1beta1.IQueryValidatorUnbondingDelegationsResponse;
|
||||
export declare const BondStatus: typeof cosmos.staking.v1beta1.BondStatus;
|
||||
export declare type BondStatusString = Exclude<keyof typeof BondStatus, "BOND_STATUS_UNSPECIFIED">;
|
||||
export interface StakingExtension {
|
||||
readonly staking: {
|
||||
readonly unverified: {
|
||||
@ -52,7 +54,7 @@ export interface StakingExtension {
|
||||
validatorAddress: string,
|
||||
paginationKey?: Uint8Array,
|
||||
) => Promise<IQueryValidatorDelegationsResponse>;
|
||||
validators: (status: string, paginationKey?: Uint8Array) => Promise<IQueryValidatorsResponse>;
|
||||
validators: (status: BondStatusString, paginationKey?: Uint8Array) => Promise<IQueryValidatorsResponse>;
|
||||
validatorUnbondingDelegations: (
|
||||
validatorAddress: string,
|
||||
paginationKey?: Uint8Array,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user