Deprecate verified queries

This commit is contained in:
Simon Warta 2021-10-24 22:35:45 +02:00
parent 64fecab2e5
commit fbaf8d7068
6 changed files with 40 additions and 7 deletions

View File

@ -109,6 +109,16 @@ discussion please reach out to the team.
## Known limitations ## Known limitations
### 0.26
1. When connecting to a Cosmos SDK 0.44+ backend, the verified queries from
`AuthExtension` and `BankExtension` as well as
`StargateClient.getAccountVerified` will fail because the storage keys are
not stable. Unverified queries can be used instead. Those queries are
deprecated now and will be removed in 0.27 ([#910]).
[#910]: https://github.com/cosmos/cosmjs/pull/910
### 0.25 ### 0.25
1. Decoding blocks of height 1 is unsupported. This is fixed in [#815] and will 1. Decoding blocks of height 1 is unsupported. This is fixed in [#815] and will

View File

@ -6,7 +6,14 @@ import { BaseAccount } from "cosmjs-types/cosmos/auth/v1beta1/auth";
import { Any } from "cosmjs-types/google/protobuf/any"; import { Any } from "cosmjs-types/google/protobuf/any";
import Long from "long"; import Long from "long";
import { nonExistentAddress, pendingWithoutSimapp, simapp, unused, validator } from "../testutils.spec"; import {
nonExistentAddress,
pendingWithoutSimapp,
pendingWithoutSimapp42,
simapp,
unused,
validator,
} from "../testutils.spec";
import { AuthExtension, setupAuthExtension } from "./auth"; import { AuthExtension, setupAuthExtension } from "./auth";
import { QueryClient } from "./queryclient"; import { QueryClient } from "./queryclient";
@ -68,7 +75,7 @@ describe("AuthExtension", () => {
describe("verified", () => { describe("verified", () => {
describe("account", () => { describe("account", () => {
it("works for unused account", async () => { it("works for unused account", async () => {
pendingWithoutSimapp(); pendingWithoutSimapp42(); // Not supported with 0.44, see "Known limitations" in README.md
const [client, tmClient] = await makeClientWithAuth(simapp.tendermintUrl); const [client, tmClient] = await makeClientWithAuth(simapp.tendermintUrl);
const account = await client.auth.verified.account(unused.address); const account = await client.auth.verified.account(unused.address);
assert(account); assert(account);
@ -85,7 +92,7 @@ describe("AuthExtension", () => {
}); });
it("works for account with pubkey and non-zero sequence", async () => { it("works for account with pubkey and non-zero sequence", async () => {
pendingWithoutSimapp(); pendingWithoutSimapp42(); // Not supported with 0.44, see "Known limitations" in README.md
const [client, tmClient] = await makeClientWithAuth(simapp.tendermintUrl); const [client, tmClient] = await makeClientWithAuth(simapp.tendermintUrl);
const account = await client.auth.verified.account(validator.delegatorAddress); const account = await client.auth.verified.account(validator.delegatorAddress);
assert(account); assert(account);
@ -102,7 +109,7 @@ describe("AuthExtension", () => {
}); });
it("returns null for non-existent address", async () => { it("returns null for non-existent address", async () => {
pendingWithoutSimapp(); pendingWithoutSimapp42(); // Not supported with 0.44, see "Known limitations" in README.md
const [client, tmClient] = await makeClientWithAuth(simapp.tendermintUrl); const [client, tmClient] = await makeClientWithAuth(simapp.tendermintUrl);
const account = await client.auth.verified.account(nonExistentAddress); const account = await client.auth.verified.account(nonExistentAddress);

View File

@ -14,6 +14,11 @@ export interface AuthExtension {
* `typeUrl` and decode the `value` using its own type decoder. * `typeUrl` and decode the `value` using its own type decoder.
*/ */
readonly account: (address: string) => Promise<Any | null>; readonly account: (address: string) => Promise<Any | null>;
/**
* @deprecated Verified queries are not supported with Cosmos SDK 0.44+.
* See "Known limitations" in README.md.
* Will be rmoved in CosmJS 0.27 (https://github.com/cosmos/cosmjs/pull/910).
*/
readonly verified: { readonly verified: {
/** /**
* Returns an account if it exists and `null` otherwise. * Returns an account if it exists and `null` otherwise.

View File

@ -4,6 +4,7 @@ import {
nonExistentAddress, nonExistentAddress,
nonNegativeIntegerMatcher, nonNegativeIntegerMatcher,
pendingWithoutSimapp, pendingWithoutSimapp,
pendingWithoutSimapp42,
simapp, simapp,
unused, unused,
} from "../testutils.spec"; } from "../testutils.spec";
@ -147,7 +148,7 @@ describe("BankExtension", () => {
describe("verified", () => { describe("verified", () => {
describe("balance", () => { describe("balance", () => {
it("works for different existing balances", async () => { it("works for different existing balances", async () => {
pendingWithoutSimapp(); pendingWithoutSimapp42(); // Not supported with 0.44, see "Known limitations" in README.md
const [client, tmClient] = await makeClientWithBank(simapp.tendermintUrl); const [client, tmClient] = await makeClientWithBank(simapp.tendermintUrl);
const response1 = await client.bank.verified.balance(unused.address, simapp.denomFee); const response1 = await client.bank.verified.balance(unused.address, simapp.denomFee);
@ -165,7 +166,7 @@ describe("BankExtension", () => {
}); });
it("returns null for non-existent balance", async () => { it("returns null for non-existent balance", async () => {
pendingWithoutSimapp(); pendingWithoutSimapp42(); // Not supported with 0.44, see "Known limitations" in README.md
const [client, tmClient] = await makeClientWithBank(simapp.tendermintUrl); const [client, tmClient] = await makeClientWithBank(simapp.tendermintUrl);
const response = await client.bank.verified.balance(unused.address, "gintonic"); const response = await client.bank.verified.balance(unused.address, "gintonic");
@ -175,7 +176,7 @@ describe("BankExtension", () => {
}); });
it("returns null for non-existent address", async () => { it("returns null for non-existent address", async () => {
pendingWithoutSimapp(); pendingWithoutSimapp42(); // Not supported with 0.44, see "Known limitations" in README.md
const [client, tmClient] = await makeClientWithBank(simapp.tendermintUrl); const [client, tmClient] = await makeClientWithBank(simapp.tendermintUrl);
const response = await client.bank.verified.balance(nonExistentAddress, simapp.denomFee); const response = await client.bank.verified.balance(nonExistentAddress, simapp.denomFee);

View File

@ -13,6 +13,11 @@ export interface BankExtension {
readonly allBalances: (address: string) => Promise<Coin[]>; readonly allBalances: (address: string) => Promise<Coin[]>;
readonly totalSupply: () => Promise<Coin[]>; readonly totalSupply: () => Promise<Coin[]>;
readonly supplyOf: (denom: string) => Promise<Coin>; readonly supplyOf: (denom: string) => Promise<Coin>;
/**
* @deprecated Verified queries are not supported with Cosmos SDK 0.44+.
* See "Known limitations" in README.md.
* Will be rmoved in CosmJS 0.27 (https://github.com/cosmos/cosmjs/pull/910).
*/
readonly verified: { readonly verified: {
readonly balance: (address: string, denom: string) => Promise<Coin | null>; readonly balance: (address: string, denom: string) => Promise<Coin | null>;
}; };

View File

@ -218,6 +218,11 @@ export class StargateClient {
} }
} }
/**
* @deprecated Verified queries are not supported with Cosmos SDK 0.44+.
* See "Known limitations" in README.md.
* Will be rmoved in CosmJS 0.27 (https://github.com/cosmos/cosmjs/pull/910).
*/
public async getAccountVerified(searchAddress: string): Promise<Account | null> { public async getAccountVerified(searchAddress: string): Promise<Account | null> {
const account = await this.forceGetQueryClient().auth.verified.account(searchAddress); const account = await this.forceGetQueryClient().auth.verified.account(searchAddress);
return account ? accountFromAny(account) : null; return account ? accountFromAny(account) : null;