Merge pull request #1308 from mvid/authz-queries
authz queries to meet the expanded types provided in the sdk
This commit is contained in:
commit
33271bc51c
@ -28,6 +28,12 @@ and this project adheres to
|
||||
[#1291]: https://github.com/cosmos/cosmjs/issues/1291
|
||||
[#1329]: https://github.com/cosmos/cosmjs/pull/1329
|
||||
|
||||
### Added
|
||||
- @cosmjs/stargate: Add `granteeGrants` and `granterGrants` queries to
|
||||
`AuthzExtension` ([#1308]).
|
||||
|
||||
[#1308]: https://github.com/cosmos/cosmjs/pull/1308
|
||||
|
||||
## [0.29.5] - 2022-12-07
|
||||
|
||||
### Fixed
|
||||
|
||||
@ -12,6 +12,7 @@ import {
|
||||
faucet,
|
||||
makeRandomAddress,
|
||||
pendingWithoutSimapp44Or46,
|
||||
pendingWithoutSimapp46,
|
||||
simapp,
|
||||
simapp44Enabled,
|
||||
simapp46Enabled,
|
||||
@ -95,7 +96,63 @@ describe("AuthzExtension", () => {
|
||||
// Decode the message
|
||||
const msgDecoded = GenericAuthorization.decode(grant.authorization.value).msg;
|
||||
|
||||
// Check if its the same one then we granted
|
||||
// Check if it's the same one then we granted
|
||||
expect(msgDecoded).toEqual(grantedMsg);
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("granter grants", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp46();
|
||||
const [client, tmClient] = await makeClientWithAuthz(simapp.tendermintUrl);
|
||||
const response = await client.authz.granterGrants(granter1Address);
|
||||
expect(response.grants.length).toEqual(1);
|
||||
const grant = response.grants[0];
|
||||
|
||||
// Needs to respond with a grant
|
||||
assertDefined(grant.authorization);
|
||||
|
||||
// Needs to have the correct granter and grantee
|
||||
expect(grant.granter).toEqual(granter1Address);
|
||||
expect(grant.grantee).toEqual(grantee1Address);
|
||||
|
||||
// Needs to be GenericAuthorization to decode it below
|
||||
expect(grant.authorization.typeUrl).toEqual("/cosmos.authz.v1beta1.GenericAuthorization");
|
||||
|
||||
// Decode the message
|
||||
const msgDecoded = GenericAuthorization.decode(grant.authorization.value).msg;
|
||||
|
||||
// Check if it's the same one then we granted
|
||||
expect(msgDecoded).toEqual(grantedMsg);
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("grantee grants", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp46();
|
||||
const [client, tmClient] = await makeClientWithAuthz(simapp.tendermintUrl);
|
||||
const response = await client.authz.granteeGrants(grantee1Address);
|
||||
expect(response.grants.length).toEqual(1);
|
||||
const grant = response.grants[0];
|
||||
|
||||
// Needs to respond with a grant
|
||||
assertDefined(grant.authorization);
|
||||
|
||||
// Needs to have the correct granter and grantee
|
||||
expect(grant.granter).toEqual(granter1Address);
|
||||
expect(grant.grantee).toEqual(grantee1Address);
|
||||
|
||||
// Needs to be GenericAuthorization to decode it below
|
||||
expect(grant.authorization.typeUrl).toEqual("/cosmos.authz.v1beta1.GenericAuthorization");
|
||||
|
||||
// Decode the message
|
||||
const msgDecoded = GenericAuthorization.decode(grant.authorization.value).msg;
|
||||
|
||||
// Check if it's the same one then we granted
|
||||
expect(msgDecoded).toEqual(grantedMsg);
|
||||
|
||||
tmClient.disconnect();
|
||||
|
||||
@ -1,4 +1,9 @@
|
||||
import { QueryClientImpl, QueryGrantsResponse } from "cosmjs-types/cosmos/authz/v1beta1/query";
|
||||
import {
|
||||
QueryClientImpl,
|
||||
QueryGranteeGrantsResponse,
|
||||
QueryGranterGrantsResponse,
|
||||
QueryGrantsResponse,
|
||||
} from "cosmjs-types/cosmos/authz/v1beta1/query";
|
||||
|
||||
import { createPagination, createProtobufRpcClient, QueryClient } from "../../queryclient";
|
||||
|
||||
@ -10,6 +15,14 @@ export interface AuthzExtension {
|
||||
msgTypeUrl: string,
|
||||
paginationKey?: Uint8Array,
|
||||
) => Promise<QueryGrantsResponse>;
|
||||
readonly granteeGrants: (
|
||||
grantee: string,
|
||||
paginationKey?: Uint8Array,
|
||||
) => Promise<QueryGranteeGrantsResponse>;
|
||||
readonly granterGrants: (
|
||||
granter: string,
|
||||
paginationKey?: Uint8Array,
|
||||
) => Promise<QueryGranterGrantsResponse>;
|
||||
};
|
||||
}
|
||||
|
||||
@ -22,14 +35,24 @@ export function setupAuthzExtension(base: QueryClient): AuthzExtension {
|
||||
return {
|
||||
authz: {
|
||||
grants: async (granter: string, grantee: string, msgTypeUrl: string, paginationKey?: Uint8Array) => {
|
||||
const response = await queryService.Grants({
|
||||
return await queryService.Grants({
|
||||
granter: granter,
|
||||
grantee: grantee,
|
||||
msgTypeUrl: msgTypeUrl,
|
||||
pagination: createPagination(paginationKey),
|
||||
});
|
||||
|
||||
return response;
|
||||
},
|
||||
granteeGrants: async (grantee: string, paginationKey?: Uint8Array) => {
|
||||
return await queryService.GranteeGrants({
|
||||
grantee: grantee,
|
||||
pagination: createPagination(paginationKey),
|
||||
});
|
||||
},
|
||||
granterGrants: async (granter: string, paginationKey?: Uint8Array) => {
|
||||
return await queryService.GranterGrants({
|
||||
granter: granter,
|
||||
pagination: createPagination(paginationKey),
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user