UNPKG

@metamask/snaps-simulation

Version:

A simulation framework for MetaMask Snaps, enabling headless testing of Snaps in a controlled environment

39 lines 1.45 kB
"use strict"; var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.getJsonRpcMock = exports.getJsonRpcMocks = exports.removeJsonRpcMock = exports.addJsonRpcMock = exports.mocksSlice = void 0; const toolkit_1 = require("@reduxjs/toolkit"); /** * The initial notifications state. */ const INITIAL_STATE = { jsonRpc: {}, }; exports.mocksSlice = (0, toolkit_1.createSlice)({ name: 'mocks', initialState: INITIAL_STATE, reducers: { addJsonRpcMock: (state, action) => { // @ts-expect-error - TS2589: Type instantiation is excessively deep and // possibly infinite. state.jsonRpc[action.payload.method] = action.payload.result; }, removeJsonRpcMock: (state, action) => { delete state.jsonRpc[action.payload]; }, }, }); _a = exports.mocksSlice.actions, exports.addJsonRpcMock = _a.addJsonRpcMock, exports.removeJsonRpcMock = _a.removeJsonRpcMock; /** * Get the JSON-RPC mocks from the state. * * @param state - The application state. * @returns The JSON-RPC mocks. */ const getJsonRpcMocks = (state) => state.mocks.jsonRpc; exports.getJsonRpcMocks = getJsonRpcMocks; /** * Get the JSON-RPC mock for a given method from the state. */ exports.getJsonRpcMock = (0, toolkit_1.createSelector)(exports.getJsonRpcMocks, (_, method) => method, (jsonRpcMocks, method) => jsonRpcMocks[method]); //# sourceMappingURL=mocks.cjs.map