tendermint-rpc: Rename Tendermint33Client

This commit is contained in:
willclarktech 2021-06-08 16:13:59 +02:00
parent 23dfbe9325
commit c676ba68a3
No known key found for this signature in database
GPG Key ID: 551A86E2E398ADF7
4 changed files with 39 additions and 40 deletions

View File

@ -24,7 +24,7 @@ export {
adaptor33,
adaptor34,
Adaptor,
Client,
Tendermint33Client,
AbciInfoResponse,
AbciQueryResponse,
Attribute,

View File

@ -1,6 +1,6 @@
export { adaptor33, adaptor34 } from "./adaptors";
export { Adaptor } from "./adaptor";
export { Client } from "./tendermint33client";
export { Tendermint33Client } from "./tendermint33client";
export {
AbciInfoRequest,
AbciQueryParams,

View File

@ -18,7 +18,7 @@ import {
} from "../testutil.spec";
import { Adaptor } from "./adaptor";
import { adaptorForVersion } from "./adaptors";
import { Client } from "./client";
import { Tendermint33Client } from "./tendermint33client";
import { buildQuery } from "./requests";
import * as responses from "./responses";
@ -26,7 +26,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
describe("create", () => {
it("can auto-discover Tendermint version and communicate", async () => {
pendingWithoutTendermint();
const client = await Client.create(rpcFactory());
const client = await Tendermint33Client.create(rpcFactory());
const info = await client.abciInfo();
expect(info).toBeTruthy();
client.disconnect();
@ -34,7 +34,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
it("can connect to Tendermint with known version", async () => {
pendingWithoutTendermint();
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
expect(await client.abciInfo()).toBeTruthy();
client.disconnect();
});
@ -42,7 +42,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
it("can get genesis", async () => {
pendingWithoutTendermint();
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
const genesis = await client.genesis();
expect(genesis).toBeTruthy();
client.disconnect();
@ -50,7 +50,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
it("can broadcast a transaction", async () => {
pendingWithoutTendermint();
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
const tx = buildKvTx(randomString(), randomString());
const response = await client.broadcastTxCommit({ tx: tx });
@ -68,7 +68,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
it("gets the same tx hash from backend as calculated locally", async () => {
pendingWithoutTendermint();
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
const tx = buildKvTx(randomString(), randomString());
const calculatedTxHash = adaptor.hashTx(tx);
@ -80,7 +80,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
it("can query the state", async () => {
pendingWithoutTendermint();
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
const key = randomString();
const value = randomString();
@ -99,7 +99,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
it("can get a commit", async () => {
pendingWithoutTendermint();
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
const response = await client.commit(4);
expect(response).toBeTruthy();
@ -114,7 +114,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
it("can get validators", async () => {
pendingWithoutTendermint();
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
const response = await client.validators({});
expect(response).toBeTruthy();
@ -132,7 +132,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
it("can get all validators", async () => {
pendingWithoutTendermint();
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
const response = await client.validatorsAll();
expect(response).toBeTruthy();
@ -150,7 +150,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
it("can call a bunch of methods", async () => {
pendingWithoutTendermint();
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
expect(await client.block()).toBeTruthy();
expect(await client.genesis()).toBeTruthy();
@ -162,7 +162,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
describe("status", () => {
it("works", async () => {
pendingWithoutTendermint();
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
const status = await client.status();
@ -192,7 +192,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
describe("blockResults", () => {
it("works", async () => {
pendingWithoutTendermint();
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
const height = 3;
const results = await client.blockResults(height);
@ -208,7 +208,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
describe("blockchain", () => {
it("returns latest in descending order by default", async () => {
pendingWithoutTendermint();
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
// Run in parallel to increase chance there is no block between the calls
const [status, blockchain] = await Promise.all([client.status(), client.blockchain()]);
@ -225,7 +225,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
it("can limit by maxHeight", async () => {
pendingWithoutTendermint();
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
const height = (await client.status()).syncInfo.latestBlockHeight;
const blockchain = await client.blockchain(undefined, height - 1);
@ -239,7 +239,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
it("works with maxHeight in the future", async () => {
pendingWithoutTendermint();
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
const height = (await client.status()).syncInfo.latestBlockHeight;
const blockchain = await client.blockchain(undefined, height + 20);
@ -253,7 +253,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
it("can limit by minHeight and maxHeight", async () => {
pendingWithoutTendermint();
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
const height = (await client.status()).syncInfo.latestBlockHeight;
const blockchain = await client.blockchain(height - 2, height - 1);
@ -267,7 +267,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
it("contains all the info", async () => {
pendingWithoutTendermint();
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
const height = (await client.status()).syncInfo.latestBlockHeight;
const blockchain = await client.blockchain(height - 1, height - 1);
@ -297,7 +297,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
describe("tx", () => {
it("can query a tx properly", async () => {
pendingWithoutTendermint();
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
const find = randomString();
const me = randomString();
@ -354,7 +354,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
beforeAll(async () => {
if (tendermintEnabled()) {
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
// eslint-disable-next-line no-inner-declarations
async function sendTx(): Promise<void> {
@ -380,7 +380,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
it("can paginate over txSearch results", async () => {
pendingWithoutTendermint();
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
const query = buildQuery({ tags: [{ key: "app.key", value: key }] });
@ -399,7 +399,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
it("can get all search results in one call", async () => {
pendingWithoutTendermint();
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
const query = buildQuery({ tags: [{ key: "app.key", value: key }] });
@ -424,7 +424,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expec
(async () => {
const events: responses.NewBlockHeaderEvent[] = [];
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
const stream = client.subscribeNewBlockHeader();
expect(stream).toBeTruthy();
const subscription = stream.subscribe({
@ -482,7 +482,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expec
const transactionData2 = buildKvTx(randomString(), randomString());
const events: responses.NewBlockEvent[] = [];
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
const stream = client.subscribeNewBlock();
const subscription = stream.subscribe({
next: (event) => {
@ -538,7 +538,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expec
pendingWithoutTendermint();
const events: responses.TxEvent[] = [];
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
const stream = client.subscribeTx();
const subscription = stream.subscribe({
next: (event) => {
@ -582,7 +582,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expec
const transactionData2 = buildKvTx(randomString(), randomString());
const events: responses.TxEvent[] = [];
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
const query = buildQuery({ tags: [{ key: "app.creator", value: expected.appCreator }] });
const stream = client.subscribeTx(query);
expect(stream).toBeTruthy();
@ -620,7 +620,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expec
it("can unsubscribe and re-subscribe to the same stream", async () => {
pendingWithoutTendermint();
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
const stream = client.subscribeNewBlockHeader();
const event1 = await firstEvent(stream);
@ -653,7 +653,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expec
it("can subscribe twice", async () => {
pendingWithoutTendermint();
const client = await Client.create(rpcFactory(), adaptor);
const client = await Tendermint33Client.create(rpcFactory(), adaptor);
const stream1 = client.subscribeNewBlockHeader();
const stream2 = client.subscribeNewBlockHeader();
@ -672,7 +672,7 @@ for (const { url, version, expected } of tendermintInstances) {
// default connection
{
const client = await Client.connect(url);
const client = await Tendermint33Client.connect(url);
const info = await client.abciInfo();
expect(info).toBeTruthy();
client.disconnect();
@ -680,7 +680,7 @@ for (const { url, version, expected } of tendermintInstances) {
// http connection
{
const client = await Client.connect("http://" + url);
const client = await Tendermint33Client.connect("http://" + url);
const info = await client.abciInfo();
expect(info).toBeTruthy();
client.disconnect();
@ -688,7 +688,7 @@ for (const { url, version, expected } of tendermintInstances) {
// ws connection
{
const client = await Client.connect("ws://" + url);
const client = await Tendermint33Client.connect("ws://" + url);
const info = await client.abciInfo();
expect(info).toBeTruthy();
client.disconnect();

View File

@ -14,8 +14,7 @@ import { adaptorForVersion } from "./adaptors";
import * as requests from "./requests";
import * as responses from "./responses";
/** @deprecated Use Tendermint34Client */
export class Client {
export class Tendermint33Client {
/**
* Creates a new Tendermint client for the given endpoint.
*
@ -23,10 +22,10 @@ export class Client {
*
* If the adaptor is not set an auto-detection is attempted.
*/
public static async connect(url: string, adaptor?: Adaptor): Promise<Client> {
public static async connect(url: string, adaptor?: Adaptor): Promise<Tendermint33Client> {
const useHttp = url.startsWith("http://") || url.startsWith("https://");
const rpcClient = useHttp ? new HttpClient(url) : new WebsocketClient(url);
return Client.create(rpcClient, adaptor);
return Tendermint33Client.create(rpcClient, adaptor);
}
/**
@ -34,13 +33,13 @@ export class Client {
*
* If the adaptor is not set an auto-detection is attempted.
*/
public static async create(rpcClient: RpcClient, adaptor?: Adaptor): Promise<Client> {
public static async create(rpcClient: RpcClient, adaptor?: Adaptor): Promise<Tendermint33Client> {
// For some very strange reason I don't understand, tests start to fail on some systems
// (our CI) when skipping the status call before doing other queries. Sleeping a little
// while did not help. Thus we query the version as a way to say "hi" to the backend,
// even in cases where we don't use the result.
const version = await this.detectVersion(rpcClient);
return new Client(rpcClient, adaptor || adaptorForVersion(version));
return new Tendermint33Client(rpcClient, adaptor || adaptorForVersion(version));
}
private static async detectVersion(client: RpcClient): Promise<string> {
@ -64,7 +63,7 @@ export class Client {
private readonly r: Responses;
/**
* Use `Client.connect` or `Client.create` to create an instance.
* Use `Client.connect` or `Tendermint33Client.create` to create an instance.
*/
private constructor(client: RpcClient, adaptor: Adaptor) {
this.client = client;