Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- **BREAKING:** `createFetchMiddleware` no longer takes `fetch`, `btoa`, `rpcUrl`, and `originHttpHeaderKey` ([#402](https://github.com/MetaMask/eth-json-rpc-middleware/pull/402))
- The existing signature (`rpcService` and `options`) is now the only way to use this function; please use that instead.

### Removed

- **BREAKING:** Remove `PayloadWithOrigin` type ([#402](https://github.com/MetaMask/eth-json-rpc-middleware/pull/402))
- There is no equivalent.
- **BREAKING:** Remove `createFetchConfigFromReq` function ([#402](https://github.com/MetaMask/eth-json-rpc-middleware/pull/402))
- There is no equivalent.

## [17.1.0]

### Added
Expand Down
67 changes: 0 additions & 67 deletions src/fetch.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
import { JsonRpcEngine } from '@metamask/json-rpc-engine';
import type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils';

import { createFetchConfigFromReq } from '.';
import { createFetchMiddleware } from './fetch';
import type { AbstractRpcService } from './types';

/**
* Generate a base64-encoded string from a binary string. This should be equivalent to
* `window.btoa`.
*
* @param stringToEncode - The string to encode.
* @returns The base64-encoded string.
*/
// eslint-disable-next-line @typescript-eslint/no-shadow
function btoa(stringToEncode: string) {
return Buffer.from(stringToEncode).toString('base64');
}

describe('createFetchMiddleware', () => {
it('calls the RPC service with the correct request headers and body when no `originHttpHeaderKey` option given', async () => {
const rpcService = buildRpcService();
Expand Down Expand Up @@ -244,60 +231,6 @@ describe('createFetchMiddleware', () => {
});
});

describe('createFetchConfigFromReq', () => {
it('should create a fetch config from a request', async () => {
const req = {
id: 1,
jsonrpc: '2.0' as const,
method: 'eth_getBlockByNumber',
params: ['0x482103', true],
};
const rpcUrl = 'http://www.xyz.io/rabbit:3456?id=100';
const { fetchUrl, fetchParams } = createFetchConfigFromReq({
btoa,
req,
rpcUrl,
});
expect(fetchUrl).toStrictEqual(rpcUrl);
expect(fetchParams).toStrictEqual({
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(req),
});
});

it('should create a fetch config with origin header', async () => {
const request = {
id: 1,
jsonrpc: '2.0' as const,
method: 'eth_getBlockByNumber',
params: ['0x482103', true],
};
const requestWithOrigin = { ...request, origin: 'happydapp.gov' };
const rpcUrl = 'http://www.xyz.io/rabbit:3456?id=100';
const originHttpHeaderKey = 'x-dapp-origin';
const { fetchUrl, fetchParams } = createFetchConfigFromReq({
btoa,
req: requestWithOrigin,
rpcUrl,
originHttpHeaderKey,
});
expect(fetchUrl).toStrictEqual(rpcUrl);
expect(fetchParams).toStrictEqual({
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'x-dapp-origin': 'happydapp.gov',
},
body: JSON.stringify(request),
});
});
});

/**
* Constructs a fake RPC service for use as a failover in tests.
*
Expand Down
Loading
Loading