From 4d10b3c3ab6dfec2b0d9594e26831bf9e991e167 Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Fri, 26 Jan 2024 11:40:22 -0700 Subject: [PATCH] fix(validity): accept a validity query param that returns interactio 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. --- src/middleware/query.ts | 6 ++++++ src/routes/contract.ts | 3 +++ tests/integration/routes.test.ts | 25 ++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/middleware/query.ts b/src/middleware/query.ts index c45d960..7de6527 100644 --- a/src/middleware/query.ts +++ b/src/middleware/query.ts @@ -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', { @@ -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(); }; diff --git a/src/routes/contract.ts b/src/routes/contract.ts index 988de58..d593ce9 100644 --- a/src/routes/contract.ts +++ b/src/routes/contract.ts @@ -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', { @@ -42,6 +43,7 @@ export async function contractHandler(ctx: KoaContext) { }); const { state, + validity, evaluationOptions, sortKey: evaluatedSortKey, } = await getContractState({ @@ -57,6 +59,7 @@ export async function contractHandler(ctx: KoaContext) { state, sortKey: evaluatedSortKey, evaluationOptions, + ...(requestedValidity && { validity }), }; } diff --git a/tests/integration/routes.test.ts b/tests/integration/routes.test.ts index a4ff045..4f3c06f 100644 --- a/tests/integration/routes.test.ts +++ b/tests/integration/routes.test.ts @@ -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; @@ -158,6 +158,29 @@ 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}?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);