From eaae577c7b6980fe22f790e258378c287336b8a2 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 24 Jun 2020 10:18:18 +0200 Subject: [PATCH] Remove duplicate parts from txsQuery tests --- packages/cosmwasm/src/restclient.spec.ts | 180 ----------------------- 1 file changed, 180 deletions(-) diff --git a/packages/cosmwasm/src/restclient.spec.ts b/packages/cosmwasm/src/restclient.spec.ts index c5973b13db..fe2c97ebd8 100644 --- a/packages/cosmwasm/src/restclient.spec.ts +++ b/packages/cosmwasm/src/restclient.spec.ts @@ -171,187 +171,8 @@ describe("RestClient", () => { }); describe("txsQuery", () => { - let posted: - | { - readonly sender: string; - readonly recipient: string; - readonly hash: string; - readonly height: number; - readonly tx: TxsResponse; - } - | undefined; - - beforeAll(async () => { - if (wasmdEnabled()) { - const pen = await Secp256k1Pen.fromMnemonic(alice.mnemonic); - const client = new SigningCosmWasmClient(wasmd.endpoint, alice.address0, (signBytes) => - pen.sign(signBytes), - ); - - const recipient = makeRandomAddress(); - const transferAmount = [ - { - denom: "ucosm", - amount: "1234567", - }, - ]; - const result = await client.sendTokens(recipient, transferAmount); - - await sleep(75); // wait until tx is indexed - const txDetails = await new RestClient(wasmd.endpoint).txById(result.transactionHash); - posted = { - sender: alice.address0, - recipient: recipient, - hash: result.transactionHash, - height: Number.parseInt(txDetails.height, 10), - tx: txDetails, - }; - } - }); - - it("can query transactions by height", async () => { - pendingWithoutWasmd(); - assert(posted); - const client = new RestClient(wasmd.endpoint); - const result = await client.txsQuery(`tx.height=${posted.height}&limit=26`); - expect(result).toEqual({ - count: jasmine.stringMatching(/^(1|2|3|4|5)$/), // 1-5 transactions as string - limit: "26", - page_number: "1", - page_total: "1", - total_count: jasmine.stringMatching(/^(1|2|3|4|5)$/), // 1-5 transactions as string - txs: jasmine.arrayContaining([posted.tx]), - }); - }); - - it("can query transactions by ID", async () => { - pendingWithoutWasmd(); - assert(posted); - const client = new RestClient(wasmd.endpoint); - const result = await client.txsQuery(`tx.hash=${posted.hash}&limit=26`); - expect(result).toEqual({ - count: "1", - limit: "26", - page_number: "1", - page_total: "1", - total_count: "1", - txs: [posted.tx], - }); - }); - - it("can query transactions by sender", async () => { - pendingWithoutWasmd(); - assert(posted); - const client = new RestClient(wasmd.endpoint); - const result = await client.txsQuery(`message.sender=${posted.sender}&limit=200`); - expect(parseInt(result.count, 10)).toBeGreaterThanOrEqual(1); - expect(parseInt(result.limit, 10)).toEqual(200); - expect(parseInt(result.page_number, 10)).toEqual(1); - expect(parseInt(result.page_total, 10)).toEqual(1); - expect(parseInt(result.total_count, 10)).toBeGreaterThanOrEqual(1); - expect(result.txs.length).toBeGreaterThanOrEqual(1); - expect(result.txs[result.txs.length - 1]).toEqual(posted.tx); - }); - - it("can query transactions by recipient", async () => { - pendingWithoutWasmd(); - assert(posted); - const client = new RestClient(wasmd.endpoint); - const result = await client.txsQuery(`transfer.recipient=${posted.recipient}&limit=200`); - expect(parseInt(result.count, 10)).toEqual(1); - expect(parseInt(result.limit, 10)).toEqual(200); - expect(parseInt(result.page_number, 10)).toEqual(1); - expect(parseInt(result.page_total, 10)).toEqual(1); - expect(parseInt(result.total_count, 10)).toEqual(1); - expect(result.txs.length).toBeGreaterThanOrEqual(1); - expect(result.txs[result.txs.length - 1]).toEqual(posted.tx); - }); - - it("can filter by tx.hash and tx.minheight", async () => { - pending("This combination is broken 🤷‍♂️. Handle client-side at higher level."); - pendingWithoutWasmd(); - assert(posted); - const client = new RestClient(wasmd.endpoint); - const hashQuery = `tx.hash=${posted.hash}`; - - { - const { count } = await client.txsQuery(`${hashQuery}&tx.minheight=0`); - expect(count).toEqual("1"); - } - - { - const { count } = await client.txsQuery(`${hashQuery}&tx.minheight=${posted.height - 1}`); - expect(count).toEqual("1"); - } - - { - const { count } = await client.txsQuery(`${hashQuery}&tx.minheight=${posted.height}`); - expect(count).toEqual("1"); - } - - { - const { count } = await client.txsQuery(`${hashQuery}&tx.minheight=${posted.height + 1}`); - expect(count).toEqual("0"); - } - }); - - it("can filter by recipient and tx.minheight", async () => { - pendingWithoutWasmd(); - assert(posted); - const client = new RestClient(wasmd.endpoint); - const recipientQuery = `transfer.recipient=${posted.recipient}`; - - { - const { count } = await client.txsQuery(`${recipientQuery}&tx.minheight=0`); - expect(count).toEqual("1"); - } - - { - const { count } = await client.txsQuery(`${recipientQuery}&tx.minheight=${posted.height - 1}`); - expect(count).toEqual("1"); - } - - { - const { count } = await client.txsQuery(`${recipientQuery}&tx.minheight=${posted.height}`); - expect(count).toEqual("1"); - } - - { - const { count } = await client.txsQuery(`${recipientQuery}&tx.minheight=${posted.height + 1}`); - expect(count).toEqual("0"); - } - }); - - it("can filter by recipient and tx.maxheight", async () => { - pendingWithoutWasmd(); - assert(posted); - const client = new RestClient(wasmd.endpoint); - const recipientQuery = `transfer.recipient=${posted.recipient}`; - - { - const { count } = await client.txsQuery(`${recipientQuery}&tx.maxheight=9999999999999`); - expect(count).toEqual("1"); - } - - { - const { count } = await client.txsQuery(`${recipientQuery}&tx.maxheight=${posted.height + 1}`); - expect(count).toEqual("1"); - } - - { - const { count } = await client.txsQuery(`${recipientQuery}&tx.maxheight=${posted.height}`); - expect(count).toEqual("1"); - } - - { - const { count } = await client.txsQuery(`${recipientQuery}&tx.maxheight=${posted.height - 1}`); - expect(count).toEqual("0"); - } - }); - it("can query by tags (module + code_id)", async () => { pendingWithoutWasmd(); - assert(posted); const client = new RestClient(wasmd.endpoint); const result = await client.txsQuery(`message.module=wasm&message.code_id=${deployedErc20.codeId}`); expect(parseInt(result.count, 10)).toBeGreaterThanOrEqual(4); @@ -397,7 +218,6 @@ describe("RestClient", () => { // Like previous test but filtered by message.action=store-code and message.action=instantiate it("can query by tags (module + code_id + action)", async () => { pendingWithoutWasmd(); - assert(posted); const client = new RestClient(wasmd.endpoint); {