Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make .create constructors non-async #1597

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cosmwasm-stargate/src/cosmwasmclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class CosmWasmClient {
* Creates an instance from a manually created Comet client.
* Use this to use `Comet38Client` or `Tendermint37Client` instead of `Tendermint34Client`.
*/
public static async create(cometClient: CometClient): Promise<CosmWasmClient> {
public static create(cometClient: CometClient): CosmWasmClient {
return new CosmWasmClient(cometClient);
}

Expand Down
5 changes: 1 addition & 4 deletions packages/stargate/src/stargateclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,7 @@ export class StargateClient {
* Creates an instance from a manually created Comet client.
* Use this to use `Comet38Client` or `Tendermint37Client` instead of `Tendermint34Client`.
*/
public static async create(
cometClient: CometClient,
options: StargateClientOptions = {},
): Promise<StargateClient> {
public static create(cometClient: CometClient, options: StargateClientOptions = {}): StargateClient {
return new StargateClient(cometClient, options);
}

Expand Down
74 changes: 37 additions & 37 deletions packages/tendermint-rpc/src/comet38/comet38client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("create", () => {
it("can auto-discover Tendermint version and communicate", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());
const info = await client.abciInfo();
expect(info).toBeTruthy();
client.disconnect();
});

it("can connect to Tendermint with known version", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());
expect(await client.abciInfo()).toBeTruthy();
client.disconnect();
});
});

it("can get genesis", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());
const genesis = await client.genesis();
expect(genesis).toBeTruthy();
client.disconnect();
Expand All @@ -50,7 +50,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("broadcastTxCommit", () => {
it("can broadcast a transaction", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());
const tx = buildKvTx(randomString(), randomString());

const response = await client.broadcastTxCommit({ tx: tx });
Expand All @@ -70,7 +70,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("broadcastTxSync", () => {
it("can broadcast a transaction", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());
const tx = buildKvTx(randomString(), randomString());

const response = await client.broadcastTxSync({ tx: tx });
Expand All @@ -86,7 +86,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("broadcastTxAsync", () => {
it("can broadcast a transaction", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());
const tx = buildKvTx(randomString(), randomString());

const response = await client.broadcastTxAsync({ tx: tx });
Expand All @@ -98,7 +98,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)

it("gets the same tx hash from backend as calculated locally", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());
const tx = buildKvTx(randomString(), randomString());
const calculatedTxHash = hashTx(tx);

Expand All @@ -111,7 +111,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("abciQuery", () => {
it("can query the state", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());

const key = randomString();
const value = randomString();
Expand All @@ -137,7 +137,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)

it("can get a commit", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());
const response = await client.commit(4);

expect(response).toBeTruthy();
Expand All @@ -152,7 +152,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)

it("can get validators", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());
const response = await client.validators({});

expect(response).toBeTruthy();
Expand All @@ -170,7 +170,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)

it("can get all validators", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());
const response = await client.validatorsAll();

expect(response).toBeTruthy();
Expand All @@ -188,7 +188,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)

it("can call a bunch of methods", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());

expect(await client.block()).toBeTruthy();
expect(await client.genesis()).toBeTruthy();
Expand All @@ -200,7 +200,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("status", () => {
it("works", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());

const status = await client.status();

Expand Down Expand Up @@ -241,7 +241,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("numUnconfirmedTxs", () => {
it("works", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());

const response = await client.numUnconfirmedTxs();

Expand All @@ -255,7 +255,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("blockResults", () => {
it("works", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());

const height = 3;
const results = await client.blockResults(height);
Expand All @@ -271,7 +271,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("blockSearch", () => {
beforeAll(async () => {
if (tendermintEnabled()) {
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());

// eslint-disable-next-line no-inner-declarations
async function sendTx(): Promise<void> {
Expand All @@ -296,7 +296,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)

it("can paginate over blockSearch results", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());

const query = buildQuery({ raw: "block.height >= 1 AND block.height <= 3" });

Expand All @@ -315,7 +315,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)

it("can get all search results in one call", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());

const query = buildQuery({ raw: "block.height >= 1 AND block.height <= 3" });

Expand All @@ -334,7 +334,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("blockchain", () => {
it("returns latest in descending order by default", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());

// Run in parallel to increase chance there is no block between the calls
const [status, blockchain] = await Promise.all([client.status(), client.blockchain()]);
Expand All @@ -351,7 +351,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)

it("can limit by maxHeight", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());

const height = (await client.status()).syncInfo.latestBlockHeight;
const blockchain = await client.blockchain(undefined, height - 1);
Expand All @@ -365,7 +365,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)

it("works with maxHeight in the future", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());

const height = (await client.status()).syncInfo.latestBlockHeight;
const blockchain = await client.blockchain(undefined, height + 20);
Expand All @@ -380,7 +380,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)

it("can limit by minHeight and maxHeight", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());

const height = (await client.status()).syncInfo.latestBlockHeight;
const blockchain = await client.blockchain(height - 2, height - 1);
Expand All @@ -394,7 +394,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)

it("contains all the info", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());

const height = (await client.status()).syncInfo.latestBlockHeight;
const blockchain = await client.blockchain(height - 1, height - 1);
Expand Down Expand Up @@ -423,7 +423,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("tx", () => {
it("can query a tx properly", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());

const find = randomString();
const me = randomString();
Expand Down Expand Up @@ -463,7 +463,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)

beforeAll(async () => {
if (tendermintEnabled()) {
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());

// eslint-disable-next-line no-inner-declarations
async function sendTx(): Promise<[Uint8Array, responses.BroadcastTxCommitResponse]> {
Expand Down Expand Up @@ -491,7 +491,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("finds a single tx by hash", async () => {
pendingWithoutTendermint();
assert(tx1 && broadcast1);
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());

const result = await client.txSearch({ query: `tx.hash='${toHex(broadcast1.hash)}'` });
expect(result.totalCount).toEqual(1);
Expand All @@ -509,7 +509,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)

it("finds a single tx by tags", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());

const txKey2 = randomString();
const txValue2 = randomString();
Expand Down Expand Up @@ -559,7 +559,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
// Code 0.35: https://github.com/tendermint/tendermint/blob/v0.35.6/internal/rpc/core/tx.go#L93
// Code 0.37: https://github.com/cometbft/cometbft/blob/v0.37.0-rc3/rpc/core/tx.go#L87
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());

const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] });

Expand All @@ -576,7 +576,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)

it("can set the order", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());

const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] });

Expand All @@ -591,7 +591,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)

it("can paginate over txSearch results", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());

const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] });

Expand All @@ -610,7 +610,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)

it("can get all search results in one call", async () => {
pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());

const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] });

Expand All @@ -634,7 +634,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue

(async () => {
const events: responses.NewBlockHeaderEvent[] = [];
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());
const stream = client.subscribeNewBlockHeader();
expect(stream).toBeTruthy();
const subscription = stream.subscribe({
Expand Down Expand Up @@ -693,7 +693,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue
const transactionData2 = buildKvTx(randomString(), randomString());

const events: responses.NewBlockEvent[] = [];
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());
const stream = client.subscribeNewBlock();
const subscription = stream.subscribe({
next: (event) => {
Expand Down Expand Up @@ -752,7 +752,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue
pendingWithoutTendermint();

const events: responses.TxEvent[] = [];
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());
const stream = client.subscribeTx();
const subscription = stream.subscribe({
next: (event) => {
Expand Down Expand Up @@ -796,7 +796,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue
const transactionData2 = buildKvTx(randomString(), randomString());

const events: responses.TxEvent[] = [];
const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());
const query = buildQuery({ tags: [{ key: "app.creator", value: expected.appCreator }] });
const stream = client.subscribeTx(query);
expect(stream).toBeTruthy();
Expand Down Expand Up @@ -834,7 +834,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue
it("can unsubscribe and re-subscribe to the same stream", async () => {
pendingWithoutTendermint();

const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());
const stream = client.subscribeNewBlockHeader();

const event1 = await firstEvent(stream);
Expand Down Expand Up @@ -867,7 +867,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue
it("can subscribe twice", async () => {
pendingWithoutTendermint();

const client = await Comet38Client.create(rpcFactory());
const client = Comet38Client.create(rpcFactory());
const stream1 = client.subscribeNewBlockHeader();
const stream2 = client.subscribeNewBlockHeader();

Expand Down
2 changes: 1 addition & 1 deletion packages/tendermint-rpc/src/comet38/comet38client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class Comet38Client {
/**
* Creates a new Tendermint client given an RPC client.
*/
public static async create(rpcClient: RpcClient): Promise<Comet38Client> {
public static create(rpcClient: RpcClient): Comet38Client {
return new Comet38Client(rpcClient);
}

Expand Down
Loading
Loading