Make .create constructors non-async

This is a braking follow-up to
https://github.com/cosmos/cosmjs/pull/1380
This commit is contained in:
Simon Warta 2024-06-25 15:26:38 +02:00
parent e819a1fc0e
commit e51d6558bf
No known key found for this signature in database
8 changed files with 116 additions and 119 deletions

View File

@ -105,7 +105,7 @@ export class CosmWasmClient {
* Creates an instance from a manually created Comet client. * Creates an instance from a manually created Comet client.
* Use this to use `Comet38Client` or `Tendermint37Client` instead of `Tendermint34Client`. * 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); return new CosmWasmClient(cometClient);
} }

View File

@ -221,10 +221,7 @@ export class StargateClient {
* Creates an instance from a manually created Comet client. * Creates an instance from a manually created Comet client.
* Use this to use `Comet38Client` or `Tendermint37Client` instead of `Tendermint34Client`. * Use this to use `Comet38Client` or `Tendermint37Client` instead of `Tendermint34Client`.
*/ */
public static async create( public static create(cometClient: CometClient, options: StargateClientOptions = {}): StargateClient {
cometClient: CometClient,
options: StargateClientOptions = {},
): Promise<StargateClient> {
return new StargateClient(cometClient, options); return new StargateClient(cometClient, options);
} }

View File

@ -25,7 +25,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("create", () => { describe("create", () => {
it("can auto-discover Tendermint version and communicate", async () => { it("can auto-discover Tendermint version and communicate", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const info = await client.abciInfo(); const info = await client.abciInfo();
expect(info).toBeTruthy(); expect(info).toBeTruthy();
client.disconnect(); client.disconnect();
@ -33,7 +33,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can connect to Tendermint with known version", async () => { it("can connect to Tendermint with known version", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
expect(await client.abciInfo()).toBeTruthy(); expect(await client.abciInfo()).toBeTruthy();
client.disconnect(); client.disconnect();
}); });
@ -41,7 +41,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can get genesis", async () => { it("can get genesis", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const genesis = await client.genesis(); const genesis = await client.genesis();
expect(genesis).toBeTruthy(); expect(genesis).toBeTruthy();
client.disconnect(); client.disconnect();
@ -50,7 +50,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("broadcastTxCommit", () => { describe("broadcastTxCommit", () => {
it("can broadcast a transaction", async () => { it("can broadcast a transaction", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const tx = buildKvTx(randomString(), randomString()); const tx = buildKvTx(randomString(), randomString());
const response = await client.broadcastTxCommit({ tx: tx }); const response = await client.broadcastTxCommit({ tx: tx });
@ -70,7 +70,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("broadcastTxSync", () => { describe("broadcastTxSync", () => {
it("can broadcast a transaction", async () => { it("can broadcast a transaction", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const tx = buildKvTx(randomString(), randomString()); const tx = buildKvTx(randomString(), randomString());
const response = await client.broadcastTxSync({ tx: tx }); const response = await client.broadcastTxSync({ tx: tx });
@ -86,7 +86,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("broadcastTxAsync", () => { describe("broadcastTxAsync", () => {
it("can broadcast a transaction", async () => { it("can broadcast a transaction", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const tx = buildKvTx(randomString(), randomString()); const tx = buildKvTx(randomString(), randomString());
const response = await client.broadcastTxAsync({ tx: tx }); const response = await client.broadcastTxAsync({ tx: tx });
@ -98,7 +98,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("gets the same tx hash from backend as calculated locally", async () => { it("gets the same tx hash from backend as calculated locally", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const tx = buildKvTx(randomString(), randomString()); const tx = buildKvTx(randomString(), randomString());
const calculatedTxHash = hashTx(tx); const calculatedTxHash = hashTx(tx);
@ -111,7 +111,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("abciQuery", () => { describe("abciQuery", () => {
it("can query the state", async () => { it("can query the state", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const key = randomString(); const key = randomString();
const value = randomString(); const value = randomString();
@ -137,7 +137,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can get a commit", async () => { it("can get a commit", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const response = await client.commit(4); const response = await client.commit(4);
expect(response).toBeTruthy(); expect(response).toBeTruthy();
@ -152,7 +152,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can get validators", async () => { it("can get validators", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const response = await client.validators({}); const response = await client.validators({});
expect(response).toBeTruthy(); expect(response).toBeTruthy();
@ -170,7 +170,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can get all validators", async () => { it("can get all validators", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const response = await client.validatorsAll(); const response = await client.validatorsAll();
expect(response).toBeTruthy(); expect(response).toBeTruthy();
@ -188,7 +188,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can call a bunch of methods", async () => { it("can call a bunch of methods", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
expect(await client.block()).toBeTruthy(); expect(await client.block()).toBeTruthy();
expect(await client.genesis()).toBeTruthy(); expect(await client.genesis()).toBeTruthy();
@ -200,7 +200,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("status", () => { describe("status", () => {
it("works", async () => { it("works", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const status = await client.status(); const status = await client.status();
@ -241,7 +241,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("numUnconfirmedTxs", () => { describe("numUnconfirmedTxs", () => {
it("works", async () => { it("works", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const response = await client.numUnconfirmedTxs(); const response = await client.numUnconfirmedTxs();
@ -255,7 +255,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("blockResults", () => { describe("blockResults", () => {
it("works", async () => { it("works", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const height = 3; const height = 3;
const results = await client.blockResults(height); const results = await client.blockResults(height);
@ -271,7 +271,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("blockSearch", () => { describe("blockSearch", () => {
beforeAll(async () => { beforeAll(async () => {
if (tendermintEnabled()) { if (tendermintEnabled()) {
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
// eslint-disable-next-line no-inner-declarations // eslint-disable-next-line no-inner-declarations
async function sendTx(): Promise<void> { async function sendTx(): Promise<void> {
@ -296,7 +296,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can paginate over blockSearch results", async () => { it("can paginate over blockSearch results", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const query = buildQuery({ raw: "block.height >= 1 AND block.height <= 3" }); const query = buildQuery({ raw: "block.height >= 1 AND block.height <= 3" });
@ -315,7 +315,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can get all search results in one call", async () => { it("can get all search results in one call", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const query = buildQuery({ raw: "block.height >= 1 AND block.height <= 3" }); const query = buildQuery({ raw: "block.height >= 1 AND block.height <= 3" });
@ -334,7 +334,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("blockchain", () => { describe("blockchain", () => {
it("returns latest in descending order by default", async () => { it("returns latest in descending order by default", async () => {
pendingWithoutTendermint(); 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 // Run in parallel to increase chance there is no block between the calls
const [status, blockchain] = await Promise.all([client.status(), client.blockchain()]); const [status, blockchain] = await Promise.all([client.status(), client.blockchain()]);
@ -351,7 +351,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can limit by maxHeight", async () => { it("can limit by maxHeight", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const height = (await client.status()).syncInfo.latestBlockHeight; const height = (await client.status()).syncInfo.latestBlockHeight;
const blockchain = await client.blockchain(undefined, height - 1); const blockchain = await client.blockchain(undefined, height - 1);
@ -365,7 +365,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("works with maxHeight in the future", async () => { it("works with maxHeight in the future", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const height = (await client.status()).syncInfo.latestBlockHeight; const height = (await client.status()).syncInfo.latestBlockHeight;
const blockchain = await client.blockchain(undefined, height + 20); const blockchain = await client.blockchain(undefined, height + 20);
@ -380,7 +380,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can limit by minHeight and maxHeight", async () => { it("can limit by minHeight and maxHeight", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const height = (await client.status()).syncInfo.latestBlockHeight; const height = (await client.status()).syncInfo.latestBlockHeight;
const blockchain = await client.blockchain(height - 2, height - 1); const blockchain = await client.blockchain(height - 2, height - 1);
@ -394,7 +394,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("contains all the info", async () => { it("contains all the info", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const height = (await client.status()).syncInfo.latestBlockHeight; const height = (await client.status()).syncInfo.latestBlockHeight;
const blockchain = await client.blockchain(height - 1, height - 1); const blockchain = await client.blockchain(height - 1, height - 1);
@ -423,7 +423,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("tx", () => { describe("tx", () => {
it("can query a tx properly", async () => { it("can query a tx properly", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const find = randomString(); const find = randomString();
const me = randomString(); const me = randomString();
@ -463,7 +463,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
beforeAll(async () => { beforeAll(async () => {
if (tendermintEnabled()) { if (tendermintEnabled()) {
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
// eslint-disable-next-line no-inner-declarations // eslint-disable-next-line no-inner-declarations
async function sendTx(): Promise<[Uint8Array, responses.BroadcastTxCommitResponse]> { async function sendTx(): Promise<[Uint8Array, responses.BroadcastTxCommitResponse]> {
@ -491,7 +491,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("finds a single tx by hash", async () => { it("finds a single tx by hash", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
assert(tx1 && broadcast1); 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)}'` }); const result = await client.txSearch({ query: `tx.hash='${toHex(broadcast1.hash)}'` });
expect(result.totalCount).toEqual(1); expect(result.totalCount).toEqual(1);
@ -509,7 +509,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("finds a single tx by tags", async () => { it("finds a single tx by tags", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const txKey2 = randomString(); const txKey2 = randomString();
const txValue2 = randomString(); const txValue2 = randomString();
@ -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.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 // Code 0.37: https://github.com/cometbft/cometbft/blob/v0.37.0-rc3/rpc/core/tx.go#L87
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] }); const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] });
@ -576,7 +576,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can set the order", async () => { it("can set the order", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] }); const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] });
@ -591,7 +591,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can paginate over txSearch results", async () => { it("can paginate over txSearch results", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] }); const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] });
@ -610,7 +610,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can get all search results in one call", async () => { it("can get all search results in one call", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] }); const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] });
@ -634,7 +634,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue
(async () => { (async () => {
const events: responses.NewBlockHeaderEvent[] = []; const events: responses.NewBlockHeaderEvent[] = [];
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const stream = client.subscribeNewBlockHeader(); const stream = client.subscribeNewBlockHeader();
expect(stream).toBeTruthy(); expect(stream).toBeTruthy();
const subscription = stream.subscribe({ const subscription = stream.subscribe({
@ -693,7 +693,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue
const transactionData2 = buildKvTx(randomString(), randomString()); const transactionData2 = buildKvTx(randomString(), randomString());
const events: responses.NewBlockEvent[] = []; const events: responses.NewBlockEvent[] = [];
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const stream = client.subscribeNewBlock(); const stream = client.subscribeNewBlock();
const subscription = stream.subscribe({ const subscription = stream.subscribe({
next: (event) => { next: (event) => {
@ -752,7 +752,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue
pendingWithoutTendermint(); pendingWithoutTendermint();
const events: responses.TxEvent[] = []; const events: responses.TxEvent[] = [];
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const stream = client.subscribeTx(); const stream = client.subscribeTx();
const subscription = stream.subscribe({ const subscription = stream.subscribe({
next: (event) => { next: (event) => {
@ -796,7 +796,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue
const transactionData2 = buildKvTx(randomString(), randomString()); const transactionData2 = buildKvTx(randomString(), randomString());
const events: responses.TxEvent[] = []; 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 query = buildQuery({ tags: [{ key: "app.creator", value: expected.appCreator }] });
const stream = client.subscribeTx(query); const stream = client.subscribeTx(query);
expect(stream).toBeTruthy(); expect(stream).toBeTruthy();
@ -834,7 +834,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue
it("can unsubscribe and re-subscribe to the same stream", async () => { it("can unsubscribe and re-subscribe to the same stream", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const stream = client.subscribeNewBlockHeader(); const stream = client.subscribeNewBlockHeader();
const event1 = await firstEvent(stream); const event1 = await firstEvent(stream);
@ -867,7 +867,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue
it("can subscribe twice", async () => { it("can subscribe twice", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Comet38Client.create(rpcFactory()); const client = Comet38Client.create(rpcFactory());
const stream1 = client.subscribeNewBlockHeader(); const stream1 = client.subscribeNewBlockHeader();
const stream2 = client.subscribeNewBlockHeader(); const stream2 = client.subscribeNewBlockHeader();

View File

@ -47,7 +47,7 @@ export class Comet38Client {
/** /**
* Creates a new Tendermint client given an RPC client. * 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); return new Comet38Client(rpcClient);
} }

View File

@ -25,7 +25,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("create", () => { describe("create", () => {
it("can auto-discover Tendermint version and communicate", async () => { it("can auto-discover Tendermint version and communicate", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const info = await client.abciInfo(); const info = await client.abciInfo();
expect(info).toBeTruthy(); expect(info).toBeTruthy();
client.disconnect(); client.disconnect();
@ -33,7 +33,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can connect to Tendermint with known version", async () => { it("can connect to Tendermint with known version", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
expect(await client.abciInfo()).toBeTruthy(); expect(await client.abciInfo()).toBeTruthy();
client.disconnect(); client.disconnect();
}); });
@ -41,7 +41,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can get genesis", async () => { it("can get genesis", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const genesis = await client.genesis(); const genesis = await client.genesis();
expect(genesis).toBeTruthy(); expect(genesis).toBeTruthy();
client.disconnect(); client.disconnect();
@ -50,7 +50,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("broadcastTxCommit", () => { describe("broadcastTxCommit", () => {
it("can broadcast a transaction", async () => { it("can broadcast a transaction", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const tx = buildKvTx(randomString(), randomString()); const tx = buildKvTx(randomString(), randomString());
const response = await client.broadcastTxCommit({ tx: tx }); const response = await client.broadcastTxCommit({ tx: tx });
@ -70,7 +70,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("broadcastTxSync", () => { describe("broadcastTxSync", () => {
it("can broadcast a transaction", async () => { it("can broadcast a transaction", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const tx = buildKvTx(randomString(), randomString()); const tx = buildKvTx(randomString(), randomString());
const response = await client.broadcastTxSync({ tx: tx }); const response = await client.broadcastTxSync({ tx: tx });
@ -86,7 +86,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("broadcastTxAsync", () => { describe("broadcastTxAsync", () => {
it("can broadcast a transaction", async () => { it("can broadcast a transaction", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const tx = buildKvTx(randomString(), randomString()); const tx = buildKvTx(randomString(), randomString());
const response = await client.broadcastTxAsync({ tx: tx }); const response = await client.broadcastTxAsync({ tx: tx });
@ -98,7 +98,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("gets the same tx hash from backend as calculated locally", async () => { it("gets the same tx hash from backend as calculated locally", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const tx = buildKvTx(randomString(), randomString()); const tx = buildKvTx(randomString(), randomString());
const calculatedTxHash = hashTx(tx); const calculatedTxHash = hashTx(tx);
@ -111,7 +111,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("abciQuery", () => { describe("abciQuery", () => {
it("can query the state", async () => { it("can query the state", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const key = randomString(); const key = randomString();
const value = randomString(); const value = randomString();
@ -137,7 +137,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can get a commit", async () => { it("can get a commit", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const response = await client.commit(4); const response = await client.commit(4);
expect(response).toBeTruthy(); expect(response).toBeTruthy();
@ -152,7 +152,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can get validators", async () => { it("can get validators", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const response = await client.validators({}); const response = await client.validators({});
expect(response).toBeTruthy(); expect(response).toBeTruthy();
@ -170,7 +170,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can get all validators", async () => { it("can get all validators", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const response = await client.validatorsAll(); const response = await client.validatorsAll();
expect(response).toBeTruthy(); expect(response).toBeTruthy();
@ -188,7 +188,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can call a bunch of methods", async () => { it("can call a bunch of methods", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
expect(await client.block()).toBeTruthy(); expect(await client.block()).toBeTruthy();
expect(await client.genesis()).toBeTruthy(); expect(await client.genesis()).toBeTruthy();
@ -200,7 +200,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("status", () => { describe("status", () => {
it("works", async () => { it("works", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const status = await client.status(); const status = await client.status();
@ -241,7 +241,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("numUnconfirmedTxs", () => { describe("numUnconfirmedTxs", () => {
it("works", async () => { it("works", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const response = await client.numUnconfirmedTxs(); const response = await client.numUnconfirmedTxs();
@ -255,7 +255,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("blockResults", () => { describe("blockResults", () => {
it("works", async () => { it("works", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const height = 3; const height = 3;
const results = await client.blockResults(height); const results = await client.blockResults(height);
@ -271,7 +271,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("blockSearch", () => { describe("blockSearch", () => {
beforeAll(async () => { beforeAll(async () => {
if (tendermintEnabled()) { if (tendermintEnabled()) {
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
// eslint-disable-next-line no-inner-declarations // eslint-disable-next-line no-inner-declarations
async function sendTx(): Promise<void> { async function sendTx(): Promise<void> {
@ -296,7 +296,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can paginate over blockSearch results", async () => { it("can paginate over blockSearch results", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const query = buildQuery({ raw: "block.height >= 1 AND block.height <= 3" }); const query = buildQuery({ raw: "block.height >= 1 AND block.height <= 3" });
@ -315,7 +315,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can get all search results in one call", async () => { it("can get all search results in one call", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const query = buildQuery({ raw: "block.height >= 1 AND block.height <= 3" }); const query = buildQuery({ raw: "block.height >= 1 AND block.height <= 3" });
@ -334,7 +334,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("blockchain", () => { describe("blockchain", () => {
it("returns latest in descending order by default", async () => { it("returns latest in descending order by default", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
// Run in parallel to increase chance there is no block between the calls // Run in parallel to increase chance there is no block between the calls
const [status, blockchain] = await Promise.all([client.status(), client.blockchain()]); const [status, blockchain] = await Promise.all([client.status(), client.blockchain()]);
@ -351,7 +351,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can limit by maxHeight", async () => { it("can limit by maxHeight", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const height = (await client.status()).syncInfo.latestBlockHeight; const height = (await client.status()).syncInfo.latestBlockHeight;
const blockchain = await client.blockchain(undefined, height - 1); const blockchain = await client.blockchain(undefined, height - 1);
@ -365,7 +365,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("works with maxHeight in the future", async () => { it("works with maxHeight in the future", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const height = (await client.status()).syncInfo.latestBlockHeight; const height = (await client.status()).syncInfo.latestBlockHeight;
const blockchain = await client.blockchain(undefined, height + 20); const blockchain = await client.blockchain(undefined, height + 20);
@ -379,7 +379,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can limit by minHeight and maxHeight", async () => { it("can limit by minHeight and maxHeight", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const height = (await client.status()).syncInfo.latestBlockHeight; const height = (await client.status()).syncInfo.latestBlockHeight;
const blockchain = await client.blockchain(height - 2, height - 1); const blockchain = await client.blockchain(height - 2, height - 1);
@ -393,7 +393,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("contains all the info", async () => { it("contains all the info", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const height = (await client.status()).syncInfo.latestBlockHeight; const height = (await client.status()).syncInfo.latestBlockHeight;
const blockchain = await client.blockchain(height - 1, height - 1); const blockchain = await client.blockchain(height - 1, height - 1);
@ -422,7 +422,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("tx", () => { describe("tx", () => {
it("can query a tx properly", async () => { it("can query a tx properly", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const find = randomString(); const find = randomString();
const me = randomString(); const me = randomString();
@ -462,7 +462,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
beforeAll(async () => { beforeAll(async () => {
if (tendermintEnabled()) { if (tendermintEnabled()) {
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
// eslint-disable-next-line no-inner-declarations // eslint-disable-next-line no-inner-declarations
async function sendTx(): Promise<[Uint8Array, responses.BroadcastTxCommitResponse]> { async function sendTx(): Promise<[Uint8Array, responses.BroadcastTxCommitResponse]> {
@ -490,7 +490,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("finds a single tx by hash", async () => { it("finds a single tx by hash", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
assert(tx1 && broadcast1); assert(tx1 && broadcast1);
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const result = await client.txSearch({ query: `tx.hash='${toHex(broadcast1.hash)}'` }); const result = await client.txSearch({ query: `tx.hash='${toHex(broadcast1.hash)}'` });
expect(result.totalCount).toEqual(1); expect(result.totalCount).toEqual(1);
@ -508,7 +508,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("finds a single tx by tags", async () => { it("finds a single tx by tags", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const txKey2 = randomString(); const txKey2 = randomString();
const txValue2 = randomString(); const txValue2 = randomString();
@ -554,7 +554,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
// Docs: https://docs.tendermint.com/master/rpc/#/Info/tx_search // Docs: https://docs.tendermint.com/master/rpc/#/Info/tx_search
// Code: https://github.com/tendermint/tendermint/blob/v0.34.10/rpc/core/tx.go#L89 // Code: https://github.com/tendermint/tendermint/blob/v0.34.10/rpc/core/tx.go#L89
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] }); const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] });
@ -571,7 +571,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can set the order", async () => { it("can set the order", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] }); const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] });
@ -586,7 +586,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can paginate over txSearch results", async () => { it("can paginate over txSearch results", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] }); const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] });
@ -605,7 +605,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can get all search results in one call", async () => { it("can get all search results in one call", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] }); const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] });
@ -629,7 +629,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue
(async () => { (async () => {
const events: responses.NewBlockHeaderEvent[] = []; const events: responses.NewBlockHeaderEvent[] = [];
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const stream = client.subscribeNewBlockHeader(); const stream = client.subscribeNewBlockHeader();
expect(stream).toBeTruthy(); expect(stream).toBeTruthy();
const subscription = stream.subscribe({ const subscription = stream.subscribe({
@ -687,7 +687,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue
const transactionData2 = buildKvTx(randomString(), randomString()); const transactionData2 = buildKvTx(randomString(), randomString());
const events: responses.NewBlockEvent[] = []; const events: responses.NewBlockEvent[] = [];
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const stream = client.subscribeNewBlock(); const stream = client.subscribeNewBlock();
const subscription = stream.subscribe({ const subscription = stream.subscribe({
next: (event) => { next: (event) => {
@ -743,7 +743,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue
pendingWithoutTendermint(); pendingWithoutTendermint();
const events: responses.TxEvent[] = []; const events: responses.TxEvent[] = [];
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const stream = client.subscribeTx(); const stream = client.subscribeTx();
const subscription = stream.subscribe({ const subscription = stream.subscribe({
next: (event) => { next: (event) => {
@ -787,7 +787,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue
const transactionData2 = buildKvTx(randomString(), randomString()); const transactionData2 = buildKvTx(randomString(), randomString());
const events: responses.TxEvent[] = []; const events: responses.TxEvent[] = [];
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const query = buildQuery({ tags: [{ key: "app.creator", value: expected.appCreator }] }); const query = buildQuery({ tags: [{ key: "app.creator", value: expected.appCreator }] });
const stream = client.subscribeTx(query); const stream = client.subscribeTx(query);
expect(stream).toBeTruthy(); expect(stream).toBeTruthy();
@ -825,7 +825,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue
it("can unsubscribe and re-subscribe to the same stream", async () => { it("can unsubscribe and re-subscribe to the same stream", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const stream = client.subscribeNewBlockHeader(); const stream = client.subscribeNewBlockHeader();
const event1 = await firstEvent(stream); const event1 = await firstEvent(stream);
@ -858,7 +858,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue
it("can subscribe twice", async () => { it("can subscribe twice", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint34Client.create(rpcFactory()); const client = Tendermint34Client.create(rpcFactory());
const stream1 = client.subscribeNewBlockHeader(); const stream1 = client.subscribeNewBlockHeader();
const stream2 = client.subscribeNewBlockHeader(); const stream2 = client.subscribeNewBlockHeader();

View File

@ -47,7 +47,7 @@ export class Tendermint34Client {
/** /**
* Creates a new Tendermint client given an RPC client. * Creates a new Tendermint client given an RPC client.
*/ */
public static async create(rpcClient: RpcClient): Promise<Tendermint34Client> { public static create(rpcClient: RpcClient): Tendermint34Client {
return new Tendermint34Client(rpcClient); return new Tendermint34Client(rpcClient);
} }

View File

@ -25,7 +25,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("create", () => { describe("create", () => {
it("can auto-discover Tendermint version and communicate", async () => { it("can auto-discover Tendermint version and communicate", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const info = await client.abciInfo(); const info = await client.abciInfo();
expect(info).toBeTruthy(); expect(info).toBeTruthy();
client.disconnect(); client.disconnect();
@ -33,7 +33,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can connect to Tendermint with known version", async () => { it("can connect to Tendermint with known version", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
expect(await client.abciInfo()).toBeTruthy(); expect(await client.abciInfo()).toBeTruthy();
client.disconnect(); client.disconnect();
}); });
@ -41,7 +41,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can get genesis", async () => { it("can get genesis", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const genesis = await client.genesis(); const genesis = await client.genesis();
expect(genesis).toBeTruthy(); expect(genesis).toBeTruthy();
client.disconnect(); client.disconnect();
@ -50,7 +50,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("broadcastTxCommit", () => { describe("broadcastTxCommit", () => {
it("can broadcast a transaction", async () => { it("can broadcast a transaction", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const tx = buildKvTx(randomString(), randomString()); const tx = buildKvTx(randomString(), randomString());
const response = await client.broadcastTxCommit({ tx: tx }); const response = await client.broadcastTxCommit({ tx: tx });
@ -70,7 +70,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("broadcastTxSync", () => { describe("broadcastTxSync", () => {
it("can broadcast a transaction", async () => { it("can broadcast a transaction", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const tx = buildKvTx(randomString(), randomString()); const tx = buildKvTx(randomString(), randomString());
const response = await client.broadcastTxSync({ tx: tx }); const response = await client.broadcastTxSync({ tx: tx });
@ -86,7 +86,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("broadcastTxAsync", () => { describe("broadcastTxAsync", () => {
it("can broadcast a transaction", async () => { it("can broadcast a transaction", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const tx = buildKvTx(randomString(), randomString()); const tx = buildKvTx(randomString(), randomString());
const response = await client.broadcastTxAsync({ tx: tx }); const response = await client.broadcastTxAsync({ tx: tx });
@ -98,7 +98,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("gets the same tx hash from backend as calculated locally", async () => { it("gets the same tx hash from backend as calculated locally", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const tx = buildKvTx(randomString(), randomString()); const tx = buildKvTx(randomString(), randomString());
const calculatedTxHash = hashTx(tx); const calculatedTxHash = hashTx(tx);
@ -111,7 +111,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("abciQuery", () => { describe("abciQuery", () => {
it("can query the state", async () => { it("can query the state", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const key = randomString(); const key = randomString();
const value = randomString(); const value = randomString();
@ -137,7 +137,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can get a commit", async () => { it("can get a commit", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const response = await client.commit(4); const response = await client.commit(4);
expect(response).toBeTruthy(); expect(response).toBeTruthy();
@ -152,7 +152,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can get validators", async () => { it("can get validators", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const response = await client.validators({}); const response = await client.validators({});
expect(response).toBeTruthy(); expect(response).toBeTruthy();
@ -170,7 +170,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can get all validators", async () => { it("can get all validators", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const response = await client.validatorsAll(); const response = await client.validatorsAll();
expect(response).toBeTruthy(); expect(response).toBeTruthy();
@ -188,7 +188,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can call a bunch of methods", async () => { it("can call a bunch of methods", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
expect(await client.block()).toBeTruthy(); expect(await client.block()).toBeTruthy();
expect(await client.genesis()).toBeTruthy(); expect(await client.genesis()).toBeTruthy();
@ -200,7 +200,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("status", () => { describe("status", () => {
it("works", async () => { it("works", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const status = await client.status(); const status = await client.status();
@ -241,7 +241,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("numUnconfirmedTxs", () => { describe("numUnconfirmedTxs", () => {
it("works", async () => { it("works", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const response = await client.numUnconfirmedTxs(); const response = await client.numUnconfirmedTxs();
@ -255,7 +255,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("blockResults", () => { describe("blockResults", () => {
it("works", async () => { it("works", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const height = 3; const height = 3;
const results = await client.blockResults(height); const results = await client.blockResults(height);
@ -271,7 +271,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("blockSearch", () => { describe("blockSearch", () => {
beforeAll(async () => { beforeAll(async () => {
if (tendermintEnabled()) { if (tendermintEnabled()) {
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
// eslint-disable-next-line no-inner-declarations // eslint-disable-next-line no-inner-declarations
async function sendTx(): Promise<void> { async function sendTx(): Promise<void> {
@ -296,7 +296,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can paginate over blockSearch results", async () => { it("can paginate over blockSearch results", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const query = buildQuery({ raw: "block.height >= 1 AND block.height <= 3" }); const query = buildQuery({ raw: "block.height >= 1 AND block.height <= 3" });
@ -315,7 +315,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can get all search results in one call", async () => { it("can get all search results in one call", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const query = buildQuery({ raw: "block.height >= 1 AND block.height <= 3" }); const query = buildQuery({ raw: "block.height >= 1 AND block.height <= 3" });
@ -334,7 +334,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("blockchain", () => { describe("blockchain", () => {
it("returns latest in descending order by default", async () => { it("returns latest in descending order by default", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
// Run in parallel to increase chance there is no block between the calls // Run in parallel to increase chance there is no block between the calls
const [status, blockchain] = await Promise.all([client.status(), client.blockchain()]); const [status, blockchain] = await Promise.all([client.status(), client.blockchain()]);
@ -351,7 +351,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can limit by maxHeight", async () => { it("can limit by maxHeight", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const height = (await client.status()).syncInfo.latestBlockHeight; const height = (await client.status()).syncInfo.latestBlockHeight;
const blockchain = await client.blockchain(undefined, height - 1); const blockchain = await client.blockchain(undefined, height - 1);
@ -365,7 +365,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("works with maxHeight in the future", async () => { it("works with maxHeight in the future", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const height = (await client.status()).syncInfo.latestBlockHeight; const height = (await client.status()).syncInfo.latestBlockHeight;
const blockchain = await client.blockchain(undefined, height + 20); const blockchain = await client.blockchain(undefined, height + 20);
@ -380,7 +380,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can limit by minHeight and maxHeight", async () => { it("can limit by minHeight and maxHeight", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const height = (await client.status()).syncInfo.latestBlockHeight; const height = (await client.status()).syncInfo.latestBlockHeight;
const blockchain = await client.blockchain(height - 2, height - 1); const blockchain = await client.blockchain(height - 2, height - 1);
@ -394,7 +394,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("contains all the info", async () => { it("contains all the info", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const height = (await client.status()).syncInfo.latestBlockHeight; const height = (await client.status()).syncInfo.latestBlockHeight;
const blockchain = await client.blockchain(height - 1, height - 1); const blockchain = await client.blockchain(height - 1, height - 1);
@ -423,7 +423,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
describe("tx", () => { describe("tx", () => {
it("can query a tx properly", async () => { it("can query a tx properly", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const find = randomString(); const find = randomString();
const me = randomString(); const me = randomString();
@ -463,7 +463,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
beforeAll(async () => { beforeAll(async () => {
if (tendermintEnabled()) { if (tendermintEnabled()) {
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
// eslint-disable-next-line no-inner-declarations // eslint-disable-next-line no-inner-declarations
async function sendTx(): Promise<[Uint8Array, responses.BroadcastTxCommitResponse]> { async function sendTx(): Promise<[Uint8Array, responses.BroadcastTxCommitResponse]> {
@ -491,7 +491,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("finds a single tx by hash", async () => { it("finds a single tx by hash", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
assert(tx1 && broadcast1); assert(tx1 && broadcast1);
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const result = await client.txSearch({ query: `tx.hash='${toHex(broadcast1.hash)}'` }); const result = await client.txSearch({ query: `tx.hash='${toHex(broadcast1.hash)}'` });
expect(result.totalCount).toEqual(1); expect(result.totalCount).toEqual(1);
@ -509,7 +509,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("finds a single tx by tags", async () => { it("finds a single tx by tags", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const txKey2 = randomString(); const txKey2 = randomString();
const txValue2 = randomString(); const txValue2 = randomString();
@ -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.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 // Code 0.37: https://github.com/cometbft/cometbft/blob/v0.37.0-rc3/rpc/core/tx.go#L87
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] }); const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] });
@ -576,7 +576,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can set the order", async () => { it("can set the order", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] }); const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] });
@ -591,7 +591,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can paginate over txSearch results", async () => { it("can paginate over txSearch results", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] }); const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] });
@ -610,7 +610,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
it("can get all search results in one call", async () => { it("can get all search results in one call", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] }); const query = buildQuery({ tags: [{ key: "app.key", value: txKey }] });
@ -634,7 +634,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue
(async () => { (async () => {
const events: responses.NewBlockHeaderEvent[] = []; const events: responses.NewBlockHeaderEvent[] = [];
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const stream = client.subscribeNewBlockHeader(); const stream = client.subscribeNewBlockHeader();
expect(stream).toBeTruthy(); expect(stream).toBeTruthy();
const subscription = stream.subscribe({ const subscription = stream.subscribe({
@ -693,7 +693,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue
const transactionData2 = buildKvTx(randomString(), randomString()); const transactionData2 = buildKvTx(randomString(), randomString());
const events: responses.NewBlockEvent[] = []; const events: responses.NewBlockEvent[] = [];
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const stream = client.subscribeNewBlock(); const stream = client.subscribeNewBlock();
const subscription = stream.subscribe({ const subscription = stream.subscribe({
next: (event) => { next: (event) => {
@ -752,7 +752,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue
pendingWithoutTendermint(); pendingWithoutTendermint();
const events: responses.TxEvent[] = []; const events: responses.TxEvent[] = [];
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const stream = client.subscribeTx(); const stream = client.subscribeTx();
const subscription = stream.subscribe({ const subscription = stream.subscribe({
next: (event) => { next: (event) => {
@ -796,7 +796,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue
const transactionData2 = buildKvTx(randomString(), randomString()); const transactionData2 = buildKvTx(randomString(), randomString());
const events: responses.TxEvent[] = []; const events: responses.TxEvent[] = [];
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const query = buildQuery({ tags: [{ key: "app.creator", value: expected.appCreator }] }); const query = buildQuery({ tags: [{ key: "app.creator", value: expected.appCreator }] });
const stream = client.subscribeTx(query); const stream = client.subscribeTx(query);
expect(stream).toBeTruthy(); expect(stream).toBeTruthy();
@ -834,7 +834,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue
it("can unsubscribe and re-subscribe to the same stream", async () => { it("can unsubscribe and re-subscribe to the same stream", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const stream = client.subscribeNewBlockHeader(); const stream = client.subscribeNewBlockHeader();
const event1 = await firstEvent(stream); const event1 = await firstEvent(stream);
@ -867,7 +867,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValue
it("can subscribe twice", async () => { it("can subscribe twice", async () => {
pendingWithoutTendermint(); pendingWithoutTendermint();
const client = await Tendermint37Client.create(rpcFactory()); const client = Tendermint37Client.create(rpcFactory());
const stream1 = client.subscribeNewBlockHeader(); const stream1 = client.subscribeNewBlockHeader();
const stream2 = client.subscribeNewBlockHeader(); const stream2 = client.subscribeNewBlockHeader();

View File

@ -47,7 +47,7 @@ export class Tendermint37Client {
/** /**
* Creates a new Tendermint client given an RPC client. * Creates a new Tendermint client given an RPC client.
*/ */
public static async create(rpcClient: RpcClient): Promise<Tendermint37Client> { public static create(rpcClient: RpcClient): Tendermint37Client {
return new Tendermint37Client(rpcClient); return new Tendermint37Client(rpcClient);
} }