Skip to content

Commit

Permalink
Add middleware test
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding committed Aug 30, 2023
1 parent bb4049c commit 261f8e2
Showing 1 changed file with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { mnemonicPhraseToBytes } from '@metamask/key-tree';
import { JsonRpcEngine } from 'json-rpc-engine';

import { DEFAULT_SRP } from '../configuration';
import { createMiscMethodMiddleware } from './middleware';

const hooks = { getMnemonic: async () => mnemonicPhraseToBytes(DEFAULT_SRP) };

describe('createMiscMethodMiddleware', () => {
it('supports metamask_getProviderState', async () => {
const engine = new JsonRpcEngine();
engine.push(createMiscMethodMiddleware());
engine.push(createMiscMethodMiddleware(hooks));

const response = await engine.handle({
jsonrpc: '2.0',
Expand All @@ -25,4 +29,40 @@ describe('createMiscMethodMiddleware', () => {
},
});
});

it('supports eth_accounts', async () => {
const engine = new JsonRpcEngine();
engine.push(createMiscMethodMiddleware(hooks));

const response = await engine.handle({
jsonrpc: '2.0',
id: 1,
method: 'eth_accounts',
params: [],
});

expect(response).toStrictEqual({
id: 1,
jsonrpc: '2.0',
result: ['0xc6d5a3c98ec9073b54fa0969957bd582e8d874bf'],
});
});

it('supports eth_requestAccounts', async () => {
const engine = new JsonRpcEngine();
engine.push(createMiscMethodMiddleware(hooks));

const response = await engine.handle({
jsonrpc: '2.0',
id: 1,
method: 'eth_requestAccounts',
params: [],
});

expect(response).toStrictEqual({
id: 1,
jsonrpc: '2.0',
result: ['0xc6d5a3c98ec9073b54fa0969957bd582e8d874bf'],
});
});
});

0 comments on commit 261f8e2

Please sign in to comment.