Skip to content

Commit 4ae6355

Browse files
committed
fix: unit tests
1 parent 6e9d1cf commit 4ae6355

4 files changed

Lines changed: 43 additions & 39 deletions

File tree

packages/bridge-controller/src/bridge-controller.sse.test.ts

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,18 +1239,20 @@ describe('BridgeController SSE', function () {
12391239
[
12401240
"Quote validation failed",
12411241
[
1242-
"lifi|trade",
1243-
"lifi|trade.chainId",
1244-
"lifi|trade.to",
1245-
"lifi|trade.from",
1246-
"lifi|trade.value",
1247-
"lifi|trade.data",
1248-
"lifi|trade.gasLimit",
1249-
"lifi|trade.unsignedPsbtBase64",
1250-
"lifi|trade.inputsToSign",
1251-
"lifi|trade.raw_data_hex",
1252-
"lifi|trade.xdrBase64",
1253-
"lifi|trade.xdr",
1242+
"At path: trade (union) -- Expected the value to satisfy a union of \`type | type | type | union | string\`, but received: [object Object]",
1243+
"At path: trade.chainId (union) -- Expected a number, but received: undefined",
1244+
"At path: trade.to (union) -- Expected a value of type \`HexString\`, but received: \`undefined\`",
1245+
"At path: trade.from (union) -- Expected a value of type \`HexString\`, but received: \`undefined\`",
1246+
"At path: trade.value (union) -- Expected a value of type \`HexString\`, but received: \`undefined\`",
1247+
"At path: trade.data (union) -- Expected a value of type \`HexString\`, but received: \`undefined\`",
1248+
"At path: trade.gasLimit (union) -- Expected a number, but received: undefined",
1249+
"At path: trade.unsignedPsbtBase64 (union) -- Expected a string, but received: undefined",
1250+
"At path: trade.inputsToSign (union) -- Expected an array value, but received: undefined",
1251+
"At path: trade.raw_data_hex (union) -- Expected a string, but received: undefined",
1252+
"At path: trade (union) -- Expected the value to satisfy a union of \`type | type\`, but received: [object Object]",
1253+
"At path: trade.xdrBase64 (union) -- Expected a string, but received: undefined",
1254+
"At path: trade.xdr (union) -- Expected a string, but received: undefined",
1255+
"At path: trade (union) -- Expected a string, but received: [object Object]",
12541256
],
12551257
]
12561258
`);
@@ -1268,21 +1270,21 @@ describe('BridgeController SSE', function () {
12681270
);
12691271
expect(consoleWarnSpy.mock.calls).toHaveLength(3);
12701272
expect(consoleWarnSpy.mock.calls[1]).toMatchInlineSnapshot(`
1271-
[
1272-
"Quote validation failed",
1273-
[
1274-
"unknown|unknown",
1275-
],
1276-
]
1277-
`);
1273+
[
1274+
"Quote validation failed",
1275+
[
1276+
"At path: <root> (type) -- Expected an object, but received: """,
1277+
],
1278+
]
1279+
`);
12781280
expect(consoleWarnSpy.mock.calls[2]).toMatchInlineSnapshot(`
1279-
[
1280-
"Quote validation failed",
1281-
[
1282-
"unknown|quote",
1283-
],
1284-
]
1285-
`);
1281+
[
1282+
"Quote validation failed",
1283+
[
1284+
"At path: quote (type) -- Expected an object, but received: undefined",
1285+
],
1286+
]
1287+
`);
12861288

12871289
expect(consoleLogSpy).toHaveBeenCalledTimes(1);
12881290
expect(fetchBridgeQuotesSpy).toHaveBeenCalledTimes(5);

packages/bridge-controller/src/utils/fetch.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,17 @@ describe('fetch', () => {
273273
'lifi|approval',
274274
'socket|trade',
275275
]);
276-
expect(mockConsoleWarn).toHaveBeenCalledTimes(1);
276+
expect(mockConsoleWarn.mock.calls).toMatchInlineSnapshot(`
277+
[
278+
[
279+
"Quote validation failed",
280+
[
281+
"lifi|approval",
282+
"socket|trade",
283+
],
284+
],
285+
]
286+
`);
277287
mockConsoleWarn.mockRestore();
278288
});
279289

packages/bridge-controller/src/utils/fetch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
formatChainIdToDec,
2828
} from './caip-formatters';
2929
import { fetchServerEvents } from './fetch-server-events';
30+
import { formatStructErrors } from './struct-error';
3031

3132
export const getClientHeaders = ({
3233
clientId,
@@ -398,6 +399,7 @@ export async function fetchBridgeQuoteStream(
398399
}
399400
} catch (error) {
400401
if (error instanceof StructError) {
402+
console.warn('Quote validation failed', formatStructErrors(error));
401403
error.failures().forEach(({ branch, path }) => {
402404
const aggregatorId =
403405
branch?.[0]?.quote?.bridgeId ??
@@ -411,7 +413,6 @@ export async function fetchBridgeQuoteStream(
411413
}
412414
const validationFailures = Array.from(uniqueValidationFailures);
413415
if (uniqueValidationFailures.size > 0) {
414-
console.warn('Quote validation failed', validationFailures);
415416
return serverEventHandlers.onQuoteValidationFailure(validationFailures);
416417
}
417418
// Rethrow any unexpected errors

packages/bridge-controller/src/validators/quote-response-v1.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,8 @@ export const QuoteResponseSchemaV1 = type({
4848
export const validateQuoteResponseV1 = (
4949
data: unknown,
5050
): data is Infer<typeof QuoteResponseSchemaV1> => {
51-
try {
52-
assert(data, QuoteResponseSchemaV1);
53-
return true;
54-
} catch (error) {
55-
if (error instanceof StructError) {
56-
console.warn('Quote validation failed', formatStructErrors(error));
57-
} else {
58-
console.warn(JSON.stringify(error, null, 2));
59-
}
60-
throw error;
61-
}
51+
assert(data, QuoteResponseSchemaV1);
52+
return true;
6253
};
6354

6455
/**

0 commit comments

Comments
 (0)