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

Commit

Permalink
fix(validity): accept a validity query param that returns interactio …
Browse files Browse the repository at this point in the history
…id and if they were valid or not

This is actually a miss when implementing `syncState` functionality. There is a related bug in the warp-sdk that does not default this value when not set - which is how we discovered this was an issue.
  • Loading branch information
dtfiedler committed Jan 26, 2024
1 parent deb1fa1 commit 83b3a75
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ You can `cp .env.sample .env` and modify them locally.

Integration tests are used to validate endpoints and response payloads. Then can be run locally via:

<<<<<<< HEAD

1. # Set `.env` to:
1. Set `.env.` to:
> > > > > > > 648e306 (chore(README): update readme)
1. Set `.env` to:

```shell
GATEWAY_HOST=localhost
Expand Down
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 @@ export async function contractHandler(ctx: KoaContext) {
warp,
sortKey: requestedSortKey,
blockHeight: requestedBlockHeight,
validity: requestedValidity,
} = ctx.state;
const { contractTxId } = ctx.params;
logger.debug('Fetching contract state', {
Expand All @@ -42,6 +43,7 @@ export async function contractHandler(ctx: KoaContext) {
});
const {
state,
validity,
evaluationOptions,
sortKey: evaluatedSortKey,
} = await getContractState({
Expand All @@ -57,6 +59,7 @@ export async function contractHandler(ctx: KoaContext) {
state,
sortKey: evaluatedSortKey,
evaluationOptions,
...(requestedValidity && { validity }),
};
}

Expand Down
23 changes: 22 additions & 1 deletion tests/integration/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('Integration tests', () => {
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,27 @@ describe('Integration tests', () => {
]);
});

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}`);
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

0 comments on commit 83b3a75

Please sign in to comment.