Skip to content

Commit

Permalink
Replace usage of @metamask/utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Gudahtt committed Mar 30, 2023
1 parent 643cf7a commit a58f2df
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion app/core/RPCMethods/RPCMethodMiddleware.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {
JsonRpcEngine,
JsonRpcFailure,
JsonRpcMiddleware,
JsonRpcRequest,
JsonRpcResponse,
JsonRpcSuccess,
} from 'json-rpc-engine';
import { assertIsJsonRpcSuccess, JsonRpcFailure } from '@metamask/utils';
import type { Transaction } from '@metamask/transaction-controller';
import { ethErrors } from 'eth-json-rpc-errors';
import Engine from '../Engine';
Expand Down Expand Up @@ -52,6 +53,24 @@ const mockGetPermittedAccounts = getPermittedAccounts as jest.Mock;
*/
const jsonrpc = '2.0' as const;

/**
* Assert that the given response was successful.
*
* TODO: Replace this with `assertIsJsonRpcSuccess` from `@metamask/utils`
*
* @param value - The value to check.
* @throws If the given value is not a valid {@link JsonRpcSuccess} object.
*/
function assertIsJsonRpcSuccess(
response: JsonRpcResponse<unknown>,
): asserts response is JsonRpcSuccess<unknown> {
if ('error' in response) {
throw new Error(`Response failed with error '${JSON.stringify('error')}'`);
} else if (!('result' in response)) {
throw new Error(`Response is missing 'result' property`);
}
}

/**
* Return a minimal set of options for `getRpcMethodMiddleware`. These options
* are complete enough to test at least some method handlers, and they are type-
Expand Down

0 comments on commit a58f2df

Please sign in to comment.