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

Add support for /block_search RPC endpoint in Tendermint 0.34.9+ #815

Merged
merged 9 commits into from
May 27, 2021
Prev Previous commit
Next Next commit
Tests
- Added block search tests
- Incremented v0.34 Tendermint version to 0.34.9
  • Loading branch information
RiccardoM authored and webmaster128 committed May 27, 2021
commit 859b4ec19f45b93b09710d350e80bdf00f412dc0
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,72 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
});
});

describe("blockSearch", () => {
const key = randomString();

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

// eslint-disable-next-line no-inner-declarations
async function sendTx(): Promise<void> {
const me = randomString();
const tx = buildKvTx(key, me);

const txRes = await client.broadcastTxCommit({ tx: tx });
expect(responses.broadcastTxCommitSuccess(txRes)).toEqual(true);
expect(txRes.height).toBeTruthy();
expect(txRes.hash.length).not.toEqual(0);
}

// send 3 txs
await sendTx();
await sendTx();
await sendTx();

client.disconnect();

await tendermintSearchIndexUpdated();
}
});

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

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

// expect one page of results
const s1 = await client.blockSearch({ query: query, page: 1, per_page: 2 });
expect(s1.totalCount).toEqual(5);
expect(s1.blocks.length).toEqual(2);

// second page
const s2 = await client.blockSearch({ query: query, page: 2, per_page: 2 });
expect(s2.totalCount).toEqual(5);
expect(s2.blocks.length).toEqual(2);

client.disconnect();
});

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

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

const sall = await client.blockSearchAll({ query: query, per_page: 2 });
expect(sall.totalCount).toEqual(5);
expect(sall.blocks.length).toEqual(5);
// make sure there are in order from lowest to highest height
const [b1, b2, b3] = sall.blocks;
expect(b2.block.header.height).toEqual(b1.block.header.height + 1);
expect(b3.block.header.height).toEqual(b2.block.header.height + 1);

client.disconnect();
});
});

describe("blockchain", () => {
it("returns latest in descending order by default", async () => {
pendingWithoutTendermint();
Expand Down