Skip to content

Commit

Permalink
100% test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
adonesky1 committed Nov 26, 2024
1 parent 3f4c297 commit 5a621b3
Showing 1 changed file with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,72 @@ describe('multichainMethodCallValidatorMiddleware', () => {
},
);

process.nextTick(() => {
try {
expect(mockNext).not.toHaveBeenCalled();
resolve();
} catch (error) {
reject(error);
}
});
});
});
it('should throw an error for an invalidly formatted "wallet_invokeMethod" request', async () => {
const request: JsonRpcRequest<Caip27Params> = {
id: 1,
jsonrpc: '2.0',
method: 'wallet_invokeMethod',
// @ts-expect-error test
params: {
scope: 'test',
request: {
method: {}, // expected to be a string
params: {
test: 'test',
},
},
},
};
const response = {} as JsonRpcResponse<typeof request>;

await new Promise<void>((resolve, reject) => {
multichainMethodCallValidatorMiddleware(
request,
response,
mockNext,
(error) => {
try {
expect(error).toBeDefined();
expect((error as JsonRpcError).message).toBe(
'Invalid method parameter(s).',
);
expect((error as JsonRpcError).code).toBe(-32602);
expect((error as JsonRpcError).data).toStrictEqual([
{
code: -32602,
data: {
got: {
method: {},
params: {
test: 'test',
},
},
param: 'request',
path: ['method'],
schema: {
type: 'string',
},
},
message: 'request.method is not of a type(s) string',
},
]);
resolve();
} catch (e) {
reject(e);
}
},
);

process.nextTick(() => {
try {
expect(mockNext).not.toHaveBeenCalled();
Expand Down

0 comments on commit 5a621b3

Please sign in to comment.