@metamask/snaps-simulation
Version:
A simulation framework for MetaMask Snaps, enabling headless testing of Snaps in a controlled environment
1 lines • 1.25 kB
Source Map (JSON)
{"version":3,"file":"mock.mjs","sourceRoot":"","sources":["../../src/middleware/mock.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,2BAAuB;AAEhD;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAY;IAEZ,OAAO,SAAS,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG;QACzD,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QAChE,IAAI,MAAM,EAAE,CAAC;YACX,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;YACzB,OAAO,GAAG,EAAE,CAAC;QACf,CAAC;QAED,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport type { Json, JsonRpcParams } from '@metamask/utils';\n\nimport type { Store } from '../store';\nimport { getJsonRpcMock } from '../store/mocks';\n\n/**\n * Create a middleware for handling JSON-RPC methods that have been mocked.\n *\n * @param store - The Redux store to use.\n * @returns A middleware function.\n */\nexport function createMockMiddleware(\n store: Store,\n): JsonRpcMiddleware<JsonRpcParams, Json> {\n return function mockMiddleware(request, response, next, end) {\n const result = getJsonRpcMock(store.getState(), request.method);\n if (result) {\n response.result = result;\n return end();\n }\n\n return next();\n };\n}\n"]}