Implement Query SlashingExtension (#1040)
* Implement Query SlashingExtension * Add proper tests for slashing * Added changes to CHANGELOG.md * Fix tests * Change test description to match the others * dont call slashingextension in stargateclient * Fix linting Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com>
This commit is contained in:
parent
333e4689a7
commit
48aeb1ddeb
@ -35,7 +35,9 @@ and this project adheres to
|
||||
is checked in `fromAmino` now instead of the constructor. This only affects
|
||||
you if multiple different protobuf type URLs map to the same Amino type
|
||||
identifier which should not be the case anyways.
|
||||
- @cosmjs/stargate: Added support for slashing queries ([#927])
|
||||
|
||||
[#927]: https://github.com/cosmos/cosmjs/issues/927
|
||||
[#989]: https://github.com/cosmos/cosmjs/issues/989
|
||||
[#994]: https://github.com/cosmos/cosmjs/issues/994
|
||||
[#1011]: https://github.com/cosmos/cosmjs/issues/1011
|
||||
|
||||
@ -10,6 +10,7 @@ export { DistributionExtension, setupDistributionExtension } from "./distributio
|
||||
export { GovExtension, GovParamsType, GovProposalId, setupGovExtension } from "./gov";
|
||||
export { IbcExtension, setupIbcExtension } from "./ibc";
|
||||
export { MintExtension, MintParams, setupMintExtension } from "./mint";
|
||||
export { setupSlashingExtension, SlashingExtension } from "./slashing";
|
||||
export { setupStakingExtension, StakingExtension } from "./staking";
|
||||
export { setupTxExtension, TxExtension } from "./tx";
|
||||
export {
|
||||
|
||||
41
packages/stargate/src/queries/slashing.spec.ts
Normal file
41
packages/stargate/src/queries/slashing.spec.ts
Normal file
@ -0,0 +1,41 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
|
||||
|
||||
import { pendingWithoutSimapp, simapp } from "../testutils.spec";
|
||||
import { QueryClient } from "./queryclient";
|
||||
import { setupSlashingExtension, SlashingExtension } from "./slashing";
|
||||
|
||||
async function makeClientWithSlashing(
|
||||
rpcUrl: string,
|
||||
): Promise<[QueryClient & SlashingExtension, Tendermint34Client]> {
|
||||
const tmClient = await Tendermint34Client.connect(rpcUrl);
|
||||
return [QueryClient.withExtensions(tmClient, setupSlashingExtension), tmClient];
|
||||
}
|
||||
|
||||
describe("SlashingExtension", () => {
|
||||
describe("signingInfos", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithSlashing(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.slashing.signingInfos();
|
||||
expect(response.info).toBeDefined();
|
||||
expect(response.info).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("params", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithSlashing(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.slashing.params();
|
||||
expect(response.params).toBeDefined();
|
||||
expect(response.params).not.toBeNull();
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
});
|
||||
44
packages/stargate/src/queries/slashing.ts
Normal file
44
packages/stargate/src/queries/slashing.ts
Normal file
@ -0,0 +1,44 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import {
|
||||
QueryParamsResponse,
|
||||
QuerySigningInfoResponse,
|
||||
QuerySigningInfosResponse,
|
||||
} from "cosmjs-types/cosmos/slashing/v1beta1/query";
|
||||
import { QueryClientImpl } from "cosmjs-types/cosmos/slashing/v1beta1/query";
|
||||
|
||||
import { QueryClient } from "./queryclient";
|
||||
import { createPagination, createProtobufRpcClient } from "./utils";
|
||||
|
||||
export interface SlashingExtension {
|
||||
readonly slashing: {
|
||||
signingInfo: (consAddress: string) => Promise<QuerySigningInfoResponse>;
|
||||
signingInfos: (paginationKey?: Uint8Array) => Promise<QuerySigningInfosResponse>;
|
||||
params: () => Promise<QueryParamsResponse>;
|
||||
};
|
||||
}
|
||||
|
||||
export function setupSlashingExtension(base: QueryClient): SlashingExtension {
|
||||
const rpc = createProtobufRpcClient(base);
|
||||
const queryService = new QueryClientImpl(rpc);
|
||||
|
||||
return {
|
||||
slashing: {
|
||||
signingInfo: async (consAddress: string) => {
|
||||
const response = await queryService.SigningInfo({
|
||||
consAddress: consAddress,
|
||||
});
|
||||
return response;
|
||||
},
|
||||
signingInfos: async (paginationKey?: Uint8Array) => {
|
||||
const response = await queryService.SigningInfos({
|
||||
pagination: createPagination(paginationKey),
|
||||
});
|
||||
return response;
|
||||
},
|
||||
params: async () => {
|
||||
const response = await queryService.Params({});
|
||||
return response;
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user