-
Notifications
You must be signed in to change notification settings - Fork 570
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
wallet_switchEthereumChain
support to snaps-jest
- Loading branch information
Showing
5 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/snaps-simulation/src/middleware/internal-methods/switch-ethereum-chain.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { Json, PendingJsonRpcResponse } from '@metamask/utils'; | ||
|
||
import { getSwitchEthereumChainHandler } from './switch-ethereum-chain'; | ||
|
||
describe('getSwitchEthereumChainHandler', () => { | ||
it('returns `null`', async () => { | ||
const end = jest.fn(); | ||
const result: PendingJsonRpcResponse<Json> = { | ||
jsonrpc: '2.0' as const, | ||
id: 1, | ||
}; | ||
|
||
await getSwitchEthereumChainHandler( | ||
{ | ||
jsonrpc: '2.0', | ||
id: 1, | ||
method: 'wallet_switchEthereumChain', | ||
params: [], | ||
}, | ||
result, | ||
jest.fn(), | ||
end, | ||
); | ||
|
||
expect(end).toHaveBeenCalled(); | ||
expect(result.result).toBeNull(); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
packages/snaps-simulation/src/middleware/internal-methods/switch-ethereum-chain.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { | ||
JsonRpcEngineEndCallback, | ||
JsonRpcEngineNextCallback, | ||
} from '@metamask/json-rpc-engine'; | ||
import type { | ||
Json, | ||
JsonRpcRequest, | ||
PendingJsonRpcResponse, | ||
} from '@metamask/utils'; | ||
|
||
/** | ||
* A mock handler for the `wallet_switchEthereumChain` method that always | ||
* returns `null`. | ||
* | ||
* @param _request - Incoming JSON-RPC request. This is ignored for this | ||
* specific handler. | ||
* @param response - The outgoing JSON-RPC response, modified to return the | ||
* result. | ||
* @param _next - The `json-rpc-engine` middleware next handler. | ||
* @param end - The `json-rpc-engine` middleware end handler. | ||
* @returns The response. | ||
*/ | ||
export async function getSwitchEthereumChainHandler( | ||
_request: JsonRpcRequest, | ||
response: PendingJsonRpcResponse<Json>, | ||
_next: JsonRpcEngineNextCallback, | ||
end: JsonRpcEngineEndCallback, | ||
// hooks: GetAccountsHandlerHooks, | ||
) { | ||
response.result = null; | ||
return end(); | ||
} |