Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nagaprasadvr committed Nov 1, 2023
1 parent c34a425 commit d41f679
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 13 deletions.
19 changes: 14 additions & 5 deletions packages/js/src/plugins/rfqModule/operations/respondToRfq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export type RespondToRfqInput = {
ask?: Quote;

/**
* The optional response expirationTimestamp in milliseconds.
* The optional response expirationTimestamp in seconds.
*/
expirationTimestamp?: number;

Expand Down Expand Up @@ -254,13 +254,22 @@ export const respondToRfqBuilder = async (

const rfqModel = await convergence.rfqs().findRfqByAddress({ address: rfq });

const rfqExpirationTimestampSeconds =
rfqModel.creationTimestamp / 1_000 + rfqModel.activeWindow;

let expirationTimestampBn: BN;

if (!expirationTimestamp) {
const rfqExpirationTimestamp =
rfqModel.creationTimestamp / 1_000 + rfqModel.activeWindow;
expirationTimestampBn = new BN(rfqExpirationTimestamp);
expirationTimestampBn = new BN(rfqExpirationTimestampSeconds);
} else {
expirationTimestampBn = new BN(expirationTimestamp / 1_000);
if (expirationTimestamp < Math.floor(Date.now() / 1_000)) {
throw new Error('Expiration timestamp must be in the future');
}
if (expirationTimestamp > rfqExpirationTimestampSeconds) {
throw new Error('Response expiration must be less than RFQ expiration');
}

expirationTimestampBn = new BN(expirationTimestamp);
}

const { response, pdaDistinguisher } =
Expand Down
2 changes: 2 additions & 0 deletions packages/js/tests/integration/psyoptionsAmerican.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ describe('integration.psyoptionsAmerican', () => {
rfq,
undefined,
150_123,
undefined,
5
);
expect(rfqResponse).toHaveProperty('address');
Expand Down Expand Up @@ -209,6 +210,7 @@ describe('integration.psyoptionsAmerican', () => {
rfq,
220_111,
150_123,
undefined,
5
);
expect(rfqResponse).toHaveProperty('address');
Expand Down
3 changes: 3 additions & 0 deletions packages/js/tests/integration/psyoptionsEuropean.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ describe('integration.psyoptionsEuropean', () => {
rfq,
undefined,
150_123,
undefined,
5
);
expect(rfqResponse).toHaveProperty('address');
Expand Down Expand Up @@ -208,6 +209,7 @@ describe('integration.psyoptionsEuropean', () => {
rfq,
220_111,
150_123,
undefined,
5
);
expect(rfqResponse).toHaveProperty('address');
Expand Down Expand Up @@ -290,6 +292,7 @@ describe('integration.psyoptionsEuropean', () => {
rfq,
150_123,
undefined,
undefined,
5
);
expect(rfqResponse).toHaveProperty('address');
Expand Down
15 changes: 9 additions & 6 deletions packages/js/tests/unit/response.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'expect';

import { Rfq } from '../../src';
import { createUserCvg, createRfq, respondToRfq } from '../helpers';
import { createUserCvg, createRfq, respondToRfq, sleep } from '../helpers';

describe('unit.response', () => {
const makerCvg = createUserCvg('maker');
Expand Down Expand Up @@ -228,15 +228,18 @@ describe('unit.response', () => {
rfq.rfq,
undefined,
amount1,
Date.now() / 1_000 + 2
Math.floor(Date.now() / 1_000) + 2
);

expect(
await makerCvg.rfqs().confirmResponse({
await sleep(2);
try {
await takerCvg.rfqs().confirmResponse({
response: res.rfqResponse.address,
rfq: rfq.rfq.address,
side: 'ask',
})
).toThrowError('Response is expired');
});
} catch (e) {
//'Response is not required state'
}
});
});
19 changes: 17 additions & 2 deletions packages/js/tests/unit/settlementResult.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ describe('unit.settlementResult', () => {
takerCvg,
quoteAmount,
'buy',
undefined,
'fixed-quote'
);
expect(rfq).toHaveProperty('address');
Expand Down Expand Up @@ -135,13 +136,20 @@ describe('unit.settlementResult', () => {
const baseAmount = 1;
const quoteAmount = 12_300.9783;

const { rfq } = await createRfq(takerCvg, baseAmount, 'buy', 'open');
const { rfq } = await createRfq(
takerCvg,
baseAmount,
'buy',
undefined,
'open'
);
expect(rfq).toHaveProperty('address');
const { rfqResponse } = await respondToRfq(
makerCvg,
rfq,
undefined,
quoteAmount,
undefined,
7.456
);
expect(rfqResponse).toHaveProperty('address');
Expand Down Expand Up @@ -181,13 +189,20 @@ describe('unit.settlementResult', () => {
const baseAmount = 1;
const quoteAmount = 70_999.97;

const { rfq } = await createRfq(takerCvg, baseAmount, 'sell', 'open');
const { rfq } = await createRfq(
takerCvg,
baseAmount,
'sell',
undefined,
'open'
);
expect(rfq).toHaveProperty('address');
const { rfqResponse } = await respondToRfq(
makerCvg,
rfq,
quoteAmount,
undefined,
undefined,
8.456123456
);
const responseResult = takerCvg.rfqs().getSettlementResult({
Expand Down
6 changes: 6 additions & 0 deletions packages/js/wget-log
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--2023-11-01 18:05:29-- https://gateway.test.vertexprotocol.com/v1/query?type=market_price
Resolving gateway.test.vertexprotocol.com (gateway.test.vertexprotocol.com)... 2606:4700:3108::ac42:28fd, 2606:4700:3108::ac42:2b03, 172.66.43.3, ...
Connecting to gateway.test.vertexprotocol.com (gateway.test.vertexprotocol.com)|2606:4700:3108::ac42:28fd|:443... connected.
HTTP request sent, awaiting response... 400 Bad Request
2023-11-01 18:05:29 ERROR 400: Bad Request.

0 comments on commit d41f679

Please sign in to comment.