Deduplicate test utils

This commit is contained in:
Simon Warta 2021-02-23 13:58:31 +01:00
parent 6448c57d83
commit e8a67119bb
3 changed files with 45 additions and 54 deletions

View File

@ -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<void> {
// 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 () => {

View File

@ -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<void> {
// 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 () => {

View File

@ -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<void> {
// 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("");
}