|
1 | 1 | import { JsonRpcEngine } from '@metamask/json-rpc-engine';
|
2 | 2 | import type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils';
|
3 | 3 |
|
4 |
| -import { createFetchConfigFromReq } from '.'; |
5 | 4 | import { createFetchMiddleware } from './fetch';
|
6 | 5 | import type { AbstractRpcService } from './types';
|
7 | 6 |
|
8 |
| -/** |
9 |
| - * Generate a base64-encoded string from a binary string. This should be equivalent to |
10 |
| - * `window.btoa`. |
11 |
| - * |
12 |
| - * @param stringToEncode - The string to encode. |
13 |
| - * @returns The base64-encoded string. |
14 |
| - */ |
15 |
| -// eslint-disable-next-line @typescript-eslint/no-shadow |
16 |
| -function btoa(stringToEncode: string) { |
17 |
| - return Buffer.from(stringToEncode).toString('base64'); |
18 |
| -} |
19 |
| - |
20 | 7 | describe('createFetchMiddleware', () => {
|
21 | 8 | it('calls the RPC service with the correct request headers and body when no `originHttpHeaderKey` option given', async () => {
|
22 | 9 | const rpcService = buildRpcService();
|
@@ -244,60 +231,6 @@ describe('createFetchMiddleware', () => {
|
244 | 231 | });
|
245 | 232 | });
|
246 | 233 |
|
247 |
| -describe('createFetchConfigFromReq', () => { |
248 |
| - it('should create a fetch config from a request', async () => { |
249 |
| - const req = { |
250 |
| - id: 1, |
251 |
| - jsonrpc: '2.0' as const, |
252 |
| - method: 'eth_getBlockByNumber', |
253 |
| - params: ['0x482103', true], |
254 |
| - }; |
255 |
| - const rpcUrl = 'http://www.xyz.io/rabbit:3456?id=100'; |
256 |
| - const { fetchUrl, fetchParams } = createFetchConfigFromReq({ |
257 |
| - btoa, |
258 |
| - req, |
259 |
| - rpcUrl, |
260 |
| - }); |
261 |
| - expect(fetchUrl).toStrictEqual(rpcUrl); |
262 |
| - expect(fetchParams).toStrictEqual({ |
263 |
| - method: 'POST', |
264 |
| - headers: { |
265 |
| - Accept: 'application/json', |
266 |
| - 'Content-Type': 'application/json', |
267 |
| - }, |
268 |
| - body: JSON.stringify(req), |
269 |
| - }); |
270 |
| - }); |
271 |
| - |
272 |
| - it('should create a fetch config with origin header', async () => { |
273 |
| - const request = { |
274 |
| - id: 1, |
275 |
| - jsonrpc: '2.0' as const, |
276 |
| - method: 'eth_getBlockByNumber', |
277 |
| - params: ['0x482103', true], |
278 |
| - }; |
279 |
| - const requestWithOrigin = { ...request, origin: 'happydapp.gov' }; |
280 |
| - const rpcUrl = 'http://www.xyz.io/rabbit:3456?id=100'; |
281 |
| - const originHttpHeaderKey = 'x-dapp-origin'; |
282 |
| - const { fetchUrl, fetchParams } = createFetchConfigFromReq({ |
283 |
| - btoa, |
284 |
| - req: requestWithOrigin, |
285 |
| - rpcUrl, |
286 |
| - originHttpHeaderKey, |
287 |
| - }); |
288 |
| - expect(fetchUrl).toStrictEqual(rpcUrl); |
289 |
| - expect(fetchParams).toStrictEqual({ |
290 |
| - method: 'POST', |
291 |
| - headers: { |
292 |
| - Accept: 'application/json', |
293 |
| - 'Content-Type': 'application/json', |
294 |
| - 'x-dapp-origin': 'happydapp.gov', |
295 |
| - }, |
296 |
| - body: JSON.stringify(request), |
297 |
| - }); |
298 |
| - }); |
299 |
| -}); |
300 |
| - |
301 | 234 | /**
|
302 | 235 | * Constructs a fake RPC service for use as a failover in tests.
|
303 | 236 | *
|
|
0 commit comments