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

fix(PE-5512): accept a validity query param that returns interactio … #100

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/middleware/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const queryMiddleware = async (ctx: KoaContext, next: Next) => {
sortKey,
page = DEFAULT_PAGE,
pageSize = DEFAULT_PAGE_SIZE,
validity,
} = ctx.query;

logger.debug('Query params provided', {
Expand Down Expand Up @@ -82,5 +83,10 @@ export const queryMiddleware = async (ctx: KoaContext, next: Next) => {
ctx.state.pageSize = +pageSize;
}

if (validity) {
logger.debug('Validity provided', { validity });
ctx.state.validity = validity === 'true' || validity === '1';
}

return next();
};
3 changes: 3 additions & 0 deletions src/routes/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
warp,
sortKey: requestedSortKey,
blockHeight: requestedBlockHeight,
validity: requestedValidity,
} = ctx.state;
const { contractTxId } = ctx.params;
logger.debug('Fetching contract state', {
Expand All @@ -42,6 +43,7 @@
});
const {
state,
validity,
evaluationOptions,
sortKey: evaluatedSortKey,
} = await getContractState({
Expand All @@ -57,6 +59,7 @@
state,
sortKey: evaluatedSortKey,
evaluationOptions,
...(requestedValidity && { validity }),
};
}

Expand Down Expand Up @@ -408,8 +411,8 @@

const associatedRecords = Object.entries(records).reduce(
(
filteredRecords: { [x: string]: any },

Check warning on line 414 in src/routes/contract.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Unexpected any. Specify a different type
[record, recordObj]: [string, any],

Check warning on line 415 in src/routes/contract.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Unexpected any. Specify a different type
) => {
if (
!filteredContractTxIdsArray.length ||
Expand Down Expand Up @@ -486,7 +489,7 @@
});

const parsedInput = Object.entries(input).reduce(
(parsedParams: { [x: string]: any }, [key, value]) => {

Check warning on line 492 in src/routes/contract.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Unexpected any. Specify a different type
// parse known integer values for parameters we care about
if (
queryParamsCastedToNumbers.includes(key) &&
Expand Down
25 changes: 24 additions & 1 deletion tests/integration/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
this.timeout(10_000);

ids = [
process.env.DEPLOYED_ANT_CONTRACT_TX_ID!,

Check warning on line 50 in tests/integration/routes.test.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Forbidden non-null assertion
process.env.DEPLOYED_REGISTRY_CONTRACT_TX_ID!,
];
id = process.env.DEPLOYED_REGISTRY_CONTRACT_TX_ID!;
Expand Down Expand Up @@ -139,7 +139,7 @@
expect(data).to.equal('Contract is blocklisted.');
expect(statusText).to.equal('Contract is blocklisted.');
});
it('should return the contract state and id and default evaluation options', async () => {
it('should return the contract state and id and default evaluation options without validity', async () => {
const { status, data } = await axios.get(`/v1/contract/${id}`);
expect(status).to.equal(200);
expect(data).to.not.be.undefined;
Expand All @@ -158,6 +158,29 @@
]);
});

it('should return the contract state and id and default evaluation options when validity is provided', async () => {
const { status, data } = await axios.get(
`/v1/contract/${id}?validity=true`,
);
expect(status).to.equal(200);
expect(data).to.not.be.undefined;
const { contractTxId, state, evaluationOptions, sortKey, validity } =
data;
expect(contractTxId).to.equal(id);
expect(evaluationOptions).not.to.be.undefined;
expect(sortKey).not.be.undefined;
expect(validity).not.to.be.undefined;
expect(state).to.include.keys([
'balances',
'owner',
'name',
'records',
'ticker',
'owner',
'controller',
]);
});

it('should return a 404 for an invalid id', async () => {
const { status } = await axios.get(`/v1/contract/non-matching-regex`);
expect(status).to.equal(404);
Expand Down
Loading