From 07f10f4c7ebeeeb0f04e5d42df2b34ca1cbae4b0 Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Tue, 28 Nov 2023 09:30:58 -0800 Subject: [PATCH] chore(tests): add integration tests for blockHeight and sortKeys --- src/api/graphql.ts | 4 +-- tests/integration/routes.test.ts | 48 ++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/api/graphql.ts b/src/api/graphql.ts index 1d6c9fb..7d736ef 100644 --- a/src/api/graphql.ts +++ b/src/api/graphql.ts @@ -102,9 +102,9 @@ export async function getDeployedContractsByWallet( export async function getWalletInteractionsForContract( arweave: Arweave, params: { - address?: string; + address: string | undefined; contractTxId: string; - blockHeight: number; + blockHeight: number | undefined; }, ): Promise<{ interactions: Map< diff --git a/tests/integration/routes.test.ts b/tests/integration/routes.test.ts index cf4c4a6..6d47f2e 100644 --- a/tests/integration/routes.test.ts +++ b/tests/integration/routes.test.ts @@ -121,13 +121,14 @@ describe('Integration tests', () => { describe('/v1', () => { describe('/contract', () => { describe('/:contractTxId', () => { - it('should return the contract state and id without any evaluation options provided', async () => { + it('should return the contract state and id and default evaluation options', async () => { const { status, data } = await axios.get(`/v1/contract/${id}`); expect(status).to.equal(200); expect(data).to.not.be.undefined; - const { contractTxId, state, evaluationOptions } = data; + const { contractTxId, state, evaluationOptions, sortKey } = data; expect(contractTxId).to.equal(id); expect(evaluationOptions).not.to.be.undefined; + expect(sortKey).not.be.undefined; expect(state).to.include.keys([ 'balances', 'owner', @@ -150,6 +151,35 @@ describe('Integration tests', () => { ); expect(status).to.equal(404); }); + + it('should return a 400 on invalid block height query param', async () => { + // block height before the interactions were created + const invalidBlockHeight = 'not-a-number'; + + const { status } = await axios.get( + `/v1/contract/${id}/interactions?blockHeight=${invalidBlockHeight}`, + ); + expect(status).to.equal(400); + }); + + it('should return contract state evaluated up to a given block height query param', async () => { + // block height before the interactions were created + const blockHeight = 1; + + const { status, data } = await axios.get( + `/v1/contract/${id}/interactions?blockHeight=${blockHeight}`, + ); + const { contractTxId, state, evaluationOptions, sortKey } = data; + expect(status).to.equal(200); + expect(data).not.to.be.undefined; + expect(contractTxId).to.equal(id); + expect(evaluationOptions).not.to.be.undefined; + expect(state).not.to.be.undefined; + expect(sortKey).not.be.undefined; + expect(sortKey.split(',')[0]).to.equal( + `${blockHeight}`.padStart(12, '0'), + ); + }); }); describe('/:contractTxId/price', () => { it('should properly handle price interaction inputs', async () => { @@ -205,6 +235,20 @@ describe('Integration tests', () => { expect(contractTxId).to.equal(id); expect(Object.keys(interactions)).not.to.contain(badInteractionTx.id); }); + + it('should only return interactions up to a provided block height', async () => { + // block height before the interactions were created + const previousInteractionHeight = 1; + + const { status, data } = await axios.get( + `/v1/contract/${id}/interactions?blockHeight=${previousInteractionHeight}`, + ); + expect(status).to.equal(200); + expect(data).to.not.be.undefined; + const { contractTxId, interactions } = data; + expect(contractTxId).to.equal(id); + expect(interactions).to.equal([]); + }); }); describe('/:contractTxId/interactions/:address', () => {