From 9263f33b6941e85decb8b83b6c2176467b11a94a Mon Sep 17 00:00:00 2001 From: Mantas Vidutis Date: Tue, 25 Oct 2022 18:27:06 -0400 Subject: [PATCH 01/12] authz queries to meet the expanded types provided in the sdk --- packages/stargate/src/modules/authz/queries.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/stargate/src/modules/authz/queries.ts b/packages/stargate/src/modules/authz/queries.ts index 9c548e6fe4..5c73d78e88 100644 --- a/packages/stargate/src/modules/authz/queries.ts +++ b/packages/stargate/src/modules/authz/queries.ts @@ -10,6 +10,8 @@ export interface AuthzExtension { msgTypeUrl: string, paginationKey?: Uint8Array, ) => Promise; + readonly granteeGrants: (grantee: string, paginationKey?: Uint8Array) => Promise; + readonly granterGrants: (granter: string, paginationKey?: Uint8Array) => Promise; }; } @@ -22,14 +24,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), + }); }, }, }; From 36fc1138495a5d1fcf5a029e2fb6984fd921d294 Mon Sep 17 00:00:00 2001 From: Mantas Vidutis Date: Thu, 24 Nov 2022 11:17:43 -0800 Subject: [PATCH 02/12] add more tests for newly exposed grant queries --- .../src/modules/authz/queries.spec.ts | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/packages/stargate/src/modules/authz/queries.spec.ts b/packages/stargate/src/modules/authz/queries.spec.ts index db516ef193..7da036d1a8 100644 --- a/packages/stargate/src/modules/authz/queries.spec.ts +++ b/packages/stargate/src/modules/authz/queries.spec.ts @@ -95,7 +95,51 @@ 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(); + }); + + it("works querying by granter", async () => { + pendingWithoutSimapp44Or46(); + 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 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(); + }); + + it("works querying by grantee", async () => { + pendingWithoutSimapp44Or46(); + 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 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(); From ecd8b97223b8ed5680452e877c1d856fdfcb274d Mon Sep 17 00:00:00 2001 From: Mantas Vidutis Date: Thu, 24 Nov 2022 11:22:53 -0800 Subject: [PATCH 03/12] no need for msg url type --- packages/stargate/src/modules/authz/queries.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/stargate/src/modules/authz/queries.spec.ts b/packages/stargate/src/modules/authz/queries.spec.ts index 7da036d1a8..6f75ee5b56 100644 --- a/packages/stargate/src/modules/authz/queries.spec.ts +++ b/packages/stargate/src/modules/authz/queries.spec.ts @@ -104,7 +104,7 @@ describe("AuthzExtension", () => { it("works querying by granter", async () => { pendingWithoutSimapp44Or46(); const [client, tmClient] = await makeClientWithAuthz(simapp.tendermintUrl); - const response = await client.authz.granterGrants(granter1Address, ""); + const response = await client.authz.granterGrants(granter1Address); expect(response.grants.length).toEqual(1); const grant = response.grants[0]; @@ -126,7 +126,7 @@ describe("AuthzExtension", () => { it("works querying by grantee", async () => { pendingWithoutSimapp44Or46(); const [client, tmClient] = await makeClientWithAuthz(simapp.tendermintUrl); - const response = await client.authz.granteeGrants(grantee1Address, ""); + const response = await client.authz.granteeGrants(grantee1Address); expect(response.grants.length).toEqual(1); const grant = response.grants[0]; From 299b3ba384796ebf3258a646e595084902a9d6d9 Mon Sep 17 00:00:00 2001 From: Mantas Vidutis Date: Thu, 24 Nov 2022 12:15:17 -0800 Subject: [PATCH 04/12] add more checks on grant addresses --- packages/stargate/src/modules/authz/queries.spec.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/stargate/src/modules/authz/queries.spec.ts b/packages/stargate/src/modules/authz/queries.spec.ts index 6f75ee5b56..a0b8acb0cd 100644 --- a/packages/stargate/src/modules/authz/queries.spec.ts +++ b/packages/stargate/src/modules/authz/queries.spec.ts @@ -111,6 +111,10 @@ describe("AuthzExtension", () => { // 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"); @@ -133,6 +137,10 @@ describe("AuthzExtension", () => { // 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"); From 091c5cb9b3609de3c5e83d53b3de2ffeb979278e Mon Sep 17 00:00:00 2001 From: Mantas Vidutis Date: Thu, 24 Nov 2022 12:28:16 -0800 Subject: [PATCH 05/12] proper types --- packages/stargate/src/modules/authz/queries.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/stargate/src/modules/authz/queries.ts b/packages/stargate/src/modules/authz/queries.ts index 5c73d78e88..f34102e040 100644 --- a/packages/stargate/src/modules/authz/queries.ts +++ b/packages/stargate/src/modules/authz/queries.ts @@ -1,4 +1,4 @@ -import { QueryClientImpl, QueryGrantsResponse } from "cosmjs-types/cosmos/authz/v1beta1/query"; +import { QueryClientImpl, QueryGrantsResponse, QueryGranterGrantsResponse, QueryGranteeGrantsResponse } from "cosmjs-types/cosmos/authz/v1beta1/query"; import { createPagination, createProtobufRpcClient, QueryClient } from "../../queryclient"; @@ -10,8 +10,8 @@ export interface AuthzExtension { msgTypeUrl: string, paginationKey?: Uint8Array, ) => Promise; - readonly granteeGrants: (grantee: string, paginationKey?: Uint8Array) => Promise; - readonly granterGrants: (granter: string, paginationKey?: Uint8Array) => Promise; + readonly granteeGrants: (grantee: string, paginationKey?: Uint8Array) => Promise; + readonly granterGrants: (granter: string, paginationKey?: Uint8Array) => Promise; }; } From a83ad207dd6c05f3747002349ccc1b6bac8ceac2 Mon Sep 17 00:00:00 2001 From: Mantas Vidutis Date: Thu, 24 Nov 2022 12:47:14 -0800 Subject: [PATCH 06/12] lint --- .../stargate/src/modules/authz/queries.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/stargate/src/modules/authz/queries.ts b/packages/stargate/src/modules/authz/queries.ts index f34102e040..dd50e3703c 100644 --- a/packages/stargate/src/modules/authz/queries.ts +++ b/packages/stargate/src/modules/authz/queries.ts @@ -1,6 +1,11 @@ -import { QueryClientImpl, QueryGrantsResponse, QueryGranterGrantsResponse, QueryGranteeGrantsResponse } from "cosmjs-types/cosmos/authz/v1beta1/query"; +import { + QueryClientImpl, + QueryGrantsResponse, + QueryGranterGrantsResponse, + QueryGranteeGrantsResponse +} from "cosmjs-types/cosmos/authz/v1beta1/query"; -import { createPagination, createProtobufRpcClient, QueryClient } from "../../queryclient"; +import {createPagination, createProtobufRpcClient, QueryClient} from "../../queryclient"; export interface AuthzExtension { readonly authz: { @@ -10,8 +15,14 @@ export interface AuthzExtension { msgTypeUrl: string, paginationKey?: Uint8Array, ) => Promise; - readonly granteeGrants: (grantee: string, paginationKey?: Uint8Array) => Promise; - readonly granterGrants: (granter: string, paginationKey?: Uint8Array) => Promise; + readonly granteeGrants: ( + grantee: string, + paginationKey?: Uint8Array, + ) => Promise; + readonly granterGrants: ( + granter: string, + paginationKey?: Uint8Array, + ) => Promise; }; } From 7e151f3f7b84c6b347df5defa5ee2648fdefb504 Mon Sep 17 00:00:00 2001 From: Mantas Vidutis Date: Thu, 24 Nov 2022 12:56:52 -0800 Subject: [PATCH 07/12] more lint --- packages/stargate/src/modules/authz/queries.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/stargate/src/modules/authz/queries.ts b/packages/stargate/src/modules/authz/queries.ts index dd50e3703c..b592d64832 100644 --- a/packages/stargate/src/modules/authz/queries.ts +++ b/packages/stargate/src/modules/authz/queries.ts @@ -2,10 +2,10 @@ import { QueryClientImpl, QueryGrantsResponse, QueryGranterGrantsResponse, - QueryGranteeGrantsResponse + QueryGranteeGrantsResponse, } from "cosmjs-types/cosmos/authz/v1beta1/query"; -import {createPagination, createProtobufRpcClient, QueryClient} from "../../queryclient"; +import { createPagination, createProtobufRpcClient, QueryClient } from "../../queryclient"; export interface AuthzExtension { readonly authz: { @@ -20,9 +20,9 @@ export interface AuthzExtension { paginationKey?: Uint8Array, ) => Promise; readonly granterGrants: ( - granter: string, + granter: string, paginationKey?: Uint8Array, - ) => Promise; + ) => Promise; }; } From eb6d9ea3784bbf6cd97cbd813565f4a023cecd60 Mon Sep 17 00:00:00 2001 From: Mantas Vidutis Date: Sat, 26 Nov 2022 16:22:31 +0100 Subject: [PATCH 08/12] lint fix --- packages/stargate/src/modules/authz/queries.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/stargate/src/modules/authz/queries.ts b/packages/stargate/src/modules/authz/queries.ts index b592d64832..0dd2b53b6d 100644 --- a/packages/stargate/src/modules/authz/queries.ts +++ b/packages/stargate/src/modules/authz/queries.ts @@ -1,8 +1,8 @@ import { QueryClientImpl, - QueryGrantsResponse, - QueryGranterGrantsResponse, QueryGranteeGrantsResponse, + QueryGranterGrantsResponse, + QueryGrantsResponse, } from "cosmjs-types/cosmos/authz/v1beta1/query"; import { createPagination, createProtobufRpcClient, QueryClient } from "../../queryclient"; From ac765342eb5dbcf4575f32febc0cc5c034e30f4c Mon Sep 17 00:00:00 2001 From: Mantas Vidutis Date: Sat, 26 Nov 2022 16:50:44 +0100 Subject: [PATCH 09/12] only test new queries in 46 --- packages/stargate/src/modules/authz/queries.spec.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/stargate/src/modules/authz/queries.spec.ts b/packages/stargate/src/modules/authz/queries.spec.ts index a0b8acb0cd..0f7f2633ab 100644 --- a/packages/stargate/src/modules/authz/queries.spec.ts +++ b/packages/stargate/src/modules/authz/queries.spec.ts @@ -12,6 +12,7 @@ import { faucet, makeRandomAddress, pendingWithoutSimapp44Or46, + pendingWithoutSimapp46, simapp, simapp44Enabled, simapp46Enabled, @@ -102,7 +103,7 @@ describe("AuthzExtension", () => { }); it("works querying by granter", async () => { - pendingWithoutSimapp44Or46(); + pendingWithoutSimapp46(); const [client, tmClient] = await makeClientWithAuthz(simapp.tendermintUrl); const response = await client.authz.granterGrants(granter1Address); expect(response.grants.length).toEqual(1); @@ -128,7 +129,7 @@ describe("AuthzExtension", () => { }); it("works querying by grantee", async () => { - pendingWithoutSimapp44Or46(); + pendingWithoutSimapp46(); const [client, tmClient] = await makeClientWithAuthz(simapp.tendermintUrl); const response = await client.authz.granteeGrants(grantee1Address); expect(response.grants.length).toEqual(1); From f461bfa0ebf5f2b24da508df1782a06afe975365 Mon Sep 17 00:00:00 2001 From: Mantas Vidutis Date: Tue, 3 Jan 2023 13:45:03 +0700 Subject: [PATCH 10/12] multiple describe blocks --- packages/stargate/src/modules/authz/queries.spec.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/stargate/src/modules/authz/queries.spec.ts b/packages/stargate/src/modules/authz/queries.spec.ts index 0f7f2633ab..22c73ac31d 100644 --- a/packages/stargate/src/modules/authz/queries.spec.ts +++ b/packages/stargate/src/modules/authz/queries.spec.ts @@ -101,8 +101,10 @@ describe("AuthzExtension", () => { tmClient.disconnect(); }); + }); - it("works querying by granter", async () => { + describe("granter grants", () => { + it("works", async () => { pendingWithoutSimapp46(); const [client, tmClient] = await makeClientWithAuthz(simapp.tendermintUrl); const response = await client.authz.granterGrants(granter1Address); @@ -127,8 +129,10 @@ describe("AuthzExtension", () => { tmClient.disconnect(); }); + }); - it("works querying by grantee", async () => { + describe("grantee grants", () => { + it("works", async () => { pendingWithoutSimapp46(); const [client, tmClient] = await makeClientWithAuthz(simapp.tendermintUrl); const response = await client.authz.granteeGrants(grantee1Address); From a73f654d822d2452e17243b4d4a9c96241726102 Mon Sep 17 00:00:00 2001 From: Mantas Vidutis Date: Tue, 3 Jan 2023 15:46:18 +0700 Subject: [PATCH 11/12] pulling main and adding changelog entry --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e037bb599e..dabec00c54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,10 +65,13 @@ and this project adheres to `HttpBatchClientOptions`, `RpcClient` ([#1311]). - @cosmjs/tendermint-rpc: Send batch immediately when full in `HttpBatchClient` ([#1310]). +- @cosmjs/stargate: Add `granteeGrants` and `granterGrants` queries to + `AuthzExtension` ([#1308]). [#1309]: https://github.com/cosmos/cosmjs/issues/1309 [#1310]: https://github.com/cosmos/cosmjs/issues/1310 [#1311]: https://github.com/cosmos/cosmjs/issues/1311 +[#1308]: https://github.com/cosmos/cosmjs/pull/1308 ### Fixed From a4a6bf051af6c85c73051e11ea6bc03c1e1f024b Mon Sep 17 00:00:00 2001 From: Mantas Vidutis Date: Tue, 3 Jan 2023 15:52:12 +0700 Subject: [PATCH 12/12] correct changelog --- CHANGELOG.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dabec00c54..7bdb018257 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -65,13 +71,10 @@ and this project adheres to `HttpBatchClientOptions`, `RpcClient` ([#1311]). - @cosmjs/tendermint-rpc: Send batch immediately when full in `HttpBatchClient` ([#1310]). -- @cosmjs/stargate: Add `granteeGrants` and `granterGrants` queries to - `AuthzExtension` ([#1308]). [#1309]: https://github.com/cosmos/cosmjs/issues/1309 [#1310]: https://github.com/cosmos/cosmjs/issues/1310 [#1311]: https://github.com/cosmos/cosmjs/issues/1311 -[#1308]: https://github.com/cosmos/cosmjs/pull/1308 ### Fixed