From dc8c58081c11566bf2052681d1759d67debdea65 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 18 Nov 2020 14:53:28 +0100 Subject: [PATCH] Specify Tendermint version explicitly in stargate --- packages/stargate/src/queries/auth.spec.ts | 4 ++-- packages/stargate/src/queries/bank.spec.ts | 4 ++-- packages/stargate/src/queries/ibc.spec.ts | 4 ++-- packages/stargate/src/queries/queryclient.spec.ts | 4 ++-- packages/stargate/src/signingstargateclient.ts | 4 ++-- packages/stargate/src/stargateclient.ts | 9 +++++++-- packages/tendermint-rpc/src/adaptors/index.ts | 1 - .../tendermint-rpc/src/adaptors/v0-33/responses.ts | 5 ++--- packages/tendermint-rpc/src/encodings.ts | 14 ++++++++++++++ packages/tendermint-rpc/types/encodings.d.ts | 7 +++++++ 10 files changed, 40 insertions(+), 16 deletions(-) diff --git a/packages/stargate/src/queries/auth.spec.ts b/packages/stargate/src/queries/auth.spec.ts index 4285c19e..602b8f29 100644 --- a/packages/stargate/src/queries/auth.spec.ts +++ b/packages/stargate/src/queries/auth.spec.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { encodePubkey } from "@cosmjs/proto-signing"; -import { Client as TendermintClient } from "@cosmjs/tendermint-rpc"; +import { adaptor34, Client as TendermintClient } from "@cosmjs/tendermint-rpc"; import { assert } from "@cosmjs/utils"; import Long from "long"; @@ -12,7 +12,7 @@ import { QueryClient } from "./queryclient"; const { Any } = google.protobuf; async function makeClientWithAuth(rpcUrl: string): Promise<[QueryClient & AuthExtension, TendermintClient]> { - const tmClient = await TendermintClient.connect(rpcUrl); + const tmClient = await TendermintClient.connect(rpcUrl, adaptor34); return [QueryClient.withExtensions(tmClient, setupAuthExtension), tmClient]; } diff --git a/packages/stargate/src/queries/bank.spec.ts b/packages/stargate/src/queries/bank.spec.ts index b45ed5eb..17ebf62e 100644 --- a/packages/stargate/src/queries/bank.spec.ts +++ b/packages/stargate/src/queries/bank.spec.ts @@ -1,4 +1,4 @@ -import { Client as TendermintClient } from "@cosmjs/tendermint-rpc"; +import { adaptor34, Client as TendermintClient } from "@cosmjs/tendermint-rpc"; import { nonExistentAddress, @@ -11,7 +11,7 @@ import { BankExtension, setupBankExtension } from "./bank"; import { QueryClient } from "./queryclient"; async function makeClientWithBank(rpcUrl: string): Promise<[QueryClient & BankExtension, TendermintClient]> { - const tmClient = await TendermintClient.connect(rpcUrl); + const tmClient = await TendermintClient.connect(rpcUrl, adaptor34); return [QueryClient.withExtensions(tmClient, setupBankExtension), tmClient]; } diff --git a/packages/stargate/src/queries/ibc.spec.ts b/packages/stargate/src/queries/ibc.spec.ts index 6d9fecd2..75bdba1f 100644 --- a/packages/stargate/src/queries/ibc.spec.ts +++ b/packages/stargate/src/queries/ibc.spec.ts @@ -1,4 +1,4 @@ -import { Client as TendermintClient } from "@cosmjs/tendermint-rpc"; +import { adaptor34, Client as TendermintClient } from "@cosmjs/tendermint-rpc"; import Long from "long"; import { cosmos, ibc } from "../codec"; @@ -8,7 +8,7 @@ import * as ibcTest from "./ibctestdata.spec"; import { QueryClient } from "./queryclient"; async function makeClientWithIbc(rpcUrl: string): Promise<[QueryClient & IbcExtension, TendermintClient]> { - const tmClient = await TendermintClient.connect(rpcUrl); + const tmClient = await TendermintClient.connect(rpcUrl, adaptor34); return [QueryClient.withExtensions(tmClient, setupIbcExtension), tmClient]; } diff --git a/packages/stargate/src/queries/queryclient.spec.ts b/packages/stargate/src/queries/queryclient.spec.ts index 6955c622..2f75e4e4 100644 --- a/packages/stargate/src/queries/queryclient.spec.ts +++ b/packages/stargate/src/queries/queryclient.spec.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { toAscii } from "@cosmjs/encoding"; -import { Client as TendermintClient } from "@cosmjs/tendermint-rpc"; +import { adaptor34, Client as TendermintClient } from "@cosmjs/tendermint-rpc"; import { cosmos } from "../codec"; import { nonNegativeIntegerMatcher, pendingWithoutSimapp, simapp, unused } from "../testutils.spec"; @@ -11,7 +11,7 @@ const { Coin } = cosmos.base.v1beta1; const { QueryAllBalancesRequest, QueryAllBalancesResponse } = cosmos.bank.v1beta1; async function makeClient(rpcUrl: string): Promise<[QueryClient, TendermintClient]> { - const tmClient = await TendermintClient.connect(rpcUrl); + const tmClient = await TendermintClient.connect(rpcUrl, adaptor34); return [QueryClient.withExtensions(tmClient), tmClient]; } diff --git a/packages/stargate/src/signingstargateclient.ts b/packages/stargate/src/signingstargateclient.ts index d4bd344a..c93c822b 100644 --- a/packages/stargate/src/signingstargateclient.ts +++ b/packages/stargate/src/signingstargateclient.ts @@ -21,7 +21,7 @@ import { OfflineSigner, Registry, } from "@cosmjs/proto-signing"; -import { Client as TendermintClient } from "@cosmjs/tendermint-rpc"; +import { adaptor34, Client as TendermintClient } from "@cosmjs/tendermint-rpc"; import { cosmos } from "./codec"; import { getMsgType } from "./encoding"; @@ -54,7 +54,7 @@ export class SigningStargateClient extends StargateClient { signer: OfflineSigner, options: SigningStargateClientOptions = {}, ): Promise { - const tmClient = await TendermintClient.connect(endpoint); + const tmClient = await TendermintClient.connect(endpoint, adaptor34); return new SigningStargateClient(tmClient, signer, options); } diff --git a/packages/stargate/src/stargateclient.ts b/packages/stargate/src/stargateclient.ts index f482d820..c4726fd9 100644 --- a/packages/stargate/src/stargateclient.ts +++ b/packages/stargate/src/stargateclient.ts @@ -13,7 +13,12 @@ import { } from "@cosmjs/launchpad"; import { Uint53, Uint64 } from "@cosmjs/math"; import { decodePubkey } from "@cosmjs/proto-signing"; -import { broadcastTxCommitSuccess, Client as TendermintClient, QueryString } from "@cosmjs/tendermint-rpc"; +import { + adaptor34, + broadcastTxCommitSuccess, + Client as TendermintClient, + QueryString, +} from "@cosmjs/tendermint-rpc"; import { assert, assertDefined } from "@cosmjs/utils"; import Long from "long"; @@ -121,7 +126,7 @@ export class StargateClient { private chainId: string | undefined; public static async connect(endpoint: string): Promise { - const tmClient = await TendermintClient.connect(endpoint); + const tmClient = await TendermintClient.connect(endpoint, adaptor34); return new StargateClient(tmClient); } diff --git a/packages/tendermint-rpc/src/adaptors/index.ts b/packages/tendermint-rpc/src/adaptors/index.ts index eb74c9c6..4a164f48 100644 --- a/packages/tendermint-rpc/src/adaptors/index.ts +++ b/packages/tendermint-rpc/src/adaptors/index.ts @@ -31,7 +31,6 @@ export const adaptor34 = v0_33; // With this alias we can swap out the implement const hashes = { v0_34: [ "ca2c9df", // v0.34.0-rc6 - "", // See https://github.com/cosmos/cosmos-sdk/issues/7963 ], }; diff --git a/packages/tendermint-rpc/src/adaptors/v0-33/responses.ts b/packages/tendermint-rpc/src/adaptors/v0-33/responses.ts index 6bfe82dc..81af176e 100644 --- a/packages/tendermint-rpc/src/adaptors/v0-33/responses.ts +++ b/packages/tendermint-rpc/src/adaptors/v0-33/responses.ts @@ -9,6 +9,7 @@ import { assertNumber, assertObject, assertSet, + assertString, Base64, Base64String, DateTime, @@ -502,9 +503,7 @@ function decodeNodeInfo(data: RpcNodeInfo): responses.NodeInfo { id: fromHex(assertNotEmpty(data.id)), listenAddr: assertNotEmpty(data.listen_addr), network: assertNotEmpty(data.network), - // TODO: Reactivate check when https://github.com/cosmos/cosmos-sdk/issues/7963 is resolved - // version: assertNotEmpty(data.version), - version: data.version, + version: assertString(data.version), // Can be empty (https://github.com/cosmos/cosmos-sdk/issues/7963) channels: assertNotEmpty(data.channels), moniker: assertNotEmpty(data.moniker), other: dictionaryToStringMap(data.other), diff --git a/packages/tendermint-rpc/src/encodings.ts b/packages/tendermint-rpc/src/encodings.ts index 9b48761a..9266fcc1 100644 --- a/packages/tendermint-rpc/src/encodings.ts +++ b/packages/tendermint-rpc/src/encodings.ts @@ -40,6 +40,20 @@ export function assertBoolean(value: boolean): boolean { return value; } +/** + * A runtime checker that ensures a given value is a string. + * + * This is used when you want to verify that data at runtime matches the expected type. + * This implies assertSet. + */ +export function assertString(value: string): string { + assertSet(value); + if (typeof (value as unknown) !== "string") { + throw new Error("Value must be a string"); + } + return value; +} + /** * A runtime checker that ensures a given value is a number * diff --git a/packages/tendermint-rpc/types/encodings.d.ts b/packages/tendermint-rpc/types/encodings.d.ts index 151d7af5..cd004f17 100644 --- a/packages/tendermint-rpc/types/encodings.d.ts +++ b/packages/tendermint-rpc/types/encodings.d.ts @@ -17,6 +17,13 @@ export declare function assertSet(value: T): T; * This implies assertSet. */ export declare function assertBoolean(value: boolean): boolean; +/** + * A runtime checker that ensures a given value is a string. + * + * This is used when you want to verify that data at runtime matches the expected type. + * This implies assertSet. + */ +export declare function assertString(value: string): string; /** * A runtime checker that ensures a given value is a number *