diff --git a/packages/tendermint-rpc/src/legacy/client.spec.ts b/packages/tendermint-rpc/src/legacy/client.spec.ts index b8d47aa3..3bf12c3f 100644 --- a/packages/tendermint-rpc/src/legacy/client.spec.ts +++ b/packages/tendermint-rpc/src/legacy/client.spec.ts @@ -7,39 +7,20 @@ import { Stream } from "xstream"; import { ExpectedValues, tendermintInstances } from "../config.spec"; import { HttpClient, RpcClient, WebsocketClient } from "../rpcclients"; -import { chainIdMatcher } from "../testutil.spec"; +import { + buildKvTx, + chainIdMatcher, + pendingWithoutTendermint, + randomString, + tendermintEnabled, + tendermintSearchIndexUpdated, +} from "../testutil.spec"; import { Adaptor } from "./adaptor"; import { adaptorForVersion } from "./adaptors"; import { Client } from "./client"; import { buildQuery } from "./requests"; import * as responses from "./responses"; -function tendermintEnabled(): boolean { - return !!process.env.TENDERMINT_ENABLED; -} - -function pendingWithoutTendermint(): void { - if (!tendermintEnabled()) { - pending("Set TENDERMINT_ENABLED to enable tendermint-based tests"); - } -} - -async function tendermintSearchIndexUpdated(): Promise { - // Tendermint needs some time before a committed transaction is found in search - return sleep(75); -} - -function buildKvTx(k: string, v: string): Uint8Array { - return toAscii(`${k}=${v}`); -} - -function randomString(): string { - const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - return Array.from({ length: 12 }) - .map(() => alphabet[Math.floor(Math.random() * alphabet.length)]) - .join(""); -} - function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expected: ExpectedValues): void { describe("create", () => { it("can auto-discover Tendermint version and communicate", async () => { diff --git a/packages/tendermint-rpc/src/tendermint34/tendermint34client.spec.ts b/packages/tendermint-rpc/src/tendermint34/tendermint34client.spec.ts index cc8c56e2..a933cc38 100644 --- a/packages/tendermint-rpc/src/tendermint34/tendermint34client.spec.ts +++ b/packages/tendermint-rpc/src/tendermint34/tendermint34client.spec.ts @@ -7,38 +7,19 @@ import { Stream } from "xstream"; import { ExpectedValues, tendermintInstances } from "../config.spec"; import { HttpClient, RpcClient, WebsocketClient } from "../rpcclients"; -import { chainIdMatcher } from "../testutil.spec"; +import { + buildKvTx, + chainIdMatcher, + pendingWithoutTendermint, + randomString, + tendermintEnabled, + tendermintSearchIndexUpdated, +} from "../testutil.spec"; import { adaptor34 } from "./adaptors"; import { buildQuery } from "./requests"; import * as responses from "./responses"; import { Tendermint34Client } from "./tendermint34client"; -function tendermintEnabled(): boolean { - return !!process.env.TENDERMINT_ENABLED; -} - -function pendingWithoutTendermint(): void { - if (!tendermintEnabled()) { - pending("Set TENDERMINT_ENABLED to enable tendermint-based tests"); - } -} - -async function tendermintSearchIndexUpdated(): Promise { - // Tendermint needs some time before a committed transaction is found in search - return sleep(75); -} - -function buildKvTx(k: string, v: string): Uint8Array { - return toAscii(`${k}=${v}`); -} - -function randomString(): string { - const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - return Array.from({ length: 12 }) - .map(() => alphabet[Math.floor(Math.random() * alphabet.length)]) - .join(""); -} - function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues): void { describe("create", () => { it("can auto-discover Tendermint version and communicate", async () => { diff --git a/packages/tendermint-rpc/src/testutil.spec.ts b/packages/tendermint-rpc/src/testutil.spec.ts index de7ecb19..8c815867 100644 --- a/packages/tendermint-rpc/src/testutil.spec.ts +++ b/packages/tendermint-rpc/src/testutil.spec.ts @@ -1 +1,30 @@ +import { toAscii } from "@cosmjs/encoding"; +import { sleep } from "@cosmjs/utils"; + export const chainIdMatcher = /^[-a-zA-Z0-9]{3,30}$/; + +export function tendermintEnabled(): boolean { + return !!process.env.TENDERMINT_ENABLED; +} + +export function pendingWithoutTendermint(): void { + if (!tendermintEnabled()) { + pending("Set TENDERMINT_ENABLED to enable tendermint-based tests"); + } +} + +export async function tendermintSearchIndexUpdated(): Promise { + // Tendermint needs some time before a committed transaction is found in search + return sleep(75); +} + +export function buildKvTx(k: string, v: string): Uint8Array { + return toAscii(`${k}=${v}`); +} + +export function randomString(): string { + const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + return Array.from({ length: 12 }) + .map(() => alphabet[Math.floor(Math.random() * alphabet.length)]) + .join(""); +}