Skip to content

Commit 48aeb1d

Browse files
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 <[email protected]>
1 parent 333e468 commit 48aeb1d

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ and this project adheres to
3535
is checked in `fromAmino` now instead of the constructor. This only affects
3636
you if multiple different protobuf type URLs map to the same Amino type
3737
identifier which should not be the case anyways.
38+
- @cosmjs/stargate: Added support for slashing queries ([#927])
3839

40+
[#927]: https://github.com/cosmos/cosmjs/issues/927
3941
[#989]: https://github.com/cosmos/cosmjs/issues/989
4042
[#994]: https://github.com/cosmos/cosmjs/issues/994
4143
[#1011]: https://github.com/cosmos/cosmjs/issues/1011

packages/stargate/src/queries/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export { DistributionExtension, setupDistributionExtension } from "./distributio
1010
export { GovExtension, GovParamsType, GovProposalId, setupGovExtension } from "./gov";
1111
export { IbcExtension, setupIbcExtension } from "./ibc";
1212
export { MintExtension, MintParams, setupMintExtension } from "./mint";
13+
export { setupSlashingExtension, SlashingExtension } from "./slashing";
1314
export { setupStakingExtension, StakingExtension } from "./staking";
1415
export { setupTxExtension, TxExtension } from "./tx";
1516
export {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* eslint-disable @typescript-eslint/naming-convention */
2+
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
3+
4+
import { pendingWithoutSimapp, simapp } from "../testutils.spec";
5+
import { QueryClient } from "./queryclient";
6+
import { setupSlashingExtension, SlashingExtension } from "./slashing";
7+
8+
async function makeClientWithSlashing(
9+
rpcUrl: string,
10+
): Promise<[QueryClient & SlashingExtension, Tendermint34Client]> {
11+
const tmClient = await Tendermint34Client.connect(rpcUrl);
12+
return [QueryClient.withExtensions(tmClient, setupSlashingExtension), tmClient];
13+
}
14+
15+
describe("SlashingExtension", () => {
16+
describe("signingInfos", () => {
17+
it("works", async () => {
18+
pendingWithoutSimapp();
19+
const [client, tmClient] = await makeClientWithSlashing(simapp.tendermintUrl);
20+
21+
const response = await client.slashing.signingInfos();
22+
expect(response.info).toBeDefined();
23+
expect(response.info).not.toBeNull();
24+
25+
tmClient.disconnect();
26+
});
27+
});
28+
29+
describe("params", () => {
30+
it("works", async () => {
31+
pendingWithoutSimapp();
32+
const [client, tmClient] = await makeClientWithSlashing(simapp.tendermintUrl);
33+
34+
const response = await client.slashing.params();
35+
expect(response.params).toBeDefined();
36+
expect(response.params).not.toBeNull();
37+
38+
tmClient.disconnect();
39+
});
40+
});
41+
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* eslint-disable @typescript-eslint/naming-convention */
2+
import {
3+
QueryParamsResponse,
4+
QuerySigningInfoResponse,
5+
QuerySigningInfosResponse,
6+
} from "cosmjs-types/cosmos/slashing/v1beta1/query";
7+
import { QueryClientImpl } from "cosmjs-types/cosmos/slashing/v1beta1/query";
8+
9+
import { QueryClient } from "./queryclient";
10+
import { createPagination, createProtobufRpcClient } from "./utils";
11+
12+
export interface SlashingExtension {
13+
readonly slashing: {
14+
signingInfo: (consAddress: string) => Promise<QuerySigningInfoResponse>;
15+
signingInfos: (paginationKey?: Uint8Array) => Promise<QuerySigningInfosResponse>;
16+
params: () => Promise<QueryParamsResponse>;
17+
};
18+
}
19+
20+
export function setupSlashingExtension(base: QueryClient): SlashingExtension {
21+
const rpc = createProtobufRpcClient(base);
22+
const queryService = new QueryClientImpl(rpc);
23+
24+
return {
25+
slashing: {
26+
signingInfo: async (consAddress: string) => {
27+
const response = await queryService.SigningInfo({
28+
consAddress: consAddress,
29+
});
30+
return response;
31+
},
32+
signingInfos: async (paginationKey?: Uint8Array) => {
33+
const response = await queryService.SigningInfos({
34+
pagination: createPagination(paginationKey),
35+
});
36+
return response;
37+
},
38+
params: async () => {
39+
const response = await queryService.Params({});
40+
return response;
41+
},
42+
},
43+
};
44+
}

0 commit comments

Comments
 (0)