diff --git a/tests/integration/routes.test.ts b/tests/integration/routes.test.ts index cf4c4a6..4741a1f 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(400); + 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(0, '12'), + ); + }); }); 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(Object.keys(interactions)).to.equal([]); + }); }); describe('/:contractTxId/interactions/:address', () => {