Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
chore(tests): add integration tests for blockHeight and sortKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler committed Nov 28, 2023
1 parent 08c691c commit 2aa5ffb
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions tests/integration/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 2aa5ffb

Please sign in to comment.